Skip to content

Commit 06f5d56

Browse files
Layczmvince292007
andauthored
feat: add the ability to lock the screen (#30)
* feat: 锁屏功能 * feat: 锁屏样式调整 * feat: complete the lock-screen screen and support shortcut keys and preference configuration --------- Co-authored-by: vince <vince292007@gmail.com>
1 parent 61dbb05 commit 06f5d56

File tree

27 files changed

+482
-48
lines changed

27 files changed

+482
-48
lines changed

apps/web-antd/src/layouts/basic.vue

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script lang="ts" setup>
2-
import { computed, ref, toRefs } from 'vue';
2+
import { computed, ref } from 'vue';
33
import { useRouter } from 'vue-router';
44
55
import { LOGIN_PATH } from '@vben/constants';
66
import { IcRoundCreditScore, MdiDriveDocument, MdiGithub } from '@vben/icons';
77
import {
88
BasicLayout,
9+
LockScreen,
910
Notification,
1011
NotificationItem,
1112
UserDropdown,
@@ -16,7 +17,7 @@ import { preferences } from '@vben-core/preferences';
1617
1718
import { $t } from '#/locales';
1819
import { resetRoutes } from '#/router';
19-
import { useAccessStore, useAppStore } from '#/store';
20+
import { storeToRefs, useAccessStore, useAppStore } from '#/store';
2021
2122
const notifications = ref<NotificationItem[]>([
2223
{
@@ -85,11 +86,18 @@ const menus = computed(() => [
8586
8687
const appStore = useAppStore();
8788
const accessStore = useAccessStore();
89+
90+
const { isLockScreen, lockScreenPassword } = storeToRefs(appStore);
8891
const {
8992
loading: loginLoading,
9093
openLoginExpiredModal,
9194
userInfo,
92-
} = toRefs(accessStore);
95+
} = storeToRefs(accessStore);
96+
97+
const avatar = computed(() => {
98+
return userInfo.value?.avatar ?? preferences.app.defaultAvatar;
99+
});
100+
93101
const router = useRouter();
94102
95103
async function handleLogout() {
@@ -105,17 +113,22 @@ function handleNoticeClear() {
105113
function handleMakeAll() {
106114
notifications.value.forEach((item) => (item.isRead = true));
107115
}
116+
117+
function handleLockScreen(password: string) {
118+
appStore.lockScreen(password);
119+
}
108120
</script>
109121

110122
<template>
111123
<BasicLayout @clear-preferences-and-logout="handleLogout">
112124
<template #user-dropdown>
113125
<UserDropdown
114-
:avatar="userInfo?.avatar ?? preferences.app.defaultAvatar"
115-
:menus="menus"
126+
:avatar
127+
:menus
116128
:text="userInfo?.realName"
117129
description="ann.vben@gmail.com"
118130
tag-text="Pro"
131+
@lock-screen="handleLockScreen"
119132
@logout="handleLogout"
120133
/>
121134
</template>
@@ -127,7 +140,7 @@ function handleMakeAll() {
127140
@make-all="handleMakeAll"
128141
/>
129142
</template>
130-
<template #dialog>
143+
<template #extra>
131144
<AuthenticationLoginExpiredModal
132145
v-model:open="openLoginExpiredModal"
133146
:loading="loginLoading"
@@ -136,5 +149,14 @@ function handleMakeAll() {
136149
@submit="accessStore.authLogin"
137150
/>
138151
</template>
152+
<template #lock-screen>
153+
<LockScreen
154+
v-if="isLockScreen"
155+
:avatar
156+
:cached-password="lockScreenPassword"
157+
@to-login="handleLogout"
158+
@unlock="appStore.unlockScreen"
159+
/>
160+
</template>
139161
</BasicLayout>
140162
</template>

apps/web-antd/src/router/routes/_essentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const essentialsRoutes: RouteRecordRaw[] = [
5151
component: () =>
5252
import('#/views/_essential/authentication/code-login.vue'),
5353
meta: {
54-
title: $t('page.essentials.code-login'),
54+
title: $t('page.essentials.codeLogin'),
5555
},
5656
},
5757
{

apps/web-antd/src/store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { InitStoreOptions } from '@vben-core/stores';
22

33
import type { App } from 'vue';
44

5-
import { initStore } from '@vben-core/stores';
5+
import { initStore, storeToRefs } from '@vben-core/stores';
66

77
/**
88
* @zh_CN 初始化pinia
@@ -13,7 +13,7 @@ async function setupStore(app: App, options: InitStoreOptions) {
1313
app.use(pinia);
1414
}
1515

16-
export { setupStore };
16+
export { setupStore, storeToRefs };
1717

1818
export { useAccessStore } from './modules/access';
1919
export { useAppStore } from './modules/app';

apps/web-antd/src/store/modules/app.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,35 @@ import { defineStore } from 'pinia';
44

55
import { useAccessStore } from './access';
66

7-
export const useAppStore = defineStore('app', () => {
8-
const accessStore = useAccessStore();
9-
const coreTabbarStore = useCoreTabbarStore();
7+
interface AppState {
8+
isLockScreen: boolean;
9+
lockScreenPassword?: string;
10+
}
1011

11-
/**
12-
* 重置所有状态
13-
*/
14-
async function resetAppState() {
15-
accessStore.reset();
16-
coreTabbarStore.$reset();
17-
}
12+
export const useAppStore = defineStore('app', {
13+
actions: {
14+
lockScreen(password: string) {
15+
this.isLockScreen = true;
16+
this.lockScreenPassword = password;
17+
},
1818

19-
return {
20-
resetAppState,
21-
};
19+
resetAppState() {
20+
const accessStore = useAccessStore();
21+
const coreTabbarStore = useCoreTabbarStore();
22+
accessStore.reset();
23+
coreTabbarStore.$reset();
24+
},
25+
26+
unlockScreen() {
27+
this.isLockScreen = false;
28+
this.lockScreenPassword = undefined;
29+
},
30+
},
31+
persist: {
32+
paths: ['isLockScreen', 'lockScreenPassword'],
33+
},
34+
state: (): AppState => ({
35+
isLockScreen: false,
36+
lockScreenPassword: undefined,
37+
}),
2238
});

packages/@core/forward/preferences/src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Preferences } from './types';
33
const defaultPreferences: Preferences = {
44
app: {
55
accessMode: 'frontend',
6-
aiAssistant: true,
76
authPageLayout: 'panel-right',
87
colorGrayMode: false,
98
colorWeakMode: false,
@@ -55,6 +54,7 @@ const defaultPreferences: Preferences = {
5554
},
5655
shortcutKeys: {
5756
enable: true,
57+
globalLockScreen: true,
5858
globalLogout: true,
5959
globalPreferences: true,
6060
globalSearch: true,
@@ -95,6 +95,7 @@ const defaultPreferences: Preferences = {
9595
fullscreen: true,
9696
globalSearch: true,
9797
languageToggle: true,
98+
lockScreen: true,
9899
notification: true,
99100
sidebarToggle: true,
100101
themeToggle: true,

packages/@core/forward/preferences/src/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ type AuthPageLayoutType = 'panel-center' | 'panel-left' | 'panel-right';
2626
interface AppPreferences {
2727
/** 权限模式 */
2828
accessMode: AccessModeType;
29-
/** 是否开启vben助手 */
30-
aiAssistant: boolean;
3129
/** 登录注册页面布局 */
3230
authPageLayout: AuthPageLayoutType;
3331
/** 是否开启灰色模式 */
@@ -136,6 +134,8 @@ interface SidebarPreferences {
136134
interface ShortcutKeyPreferences {
137135
/** 是否启用快捷键-全局 */
138136
enable: boolean;
137+
/** 是否启用全局锁屏快捷键 */
138+
globalLockScreen: boolean;
139139
/** 是否启用全局注销快捷键 */
140140
globalLogout: boolean;
141141
/** 是否启用全局偏好设置快捷键 */
@@ -194,6 +194,8 @@ interface WidgetPreferences {
194194
globalSearch: boolean;
195195
/** 是否启用语言切换部件 */
196196
languageToggle: boolean;
197+
/** 是否开启锁屏功能 */
198+
lockScreen: boolean;
197199
/** 是否显示通知部件 */
198200
notification: boolean;
199201
/** 是否显示侧边栏显示/隐藏部件 */

packages/@core/forward/preferences/src/use-preferences.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ function usePreferences() {
125125
return enable && globalLogout;
126126
});
127127

128+
const globalLockScreenShortcutKey = computed(() => {
129+
const { enable, globalLockScreen } = shortcutKeysPreferences.value;
130+
return enable && globalLockScreen;
131+
});
132+
128133
/**
129134
* @zh_CN 是否启用全局偏好设置快捷键
130135
*/
@@ -138,6 +143,7 @@ function usePreferences() {
138143
authPanelLeft,
139144
authPanelRight,
140145
diffPreference,
146+
globalLockScreenShortcutKey,
141147
globalLogoutShortcutKey,
142148
globalPreferencesShortcutKey,
143149
globalSearchShortcutKey,

packages/@core/locales/src/langs/en-US.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@
6868
"noResults": "No Search Results Found",
6969
"noRecent": "No Search History",
7070
"recent": "Search History"
71+
},
72+
"lockScreen": {
73+
"title": "Lock Screen",
74+
"screenButton": "Locking",
75+
"password": "Password",
76+
"placeholder": "Please enter password",
77+
"unlock": "Click to unlock",
78+
"errorPasswordTip": "Password error, please re-enter",
79+
"backToLogin": "Back to login",
80+
"entry": "Enter the system"
7181
}
7282
},
7383
"authentication": {
@@ -263,7 +273,8 @@
263273
"languageToggle": "Enable Language Toggle",
264274
"notification": "Enable Notification",
265275
"sidebarToggle": "Enable Sidebar Toggle",
266-
"aiAssistant": "Enable AI Assistant"
276+
"aiAssistant": "Enable AI Assistant",
277+
"lockScreen": "Enable Lock Screen"
267278
}
268279
}
269280
}

packages/@core/locales/src/langs/zh-CN.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@
6868
"noResults": "未找到搜索结果",
6969
"noRecent": "没有搜索历史",
7070
"recent": "搜索历史"
71+
},
72+
"lockScreen": {
73+
"title": "锁定屏幕",
74+
"screenButton": "锁定",
75+
"password": "密码",
76+
"placeholder": "请输入锁屏密码",
77+
"unlock": "点击解锁",
78+
"errorPasswordTip": "密码错误,请重新输入",
79+
"backToLogin": "返回登录",
80+
"entry": "进入系统"
7181
}
7282
},
7383
"authentication": {
@@ -263,7 +273,8 @@
263273
"languageToggle": "启用语言切换",
264274
"notification": "启用通知",
265275
"sidebarToggle": "启用侧边栏切换",
266-
"aiAssistant": "启用 AI 助手"
276+
"aiAssistant": "启用 AI 助手",
277+
"lockScreen": "启用锁屏"
267278
}
268279
}
269280
}

packages/@core/shared/design/src/scss-bem/bem.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@forward './constants.scss';
1+
@forward './constants';
22

33
@mixin b($block) {
44
$B: $namespace + '-' + $block !global;

0 commit comments

Comments
 (0)