刘光辉
11 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { BasicUserInfo } from '@vben-core/typings';
 
import { mergeWithArrayOverride } from '@vben-core/shared/utils';
 
import { acceptHMRUpdate, defineStore } from 'pinia';
 
interface UserState {
  /**
   * 用户信息
   */
  userInfo: BasicUserInfo | null;
}
 
/**
 * @zh_CN 用户信息相关
 */
export const useUserStore = defineStore('core-user', {
  actions: {
    setUserInfo(userInfo: null | Partial<BasicUserInfo>) {
      // 设置用户信息
      this.userInfo = mergeWithArrayOverride(userInfo || {}, this.userInfo || {}) as BasicUserInfo;
    },
  },
  getters: {
    getUserInfo(): BasicUserInfo | null {
      return this.userInfo || null;
    },
  },
  state: (): UserState => ({
    userInfo: null,
  }),
});
 
// 解决热更新问题
const hot = import.meta.hot;
if (hot) {
  hot.accept(acceptHMRUpdate(useUserStore, hot));
}