feat(projects): 主题配置抽屉: 迁移其他功能

This commit is contained in:
Soybean
2022-01-09 13:25:42 +08:00
parent 912bfdf439
commit 6d132c5977
10 changed files with 269 additions and 6 deletions

View File

@ -32,7 +32,6 @@ interface AuthStore {
export const useAuthStore = defineStore('auth-store', () => {
const { toLogin, toLoginRedirect } = useRouterPush(false);
const { loading: loginLoding, startLoading: startLoginLoading, endLoading: endLoginLoading } = useLoading();
const userInfo: Auth.UserInfo = reactive(getUserInfo());
function handleSetUserInfo(data: Auth.UserInfo) {
@ -46,12 +45,18 @@ export const useAuthStore = defineStore('auth-store', () => {
const isLogin = computed(() => Boolean(token.value));
const { loading: loginLoding, startLoading: startLoginLoading, endLoading: endLoginLoading } = useLoading();
function resetStore() {
handleSetUserInfo(getUserInfo());
handleSetToken(getToken());
}
function resetAuthStore(pushRoute: boolean = true) {
const auth = useAuthStore();
const route = unref(globalRouter.currentRoute);
clearAuthStorage();
auth.$reset();
resetStore();
if (pushRoute && route.meta.requiresAuth) {
toLogin();

View File

@ -67,6 +67,8 @@ interface ThemeStore extends LayoutFunc, HeaderFunc, TabFunc, SiderFunc, FooterF
naiveThemeOverrides: ComputedRef<GlobalThemeOverrides>;
/** naive-ui暗黑主题 */
naiveTheme: ComputedRef<BuiltInGlobalTheme | undefined>;
/** 重置状态 */
resetThemeStore(): void;
}
export const useThemeStore = defineStore('theme-store', () => {
@ -148,6 +150,11 @@ export const useThemeStore = defineStore('theme-store', () => {
);
const naiveTheme = computed(() => (darkMode.value ? darkTheme : undefined));
/** 重置theme状态 */
function resetThemeStore() {
setDarkMode(false);
}
/** 初始化css vars, 并添加至html */
function initThemeCssVars() {
const updatedThemeVars = { ...naiveThemeOverrides.value.common };
@ -214,7 +221,8 @@ export const useThemeStore = defineStore('theme-store', () => {
setPageIsAnimate,
setPageAnimateMode,
naiveThemeOverrides,
naiveTheme
naiveTheme,
resetThemeStore
};
return themeStore;