@kevairy/template 0.1.2 → 0.1.4

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.
Files changed (95) hide show
  1. package/package.json +1 -1
  2. package/template/.env +4 -0
  3. package/template/.env.production +6 -0
  4. package/template/.prettierignore +2 -0
  5. package/template/_gitignore +4 -1
  6. package/template/package.json +10 -0
  7. package/template/scripts/gen-offline-icons.mjs +84 -0
  8. package/template/src/adapters/auth/index.ts +1 -1
  9. package/template/src/adapters/auth/types.ts +6 -1
  10. package/template/src/api/auth.ts +3 -2
  11. package/template/src/components/core/forms/art-wang-editor/index.vue +0 -5
  12. package/template/src/components/core/layouts/art-guide/index.vue +131 -0
  13. package/template/src/components/core/layouts/art-header-bar/index.vue +26 -26
  14. package/template/src/components/core/layouts/art-header-bar/widget/ArtUserMenu.vue +17 -1
  15. package/template/src/components/core/layouts/art-page-content/index.vue +8 -1
  16. package/template/src/components/core/layouts/art-screen-lock/index.vue +325 -0
  17. package/template/src/components/core/layouts/art-settings-panel/widget/SettingActions.vue +0 -1
  18. package/template/src/components/core/media/art-cutter-img/index.vue +0 -1
  19. package/template/src/components/core/media/art-video-player/index.vue +0 -10
  20. package/template/src/config/index.ts +8 -1
  21. package/template/src/config/modules/component.ts +14 -0
  22. package/template/src/config/modules/guide.ts +122 -0
  23. package/template/src/config/modules/headerBar.ts +4 -0
  24. package/template/src/config/setting.ts +2 -2
  25. package/template/src/directives/core/access.ts +125 -0
  26. package/template/src/directives/core/auth.ts +7 -62
  27. package/template/src/directives/core/roles.ts +5 -83
  28. package/template/src/env.d.ts +1 -0
  29. package/template/src/hooks/core/useAuth.ts +2 -74
  30. package/template/src/hooks/core/useGuide.ts +122 -0
  31. package/template/src/hooks/core/useHeaderBar.ts +6 -0
  32. package/template/src/hooks/core/usePermission.ts +41 -0
  33. package/template/src/hooks/index.ts +1 -0
  34. package/template/src/locales/index.ts +0 -1
  35. package/template/src/locales/langs/en.json +77 -6
  36. package/template/src/locales/langs/zh.json +77 -6
  37. package/template/src/main.ts +19 -9
  38. package/template/src/router/core/IframeRouteManager.ts +4 -2
  39. package/template/src/router/core/MenuProcessor.ts +5 -40
  40. package/template/src/router/core/RoutePermissionValidator.ts +6 -149
  41. package/template/src/router/core/access.ts +79 -0
  42. package/template/src/router/guards/afterEach.ts +6 -10
  43. package/template/src/router/guards/beforeEach.ts +143 -100
  44. package/template/src/router/guards/error.ts +42 -0
  45. package/template/src/router/index.ts +2 -0
  46. package/template/src/router/modules/examples.ts +4 -3
  47. package/template/src/router/routes/staticRoutes.ts +5 -3
  48. package/template/src/services/auth.ts +32 -10
  49. package/template/src/services/permission.ts +21 -0
  50. package/template/src/store/modules/lock.ts +125 -0
  51. package/template/src/store/modules/menu.ts +28 -8
  52. package/template/src/store/modules/setting.ts +8 -15
  53. package/template/src/store/modules/user.ts +73 -33
  54. package/template/src/store/modules/worktab.ts +1 -1
  55. package/template/src/types/api/api.d.ts +4 -1
  56. package/template/src/types/config/index.ts +9 -0
  57. package/template/src/types/directive/directive.d.ts +1 -0
  58. package/template/src/types/import/components.d.ts +2 -0
  59. package/template/src/types/router/index.ts +6 -0
  60. package/template/src/utils/http/contract.ts +51 -19
  61. package/template/src/utils/http/error.ts +73 -26
  62. package/template/src/utils/http/index.ts +160 -165
  63. package/template/src/utils/http/request-manager.ts +124 -0
  64. package/template/src/utils/http/status.ts +1 -0
  65. package/template/src/utils/permission/index.ts +66 -0
  66. package/template/src/utils/session.ts +24 -0
  67. package/template/src/utils/socket/index.ts +27 -2
  68. package/template/src/utils/storage/storage-config.ts +15 -0
  69. package/template/src/utils/storage/storage.ts +5 -3
  70. package/template/src/utils/sys/diagnostics.ts +180 -0
  71. package/template/src/utils/sys/error-handle.ts +56 -126
  72. package/template/src/utils/sys/mittBus.ts +5 -0
  73. package/template/src/utils/sys/recovery.ts +31 -0
  74. package/template/src/utils/ui/iconify-loader.ts +32 -18
  75. package/template/src/utils/ui/offline-icons.json +77 -0
  76. package/template/src/views/examples/permissions/index.vue +69 -13
  77. package/template/src/views/examples/search-table/index.vue +2 -3
  78. package/template/src/views/exception/403/index.vue +33 -0
  79. package/template/src/views/exception/500/index.vue +52 -10
  80. package/template/tests/e2e/auth.spec.ts +24 -6
  81. package/template/tests/e2e/helpers/guide.ts +9 -0
  82. package/template/tests/e2e/permissions.spec.ts +53 -0
  83. package/template/tests/e2e/search-table.spec.ts +2 -0
  84. package/template/tests/e2e/session-recovery.spec.ts +49 -0
  85. package/template/tests/unit/diagnostics/diagnostics.spec.ts +132 -0
  86. package/template/tests/unit/diagnostics/router.spec.ts +84 -0
  87. package/template/tests/unit/http/auth-lifecycle.spec.ts +203 -0
  88. package/template/tests/unit/http/contract.spec.ts +46 -0
  89. package/template/tests/unit/http/request.spec.ts +487 -0
  90. package/template/tests/unit/permissions/guard.spec.ts +261 -0
  91. package/template/tests/unit/permissions/guide.spec.ts +30 -0
  92. package/template/tests/unit/permissions/rules.spec.ts +106 -0
  93. package/template/tests/unit/permissions/state-and-directives.spec.ts +176 -0
  94. package/template/tests/unit/router/examples.spec.ts +5 -1
  95. package/template/vite.config.ts +8 -2
@@ -0,0 +1,125 @@
1
+ /**
2
+ * 锁屏状态管理模块
3
+ *
4
+ * 管理锁屏的锁定状态与「独立锁屏密码」。
5
+ *
6
+ * ## 主要功能
7
+ *
8
+ * - 锁定 / 解锁状态管理
9
+ * - 独立锁屏密码的设置与校验(与登录密码无关)
10
+ * - 密码以哈希形式本地存储,避免明文落盘
11
+ *
12
+ * ## 使用场景
13
+ *
14
+ * - 顶栏锁屏按钮触发锁定
15
+ * - 锁屏界面校验密码后解锁
16
+ * - 退出登录时解除锁定状态
17
+ *
18
+ * ## 持久化
19
+ *
20
+ * - 使用 localStorage 存储
21
+ * - 存储键:sys-v{version}-lock
22
+ * - 持久化 isLocked 与 passwordHash,刷新页面后仍保持锁定
23
+ *
24
+ * @module store/modules/lock
25
+ * @author Art Design Pro Team
26
+ */
27
+ import { defineStore } from 'pinia'
28
+ import { ref, computed } from 'vue'
29
+
30
+ /**
31
+ * 对锁屏密码做哈希,避免明文存储。
32
+ * 优先使用 Web Crypto 的 SHA-256;在不支持的安全上下文下降级为 FNV-1a。
33
+ * @param password 明文密码
34
+ * @returns 哈希字符串
35
+ */
36
+ async function hashPassword(password: string): Promise<string> {
37
+ try {
38
+ if (globalThis.crypto?.subtle) {
39
+ const data = new TextEncoder().encode(password)
40
+ const digest = await crypto.subtle.digest('SHA-256', data)
41
+ return Array.from(new Uint8Array(digest))
42
+ .map((byte) => byte.toString(16).padStart(2, '0'))
43
+ .join('')
44
+ }
45
+ } catch {
46
+ // 忽略异常,走降级方案
47
+ }
48
+
49
+ // 降级:FNV-1a 32 位哈希(仅用于不支持 Web Crypto 的环境)
50
+ let hash = 0x811c9dc5
51
+ for (let i = 0; i < password.length; i++) {
52
+ hash ^= password.charCodeAt(i)
53
+ hash = Math.imul(hash, 0x01000193) >>> 0
54
+ }
55
+ return `fnv-${hash.toString(16)}`
56
+ }
57
+
58
+ /**
59
+ * 锁屏状态管理
60
+ * 管理锁定状态与独立锁屏密码
61
+ */
62
+ export const useLockStore = defineStore(
63
+ 'lockStore',
64
+ () => {
65
+ /** 是否处于锁定状态 */
66
+ const isLocked = ref(false)
67
+ /** 锁屏密码哈希(独立于登录密码,仅本地存储) */
68
+ const passwordHash = ref('')
69
+
70
+ /** 是否已设置锁屏密码 */
71
+ const hasPassword = computed(() => Boolean(passwordHash.value))
72
+
73
+ /** 进入锁定状态 */
74
+ const lock = () => {
75
+ isLocked.value = true
76
+ }
77
+
78
+ /** 解除锁定状态(保留已设置的密码) */
79
+ const unlock = () => {
80
+ isLocked.value = false
81
+ }
82
+
83
+ /**
84
+ * 设置锁屏密码(存储哈希)
85
+ * @param password 明文密码
86
+ */
87
+ const setPassword = async (password: string) => {
88
+ passwordHash.value = await hashPassword(password)
89
+ }
90
+
91
+ /**
92
+ * 校验解锁密码是否正确
93
+ * @param password 待校验的明文密码
94
+ * @returns 是否匹配
95
+ */
96
+ const verifyPassword = async (password: string): Promise<boolean> => {
97
+ if (!passwordHash.value) return false
98
+ return (await hashPassword(password)) === passwordHash.value
99
+ }
100
+
101
+ /** 清空锁屏状态与密码 */
102
+ const reset = () => {
103
+ isLocked.value = false
104
+ passwordHash.value = ''
105
+ }
106
+
107
+ return {
108
+ isLocked,
109
+ passwordHash,
110
+ hasPassword,
111
+ lock,
112
+ unlock,
113
+ setPassword,
114
+ verifyPassword,
115
+ reset
116
+ }
117
+ },
118
+ {
119
+ persist: {
120
+ key: 'lock',
121
+ storage: localStorage,
122
+ pick: ['isLocked', 'passwordHash']
123
+ }
124
+ }
125
+ )
@@ -29,9 +29,11 @@
29
29
  * @author Art Design Pro Team
30
30
  */
31
31
  import { defineStore } from 'pinia'
32
- import { ref } from 'vue'
32
+ import { ref, shallowRef, computed } from 'vue'
33
33
  import { AppRouteRecord } from '@/types/router'
34
- import { getFirstMenuPath } from '@/utils'
34
+ import { useUserStore } from './user'
35
+ import AppConfig from '@/config'
36
+ import { filterAccessibleRoutes, firstAccessiblePath, canAccessRoute } from '@/router/core/access'
35
37
  import { HOME_PAGE_PATH } from '@/router'
36
38
 
37
39
  /**
@@ -40,9 +42,25 @@ import { HOME_PAGE_PATH } from '@/router'
40
42
  */
41
43
  export const useMenuStore = defineStore('menuStore', () => {
42
44
  /** 首页路径 */
43
- const homePath = ref(HOME_PAGE_PATH)
44
- /** 菜单列表 */
45
- const menuList = ref<AppRouteRecord[]>([])
45
+ const preferredHomePath = ref(HOME_PAGE_PATH)
46
+ // 只保存适配器返回的路由源,授权树随当前用户权限重新计算。
47
+ const routeList = shallowRef<AppRouteRecord[]>([])
48
+ const access = computed(() => {
49
+ const user = useUserStore()
50
+ return {
51
+ ready: user.permissionsReady,
52
+ permissions: user.permissions,
53
+ roles: user.roles,
54
+ wildcard: AppConfig.accessControl.wildcardPermission
55
+ }
56
+ })
57
+ const menuList = computed(() => filterAccessibleRoutes(routeList.value, access.value))
58
+ const homePath = computed(() => {
59
+ const preferred = preferredHomePath.value
60
+ if (preferred && preferred !== '/' && canAccessRoute(preferred, menuList.value, access.value))
61
+ return preferred
62
+ return firstAccessiblePath(menuList.value) || '/403'
63
+ })
46
64
  /** 菜单宽度 */
47
65
  const menuWidth = ref('')
48
66
  /** 存储路由移除函数的数组 */
@@ -53,8 +71,8 @@ export const useMenuStore = defineStore('menuStore', () => {
53
71
  * @param list 菜单路由记录数组
54
72
  */
55
73
  const setMenuList = (list: AppRouteRecord[]) => {
56
- menuList.value = list
57
- setHomePath(HOME_PAGE_PATH || getFirstMenuPath(list))
74
+ routeList.value = list
75
+ preferredHomePath.value = HOME_PAGE_PATH
58
76
  }
59
77
 
60
78
  /**
@@ -68,7 +86,7 @@ export const useMenuStore = defineStore('menuStore', () => {
68
86
  * @param path 主页路径
69
87
  */
70
88
  const setHomePath = (path: string) => {
71
- homePath.value = path
89
+ preferredHomePath.value = path
72
90
  }
73
91
 
74
92
  /**
@@ -96,7 +114,9 @@ export const useMenuStore = defineStore('menuStore', () => {
96
114
  }
97
115
 
98
116
  return {
117
+ homePath,
99
118
  menuList,
119
+ routeList,
100
120
  menuWidth,
101
121
  removeRouteFns,
102
122
  setMenuList,
@@ -82,8 +82,6 @@ export const useSettingStore = defineStore(
82
82
  const showLanguage = ref(SETTING_DEFAULT_CONFIG.showLanguage)
83
83
  /** 是否显示进度条 */
84
84
  const showNprogress = ref(SETTING_DEFAULT_CONFIG.showNprogress)
85
- /** 是否显示设置引导 */
86
- const showSettingGuide = ref(SETTING_DEFAULT_CONFIG.showSettingGuide)
87
85
  /** 是否显示节日文本 */
88
86
  const showFestivalText = ref(SETTING_DEFAULT_CONFIG.showFestivalText)
89
87
  /** 是否显示水印 */
@@ -100,6 +98,8 @@ export const useSettingStore = defineStore(
100
98
  const refresh = ref(SETTING_DEFAULT_CONFIG.refresh)
101
99
  /** 是否加载节日烟花 */
102
100
  const holidayFireworksLoaded = ref(SETTING_DEFAULT_CONFIG.holidayFireworksLoaded)
101
+ /** 新手引导是否已完成(控制首次自动播放) */
102
+ const hasCompletedGuide = ref(SETTING_DEFAULT_CONFIG.hasCompletedGuide)
103
103
 
104
104
  // 样式设置
105
105
  /** 边框模式 */
@@ -290,17 +290,11 @@ export const useSettingStore = defineStore(
290
290
  }
291
291
 
292
292
  /**
293
- * 隐藏设置引导
293
+ * 标记新手引导已完成
294
+ * 首次自动播放结束或用户手动关闭后调用,避免重复自动弹出
294
295
  */
295
- const hideSettingGuide = () => {
296
- showSettingGuide.value = false
297
- }
298
-
299
- /**
300
- * 显示设置引导
301
- */
302
- const openSettingGuide = () => {
303
- showSettingGuide.value = true
296
+ const completeGuide = () => {
297
+ hasCompletedGuide.value = true
304
298
  }
305
299
 
306
300
  /**
@@ -393,7 +387,7 @@ export const useSettingStore = defineStore(
393
387
  showLanguage,
394
388
  showNprogress,
395
389
  colorWeak,
396
- showSettingGuide,
390
+ hasCompletedGuide,
397
391
  pageTransition,
398
392
  tabStyle,
399
393
  menuOpen,
@@ -427,8 +421,7 @@ export const useSettingStore = defineStore(
427
421
  setLanguage,
428
422
  setNprogress,
429
423
  setColorWeak,
430
- hideSettingGuide,
431
- openSettingGuide,
424
+ completeGuide,
432
425
  setPageTransition,
433
426
  setTabStyle,
434
427
  setMenuOpen,
@@ -41,7 +41,15 @@ import { AppRouteRecord } from '@/types/router'
41
41
  import { setPageTitle } from '@/utils/router'
42
42
  import { resetRouterState } from '@/router/guards/beforeEach'
43
43
  import { useMenuStore } from './menu'
44
+ import { useLockStore } from './lock'
44
45
  import { StorageConfig } from '@/utils/storage/storage-config'
46
+ import { normalizeGrants } from '@/utils/permission'
47
+ import {
48
+ cancelAllPendingRequests,
49
+ closeSessionRequests,
50
+ invalidateSessionRequests
51
+ } from '@/utils/http/request-manager'
52
+ import { runSessionCleanups } from '@/utils/session'
45
53
 
46
54
  /**
47
55
  * 用户状态管理
@@ -54,8 +62,16 @@ export const useUserStore = defineStore(
54
62
  const language = ref(LanguageEnum.ZH)
55
63
  // 登录状态
56
64
  const isLogin = ref(false)
65
+ const isSigningOut = ref(false)
66
+ const sessionEpoch = ref(0)
57
67
  // 用户信息
58
68
  const info = ref<Partial<Api.Auth.UserInfo>>({})
69
+ // 不持久化授权和加载状态,刷新后必须重新获取。
70
+ const permissionsReady = ref(false)
71
+ const permissions = computed(() =>
72
+ normalizeGrants(info.value.permissions ?? info.value.buttons)
73
+ )
74
+ const roles = computed(() => normalizeGrants(info.value.roles))
59
75
  // 搜索历史记录
60
76
  const searchHistory = ref<AppRouteRecord[]>([])
61
77
  // 访问令牌
@@ -75,7 +91,14 @@ export const useUserStore = defineStore(
75
91
  * @param newInfo 新的用户信息
76
92
  */
77
93
  const setUserInfo = (newInfo: Api.Auth.UserInfo) => {
78
- info.value = newInfo
94
+ const grants = normalizeGrants(newInfo.permissions ?? newInfo.buttons)
95
+ info.value = {
96
+ ...newInfo,
97
+ permissions: grants,
98
+ buttons: grants,
99
+ roles: normalizeGrants(newInfo.roles)
100
+ }
101
+ permissionsReady.value = true
79
102
  }
80
103
 
81
104
  /**
@@ -109,12 +132,41 @@ export const useUserStore = defineStore(
109
132
  * @param newRefreshToken 刷新令牌(可选)
110
133
  */
111
134
  const setToken = (newAccessToken: string, newRefreshToken?: string) => {
135
+ if (newAccessToken !== accessToken.value) cancelAllPendingRequests()
112
136
  accessToken.value = newAccessToken
113
137
  refreshToken.value = newRefreshToken || ''
114
138
  }
115
139
 
116
- /** 建立已认证会话。 */
140
+ const resetSessionData = () => {
141
+ const currentUserId = info.value.userId
142
+ if (currentUserId !== undefined && currentUserId !== null) {
143
+ localStorage.setItem(StorageConfig.LAST_USER_ID_KEY, String(currentUserId))
144
+ }
145
+ sessionEpoch.value++
146
+ info.value = {}
147
+ permissionsReady.value = false
148
+ searchHistory.value = []
149
+ // 列表等待身份确认后恢复;页面实例、当前页和缓存排除表不跨会话。
150
+ const worktabs = useWorktabStore()
151
+ worktabs.current = {}
152
+ worktabs.keepAliveExclude = []
153
+ useMenuStore().setHomePath('')
154
+ useLockStore().reset()
155
+ resetRouterState(0)
156
+ runSessionCleanups()
157
+ }
158
+
159
+ const beginSignOut = () => {
160
+ closeSessionRequests()
161
+ isSigningOut.value = true
162
+ resetRouterState(0)
163
+ }
164
+
165
+ /** 建立已认证会话,直接切换账号也经过完整的缓存边界。 */
117
166
  const establishSession = (newAccessToken: string, newRefreshToken?: string) => {
167
+ invalidateSessionRequests()
168
+ resetSessionData()
169
+ isSigningOut.value = false
118
170
  setToken(newAccessToken, newRefreshToken)
119
171
  setLoginStatus(true)
120
172
  }
@@ -124,27 +176,15 @@ export const useUserStore = defineStore(
124
176
  * 如果是同一账号重新登录,保留工作台标签页
125
177
  */
126
178
  const clearAuthState = (redirectToLogin = true) => {
127
- // 保存当前用户 ID,用于下次登录时判断是否为同一用户
128
- const currentUserId = info.value.userId
129
- if (currentUserId) {
130
- localStorage.setItem(StorageConfig.LAST_USER_ID_KEY, String(currentUserId))
131
- }
132
-
133
- // 清空用户信息
134
- info.value = {}
179
+ invalidateSessionRequests()
180
+ resetSessionData()
181
+ isSigningOut.value = false
135
182
  // 重置登录状态
136
183
  isLogin.value = false
137
184
  // 清空访问令牌
138
185
  accessToken.value = ''
139
186
  // 清空刷新令牌
140
187
  refreshToken.value = ''
141
- // 注意:不清空工作台标签页,等下次登录时根据用户判断
142
- // 移除iframe路由缓存
143
- sessionStorage.removeItem('iframeRoutes')
144
- // 清空主页路径
145
- useMenuStore().setHomePath('')
146
- // 重置路由状态
147
- resetRouterState(500)
148
188
  if (!redirectToLogin) return
149
189
 
150
190
  // 跳转到登录页,携带当前路由作为 redirect 参数
@@ -168,29 +208,28 @@ export const useUserStore = defineStore(
168
208
  const lastUserId = localStorage.getItem(StorageConfig.LAST_USER_ID_KEY)
169
209
  const currentUserId = info.value.userId
170
210
 
171
- // 无法获取当前用户 ID,跳过检查
172
- if (!currentUserId) return
173
-
174
- // 首次登录或缓存已清除,保留现有标签页
175
- if (!lastUserId) {
176
- return
177
- }
178
-
179
- // 不同用户登录,清空工作台标签页
180
- if (String(currentUserId) !== lastUserId) {
181
- const worktabStore = useWorktabStore()
182
- worktabStore.opened = []
183
- worktabStore.keepAliveExclude = []
211
+ // 来源不明或不同账号的持久化标签不恢复;数字 0 也是有效 ID。
212
+ if (
213
+ currentUserId === undefined ||
214
+ currentUserId === null ||
215
+ lastUserId !== String(currentUserId)
216
+ ) {
217
+ useWorktabStore().clearAll()
184
218
  }
185
-
186
- // 清除临时存储
187
- localStorage.removeItem(StorageConfig.LAST_USER_ID_KEY)
219
+ if (currentUserId !== undefined && currentUserId !== null) {
220
+ localStorage.setItem(StorageConfig.LAST_USER_ID_KEY, String(currentUserId))
221
+ } else localStorage.removeItem(StorageConfig.LAST_USER_ID_KEY)
188
222
  }
189
223
 
190
224
  return {
191
225
  language,
192
226
  isLogin,
227
+ isSigningOut,
228
+ sessionEpoch,
193
229
  info,
230
+ permissionsReady,
231
+ permissions,
232
+ roles,
194
233
  searchHistory,
195
234
  accessToken,
196
235
  refreshToken,
@@ -203,6 +242,7 @@ export const useUserStore = defineStore(
203
242
  setSearchHistory,
204
243
  setToken,
205
244
  establishSession,
245
+ beginSignOut,
206
246
  clearAuthState,
207
247
  logOut,
208
248
  checkAndClearWorktabs
@@ -446,7 +446,7 @@ export const useWorktabStore = defineStore(
446
446
  path: tab.path,
447
447
  query: (tab.query as LocationQueryRaw) || undefined
448
448
  })
449
- return resolved.matched.length > 0
449
+ return resolved.matched.length > 0 && resolved.name !== 'Exception404'
450
450
  }
451
451
  return false
452
452
  } catch {
@@ -75,7 +75,10 @@ declare namespace Api {
75
75
 
76
76
  /** 用户信息 */
77
77
  interface UserInfo {
78
- buttons: string[]
78
+ /** 标准操作权限集合;显式空数组表示没有操作权限。 */
79
+ permissions?: string[]
80
+ /** 兼容旧认证适配器,仅在未提供 permissions 时作为输入。 */
81
+ buttons?: string[]
79
82
  roles: string[]
80
83
  userId: number | string
81
84
  userName: string
@@ -95,6 +95,10 @@ export interface AppNavigationConfig {
95
95
  titleTemplate: string
96
96
  }
97
97
 
98
+ export interface AppAccessControlConfig {
99
+ wildcardPermission: string | false
100
+ }
101
+
98
102
  export interface AppFeatureConfig {
99
103
  menuButton: boolean
100
104
  refreshButton: boolean
@@ -110,6 +114,8 @@ export interface AppFeatureConfig {
110
114
  chat: boolean
111
115
  watermark: boolean
112
116
  festivalEffects: boolean
117
+ screenLock: boolean
118
+ guide: boolean
113
119
  examples: boolean
114
120
  }
115
121
 
@@ -167,6 +173,7 @@ export interface FastEnterConfig {
167
173
  export interface SystemConfig {
168
174
  // 系统基础信息
169
175
  systemInfo: SystemBasicConfig
176
+ accessControl: AppAccessControlConfig
170
177
  navigation: AppNavigationConfig
171
178
  features: AppFeatureConfig
172
179
  storage: AppStorageConfig
@@ -250,4 +257,6 @@ export interface HeaderBarFeatureConfig {
250
257
  settings: FeatureConfigItem
251
258
  /** 主题切换 */
252
259
  themeToggle: FeatureConfigItem
260
+ /** 锁屏功能 */
261
+ screenLock: FeatureConfigItem
253
262
  }
@@ -8,6 +8,7 @@ import type {
8
8
  declare module 'vue' {
9
9
  export interface GlobalDirectives {
10
10
  vAuth: AuthDirective
11
+ vPermission: AuthDirective
11
12
  vRoles: RolesDirective
12
13
  vRipple: RippleDirective
13
14
  vHighlight: HighlightDirective
@@ -35,6 +35,7 @@ declare module 'vue' {
35
35
  ArtForm: typeof import('./../../components/core/forms/art-form/index.vue')['default']
36
36
  ArtGlobalComponent: typeof import('./../../components/core/layouts/art-global-component/index.vue')['default']
37
37
  ArtGlobalSearch: typeof import('./../../components/core/layouts/art-global-search/index.vue')['default']
38
+ ArtGuide: typeof import('./../../components/core/layouts/art-guide/index.vue')['default']
38
39
  ArtHBarChart: typeof import('./../../components/core/charts/art-h-bar-chart/index.vue')['default']
39
40
  ArtHeaderBar: typeof import('./../../components/core/layouts/art-header-bar/index.vue')['default']
40
41
  ArtHorizontalMenu: typeof import('./../../components/core/layouts/art-menus/art-horizontal-menu/index.vue')['default']
@@ -54,6 +55,7 @@ declare module 'vue' {
54
55
  ArtResultPage: typeof import('./../../components/core/views/result/ArtResultPage.vue')['default']
55
56
  ArtRingChart: typeof import('./../../components/core/charts/art-ring-chart/index.vue')['default']
56
57
  ArtScatterChart: typeof import('./../../components/core/charts/art-scatter-chart/index.vue')['default']
58
+ ArtScreenLock: typeof import('./../../components/core/layouts/art-screen-lock/index.vue')['default']
57
59
  ArtSettingsPanel: typeof import('./../../components/core/layouts/art-settings-panel/index.vue')['default']
58
60
  ArtSidebarMenu: typeof import('./../../components/core/layouts/art-menus/art-sidebar-menu/index.vue')['default']
59
61
  ArtStatsCard: typeof import('./../../components/core/cards/art-stats-card/index.vue')['default']
@@ -27,6 +27,8 @@ import { RouteRecordRaw } from 'vue-router'
27
27
  * 定义路由的各种配置属性
28
28
  */
29
29
  export interface RouteMeta extends Record<string | number | symbol, unknown> {
30
+ /** 静态路由是否要求认证;动态路由始终要求认证。 */
31
+ requiresAuth?: boolean
30
32
  /** 路由标题 */
31
33
  title: string
32
34
  /** 路由图标 */
@@ -54,6 +56,10 @@ export interface RouteMeta extends Record<string | number | symbol, unknown> {
54
56
  isFirstLevel?: boolean
55
57
  /** 角色权限 */
56
58
  roles?: string[]
59
+ /** 进入页面所需的操作权限,与 authList 的动作描述分离。 */
60
+ permissions?: string[]
61
+ /** permissions 默认满足任一项;all 表示全部满足。 */
62
+ permissionMode?: 'any' | 'all'
57
63
  /** 是否固定标签页 */
58
64
  fixedTab?: boolean
59
65
  /** 激活菜单路径 */
@@ -13,27 +13,59 @@ export function isApiSuccessCode(code: number): boolean {
13
13
  return code === 0 || code === ApiStatus.success
14
14
  }
15
15
 
16
+ /** 类型标签和 JSON 转义避免分隔符碰撞。非 JSON 数据不参与自动去重。 */
16
17
  export function stableSerialize(payload: unknown): string {
17
- if (payload === undefined || payload === null) return ''
18
- if (typeof payload !== 'object') return String(payload)
19
- if (payload instanceof FormData || payload instanceof Blob || payload instanceof ArrayBuffer) {
20
- return payload.constructor.name
18
+ const ancestors = new WeakSet<object>()
19
+ const encode = (value: unknown): unknown => {
20
+ if (value === null) return ['null']
21
+ if (value === undefined) return ['undefined']
22
+ if (typeof value === 'string' || typeof value === 'boolean') return [typeof value, value]
23
+ if (typeof value === 'number') return ['number', Object.is(value, -0) ? '-0' : String(value)]
24
+ if (typeof value !== 'object') throw new TypeError('Unsupported request-key value')
25
+ const prototype = Object.getPrototypeOf(value)
26
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
27
+ throw new TypeError('Only plain JSON data can be automatically deduplicated')
28
+ }
29
+ if (ancestors.has(value)) throw new TypeError('Circular request-key value')
30
+ ancestors.add(value)
31
+ try {
32
+ if (Array.isArray(value)) {
33
+ return [
34
+ 'array',
35
+ Array.from({ length: value.length }, (_, index) =>
36
+ Object.hasOwn(value, index) ? encode(value[index]) : ['hole']
37
+ )
38
+ ]
39
+ }
40
+ return [
41
+ 'object',
42
+ Object.keys(value)
43
+ .sort()
44
+ .map((key) => [key, encode((value as Record<string, unknown>)[key])])
45
+ ]
46
+ } finally {
47
+ ancestors.delete(value)
48
+ }
21
49
  }
22
-
23
- if (Array.isArray(payload)) return `[${payload.map(stableSerialize).join(',')}]`
24
-
25
- return `{${Object.entries(payload as Record<string, unknown>)
26
- .sort(([left], [right]) => left.localeCompare(right))
27
- .map(([key, value]) => `${key}:${stableSerialize(value)}`)
28
- .join(',')}}`
50
+ return JSON.stringify(encode(payload))
29
51
  }
30
52
 
31
- /** 为重复请求取消生成与对象属性顺序无关的稳定键。 */
32
- export function createRequestKey(config: AxiosRequestConfig): string {
33
- return [
34
- config.method?.toUpperCase() || 'GET',
35
- config.url || '',
36
- stableSerialize(config.params),
37
- stableSerialize(config.data)
38
- ].join('|')
53
+ /** 不支持可靠比较的数据返回 undefined,跳过去重但照常发送请求。 */
54
+ export function createRequestKey(config: AxiosRequestConfig): string | undefined {
55
+ if (config.paramsSerializer || config.transformRequest) return undefined
56
+ try {
57
+ return stableSerialize({
58
+ method: config.method?.toUpperCase() || 'GET',
59
+ baseURL: config.baseURL ?? '',
60
+ url: config.url ?? '',
61
+ params: config.params,
62
+ data: config.data,
63
+ responseType: config.responseType ?? 'json',
64
+ auth: config.auth,
65
+ withCredentials: config.withCredentials,
66
+ headers: config.headers
67
+ })
68
+ } catch {
69
+ return undefined
70
+ }
39
71
  }