fix(水印): 解决登录成功后水印不更新问题-改为mittbus

This commit is contained in:
2024-08-23 10:26:00 +08:00
parent 816035306b
commit d57a423877
3 changed files with 10 additions and 9 deletions

View File

@ -16,12 +16,6 @@ import { Local, Session } from '/@/utils/storage';
import mittBus from '/@/utils/mitt'; import mittBus from '/@/utils/mitt';
import setIntroduction from '/@/utils/setIconfont'; import setIntroduction from '/@/utils/setIconfont';
provide('onWartermarkChange', () => {
if (settingRef.value) {
settingRef.value.onWartermarkChange();
}
});
// //
const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue')); const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
const Setings = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/setings.vue')); const Setings = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/setings.vue'));
@ -64,6 +58,10 @@ onMounted(() => {
mittBus.on('openSetingsDrawer', () => { mittBus.on('openSetingsDrawer', () => {
settingRef.value.openDrawer(); settingRef.value.openDrawer();
}); });
//
mittBus.on('updateWartermark', () => {
settingRef.value.onWartermarkChange();
});
// //
if (Local.get('themeConfig')) { if (Local.get('themeConfig')) {
storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') }); storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
@ -75,9 +73,10 @@ onMounted(() => {
} }
}); });
}); });
// /i18n // /i18n/
onUnmounted(() => { onUnmounted(() => {
mittBus.off('openSetingsDrawer', () => {}); mittBus.off('openSetingsDrawer', () => {});
mittBus.off('updateWartermark', () => {});
}); });
// //
watch( watch(

2
src/types/mitt.d.ts vendored
View File

@ -11,6 +11,7 @@
* @method openShareTagsView TagsView * @method openShareTagsView TagsView
* @method onTagsViewRefreshRouterView tagsview * @method onTagsViewRefreshRouterView tagsview
* @method onCurrentContextmenuClick tagsview * @method onCurrentContextmenuClick tagsview
* @method updateWartermark
*/ */
declare type MittType<T = any> = { declare type MittType<T = any> = {
openSetingsDrawer?: string; openSetingsDrawer?: string;
@ -23,6 +24,7 @@ declare type MittType<T = any> = {
openShareTagsView?: string; openShareTagsView?: string;
onTagsViewRefreshRouterView?: T; onTagsViewRefreshRouterView?: T;
onCurrentContextmenuClick?: T; onCurrentContextmenuClick?: T;
updateWartermark?: T;
}; };
// mitt 参数类型定义 // mitt 参数类型定义

View File

@ -40,13 +40,13 @@ import { formatAxis } from '/@/utils/formatTime';
import { useMessage } from '/@/hooks/message'; import { useMessage } from '/@/hooks/message';
import { Session } from '/@/utils/storage'; import { Session } from '/@/utils/storage';
import { initBackEndControlRoutes } from '/@/router/backEnd'; import { initBackEndControlRoutes } from '/@/router/backEnd';
import mittBus from '/@/utils/mitt';
// //
const Password = defineAsyncComponent(() => import('./component/password.vue')); const Password = defineAsyncComponent(() => import('./component/password.vue'));
const Mobile = defineAsyncComponent(() => import('./component/mobile.vue')); const Mobile = defineAsyncComponent(() => import('./component/mobile.vue'));
const Register = defineAsyncComponent(() => import('./component/register.vue')); const Register = defineAsyncComponent(() => import('./component/register.vue'));
const onWartermarkChange = inject<() => void>('onWartermarkChange');
// //
const storesThemeConfig = useThemeConfig(); const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig); const { themeConfig } = storeToRefs(storesThemeConfig);
@ -73,7 +73,7 @@ const signInSuccess = async () => {
Session.clear(); Session.clear();
} else { } else {
// //
onWartermarkChange && onWartermarkChange() mittBus.emit('updateWartermark');
// //
let currentTimeInfo = formatAxis(new Date()); let currentTimeInfo = formatAxis(new Date());
if (route.query?.redirect) { if (route.query?.redirect) {