Skip to content

Commit

Permalink
fix(水印): 解决登录成功后水印不更新问题-改为mittbus
Browse files Browse the repository at this point in the history
  • Loading branch information
committed Aug 23, 2024
1 parent 8160353 commit d57a423
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ import { Local, Session } from '/@/utils/storage';
import mittBus from '/@/utils/mitt';
import setIntroduction from '/@/utils/setIconfont';
provide('onWartermarkChange', () => {
if (settingRef.value) {
settingRef.value.onWartermarkChange();
}
});
// 引入组件
const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
const Setings = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/setings.vue'));
Expand Down Expand Up @@ -64,6 +58,10 @@ onMounted(() => {
mittBus.on('openSetingsDrawer', () => {
settingRef.value.openDrawer();
});
// 监听登录成功后重新加载水印
mittBus.on('updateWartermark', () => {
settingRef.value.onWartermarkChange();
});
// 获取缓存中的布局配置
if (Local.get('themeConfig')) {
storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
Expand All @@ -75,9 +73,10 @@ onMounted(() => {
}
});
});
// 页面销毁时,关闭监听布局配置/i18n监听
// 页面销毁时,关闭监听布局配置/i18n监听/更新水印
onUnmounted(() => {
mittBus.off('openSetingsDrawer', () => {});
mittBus.off('updateWartermark', () => {});
});
// 监听路由的变化,设置网站标题
watch(
Expand Down
2 changes: 2 additions & 0 deletions src/types/mitt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @method openShareTagsView 布局设置弹窗,开启 TagsView 共用
* @method onTagsViewRefreshRouterView tagsview 刷新界面
* @method onCurrentContextmenuClick tagsview 右键菜单每项点击时
* @method updateWartermark 更新水印显示内容
*/
declare type MittType<T = any> = {
openSetingsDrawer?: string;
Expand All @@ -23,6 +24,7 @@ declare type MittType<T = any> = {
openShareTagsView?: string;
onTagsViewRefreshRouterView?: T;
onCurrentContextmenuClick?: T;
updateWartermark?: T;
};

// mitt 参数类型定义
Expand Down
4 changes: 2 additions & 2 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import { formatAxis } from '/@/utils/formatTime';
import { useMessage } from '/@/hooks/message';
import { Session } from '/@/utils/storage';
import { initBackEndControlRoutes } from '/@/router/backEnd';
import mittBus from '/@/utils/mitt';
// 引入组件
const Password = defineAsyncComponent(() => import('./component/password.vue'));
const Mobile = defineAsyncComponent(() => import('./component/mobile.vue'));
const Register = defineAsyncComponent(() => import('./component/register.vue'));
const onWartermarkChange = inject<() => void>('onWartermarkChange');
// 定义变量内容
const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig);
Expand All @@ -73,7 +73,7 @@ const signInSuccess = async () => {
Session.clear();
} else {
// 重新加载水印
onWartermarkChange && onWartermarkChange()
mittBus.emit('updateWartermark');
// 初始化登录成功时间问候语
let currentTimeInfo = formatAxis(new Date());
if (route.query?.redirect) {
Expand Down

0 comments on commit d57a423

Please sign in to comment.