| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /*
- * @Author: wjc
- * @Date: 2023-11-27 15:35:24
- * @LastEditors: LiZhiWei
- * @LastEditTime: 2026-01-09 16:45:59
- * @Description:
- */
- import { getToken } from '@/utils/auth'
- interface IUser {
- id?: string
- }
- export const useUserStore = defineStore('user', {
- state: () => {
- return {
- userInfo: {} as IUser,
- navMenu: [],
- }
- },
- getters: {
- getUser(): IUser {
- if (process.browser) {
- const token = getToken()
- const userInfo = localStorage.getItem('userInfo')
- if (userInfo && token) {
- return JSON.parse(userInfo)
- }
- return this.userInfo
- } else {
- return this.userInfo
- }
- },
- getEnterpriseUserId(): string {
- return this.userInfo.id || ''
- },
- },
- actions: {
- clearUserInfo() {
- this.userInfo = {}
- },
- },
- })
|