Skip to content

Commit

Permalink
feat: use vite HRM to update user permission when assets.js change
Browse files Browse the repository at this point in the history
  • Loading branch information
d3george authored and d3george committed Nov 12, 2024
1 parent 771be2f commit cfde69f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/_mock/assets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { faker } from '@faker-js/faker';
import useUserStore from '@/store/userStore';

import { BasicStatus, PermissionType } from '#/enum';

/**
* Organization data mock
*/
Expand Down Expand Up @@ -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
});
});
}

0 comments on commit cfde69f

Please sign in to comment.