This commit is contained in:
ygx
2026-03-07 20:11:25 +08:00
parent 8fab91c5c7
commit f7bbb5ee46
74 changed files with 6540 additions and 2636 deletions

View File

@@ -3,9 +3,13 @@ import { Notification } from '@arco-design/web-vue'
import type { NotificationReturn } from '@arco-design/web-vue/es/notification/interface'
import type { RouteRecordNormalized } from 'vue-router'
import defaultSettings from '@/config/settings.json'
import { getMenuList } from '@/api/user'
import { userPmn } from '@/api/module/user'
import { localMenuData } from '@/router/menu-data'
import { buildTree } from '@/utils/tree'
import SafeStorage, { AppStorageKey } from "@/utils/safeStorage";
import { AppState } from './types'
const useAppStore = defineStore('app', {
state: (): AppState => ({ ...defaultSettings }),
@@ -45,27 +49,24 @@ const useAppStore = defineStore('app', {
this.hideMenu = value
},
async fetchServerMenuConfig() {
const userInfo = SafeStorage.get(AppStorageKey.USER_INFO) as any
let notifyInstance: NotificationReturn | null = null
try {
notifyInstance = Notification.info({
id: 'menuNotice', // Keep the instance id the same
content: 'loading',
closable: true,
})
const { data } = await getMenuList()
this.serverMenu = data
notifyInstance = Notification.success({
id: 'menuNotice',
content: 'success',
closable: true,
})
// 使用本地菜单数据(接口未准备好)
// TODO: 接口准备好后,取消下面的注释,使用真实接口数据
const res = await userPmn({ id: userInfo.user_id, workspace: import.meta.env.VITE_APP_WORKSPACE })
console.log('res', res)
if (res.code === 0 && res?.details?.length) {
console.log('buildTree', buildTree(res.details[0].permissions))
}
// this.serverMenu = data
// 使用本地数据
this.serverMenu = localMenuData as unknown as RouteRecordNormalized[]
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
notifyInstance = Notification.error({
id: 'menuNotice',
content: 'error',
closable: true,
})
}
},
clearServerMenu() {

View File

@@ -1,7 +1,10 @@
import { LoginData, getUserInfo, login as userLogin, logout as userLogout } from '@/api/user'
import { login, logout } from '@/api/module/user'
import { LoginData } from '@/api/types'
import { request } from '@/api/request'
import { clearToken, setToken } from '@/utils/auth'
import { removeRouteListener } from '@/utils/route-listener'
import { defineStore } from 'pinia'
import SafeStorage, { AppStorageKey } from "@/utils/safeStorage";
import useAppStore from '../app'
import { UserState } from './types'
@@ -23,6 +26,7 @@ const useUserStore = defineStore('user', {
accountId: undefined,
certification: undefined,
role: '',
userInfo: SafeStorage.get(AppStorageKey.USER_INFO)
}),
getters: {
@@ -50,16 +54,22 @@ const useUserStore = defineStore('user', {
// Get user's information
async info() {
const res = await getUserInfo()
this.setInfo(res.data)
// const res = await request.post('/rbac2/v1/user/info') as any
// request 拦截器已经返回 response.data所以 res 就是用户信息
// this.setInfo(res.data || res)
},
// Login
async login(loginForm: LoginData) {
try {
const res = await userLogin(loginForm)
setToken(res.data.token)
const { code, details } = await login(loginForm as any) as any
if (code === 0 && details?.token) {
setToken(details.token)
SafeStorage.set(AppStorageKey.USER_INFO, details)
this.userInfo = details
} else {
throw new Error('登录失败:未获取到 token')
}
} catch (err) {
clearToken()
throw err
@@ -71,11 +81,12 @@ const useUserStore = defineStore('user', {
clearToken()
removeRouteListener()
appStore.clearServerMenu()
SafeStorage.clearAppStorage()
},
// Logout
async logout() {
try {
await userLogout()
// await logout()
} finally {
this.logoutCallBack()
}

View File

@@ -16,4 +16,5 @@ export interface UserState {
accountId?: string
certification?: number
role: RoleType
userInfo?: any
}