xto-fronted 0.1.1 → 0.1.2
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/{403-MQkNUulz.js → 403-DM5wfQkM.js} +6 -6
- package/dist/{404-BOFYLq4X.js → 404-BurAu5LC.js} +7 -7
- package/dist/api/auth.d.ts +9 -8
- package/dist/api/menu.d.ts +3 -0
- package/dist/api/user.d.ts +2 -12
- package/dist/composables/index.d.ts +8 -0
- package/dist/composables/useApp.d.ts +64 -0
- package/dist/composables/useAuth.d.ts +19 -4
- package/dist/composables/useMenu.d.ts +34 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/index-BNiEld34.js +15 -0
- package/dist/index-Be9RiEfo.js +98 -0
- package/dist/index-BqRv1bdN.js +1185 -0
- package/dist/index-CQLVXvNJ.js +15 -0
- package/dist/index-CyiE8n2V.js +15 -0
- package/dist/index-xauR1bOL.js +15 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.es.js +50 -66
- package/dist/index.umd.js +1 -1
- package/dist/stores/auth.d.ts +60 -23
- package/dist/stores/menu.d.ts +40 -29
- package/dist/stores/user.d.ts +63 -84
- package/dist/style.css +1 -1
- package/dist/utils/auth.d.ts +15 -7
- package/dist/utils/permission.d.ts +1 -6
- package/dist/views/system/menu/index.vue.d.ts +1 -3
- package/dist/views/system/role/index.vue.d.ts +1 -3
- package/dist/views/system/user/index.vue.d.ts +1 -3
- package/package.json +21 -26
- package/.env.development +0 -4
- package/.env.production +0 -4
- package/dist/index-BJxYdNPy.js +0 -475
- package/dist/index-BvnIIBR1.js +0 -142
- package/dist/index-CEvAq6KE.js +0 -372
- package/dist/index-DPkqej__.js +0 -345
- package/dist/index-pq9Z5K62.js +0 -184
- package/dist/index-vVfjShJR.js +0 -1183
- package/index.html +0 -13
- package/public/vite.svg +0 -10
- package/src/App.vue +0 -20
- package/src/api/auth.ts +0 -26
- package/src/api/system.ts +0 -65
- package/src/api/user.ts +0 -46
- package/src/assets/styles/_dark.scss +0 -407
- package/src/assets/styles/_reset.scss +0 -126
- package/src/assets/styles/_root.scss +0 -140
- package/src/assets/styles/_transition.scss +0 -119
- package/src/assets/styles/_variables.scss +0 -45
- package/src/assets/styles/index.scss +0 -187
- package/src/components/Layout/Footer.vue +0 -17
- package/src/components/Layout/Header.vue +0 -390
- package/src/components/Layout/Sidebar.vue +0 -297
- package/src/components/Layout/Tabs.vue +0 -134
- package/src/components/Layout/index.vue +0 -62
- package/src/composables/useAuth.ts +0 -45
- package/src/composables/useForm.ts +0 -79
- package/src/composables/useTable.ts +0 -97
- package/src/directives/permission.ts +0 -38
- package/src/enums/index.ts +0 -63
- package/src/env.d.ts +0 -17
- package/src/index.ts +0 -39
- package/src/main.ts +0 -34
- package/src/router/dynamicRoutes.ts +0 -163
- package/src/router/index.ts +0 -81
- package/src/router/staticRoutes.ts +0 -43
- package/src/stores/app.ts +0 -145
- package/src/stores/auth.ts +0 -32
- package/src/stores/index.ts +0 -15
- package/src/stores/menu.ts +0 -80
- package/src/stores/user.ts +0 -73
- package/src/types/api.d.ts +0 -84
- package/src/types/global.d.ts +0 -45
- package/src/types/router.d.ts +0 -48
- package/src/types/xto.d.ts +0 -149
- package/src/utils/auth.ts +0 -62
- package/src/utils/permission.ts +0 -42
- package/src/utils/request.ts +0 -126
- package/src/utils/storage.ts +0 -63
- package/src/views/dashboard/index.vue +0 -284
- package/src/views/error/403.vue +0 -57
- package/src/views/error/404.vue +0 -57
- package/src/views/login/index.vue +0 -248
- package/src/views/system/menu/index.vue +0 -381
- package/src/views/system/role/index.vue +0 -304
- package/src/views/system/user/index.vue +0 -327
- package/tsconfig.json +0 -26
- package/tsconfig.node.json +0 -11
- package/vite.config.ts +0 -139
package/src/types/api.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
// 用户信息
|
|
28
|
-
export interface UserInfo {
|
|
29
|
-
id: number | string
|
|
30
|
-
username: string
|
|
31
|
-
nickname: string
|
|
32
|
-
avatar?: string
|
|
33
|
-
email?: string
|
|
34
|
-
phone?: string
|
|
35
|
-
status: number
|
|
36
|
-
roles: string[]
|
|
37
|
-
permissions: string[]
|
|
38
|
-
createTime?: string
|
|
39
|
-
updateTime?: string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 登录请求
|
|
43
|
-
export interface LoginParams {
|
|
44
|
-
username: string
|
|
45
|
-
password: string
|
|
46
|
-
captcha?: string
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 登录响应
|
|
50
|
-
export interface LoginResult {
|
|
51
|
-
token: string
|
|
52
|
-
refreshToken: string
|
|
53
|
-
expireTime: number
|
|
54
|
-
user: UserInfo
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 菜单项
|
|
58
|
-
export interface MenuItem {
|
|
59
|
-
id: number | string
|
|
60
|
-
name: string
|
|
61
|
-
path: string
|
|
62
|
-
component?: string
|
|
63
|
-
redirect?: string
|
|
64
|
-
icon?: string
|
|
65
|
-
title: string
|
|
66
|
-
hidden?: boolean
|
|
67
|
-
keepAlive?: boolean
|
|
68
|
-
affix?: boolean
|
|
69
|
-
order?: number
|
|
70
|
-
parentId?: number | string | null
|
|
71
|
-
children?: MenuItem[]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 角色信息
|
|
75
|
-
export interface RoleInfo {
|
|
76
|
-
id: number | string
|
|
77
|
-
name: string
|
|
78
|
-
code: string
|
|
79
|
-
description?: string
|
|
80
|
-
status: number
|
|
81
|
-
permissions: string[]
|
|
82
|
-
createTime?: string
|
|
83
|
-
updateTime?: string
|
|
84
|
-
}
|
package/src/types/global.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 全局类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// 通用对象类型
|
|
6
|
-
export type AnyObject = Record<string, unknown>
|
|
7
|
-
|
|
8
|
-
// 通用函数类型
|
|
9
|
-
export type AnyFunction = (...args: unknown[]) => unknown
|
|
10
|
-
|
|
11
|
-
// 值类型
|
|
12
|
-
export type ValueOf<T> = T[keyof T]
|
|
13
|
-
|
|
14
|
-
// 可空类型
|
|
15
|
-
export type Nullable<T> = T | null
|
|
16
|
-
|
|
17
|
-
// 可选类型
|
|
18
|
-
export type Optional<T> = T | undefined
|
|
19
|
-
|
|
20
|
-
// 深度可选
|
|
21
|
-
export type DeepPartial<T> = {
|
|
22
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 深度必需
|
|
26
|
-
export type DeepRequired<T> = {
|
|
27
|
-
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 深度只读
|
|
31
|
-
export type DeepReadonly<T> = {
|
|
32
|
-
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 提取数组元素类型
|
|
36
|
-
export type ArrayElement<T> = T extends readonly (infer E)[] ? E : never
|
|
37
|
-
|
|
38
|
-
// 提取 Promise 值类型
|
|
39
|
-
export type Awaited<T> = T extends Promise<infer U> ? U : T
|
|
40
|
-
|
|
41
|
-
// 排除 null 和 undefined
|
|
42
|
-
export type NonNullable<T> = T extends null | undefined ? never : T
|
|
43
|
-
|
|
44
|
-
// 枚举值类型
|
|
45
|
-
export type EnumValue<T extends Record<string, string | number>> = T[keyof T]
|
package/src/types/router.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 路由类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import 'vue-router'
|
|
6
|
-
|
|
7
|
-
declare module 'vue-router' {
|
|
8
|
-
interface RouteMeta {
|
|
9
|
-
// 页面标题
|
|
10
|
-
title?: string
|
|
11
|
-
// 图标
|
|
12
|
-
icon?: string
|
|
13
|
-
// 是否隐藏菜单
|
|
14
|
-
hidden?: boolean
|
|
15
|
-
// 是否缓存页面
|
|
16
|
-
keepAlive?: boolean
|
|
17
|
-
// 是否固定在 tabs 中
|
|
18
|
-
affix?: boolean
|
|
19
|
-
// 权限标识
|
|
20
|
-
permissions?: string[]
|
|
21
|
-
// 角色标识
|
|
22
|
-
roles?: string[]
|
|
23
|
-
// 面包屑
|
|
24
|
-
breadcrumb?: boolean
|
|
25
|
-
// 当前激活菜单
|
|
26
|
-
activeMenu?: string
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 路由项
|
|
31
|
-
export interface AppRoute {
|
|
32
|
-
path: string
|
|
33
|
-
name?: string
|
|
34
|
-
redirect?: string
|
|
35
|
-
component?: () => Promise<unknown>
|
|
36
|
-
meta?: RouteMeta
|
|
37
|
-
children?: AppRoute[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 动态路由
|
|
41
|
-
export interface DynamicRoute {
|
|
42
|
-
path: string
|
|
43
|
-
name: string
|
|
44
|
-
component: string
|
|
45
|
-
redirect?: string
|
|
46
|
-
meta?: RouteMeta
|
|
47
|
-
children?: DynamicRoute[]
|
|
48
|
-
}
|
package/src/types/xto.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
declare module '@xto/core' {
|
|
2
|
-
export const version: string
|
|
3
|
-
export function install(app: any): void
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
declare module '@xto/core/es/index/index.mjs' {
|
|
7
|
-
export * from '@xto/core'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module '@xto/core/es/theme/index.mjs' {
|
|
11
|
-
export const theme: any
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare module '@xto/core/es/hooks/index.mjs' {
|
|
15
|
-
export const hooks: any
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare module '@xto/core/es/utils/index.mjs' {
|
|
19
|
-
export const utils: any
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare module '@xto/base' {
|
|
23
|
-
import { DefineComponent } from 'vue'
|
|
24
|
-
export const Button: DefineComponent<any, any, any>
|
|
25
|
-
export const Loading: DefineComponent<any, any, any>
|
|
26
|
-
export const Icon: DefineComponent<any, any, any>
|
|
27
|
-
export const Avatar: DefineComponent<any, any, any>
|
|
28
|
-
export const Badge: DefineComponent<any, any, any>
|
|
29
|
-
export const Tag: DefineComponent<any, any, any>
|
|
30
|
-
export const Divider: DefineComponent<any, any, any>
|
|
31
|
-
export const Space: DefineComponent<any, any, any>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare module '@xto/base/es/style.css' {
|
|
35
|
-
const content: string
|
|
36
|
-
export default content
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare module '@xto/form' {
|
|
40
|
-
import { DefineComponent } from 'vue'
|
|
41
|
-
export const Input: DefineComponent<any, any, any>
|
|
42
|
-
export const InputNumber: DefineComponent<any, any, any>
|
|
43
|
-
export const Select: DefineComponent<any, any, any>
|
|
44
|
-
export const Checkbox: DefineComponent<any, any, any>
|
|
45
|
-
export const Radio: DefineComponent<any, any, any>
|
|
46
|
-
export const Switch: DefineComponent<any, any, any>
|
|
47
|
-
export const DatePicker: DefineComponent<any, any, any>
|
|
48
|
-
export const Form: DefineComponent<any, any, any>
|
|
49
|
-
export const FormItem: DefineComponent<any, any, any>
|
|
50
|
-
export const Upload: DefineComponent<any, any, any>
|
|
51
|
-
export const FormRule: any
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare module '@xto/form/es/style.css' {
|
|
55
|
-
const content: string
|
|
56
|
-
export default content
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare module '@xto/data' {
|
|
60
|
-
import { DefineComponent } from 'vue'
|
|
61
|
-
export const Table: DefineComponent<any, any, any>
|
|
62
|
-
export const Pagination: DefineComponent<any, any, any>
|
|
63
|
-
export const Tree: DefineComponent<any, any, any>
|
|
64
|
-
export const TreeNode: DefineComponent<any, any, any>
|
|
65
|
-
export const List: DefineComponent<any, any, any>
|
|
66
|
-
export const Card: DefineComponent<any, any, any>
|
|
67
|
-
export const Descriptions: DefineComponent<any, any, any>
|
|
68
|
-
export const Tag: DefineComponent<any, any, any>
|
|
69
|
-
export const Progress: DefineComponent<any, any, any>
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare module '@xto/data/es/style.css' {
|
|
73
|
-
const content: string
|
|
74
|
-
export default content
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
declare module '@xto/feedback' {
|
|
78
|
-
import { DefineComponent } from 'vue'
|
|
79
|
-
export const Message: {
|
|
80
|
-
success: (msg: string) => void
|
|
81
|
-
error: (msg: string) => void
|
|
82
|
-
warning: (msg: string) => void
|
|
83
|
-
info: (msg: string) => void
|
|
84
|
-
}
|
|
85
|
-
export const Notification: {
|
|
86
|
-
success: (options: any) => void
|
|
87
|
-
error: (options: any) => void
|
|
88
|
-
warning: (options: any) => void
|
|
89
|
-
info: (options: any) => void
|
|
90
|
-
}
|
|
91
|
-
export const Modal: DefineComponent<any, any, any>
|
|
92
|
-
export const Drawer: DefineComponent<any, any, any>
|
|
93
|
-
export const Popconfirm: DefineComponent<any, any, any>
|
|
94
|
-
export const Tooltip: DefineComponent<any, any, any>
|
|
95
|
-
export const Popover: DefineComponent<any, any, any>
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
declare module '@xto/feedback/es/style.css' {
|
|
99
|
-
const content: string
|
|
100
|
-
export default content
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
declare module '@xto/navigation' {
|
|
104
|
-
import { DefineComponent } from 'vue'
|
|
105
|
-
export const Menu: DefineComponent<any, any, any>
|
|
106
|
-
export const MenuItem: DefineComponent<any, any, any>
|
|
107
|
-
export const SubMenu: DefineComponent<any, any, any>
|
|
108
|
-
export const Tabs: DefineComponent<any, any, any>
|
|
109
|
-
export const TabPane: DefineComponent<any, any, any>
|
|
110
|
-
export const Breadcrumb: DefineComponent<any, any, any>
|
|
111
|
-
export const BreadcrumbItem: DefineComponent<any, any, any>
|
|
112
|
-
export const Dropdown: DefineComponent<any, any, any>
|
|
113
|
-
export const DropdownMenu: DefineComponent<any, any, any>
|
|
114
|
-
export const DropdownItem: DefineComponent<any, any, any>
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
declare module '@xto/navigation/es/style.css' {
|
|
118
|
-
const content: string
|
|
119
|
-
export default content
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
declare module '@xto/layout' {
|
|
123
|
-
import { DefineComponent } from 'vue'
|
|
124
|
-
export const Layout: DefineComponent<any, any, any>
|
|
125
|
-
export const Header: DefineComponent<any, any, any>
|
|
126
|
-
export const Sider: DefineComponent<any, any, any>
|
|
127
|
-
export const Content: DefineComponent<any, any, any>
|
|
128
|
-
export const Footer: DefineComponent<any, any, any>
|
|
129
|
-
export const Container: DefineComponent<any, any, any>
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
declare module '@xto/layout/es/style.css' {
|
|
133
|
-
const content: string
|
|
134
|
-
export default content
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
declare module '@xto/business' {
|
|
138
|
-
import { DefineComponent } from 'vue'
|
|
139
|
-
export const LoginForm: DefineComponent<any, any, any>
|
|
140
|
-
export const RegisterForm: DefineComponent<any, any, any>
|
|
141
|
-
export const SearchResult: DefineComponent<any, any, any>
|
|
142
|
-
export const Comment: DefineComponent<any, any, any>
|
|
143
|
-
export const Statistic: DefineComponent<any, any, any>
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
declare module '@xto/business/es/style.css' {
|
|
147
|
-
const content: string
|
|
148
|
-
export default content
|
|
149
|
-
}
|
package/src/utils/auth.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token 管理
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { local } from './storage'
|
|
6
|
-
|
|
7
|
-
const TOKEN_KEY = 'token'
|
|
8
|
-
const REFRESH_TOKEN_KEY = 'refresh_token'
|
|
9
|
-
const TOKEN_EXPIRE_KEY = 'token_expire'
|
|
10
|
-
|
|
11
|
-
export interface TokenInfo {
|
|
12
|
-
token: string
|
|
13
|
-
refreshToken: string
|
|
14
|
-
expireTime: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const getToken = (): string | null => {
|
|
18
|
-
return local.get<string>(TOKEN_KEY)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const setToken = (token: string): void => {
|
|
22
|
-
local.set(TOKEN_KEY, token)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const getRefreshToken = (): string | null => {
|
|
26
|
-
return local.get<string>(REFRESH_TOKEN_KEY)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const setRefreshToken = (refreshToken: string): void => {
|
|
30
|
-
local.set(REFRESH_TOKEN_KEY, refreshToken)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const getTokenExpire = (): number | null => {
|
|
34
|
-
return local.get<number>(TOKEN_EXPIRE_KEY)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const setTokenExpire = (expireTime: number): void => {
|
|
38
|
-
local.set(TOKEN_EXPIRE_KEY, expireTime)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const setTokenInfo = (info: TokenInfo): void => {
|
|
42
|
-
setToken(info.token)
|
|
43
|
-
setRefreshToken(info.refreshToken)
|
|
44
|
-
setTokenExpire(info.expireTime)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const clearToken = (): void => {
|
|
48
|
-
local.remove(TOKEN_KEY)
|
|
49
|
-
local.remove(REFRESH_TOKEN_KEY)
|
|
50
|
-
local.remove(TOKEN_EXPIRE_KEY)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const isTokenExpired = (): boolean => {
|
|
54
|
-
const expireTime = getTokenExpire()
|
|
55
|
-
if (!expireTime) return true
|
|
56
|
-
return Date.now() > expireTime
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const hasToken = (): boolean => {
|
|
60
|
-
const token = getToken()
|
|
61
|
-
return !!token && !isTokenExpired()
|
|
62
|
-
}
|
package/src/utils/permission.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 权限工具函数
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useUserStore } from '@/stores/user'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 检查是否有权限
|
|
9
|
-
* @param permission 权限标识
|
|
10
|
-
*/
|
|
11
|
-
export function hasPermission(permission: string | string[]): boolean {
|
|
12
|
-
const userStore = useUserStore()
|
|
13
|
-
const permissions = userStore.permissions
|
|
14
|
-
|
|
15
|
-
if (Array.isArray(permission)) {
|
|
16
|
-
return permission.some(p => permissions.includes(p))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return permissions.includes(permission)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 检查是否有角色
|
|
24
|
-
* @param role 角色标识
|
|
25
|
-
*/
|
|
26
|
-
export function hasRole(role: string | string[]): boolean {
|
|
27
|
-
const userStore = useUserStore()
|
|
28
|
-
const roles = userStore.roles
|
|
29
|
-
|
|
30
|
-
if (Array.isArray(role)) {
|
|
31
|
-
return role.some(r => roles.includes(r))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return roles.includes(role)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 检查是否是管理员
|
|
39
|
-
*/
|
|
40
|
-
export function isAdmin(): boolean {
|
|
41
|
-
return hasRole('admin')
|
|
42
|
-
}
|
package/src/utils/request.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Axios 请求封装
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
|
6
|
-
import { getToken, clearToken } from './auth'
|
|
7
|
-
import { Message } from '@xto/feedback'
|
|
8
|
-
|
|
9
|
-
// 响应数据接口
|
|
10
|
-
export interface ApiResponse<T = unknown> {
|
|
11
|
-
code: number
|
|
12
|
-
data: T
|
|
13
|
-
message: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 分页参数
|
|
17
|
-
export interface PageParams {
|
|
18
|
-
page: number
|
|
19
|
-
pageSize: number
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 分页响应
|
|
23
|
-
export interface PageResponse<T> {
|
|
24
|
-
list: T[]
|
|
25
|
-
total: number
|
|
26
|
-
page: number
|
|
27
|
-
pageSize: number
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 创建 axios 实例
|
|
31
|
-
const createRequest = (): AxiosInstance => {
|
|
32
|
-
const instance = axios.create({
|
|
33
|
-
baseURL: import.meta.env.VITE_API_BASE_URL,
|
|
34
|
-
timeout: 15000,
|
|
35
|
-
headers: {
|
|
36
|
-
'Content-Type': 'application/json'
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
// 请求拦截器
|
|
41
|
-
instance.interceptors.request.use(
|
|
42
|
-
(config: InternalAxiosRequestConfig) => {
|
|
43
|
-
const token = getToken()
|
|
44
|
-
if (token) {
|
|
45
|
-
config.headers.Authorization = `Bearer ${token}`
|
|
46
|
-
}
|
|
47
|
-
return config
|
|
48
|
-
},
|
|
49
|
-
(error) => {
|
|
50
|
-
return Promise.reject(error)
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
// 响应拦截器
|
|
55
|
-
instance.interceptors.response.use(
|
|
56
|
-
(response: AxiosResponse<ApiResponse>) => {
|
|
57
|
-
const { data } = response
|
|
58
|
-
|
|
59
|
-
// 成功
|
|
60
|
-
if (data.code === 200 || data.code === 0) {
|
|
61
|
-
return response
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 业务错误
|
|
65
|
-
Message.error(data.message || '请求失败')
|
|
66
|
-
return Promise.reject(new Error(data.message || '请求失败'))
|
|
67
|
-
},
|
|
68
|
-
(error) => {
|
|
69
|
-
const { response } = error
|
|
70
|
-
|
|
71
|
-
if (response) {
|
|
72
|
-
switch (response.status) {
|
|
73
|
-
case 401:
|
|
74
|
-
Message.error('登录已过期,请重新登录')
|
|
75
|
-
clearToken()
|
|
76
|
-
window.location.href = '/login'
|
|
77
|
-
break
|
|
78
|
-
case 403:
|
|
79
|
-
Message.error('没有权限访问')
|
|
80
|
-
break
|
|
81
|
-
case 404:
|
|
82
|
-
Message.error('请求资源不存在')
|
|
83
|
-
break
|
|
84
|
-
case 500:
|
|
85
|
-
Message.error('服务器错误')
|
|
86
|
-
break
|
|
87
|
-
default:
|
|
88
|
-
Message.error(response.data?.message || '请求失败')
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
Message.error('网络连接失败')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return Promise.reject(error)
|
|
95
|
-
}
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
return instance
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const request = createRequest()
|
|
102
|
-
|
|
103
|
-
// 请求方法
|
|
104
|
-
export const http = {
|
|
105
|
-
get<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
|
|
106
|
-
return request.get(url, config).then((res) => res.data)
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
|
|
110
|
-
return request.post(url, data, config).then((res) => res.data)
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
|
|
114
|
-
return request.put(url, data, config).then((res) => res.data)
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
patch<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
|
|
118
|
-
return request.patch(url, data, config).then((res) => res.data)
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
delete<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
|
|
122
|
-
return request.delete(url, config).then((res) => res.data)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default request
|
package/src/utils/storage.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 本地存储封装
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const prefix = 'xto_'
|
|
6
|
-
|
|
7
|
-
interface StorageWrapper {
|
|
8
|
-
get<T>(key: string): T | null
|
|
9
|
-
set(key: string, value: unknown): void
|
|
10
|
-
remove(key: string): void
|
|
11
|
-
clear(): void
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const createStorage = (storage: globalThis.Storage): StorageWrapper => {
|
|
15
|
-
return {
|
|
16
|
-
get<T>(key: string): T | null {
|
|
17
|
-
const value = storage.getItem(prefix + key)
|
|
18
|
-
if (!value) return null
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(value) as T
|
|
21
|
-
} catch {
|
|
22
|
-
return value as unknown as T
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
set(key: string, value: unknown): void {
|
|
26
|
-
if (value === null || value === undefined) {
|
|
27
|
-
storage.removeItem(prefix + key)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
const stringValue = typeof value === 'string' ? value : JSON.stringify(value)
|
|
31
|
-
storage.setItem(prefix + key, stringValue)
|
|
32
|
-
},
|
|
33
|
-
remove(key: string): void {
|
|
34
|
-
storage.removeItem(prefix + key)
|
|
35
|
-
},
|
|
36
|
-
clear(): void {
|
|
37
|
-
const keys = Object.keys(storage)
|
|
38
|
-
keys.forEach(key => {
|
|
39
|
-
if (key.startsWith(prefix)) {
|
|
40
|
-
storage.removeItem(key)
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const localStorageUtil = createStorage(window.localStorage)
|
|
48
|
-
export const sessionStorageUtil = createStorage(window.sessionStorage)
|
|
49
|
-
|
|
50
|
-
// 快捷方法
|
|
51
|
-
export const local = {
|
|
52
|
-
get: localStorageUtil.get,
|
|
53
|
-
set: localStorageUtil.set,
|
|
54
|
-
remove: localStorageUtil.remove,
|
|
55
|
-
clear: localStorageUtil.clear
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const session = {
|
|
59
|
-
get: sessionStorageUtil.get,
|
|
60
|
-
set: sessionStorageUtil.set,
|
|
61
|
-
remove: sessionStorageUtil.remove,
|
|
62
|
-
clear: sessionStorageUtil.clear
|
|
63
|
-
}
|