xto-fronted 0.4.60 → 0.4.62

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/package.json CHANGED
@@ -1,86 +1,86 @@
1
- {
2
- "name": "xto-fronted",
3
- "version": "0.4.60",
4
- "private": false,
5
- "type": "module",
6
- "description": "XTO 前端应用框架",
7
- "main": "dist/index.umd.js",
8
- "module": "dist/index.es.js",
9
- "types": "dist/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/index.es.js",
13
- "require": "./dist/index.umd.js",
14
- "types": "./dist/index.d.ts"
15
- },
16
- "./style.css": "./dist/style.css",
17
- "./style.scss": "./src/style.scss"
18
- },
19
- "files": [
20
- "dist",
21
- "src",
22
- "public",
23
- "index.html",
24
- "vite.config.ts",
25
- "tsconfig.json",
26
- "tsconfig.node.json",
27
- ".env.development",
28
- ".env.production"
29
- ],
30
- "scripts": {
31
- "dev": "vite",
32
- "build": "vue-tsc && vite build",
33
- "build:lib": "vue-tsc && vite build --mode lib",
34
- "preview": "vite preview",
35
- "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix"
36
- },
37
- "peerDependencies": {
38
- "@xto/base": "^1.3.2",
39
- "@xto/business": "^1.1.0",
40
- "@xto/core": "^1.0.2",
41
- "@xto/data": "^1.1.1",
42
- "@xto/feedback": "^1.1.5",
43
- "@xto/form": "^1.1.2",
44
- "@xto/layout": "^1.0.6",
45
- "@xto/navigation": "^1.2.4",
46
- "axios": "^1.6.0",
47
- "pinia": "^2.1.0",
48
- "vue": "^3.4.0",
49
- "vue-router": "^4.3.0"
50
- },
51
- "devDependencies": {
52
- "@types/node": "^20.11.30",
53
- "@vitejs/plugin-vue": "^5.0.4",
54
- "@xto/base": "^1.3.2",
55
- "@xto/business": "^1.1.0",
56
- "@xto/core": "^1.0.2",
57
- "@xto/data": "^1.1.1",
58
- "@xto/feedback": "^1.1.5",
59
- "@xto/form": "^1.1.2",
60
- "@xto/layout": "^1.0.6",
61
- "@xto/navigation": "^1.2.4",
62
- "axios": "^1.6.8",
63
- "pinia": "^2.1.7",
64
- "sass": "^1.72.0",
65
- "sass-embedded": "^1.72.0",
66
- "typescript": "^5.4.2",
67
- "vite": "^5.2.0",
68
- "vite-plugin-dts": "^4.5.4",
69
- "vue": "^3.4.21",
70
- "vue-router": "^4.3.0",
71
- "vue-tsc": "^2.0.6"
72
- },
73
- "keywords": [
74
- "vue",
75
- "vue3",
76
- "admin",
77
- "template",
78
- "xto"
79
- ],
80
- "author": "",
81
- "license": "MIT",
82
- "repository": {
83
- "type": "git",
84
- "url": ""
85
- }
86
- }
1
+ {
2
+ "name": "xto-fronted",
3
+ "version": "0.4.62",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "XTO 前端应用框架",
7
+ "main": "dist/index.umd.js",
8
+ "module": "dist/index.es.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.umd.js",
14
+ "types": "./dist/index.d.ts"
15
+ },
16
+ "./style.css": "./dist/style.css",
17
+ "./style.scss": "./src/style.scss"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src",
22
+ "public",
23
+ "index.html",
24
+ "vite.config.ts",
25
+ "tsconfig.json",
26
+ "tsconfig.node.json",
27
+ ".env.development",
28
+ ".env.production"
29
+ ],
30
+ "peerDependencies": {
31
+ "@xto/base": "^1.3.2",
32
+ "@xto/business": "^1.1.0",
33
+ "@xto/core": "^1.0.2",
34
+ "@xto/data": "^1.1.1",
35
+ "@xto/feedback": "^1.1.5",
36
+ "@xto/form": "^1.1.2",
37
+ "@xto/layout": "^1.0.6",
38
+ "@xto/navigation": "^1.2.4",
39
+ "axios": "^1.6.0",
40
+ "pinia": "^2.1.0",
41
+ "vue": "^3.4.0",
42
+ "vue-router": "^4.3.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^20.11.30",
46
+ "@vitejs/plugin-vue": "^5.0.4",
47
+ "@xto/base": "^1.3.2",
48
+ "@xto/business": "^1.1.0",
49
+ "@xto/core": "^1.0.2",
50
+ "@xto/data": "^1.1.1",
51
+ "@xto/feedback": "^1.1.5",
52
+ "@xto/form": "^1.1.2",
53
+ "@xto/layout": "^1.0.6",
54
+ "@xto/navigation": "^1.2.4",
55
+ "axios": "^1.6.8",
56
+ "pinia": "^2.1.7",
57
+ "sass": "^1.72.0",
58
+ "sass-embedded": "^1.72.0",
59
+ "typescript": "^5.4.2",
60
+ "vite": "^5.2.0",
61
+ "vite-plugin-dts": "^4.5.4",
62
+ "vue": "^3.4.21",
63
+ "vue-router": "^4.3.0",
64
+ "vue-tsc": "^2.0.6"
65
+ },
66
+ "keywords": [
67
+ "vue",
68
+ "vue3",
69
+ "admin",
70
+ "template",
71
+ "xto"
72
+ ],
73
+ "author": "",
74
+ "license": "MIT",
75
+ "repository": {
76
+ "type": "git",
77
+ "url": ""
78
+ },
79
+ "scripts": {
80
+ "dev": "vite",
81
+ "build": "vue-tsc && vite build",
82
+ "build:lib": "vue-tsc && vite build --mode lib",
83
+ "preview": "vite preview",
84
+ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix"
85
+ }
86
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,42 @@
1
1
  // 样式
2
2
  import './style.scss'
3
3
 
4
+ // 配置
5
+ import { initAppConfig, getAppId, getClientId, getApiBaseUrl } from './utils/config'
6
+
7
+ // XtoConfig 类型定义
8
+ export interface XtoConfig {
9
+ appName?: string
10
+ appId?: string
11
+ clientId?: string
12
+ apiBaseUrl?: string
13
+ indexPath?: string
14
+ loginPath?: string
15
+ }
16
+
17
+ /**
18
+ * 初始化 XTO 应用
19
+ * 在项目入口文件中调用此函数设置应用配置
20
+ * @param config 应用配置
21
+ */
22
+ export function createXtoApp(config: Partial<XtoConfig>) {
23
+ initAppConfig({
24
+ appId: config.appId,
25
+ clientId: config.clientId,
26
+ apiBaseUrl: config.apiBaseUrl
27
+ })
28
+ return {
29
+ config: {
30
+ appName: config.appName || 'XTO App',
31
+ appId: getAppId(),
32
+ clientId: getClientId(),
33
+ apiBaseUrl: getApiBaseUrl(),
34
+ indexPath: config.indexPath || '/dashboard',
35
+ loginPath: config.loginPath || '/login'
36
+ }
37
+ }
38
+ }
39
+
4
40
  // 组件
5
41
  export { default as Layout } from './components/Layout/index.vue'
6
42
  export { default as Header } from './components/Layout/Header.vue'
@@ -1,173 +1,173 @@
1
- /**
2
- * 动态路由模板
3
- */
4
-
5
- import type { RouteRecordRaw } from 'vue-router'
6
-
7
- // 布局路由(包含默认子路由和 catch-all 404)
8
- export const layoutRoute: RouteRecordRaw = {
9
- path: '/',
10
- name: 'Layout',
11
- component: () => import('@/components/Layout/index.vue'),
12
- redirect: '/dashboard',
13
- children: [
14
- {
15
- path: '/dashboard',
16
- name: 'Dashboard',
17
- component: () => import('@/views/dashboard/index.vue'),
18
- meta: {
19
- title: '仪表盘',
20
- icon: 'dashboard',
21
- keepAlive: true,
22
- affix: true
23
- }
24
- },
25
- {
26
- path: '/system/user',
27
- name: 'SystemUser',
28
- component: () => import('@/views/system/user/index.vue'),
29
- meta: {
30
- title: '用户管理',
31
- icon: 'user',
32
- keepAlive: true
33
- }
34
- },
35
- {
36
- path: '/system/role',
37
- name: 'SystemRole',
38
- component: () => import('@/views/system/role/index.vue'),
39
- meta: {
40
- title: '角色管理',
41
- icon: 'role',
42
- keepAlive: true
43
- }
44
- },
45
- {
46
- path: '/system/menu',
47
- name: 'SystemMenu',
48
- component: () => import('@/views/system/menu/index.vue'),
49
- meta: {
50
- title: '菜单管理',
51
- icon: 'menu',
52
- keepAlive: true
53
- }
54
- },
55
- // catch-all 路由:让 404 在 Layout 内部渲染,保持左侧菜单显示
56
- {
57
- path: '/:pathMatch(.*)*',
58
- name: 'CatchAll',
59
- component: () => import('@/views/error/404.vue'),
60
- meta: {
61
- title: '404',
62
- hidden: true
63
- }
64
- }
65
- ]
66
- }
67
-
68
- // 默认路由(用于开发,后续由后端返回)
69
- export const defaultDynamicRoutes: RouteRecordRaw[] = [
70
- {
71
- path: '/dashboard',
72
- name: 'Dashboard',
73
- component: () => import('@/views/dashboard/index.vue'),
74
- meta: {
75
- title: '仪表盘',
76
- icon: 'dashboard',
77
- keepAlive: true,
78
- affix: true
79
- }
80
- },
81
- {
82
- path: '/system',
83
- name: 'System',
84
- redirect: '/system/user',
85
- meta: {
86
- title: '系统管理',
87
- icon: 'setting'
88
- },
89
- children: [
90
- {
91
- path: 'user',
92
- name: 'SystemUser',
93
- component: () => import('@/views/system/user/index.vue'),
94
- meta: {
95
- title: '用户管理',
96
- icon: 'user',
97
- keepAlive: true
98
- }
99
- },
100
- {
101
- path: 'role',
102
- name: 'SystemRole',
103
- component: () => import('@/views/system/role/index.vue'),
104
- meta: {
105
- title: '角色管理',
106
- icon: 'role',
107
- keepAlive: true
108
- }
109
- },
110
- {
111
- path: 'menu',
112
- name: 'SystemMenu',
113
- component: () => import('@/views/system/menu/index.vue'),
114
- meta: {
115
- title: '菜单管理',
116
- icon: 'menu',
117
- keepAlive: true
118
- }
119
- }
120
- ]
121
- }
122
- ]
123
-
124
- // Mock 菜单数据(参考 tineco-ui 格式)
125
- export const mockMenuData = [
126
- {
127
- menuCode: 'dashboard',
128
- menuName: '仪表盘',
129
- menuUrl: '/dashboard',
130
- icon: 'dashboard',
131
- closable: true,
132
- isDefault: true,
133
- isOut: false
134
- },
135
- {
136
- menuCode: 'system',
137
- menuName: '系统管理',
138
- menuUrl: '/system',
139
- icon: 'setting',
140
- closable: false,
141
- isDefault: false,
142
- isOut: false,
143
- children: [
144
- {
145
- menuCode: 'system_user',
146
- menuName: '用户管理',
147
- menuUrl: '/system/user',
148
- icon: 'user',
149
- closable: true,
150
- isDefault: false,
151
- isOut: false
152
- },
153
- {
154
- menuCode: 'system_role',
155
- menuName: '角色管理',
156
- menuUrl: '/system/role',
157
- icon: 'role',
158
- closable: true,
159
- isDefault: false,
160
- isOut: false
161
- },
162
- {
163
- menuCode: 'system_menu',
164
- menuName: '菜单管理',
165
- menuUrl: '/system/menu',
166
- icon: 'menu',
167
- closable: true,
168
- isDefault: false,
169
- isOut: false
170
- }
171
- ]
172
- }
1
+ /**
2
+ * 动态路由模板
3
+ */
4
+
5
+ import type { RouteRecordRaw } from 'vue-router'
6
+
7
+ // 布局路由(包含默认子路由和 catch-all 404)
8
+ export const layoutRoute: RouteRecordRaw = {
9
+ path: '/',
10
+ name: 'Layout',
11
+ component: () => import('@/components/Layout/index.vue'),
12
+ redirect: '/dashboard',
13
+ children: [
14
+ {
15
+ path: '/dashboard',
16
+ name: 'Dashboard',
17
+ component: () => import('@/views/dashboard/index.vue'),
18
+ meta: {
19
+ title: '仪表盘',
20
+ icon: 'dashboard',
21
+ keepAlive: true,
22
+ affix: true
23
+ }
24
+ },
25
+ {
26
+ path: '/system/user',
27
+ name: 'SystemUser',
28
+ component: () => import('@/views/system/user/index.vue'),
29
+ meta: {
30
+ title: '用户管理',
31
+ icon: 'user',
32
+ keepAlive: true
33
+ }
34
+ },
35
+ {
36
+ path: '/system/role',
37
+ name: 'SystemRole',
38
+ component: () => import('@/views/system/role/index.vue'),
39
+ meta: {
40
+ title: '角色管理',
41
+ icon: 'role',
42
+ keepAlive: true
43
+ }
44
+ },
45
+ {
46
+ path: '/system/menu',
47
+ name: 'SystemMenu',
48
+ component: () => import('@/views/system/menu/index.vue'),
49
+ meta: {
50
+ title: '菜单管理',
51
+ icon: 'menu',
52
+ keepAlive: true
53
+ }
54
+ },
55
+ // catch-all 路由:让 404 在 Layout 内部渲染,保持左侧菜单显示
56
+ {
57
+ path: '/:pathMatch(.*)*',
58
+ name: 'CatchAll',
59
+ component: () => import('@/views/error/404.vue'),
60
+ meta: {
61
+ title: '404',
62
+ hidden: true
63
+ }
64
+ }
65
+ ]
66
+ }
67
+
68
+ // 默认路由(用于开发,后续由后端返回)
69
+ export const defaultDynamicRoutes: RouteRecordRaw[] = [
70
+ {
71
+ path: '/dashboard',
72
+ name: 'Dashboard',
73
+ component: () => import('@/views/dashboard/index.vue'),
74
+ meta: {
75
+ title: '仪表盘',
76
+ icon: 'dashboard',
77
+ keepAlive: true,
78
+ affix: true
79
+ }
80
+ },
81
+ {
82
+ path: '/system',
83
+ name: 'System',
84
+ redirect: '/system/user',
85
+ meta: {
86
+ title: '系统管理',
87
+ icon: 'setting'
88
+ },
89
+ children: [
90
+ {
91
+ path: 'user',
92
+ name: 'SystemUser',
93
+ component: () => import('@/views/system/user/index.vue'),
94
+ meta: {
95
+ title: '用户管理',
96
+ icon: 'user',
97
+ keepAlive: true
98
+ }
99
+ },
100
+ {
101
+ path: 'role',
102
+ name: 'SystemRole',
103
+ component: () => import('@/views/system/role/index.vue'),
104
+ meta: {
105
+ title: '角色管理',
106
+ icon: 'role',
107
+ keepAlive: true
108
+ }
109
+ },
110
+ {
111
+ path: 'menu',
112
+ name: 'SystemMenu',
113
+ component: () => import('@/views/system/menu/index.vue'),
114
+ meta: {
115
+ title: '菜单管理',
116
+ icon: 'menu',
117
+ keepAlive: true
118
+ }
119
+ }
120
+ ]
121
+ }
122
+ ]
123
+
124
+ // Mock 菜单数据(参考 tineco-ui 格式)
125
+ export const mockMenuData = [
126
+ {
127
+ menuCode: 'dashboard',
128
+ menuName: '仪表盘',
129
+ menuUrl: '/dashboard',
130
+ icon: 'dashboard',
131
+ closable: true,
132
+ isDefault: true,
133
+ isOut: false
134
+ },
135
+ {
136
+ menuCode: 'system',
137
+ menuName: '系统管理',
138
+ menuUrl: '/system',
139
+ icon: 'setting',
140
+ closable: false,
141
+ isDefault: false,
142
+ isOut: false,
143
+ children: [
144
+ {
145
+ menuCode: 'system_user',
146
+ menuName: '用户管理',
147
+ menuUrl: '/system/user',
148
+ icon: 'user',
149
+ closable: true,
150
+ isDefault: false,
151
+ isOut: false
152
+ },
153
+ {
154
+ menuCode: 'system_role',
155
+ menuName: '角色管理',
156
+ menuUrl: '/system/role',
157
+ icon: 'role',
158
+ closable: true,
159
+ isDefault: false,
160
+ isOut: false
161
+ },
162
+ {
163
+ menuCode: 'system_menu',
164
+ menuName: '菜单管理',
165
+ menuUrl: '/system/menu',
166
+ icon: 'menu',
167
+ closable: true,
168
+ isDefault: false,
169
+ isOut: false
170
+ }
171
+ ]
172
+ }
173
173
  ]
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { Router } from 'vue-router'
6
- import { getToken } from '@/utils/auth'
6
+ import { getToken, clearToken } from '@/utils/auth'
7
7
  import { useUserStore } from '@/stores/user'
8
8
  import { useMenuStore } from '@/stores/menu'
9
9
  import { useAppStore } from '@/stores/app'
@@ -99,14 +99,12 @@ export function setupRouterGuards(router: Router, options: RouterGuardOptions =
99
99
  // 重新导航到目标路由,确保动态路由已添加
100
100
  next({ ...to, replace: true })
101
101
  } catch (error) {
102
- // 获取用户信息失败,清除 token 并跳转到登录页
102
+ // 获取用户信息失败,清除所有 token 相关数据并跳转到登录页
103
103
  console.error('获取用户信息失败:', error)
104
104
  userStore.clearUserInfo()
105
105
  menuStore.clearMenu()
106
- // 清除 token
107
- localStorage.removeItem('token')
108
- localStorage.removeItem('token_type')
109
- localStorage.removeItem('refresh_token')
106
+ // 使用 clearToken 清除所有 token 相关数据(包括 expires_time、refresh_time 等)
107
+ clearToken()
110
108
  next({ path: loginPath, query: { redirect: to.fullPath } })
111
109
  }
112
110
  }