Browse Source

🎟 优化

master
wangxiang 3 years ago
parent
commit
c988aa1944
  1. 10
      kicc-ui/src/store/modules/app.ts
  2. 13
      kicc-ui/src/store/modules/locale.ts
  3. 13
      kicc-ui/src/store/modules/lock.ts
  4. 20
      kicc-ui/src/store/modules/multipleTab.ts
  5. 8
      kicc-ui/src/store/modules/user.ts

10
kicc-ui/src/store/modules/app.ts

@ -29,7 +29,7 @@ interface AppState { @@ -29,7 +29,7 @@ interface AppState {
pageLoading: boolean;
// 项目配置
projectConfig: ProjectConfig | null;
// 当窗口收缩时,记住一些状态,在窗口恢复时恢复这些状态
// 当窗口收缩时,记住一些状态,在窗口恢复时恢复这些状态
beforeMiniInfo: BeforeMiniState;
}
@ -37,7 +37,7 @@ let timeId: TimeoutHandle; @@ -37,7 +37,7 @@ let timeId: TimeoutHandle;
export const useAppStore = defineStore({
id: 'app',
state: (): AppState => ({
darkMode: undefined,
darkMode: localStorage.getItem(APP_DARK_MODE_KEY_),
pageLoading: false,
projectConfig: Persistent.getLocal(PROJ_CFG_KEY),
beforeMiniInfo: {},
@ -47,7 +47,7 @@ export const useAppStore = defineStore({ @@ -47,7 +47,7 @@ export const useAppStore = defineStore({
return this.pageLoading;
},
getDarkMode(): 'light' | 'dark' | string {
return this.darkMode || localStorage.getItem(APP_DARK_MODE_KEY_) || darkMode;
return this.darkMode || darkMode;
},
getBeforeMiniInfo(): BeforeMiniState {
return this.beforeMiniInfo;
@ -98,8 +98,8 @@ export const useAppStore = defineStore({ @@ -98,8 +98,8 @@ export const useAppStore = defineStore({
this.setPageLoading(loading);
clearTimeout(timeId);
}
},
},
}
}
});
// 需要在设置之外使用

13
kicc-ui/src/store/modules/locale.ts

@ -41,16 +41,11 @@ export const useLocaleStore = defineStore({ @@ -41,16 +41,11 @@ export const useLocaleStore = defineStore({
this.localInfo = { ...this.localInfo, ...info };
ls.set(LOCALE_KEY, this.localInfo);
},
/**
*
*/
/** 初始化多语言信息并从本地缓存加载现有配置 */
initLocale() {
this.setLocaleInfo({
...localeSetting,
...this.localInfo,
});
},
},
this.setLocaleInfo({ ...localeSetting, ...this.localInfo });
}
}
});
// 需要在设置之外使用

13
kicc-ui/src/store/modules/lock.ts

@ -26,20 +26,25 @@ export const useLockStore = defineStore({ @@ -26,20 +26,25 @@ export const useLockStore = defineStore({
},
},
actions: {
/** 设置锁屏 */
setLockInfo(info: LockInfo) {
this.lockInfo = Object.assign({}, this.lockInfo, info);
Persistent.setLocal(LOCK_INFO_KEY, this.lockInfo, true);
},
/** 还原锁屏数据 */
resetLockInfo() {
Persistent.removeLocal(LOCK_INFO_KEY, true);
this.lockInfo = null;
},
/** 解锁锁屏 */
async unLock(password?: string) {
const userStore = useUserStore();
// 浏览器存在当前锁屏信息缓存,直接比对当前用户密码
if (this.lockInfo?.pwd === password) {
this.resetLockInfo();
return true;
}
// 浏览器缓存已经清空,需要重新登录验证当前用户密码
const tryLogin = async () => {
try {
const username = userStore.getUserInfo.userName;
@ -51,15 +56,13 @@ export const useLockStore = defineStore({ @@ -51,15 +56,13 @@ export const useLockStore = defineStore({
realKey: '',
code: '',
});
if (res) {
this.resetLockInfo();
}
if (res) this.resetLockInfo();
return res;
} catch (error) {
return false;
}
};
return await tryLogin();
},
},
}
}
});

20
kicc-ui/src/store/modules/multipleTab.ts

@ -125,7 +125,7 @@ export const useMultipleTabStore = defineStore({ @@ -125,7 +125,7 @@ export const useMultipleTabStore = defineStore({
this.tabList.splice(updateIndex, 1, curTab);
// 添加选项卡
} else this.tabList.push(route);
this.updateCacheTab();
await this.updateCacheTab();
cacheTab && Persistent.setLocal(MULTIPLE_TABS_KEY, this.tabList);
},
/** 关闭标签页 */
@ -173,7 +173,7 @@ export const useMultipleTabStore = defineStore({ @@ -173,7 +173,7 @@ export const useMultipleTabStore = defineStore({
/** 标签新增与删除回调处理,用于关闭标签页 */
async closeTabByKey(key: string, router: Router) {
const index = this.tabList.findIndex((item) => (item.fullPath || item.path) === key);
index !== -1 && this.closeTab(this.tabList[index], router);
index !== -1 && await this.closeTab(this.tabList[index], router);
},
/** 对选项卡进行排序 */
async sortTabs(oldIndex: number, newIndex: number) {
@ -192,9 +192,9 @@ export const useMultipleTabStore = defineStore({ @@ -192,9 +192,9 @@ export const useMultipleTabStore = defineStore({
const affix = item?.meta?.affix ?? false;
if (!affix) pathList.push(item.fullPath);
}
this.bulkCloseTabs(pathList);
await this.bulkCloseTabs(pathList);
}
this.updateCacheTab();
await this.updateCacheTab();
handleGotoPage(router);
},
/** 关闭左侧标签并跳转 */
@ -207,9 +207,9 @@ export const useMultipleTabStore = defineStore({ @@ -207,9 +207,9 @@ export const useMultipleTabStore = defineStore({
const affix = item?.meta?.affix ?? false;
if (!affix) pathList.push(item.fullPath);
}
this.bulkCloseTabs(pathList);
await this.bulkCloseTabs(pathList);
}
this.updateCacheTab();
await this.updateCacheTab();
handleGotoPage(router);
},
/** 关闭全部标签并跳转 */
@ -230,8 +230,8 @@ export const useMultipleTabStore = defineStore({ @@ -230,8 +230,8 @@ export const useMultipleTabStore = defineStore({
if (!affix) pathList.push(closeItem.fullPath);
}
}
this.bulkCloseTabs(pathList);
this.updateCacheTab();
await this.bulkCloseTabs(pathList);
await this.updateCacheTab();
handleGotoPage(router);
},
/** 批量关闭标签页 */
@ -254,8 +254,8 @@ export const useMultipleTabStore = defineStore({ @@ -254,8 +254,8 @@ export const useMultipleTabStore = defineStore({
findTab.path = fullPath;
await this.updateCacheTab();
}
},
},
}
}
});
// 需要在设置之外使用

8
kicc-ui/src/store/modules/user.ts

@ -144,7 +144,7 @@ export const useUserStore = defineStore({ @@ -144,7 +144,7 @@ export const useUserStore = defineStore({
this.setAccessToken('');
this.setRefreshToken('');
this.setSessionTimeout(false);
goLogin && router.push(PageEnum.BASE_LOGIN);
goLogin && await router.push(PageEnum.BASE_LOGIN);
},
/** 退出前确认 */
confirmLoginOut() {
@ -156,10 +156,10 @@ export const useUserStore = defineStore({ @@ -156,10 +156,10 @@ export const useUserStore = defineStore({
content: t('sys.app.logoutMessage'),
onOk: async () => {
await this.logout(true);
},
}
});
},
},
}
}
});
// 需要在设置之外使用

Loading…
Cancel
Save