diff --git a/src/_mock/assets.js b/src/_mock/assets.js index 53404792..2b393bd0 100644 --- a/src/_mock/assets.js +++ b/src/_mock/assets.js @@ -1,7 +1,7 @@ import { faker } from '@faker-js/faker'; +import useUserStore from '@/store/userStore'; import { BasicStatus, PermissionType } from '#/enum'; - /** * Organization data mock */ @@ -528,3 +528,30 @@ export const TEST_USER = { permissions: TEST_ROLE.permission, }; export const USER_LIST = [DEFAULT_USER, TEST_USER]; + + +// * Hot update, updating user permissions, only effective in the development environment +if (import.meta.hot) { + import.meta.hot.accept((newModule) => { + if (!newModule) return; + + const { DEFAULT_USER, TEST_USER, PERMISSION_LIST } = newModule; + + // 使用 getState() 和 setState() 直接操作 store + const { userInfo, actions: { setUserInfo } } = useUserStore.getState(); + + if (!userInfo?.username) return; + + const newUserInfo = userInfo.username === DEFAULT_USER.username + ? DEFAULT_USER + : TEST_USER; + + // 使用 store.actions 更新状态 + setUserInfo(newUserInfo); + + console.log('[HMR] User permissions updated:', { + username: newUserInfo.username, + permissions: newUserInfo.permissions + }); + }); +}