add lock application menu

This commit is contained in:
MaysWind
2023-07-09 13:13:35 +08:00
parent f90430e544
commit b555af0df7
5 changed files with 36 additions and 7 deletions
+6
View File
@@ -164,6 +164,11 @@ function clearUserInfo() {
localStorage.removeItem(userInfoLocalStorageKey); localStorage.removeItem(userInfoLocalStorageKey);
} }
function clearSessionToken() {
sessionStorage.removeItem(tokenSessionStorageKey);
sessionStorage.removeItem(appLockStateSessionStorageKey);
}
function clearTokenAndUserInfo(clearAppLockState) { function clearTokenAndUserInfo(clearAppLockState) {
if (clearAppLockState) { if (clearAppLockState) {
sessionStorage.removeItem(appLockStateSessionStorageKey); sessionStorage.removeItem(appLockStateSessionStorageKey);
@@ -191,5 +196,6 @@ export default {
updateToken, updateToken,
updateUserInfo, updateUserInfo,
clearUserInfo, clearUserInfo,
clearSessionToken,
clearTokenAndUserInfo clearTokenAndUserInfo
}; };
+1
View File
@@ -1124,6 +1124,7 @@ export default {
'Unable to get current two factor authentication status': 'Unable to get current two factor authentication status', 'Unable to get current two factor authentication status': 'Unable to get current two factor authentication status',
'Unable to enable two factor authentication': 'Unable to enable two factor authentication', 'Unable to enable two factor authentication': 'Unable to enable two factor authentication',
'Unable to disable two factor authentication': 'Unable to disable two factor authentication', 'Unable to disable two factor authentication': 'Unable to disable two factor authentication',
'Lock Application': 'Lock Application',
'Log Out': 'Log Out', 'Log Out': 'Log Out',
'Are you sure you want to log out?': 'Are you sure you want to log out?', 'Are you sure you want to log out?': 'Are you sure you want to log out?',
'Unable to logout': 'Unable to logout', 'Unable to logout': 'Unable to logout',
+1
View File
@@ -1124,6 +1124,7 @@ export default {
'Unable to get current two factor authentication status': '无法获取当前两步验证状态', 'Unable to get current two factor authentication status': '无法获取当前两步验证状态',
'Unable to enable two factor authentication': '无法启用两步验证', 'Unable to enable two factor authentication': '无法启用两步验证',
'Unable to disable two factor authentication': '无法禁用两步验证', 'Unable to disable two factor authentication': '无法禁用两步验证',
'Lock Application': '锁定应用',
'Log Out': '退出登录', 'Log Out': '退出登录',
'Are you sure you want to log out?': '您确定要退出登录?', 'Are you sure you want to log out?': '您确定要退出登录?',
'Unable to logout': '无法退出登录', 'Unable to logout': '无法退出登录',
+15 -7
View File
@@ -17,9 +17,11 @@ import { isObject, isString } from '@/lib/common.js';
export const useRootStore = defineStore('root', { export const useRootStore = defineStore('root', {
actions: { actions: {
resetAllStates() { resetAllStates(resetUserInfoAndSettings) {
const exchangeRatesStore = useExchangeRatesStore(); if (resetUserInfoAndSettings) {
exchangeRatesStore.resetLatestExchangeRates(); const exchangeRatesStore = useExchangeRatesStore();
exchangeRatesStore.resetLatestExchangeRates();
}
const statisticsStore = useStatisticsStore(); const statisticsStore = useStatisticsStore();
statisticsStore.resetTransactionStatistics(); statisticsStore.resetTransactionStatistics();
@@ -39,8 +41,10 @@ export const useRootStore = defineStore('root', {
const accountsStore = useAccountsStore(); const accountsStore = useAccountsStore();
accountsStore.resetAccounts(); accountsStore.resetAccounts();
const userStore = useUserStore(); if (resetUserInfoAndSettings) {
userStore.resetUserInfo(); const userStore = useUserStore();
userStore.resetUserInfo();
}
}, },
authorize({ loginName, password }) { authorize({ loginName, password }) {
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
@@ -204,6 +208,10 @@ export const useRootStore = defineStore('root', {
}); });
}); });
}, },
lock() {
userState.clearSessionToken();
this.resetAllStates(false);
},
logout() { logout() {
const self = this; const self = this;
@@ -218,7 +226,7 @@ export const useRootStore = defineStore('root', {
userState.clearTokenAndUserInfo(true); userState.clearTokenAndUserInfo(true);
userState.clearWebAuthnConfig(); userState.clearWebAuthnConfig();
self.resetAllStates(); self.resetAllStates(true);
resolve(data.result); resolve(data.result);
}).catch(error => { }).catch(error => {
@@ -237,7 +245,7 @@ export const useRootStore = defineStore('root', {
forceLogout() { forceLogout() {
userState.clearTokenAndUserInfo(true); userState.clearTokenAndUserInfo(true);
userState.clearWebAuthnConfig(); userState.clearWebAuthnConfig();
this.resetAllStates(); this.resetAllStates(true);
}, },
updateUserProfile({ profile, currentPassword }) { updateUserProfile({ profile, currentPassword }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
+13
View File
@@ -144,6 +144,10 @@
:title="$t('Application Settings')" :title="$t('Application Settings')"
to="/app/settings"></v-list-item> to="/app/settings"></v-list-item>
<v-divider class="my-2"/> <v-divider class="my-2"/>
<v-list-item :prepend-icon="icons.lock"
:title="$t('Lock Application')"
v-if="isEnableApplicationLock"
@click="lock"></v-list-item>
<v-list-item :disabled="logouting" <v-list-item :disabled="logouting"
:prepend-icon="icons.logout" :prepend-icon="icons.logout"
:title="$t('Log Out')" :title="$t('Log Out')"
@@ -201,6 +205,7 @@ import {
mdiWeatherNight, mdiWeatherNight,
mdiAccount, mdiAccount,
mdiAccountCogOutline, mdiAccountCogOutline,
mdiLockOutline,
mdiLogout mdiLogout
} from '@mdi/js'; } from '@mdi/js';
@@ -229,6 +234,7 @@ export default {
themeDark: mdiWeatherNight, themeDark: mdiWeatherNight,
user: mdiAccount, user: mdiAccount,
profile: mdiAccountCogOutline, profile: mdiAccountCogOutline,
lock: mdiLockOutline,
logout: mdiLogout logout: mdiLogout
} }
} }
@@ -260,6 +266,9 @@ export default {
} }
} }
} }
},
isEnableApplicationLock() {
return this.settingsStore.appSettings.applicationLock;
} }
}, },
setup() { setup() {
@@ -273,6 +282,10 @@ export default {
handleNavScroll(e) { handleNavScroll(e) {
this.isVerticalNavScrolled = e.target.scrollTop > 0; this.isVerticalNavScrolled = e.target.scrollTop > 0;
}, },
lock() {
this.rootStore.lock();
this.$router.replace('/unlock');
},
logout() { logout() {
const self = this; const self = this;