xto-fronted 0.4.110 → 0.4.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.js +1 -1
- package/dist/composables/useApp.d.ts +1 -0
- package/dist/{index-Ch8vmOiD.js → index-BNLsx1WO.js} +1 -1
- package/dist/{index-DTWHgS2f.js → index-Cjel_bu8.js} +579 -575
- package/dist/{index-C3r5dnEs.js → index-DB43988M.js} +1 -1
- package/dist/{index-CLcJb_H7.js → index-DKHtW-p9.js} +1 -1
- package/dist/{index-BMIR-PSJ.js → index-q2D-YeQK.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/stores/user.d.ts +10 -1
- package/dist/style.css +1 -1
- package/dist/{user-CHxvQHYq.js → user-Dr3u-kRk.js} +336 -332
- package/dist/utils/config.d.ts +6 -1
- package/package.json +1 -1
- package/src/components/Layout/Header.vue +1012 -1012
- package/src/directives/permission.ts +36 -36
- package/src/stores/app.ts +179 -179
- package/src/stores/menu.ts +109 -109
- package/src/stores/user.ts +52 -50
- package/src/types/api.d.ts +81 -80
- package/src/utils/config.ts +16 -3
- package/src/utils/permission.ts +39 -39
package/src/stores/user.ts
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 用户状态
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { defineStore } from 'pinia'
|
|
6
|
-
import { ref, computed } from 'vue'
|
|
7
|
-
import type { UserInfo } from '@/types/api'
|
|
8
|
-
import { local } from '@/utils/storage'
|
|
9
|
-
|
|
10
|
-
const USER_INFO_KEY = 'user_info'
|
|
11
|
-
|
|
12
|
-
export const useUserStore = defineStore('user', () => {
|
|
13
|
-
// 状态
|
|
14
|
-
const userInfo = ref<UserInfo | null>(local.get<UserInfo>(USER_INFO_KEY))
|
|
15
|
-
|
|
16
|
-
// 计算属性
|
|
17
|
-
const isLoggedIn = computed(() => !!userInfo.value)
|
|
18
|
-
const userId = computed(() => userInfo.value?.userId || '')
|
|
19
|
-
const userName = computed(() => userInfo.value?.userName || '')
|
|
20
|
-
const departmentName = computed(() => userInfo.value?.departmentName || '')
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 用户状态
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { defineStore } from 'pinia'
|
|
6
|
+
import { ref, computed } from 'vue'
|
|
7
|
+
import type { UserInfo } from '@/types/api'
|
|
8
|
+
import { local } from '@/utils/storage'
|
|
9
|
+
|
|
10
|
+
const USER_INFO_KEY = 'user_info'
|
|
11
|
+
|
|
12
|
+
export const useUserStore = defineStore('user', () => {
|
|
13
|
+
// 状态
|
|
14
|
+
const userInfo = ref<UserInfo | null>(local.get<UserInfo>(USER_INFO_KEY))
|
|
15
|
+
|
|
16
|
+
// 计算属性
|
|
17
|
+
const isLoggedIn = computed(() => !!userInfo.value)
|
|
18
|
+
const userId = computed(() => userInfo.value?.userId || '')
|
|
19
|
+
const userName = computed(() => userInfo.value?.userName || '')
|
|
20
|
+
const departmentName = computed(() => userInfo.value?.departmentName || '')
|
|
21
|
+
const roleName = computed(() => userInfo.value?.roleName || '')
|
|
22
|
+
const email = computed(() => userInfo.value?.email || '')
|
|
23
|
+
const mobilePhone = computed(() => userInfo.value?.mobilePhone || '')
|
|
24
|
+
const positionName = computed(() => userInfo.value?.positionName || '')
|
|
25
|
+
const avatar = computed(() => userInfo.value?.avatar || '')
|
|
26
|
+
|
|
27
|
+
// 设置用户信息
|
|
28
|
+
const setUserInfo = (info: UserInfo) => {
|
|
29
|
+
userInfo.value = info
|
|
30
|
+
local.set(USER_INFO_KEY, info)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 清除用户信息
|
|
34
|
+
const clearUserInfo = () => {
|
|
35
|
+
userInfo.value = null
|
|
36
|
+
local.remove(USER_INFO_KEY)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
userInfo,
|
|
41
|
+
isLoggedIn,
|
|
42
|
+
userId,
|
|
43
|
+
userName,
|
|
44
|
+
departmentName,
|
|
45
|
+
roleName,
|
|
46
|
+
email,
|
|
47
|
+
mobilePhone,
|
|
48
|
+
positionName,
|
|
49
|
+
avatar,
|
|
50
|
+
setUserInfo,
|
|
51
|
+
clearUserInfo
|
|
52
|
+
}
|
|
51
53
|
})
|
package/src/types/api.d.ts
CHANGED
|
@@ -1,81 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API 通用类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// 基础响应
|
|
6
|
-
export interface ApiResponse<T = unknown> {
|
|
7
|
-
code: number
|
|
8
|
-
data: T
|
|
9
|
-
message: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// 分页请求参数
|
|
13
|
-
export interface PageParams {
|
|
14
|
-
page: number
|
|
15
|
-
pageSize: number
|
|
16
|
-
[key: string]: unknown
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 分页响应
|
|
20
|
-
export interface PageResponse<T> {
|
|
21
|
-
list: T[]
|
|
22
|
-
total: number
|
|
23
|
-
page: number
|
|
24
|
-
pageSize: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 用户信息(参考 tineco-ui)
|
|
28
|
-
export interface UserInfo {
|
|
29
|
-
appId: string
|
|
30
|
-
userId: string
|
|
31
|
-
userName: string
|
|
32
|
-
departmentName?: string
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
/**
|
|
2
|
+
* API 通用类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// 基础响应
|
|
6
|
+
export interface ApiResponse<T = unknown> {
|
|
7
|
+
code: number
|
|
8
|
+
data: T
|
|
9
|
+
message: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 分页请求参数
|
|
13
|
+
export interface PageParams {
|
|
14
|
+
page: number
|
|
15
|
+
pageSize: number
|
|
16
|
+
[key: string]: unknown
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 分页响应
|
|
20
|
+
export interface PageResponse<T> {
|
|
21
|
+
list: T[]
|
|
22
|
+
total: number
|
|
23
|
+
page: number
|
|
24
|
+
pageSize: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 用户信息(参考 tineco-ui)
|
|
28
|
+
export interface UserInfo {
|
|
29
|
+
appId: string
|
|
30
|
+
userId: string
|
|
31
|
+
userName: string
|
|
32
|
+
departmentName?: string
|
|
33
|
+
roleName?: string
|
|
34
|
+
email?: string
|
|
35
|
+
mobilePhone?: string
|
|
36
|
+
positionName?: string
|
|
37
|
+
avatar?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 登录请求参数(参考 tineco-ui)
|
|
41
|
+
export interface LoginParams {
|
|
42
|
+
appId: string
|
|
43
|
+
clientId: string
|
|
44
|
+
uid: string
|
|
45
|
+
password: string
|
|
46
|
+
code?: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 登录响应(参考 tineco-ui)
|
|
50
|
+
export interface LoginResult {
|
|
51
|
+
access_token: string
|
|
52
|
+
token_type: string
|
|
53
|
+
refresh_token: string
|
|
54
|
+
expires_time: number
|
|
55
|
+
refresh_time: number
|
|
56
|
+
code?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 菜单项(参考 tineco-ui)
|
|
60
|
+
export interface MenuItem {
|
|
61
|
+
menuCode: string
|
|
62
|
+
menuName: string
|
|
63
|
+
menuUrl: string
|
|
64
|
+
icon?: string
|
|
65
|
+
closable?: boolean
|
|
66
|
+
isDefault?: boolean
|
|
67
|
+
isOut?: boolean
|
|
68
|
+
type?: number // 1 为按钮,其他为菜单
|
|
69
|
+
children?: MenuItem[]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 角色信息
|
|
73
|
+
export interface RoleInfo {
|
|
74
|
+
id: number | string
|
|
75
|
+
name: string
|
|
76
|
+
code: string
|
|
77
|
+
description?: string
|
|
78
|
+
status: number
|
|
79
|
+
permissions: string[]
|
|
80
|
+
createTime?: string
|
|
81
|
+
updateTime?: string
|
|
81
82
|
}
|
package/src/utils/config.ts
CHANGED
|
@@ -22,7 +22,12 @@ let runtimeConfig: Record<string, string> = {}
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* 加载运行时配置
|
|
25
|
-
*
|
|
25
|
+
* 仅在生产部署环境加载 config.json,开发环境自动跳过
|
|
26
|
+
*
|
|
27
|
+
* 注意:不能使用 import.meta.env.PROD 判断,因为作为 npm 库构建时
|
|
28
|
+
* Vite 会将 import.meta.env.PROD 静态替换为 true,导致开发环境也会尝试加载
|
|
29
|
+
* 改用 window.location 协议判断:file:// 或 localhost 开发服务器视为开发环境
|
|
30
|
+
*
|
|
26
31
|
* @param basePath 应用基础路径,如 '/admin' 或 '/sea'
|
|
27
32
|
*/
|
|
28
33
|
export async function loadRuntimeConfig(basePath?: string): Promise<Record<string, string>> {
|
|
@@ -31,8 +36,16 @@ export async function loadRuntimeConfig(basePath?: string): Promise<Record<strin
|
|
|
31
36
|
return runtimeConfig
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
//
|
|
35
|
-
|
|
39
|
+
// 判断是否为生产部署环境
|
|
40
|
+
// 开发环境特征:localhost / 127.0.0.1 / 0.0.0.0 / file:// 协议
|
|
41
|
+
const isDevServer = typeof window !== 'undefined' && (
|
|
42
|
+
window.location.hostname === 'localhost' ||
|
|
43
|
+
window.location.hostname === '127.0.0.1' ||
|
|
44
|
+
window.location.hostname === '0.0.0.0' ||
|
|
45
|
+
window.location.protocol === 'file:'
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if (!isDevServer) {
|
|
36
49
|
try {
|
|
37
50
|
// 确定配置文件路径
|
|
38
51
|
const configPath = basePath ? `${basePath}/config.json` : '/config.json'
|
package/src/utils/permission.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 权限工具函数
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useMenuStore } from '@/stores/menu'
|
|
6
|
-
import { useUserStore } from '@/stores/user'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 检查是否有权限
|
|
10
|
-
* @param permission 权限标识(菜单 code)
|
|
11
|
-
*/
|
|
12
|
-
export function hasPermission(permission: string | string[]): boolean {
|
|
13
|
-
const userStore = useUserStore()
|
|
14
|
-
const menuStore = useMenuStore()
|
|
15
|
-
|
|
16
|
-
// 未登录则无权限
|
|
17
|
-
if (!userStore.isLoggedIn) {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 使用菜单 store 中的权限判断
|
|
22
|
-
return menuStore.hasPermission(permission)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 检查是否有角色
|
|
27
|
-
* @param _role 角色标识(暂不使用)
|
|
28
|
-
*/
|
|
29
|
-
export function hasRole(_role: string | string[]): boolean {
|
|
30
|
-
const userStore = useUserStore()
|
|
31
|
-
// tineco-ui 不支持 roles 字段,暂时返回已登录状态
|
|
32
|
-
return userStore.isLoggedIn
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 检查是否是管理员
|
|
37
|
-
*/
|
|
38
|
-
export function isAdmin(): boolean {
|
|
39
|
-
return true // tineco-ui 不支持 roles 字段,暂时返回 true
|
|
1
|
+
/**
|
|
2
|
+
* 权限工具函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useMenuStore } from '@/stores/menu'
|
|
6
|
+
import { useUserStore } from '@/stores/user'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 检查是否有权限
|
|
10
|
+
* @param permission 权限标识(菜单 code)
|
|
11
|
+
*/
|
|
12
|
+
export function hasPermission(permission: string | string[]): boolean {
|
|
13
|
+
const userStore = useUserStore()
|
|
14
|
+
const menuStore = useMenuStore()
|
|
15
|
+
|
|
16
|
+
// 未登录则无权限
|
|
17
|
+
if (!userStore.isLoggedIn) {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 使用菜单 store 中的权限判断
|
|
22
|
+
return menuStore.hasPermission(permission)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 检查是否有角色
|
|
27
|
+
* @param _role 角色标识(暂不使用)
|
|
28
|
+
*/
|
|
29
|
+
export function hasRole(_role: string | string[]): boolean {
|
|
30
|
+
const userStore = useUserStore()
|
|
31
|
+
// tineco-ui 不支持 roles 字段,暂时返回已登录状态
|
|
32
|
+
return userStore.isLoggedIn
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 检查是否是管理员
|
|
37
|
+
*/
|
|
38
|
+
export function isAdmin(): boolean {
|
|
39
|
+
return true // tineco-ui 不支持 roles 字段,暂时返回 true
|
|
40
40
|
}
|