@kevairy/template 0.1.3 → 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 (67) hide show
  1. package/package.json +1 -1
  2. package/template/.env +2 -2
  3. package/template/.env.production +6 -0
  4. package/template/src/adapters/auth/index.ts +1 -1
  5. package/template/src/adapters/auth/types.ts +6 -1
  6. package/template/src/api/auth.ts +3 -2
  7. package/template/src/components/core/layouts/art-guide/index.vue +9 -1
  8. package/template/src/components/core/layouts/art-page-content/index.vue +8 -1
  9. package/template/src/config/index.ts +4 -0
  10. package/template/src/directives/core/access.ts +125 -0
  11. package/template/src/directives/core/auth.ts +7 -62
  12. package/template/src/directives/core/roles.ts +5 -83
  13. package/template/src/env.d.ts +1 -0
  14. package/template/src/hooks/core/useAuth.ts +2 -74
  15. package/template/src/hooks/core/useGuide.ts +6 -0
  16. package/template/src/hooks/core/usePermission.ts +41 -0
  17. package/template/src/hooks/index.ts +1 -0
  18. package/template/src/locales/langs/en.json +11 -1
  19. package/template/src/locales/langs/zh.json +11 -1
  20. package/template/src/main.ts +18 -10
  21. package/template/src/router/core/IframeRouteManager.ts +4 -2
  22. package/template/src/router/core/MenuProcessor.ts +5 -40
  23. package/template/src/router/core/RoutePermissionValidator.ts +6 -149
  24. package/template/src/router/core/access.ts +79 -0
  25. package/template/src/router/guards/afterEach.ts +6 -10
  26. package/template/src/router/guards/beforeEach.ts +143 -100
  27. package/template/src/router/guards/error.ts +42 -0
  28. package/template/src/router/index.ts +2 -0
  29. package/template/src/router/modules/examples.ts +4 -3
  30. package/template/src/router/routes/staticRoutes.ts +5 -3
  31. package/template/src/services/auth.ts +32 -10
  32. package/template/src/services/permission.ts +21 -0
  33. package/template/src/store/modules/menu.ts +28 -8
  34. package/template/src/store/modules/user.ts +72 -35
  35. package/template/src/store/modules/worktab.ts +1 -1
  36. package/template/src/types/api/api.d.ts +4 -1
  37. package/template/src/types/config/index.ts +5 -0
  38. package/template/src/types/directive/directive.d.ts +1 -0
  39. package/template/src/types/router/index.ts +6 -0
  40. package/template/src/utils/http/contract.ts +51 -19
  41. package/template/src/utils/http/error.ts +73 -26
  42. package/template/src/utils/http/index.ts +160 -167
  43. package/template/src/utils/http/request-manager.ts +124 -0
  44. package/template/src/utils/http/status.ts +1 -0
  45. package/template/src/utils/permission/index.ts +66 -0
  46. package/template/src/utils/session.ts +24 -0
  47. package/template/src/utils/storage/storage-config.ts +15 -0
  48. package/template/src/utils/storage/storage.ts +5 -3
  49. package/template/src/utils/sys/diagnostics.ts +180 -0
  50. package/template/src/utils/sys/error-handle.ts +56 -126
  51. package/template/src/utils/sys/recovery.ts +31 -0
  52. package/template/src/views/examples/permissions/index.vue +69 -13
  53. package/template/src/views/exception/403/index.vue +33 -0
  54. package/template/src/views/exception/500/index.vue +52 -10
  55. package/template/tests/e2e/permissions.spec.ts +53 -0
  56. package/template/tests/e2e/session-recovery.spec.ts +49 -0
  57. package/template/tests/unit/diagnostics/diagnostics.spec.ts +132 -0
  58. package/template/tests/unit/diagnostics/router.spec.ts +84 -0
  59. package/template/tests/unit/http/auth-lifecycle.spec.ts +203 -0
  60. package/template/tests/unit/http/contract.spec.ts +46 -0
  61. package/template/tests/unit/http/request.spec.ts +487 -0
  62. package/template/tests/unit/permissions/guard.spec.ts +261 -0
  63. package/template/tests/unit/permissions/guide.spec.ts +30 -0
  64. package/template/tests/unit/permissions/rules.spec.ts +106 -0
  65. package/template/tests/unit/permissions/state-and-directives.spec.ts +176 -0
  66. package/template/tests/unit/router/examples.spec.ts +5 -1
  67. package/template/vite.config.ts +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevairy/template",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Project template consumed by @kevairy/cli",
5
5
  "keywords": [
6
6
  "vue",
package/template/.env CHANGED
@@ -18,8 +18,8 @@ VITE_WITH_CREDENTIALS = false
18
18
  # Authorization 头前缀;接入业务后端时可按约定设置为 Bearer 等值。
19
19
  VITE_AUTH_SCHEME =
20
20
 
21
- # 网络类错误(超时/5xx)的最大重试次数,默认 0(不重试)。
22
- # 注意:POST 等非幂等请求重试有重复提交风险,开启前请确认后端幂等性。
21
+ # GET/HEAD 在网络故障、超时或指定 HTTP 5xx 下的额外重试次数,默认 0。
22
+ # 写请求默认不重试;确认后端幂等后,按单请求 retry.allowUnsafe 显式开启。
23
23
  VITE_HTTP_MAX_RETRIES = 0
24
24
 
25
25
  # 是否打开路由信息
@@ -5,3 +5,9 @@ VITE_BASE_URL = /
5
5
 
6
6
  # API 地址前缀
7
7
  VITE_API_URL = /api/
8
+
9
+ # CI 可注入 Git SHA / 发布编号;留空时自动使用构建时间。
10
+ VITE_BUILD_ID =
11
+
12
+ # true 生成 hidden sourcemap;上传诊断平台后必须从静态部署目录删除 .map 文件。
13
+ VITE_BUILD_SOURCEMAP = false
@@ -1,6 +1,6 @@
1
1
  import { mockAuthAdapter } from './mock'
2
2
 
3
- export type { AuthAdapter } from './types'
3
+ export type { AuthAdapter, LogoutContext } from './types'
4
4
 
5
5
  /**
6
6
  * 模板固定使用 Mock。项目迁移时只在项目分支替换此处注入的实现,
@@ -3,9 +3,14 @@
3
3
  *
4
4
  * 页面、Store 和路由守卫只依赖此契约;项目接口字段必须在适配器内部转换。
5
5
  */
6
+ export interface LogoutContext {
7
+ /** HTTP 退出请求必须透传此 scope,普通请求在退出期间会被取消。 */
8
+ requestScope: symbol
9
+ }
10
+
6
11
  export interface AuthAdapter {
7
12
  readonly name: string
8
13
  login(params: Api.Auth.LoginParams): Promise<Api.Auth.LoginResponse>
9
14
  getUserInfo(): Promise<Api.Auth.UserInfo>
10
- logout(): Promise<void>
15
+ logout(context?: LogoutContext): Promise<void>
11
16
  }
@@ -1,4 +1,5 @@
1
1
  import { authAdapter } from '@/adapters/auth'
2
+ import type { LogoutContext } from '@/adapters/auth'
2
3
 
3
4
  /**
4
5
  * 登录
@@ -18,6 +19,6 @@ export function fetchGetUserInfo() {
18
19
  }
19
20
 
20
21
  /** 退出当前账号 */
21
- export function fetchLogout() {
22
- return authAdapter.logout()
22
+ export function fetchLogout(context?: LogoutContext) {
23
+ return authAdapter.logout(context)
23
24
  }
@@ -6,6 +6,7 @@
6
6
  </template>
7
7
 
8
8
  <script setup lang="ts">
9
+ import { nextTick, onMounted, onUnmounted } from 'vue'
9
10
  import 'driver.js/dist/driver.css'
10
11
  import { useGuide } from '@/hooks/core/useGuide'
11
12
  import { useSettingStore } from '@/store/modules/setting'
@@ -16,6 +17,8 @@
16
17
 
17
18
  const settingStore = useSettingStore()
18
19
  const { start, destroy } = useGuide()
20
+ let startTimer: ReturnType<typeof setTimeout> | undefined
21
+ let unmounted = false
19
22
 
20
23
  onMounted(() => {
21
24
  // 用户菜单「新手引导」入口:手动重新播放
@@ -24,12 +27,17 @@
24
27
  // 首次进入且功能开启时自动播放;延迟等待顶栏各按钮渲染完成
25
28
  if (AppConfig.features.guide && !settingStore.hasCompletedGuide) {
26
29
  nextTick(() => {
27
- setTimeout(start, 600)
30
+ if (unmounted) return
31
+ startTimer = setTimeout(() => {
32
+ if (!settingStore.hasCompletedGuide) start()
33
+ }, 600)
28
34
  })
29
35
  }
30
36
  })
31
37
 
32
38
  onUnmounted(() => {
39
+ unmounted = true
40
+ clearTimeout(startTimer)
33
41
  mittBus.off('startGuide', start)
34
42
  destroy()
35
43
  })
@@ -14,7 +14,12 @@
14
14
  </div>
15
15
  </div>
16
16
 
17
- <RouterView v-if="isRefresh" v-slot="{ Component, route }" :style="contentStyle">
17
+ <RouterView
18
+ v-if="isRefresh"
19
+ :key="sessionEpoch"
20
+ v-slot="{ Component, route }"
21
+ :style="contentStyle"
22
+ >
18
23
  <!-- 缓存路由动画 -->
19
24
  <Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear>
20
25
  <KeepAlive :max="10" :exclude="keepAliveExclude">
@@ -53,6 +58,7 @@
53
58
  import { useAutoLayoutHeight } from '@/hooks/core/useLayoutHeight'
54
59
  import { useSettingStore } from '@/store/modules/setting'
55
60
  import { useWorktabStore } from '@/store/modules/worktab'
61
+ import { useUserStore } from '@/store/modules/user'
56
62
  import AppConfig from '@/config'
57
63
 
58
64
  defineOptions({ name: 'ArtPageContent' })
@@ -61,6 +67,7 @@
61
67
  const { containerMinHeight } = useAutoLayoutHeight()
62
68
  const { pageTransition, containerWidth, refresh } = storeToRefs(useSettingStore())
63
69
  const { keepAliveExclude } = storeToRefs(useWorktabStore())
70
+ const { sessionEpoch } = storeToRefs(useUserStore())
64
71
 
65
72
  const isRefresh = shallowRef(true)
66
73
  const isOpenRouteInfo = import.meta.env.VITE_OPEN_ROUTE_INFO
@@ -50,6 +50,10 @@ const appConfig: SystemConfig = {
50
50
  loginRouteName: 'Login',
51
51
  titleTemplate: '{page} - {app}'
52
52
  },
53
+ accessControl: {
54
+ // 设置为 false 可关闭超级权限通配符;不根据角色名称推断超级权限。
55
+ wildcardPermission: '*:*:*'
56
+ },
53
57
  features: {
54
58
  menuButton: true,
55
59
  refreshButton: true,
@@ -0,0 +1,125 @@
1
+ import {
2
+ shallowRef,
3
+ watchEffect,
4
+ type ObjectDirective,
5
+ type ShallowRef,
6
+ type WatchStopHandle
7
+ } from 'vue'
8
+ import { usePermission } from '@/hooks/core/usePermission'
9
+ import type { PermissionRequirement } from '@/utils/permission'
10
+
11
+ interface ElementState {
12
+ binding: ShallowRef<{ value: PermissionRequirement; disabled: boolean; all: boolean }>
13
+ stop: WatchStopHandle
14
+ restore: () => void
15
+ capture: () => void
16
+ }
17
+
18
+ /** 隐藏而非移除节点,权限恢复时 Vue 仍能管理、更新原节点。 */
19
+ export function createAccessDirective(
20
+ role = false
21
+ ): ObjectDirective<HTMLElement, PermissionRequirement> {
22
+ const states = new WeakMap<HTMLElement, ElementState>()
23
+ return {
24
+ beforeMount(el, binding) {
25
+ const permission = usePermission()
26
+ const original = {
27
+ display: el.style.display,
28
+ displayPriority: el.style.getPropertyPriority('display'),
29
+ disabled: el.getAttribute('disabled'),
30
+ ariaDisabled: el.getAttribute('aria-disabled'),
31
+ disabledClass: el.classList.contains('is-disabled'),
32
+ pointerEvents: el.style.pointerEvents
33
+ }
34
+ let applied = false
35
+ const current = shallowRef({
36
+ value: binding.value,
37
+ disabled: !!binding.modifiers.disabled,
38
+ all: !!binding.modifiers.all
39
+ })
40
+ const restore = () => {
41
+ if (!applied) return
42
+ el.style.setProperty('display', original.display, original.displayPriority)
43
+ el.style.pointerEvents = original.pointerEvents
44
+ if (original.disabled === null) el.removeAttribute('disabled')
45
+ else el.setAttribute('disabled', original.disabled)
46
+ if (original.ariaDisabled === null) el.removeAttribute('aria-disabled')
47
+ else el.setAttribute('aria-disabled', original.ariaDisabled)
48
+ el.classList.toggle('is-disabled', original.disabledClass)
49
+ applied = false
50
+ }
51
+ const allowed = () => {
52
+ const { value, all } = current.value
53
+ return role
54
+ ? all
55
+ ? permission.hasAllRoles(value)
56
+ : permission.hasRole(value)
57
+ : all
58
+ ? permission.hasAllPermissions(value)
59
+ : permission.hasPermission(value)
60
+ }
61
+ // disabled 属性只对原生表单元素生效,其他元素同时拦截鼠标和键盘激活。
62
+ const block = (event: Event) => {
63
+ if (event instanceof KeyboardEvent && !['Enter', ' '].includes(event.key)) return
64
+ if (!allowed()) {
65
+ event.preventDefault()
66
+ event.stopImmediatePropagation()
67
+ }
68
+ }
69
+ el.addEventListener('click', block, true)
70
+ el.addEventListener('keydown', block, true)
71
+ const stop = watchEffect(
72
+ () => {
73
+ restore()
74
+ if (allowed()) return
75
+ applied = true
76
+ if (current.value.disabled) {
77
+ el.setAttribute('disabled', '')
78
+ el.setAttribute('aria-disabled', 'true')
79
+ el.classList.add('is-disabled')
80
+ el.style.pointerEvents = 'none'
81
+ } else {
82
+ el.style.setProperty('display', 'none', 'important')
83
+ }
84
+ },
85
+ { flush: 'sync' }
86
+ )
87
+ states.set(el, {
88
+ binding: current,
89
+ restore,
90
+ capture: () => {
91
+ original.display = el.style.display
92
+ original.displayPriority = el.style.getPropertyPriority('display')
93
+ original.disabled = el.getAttribute('disabled')
94
+ original.ariaDisabled = el.getAttribute('aria-disabled')
95
+ original.disabledClass = el.classList.contains('is-disabled')
96
+ original.pointerEvents = el.style.pointerEvents
97
+ },
98
+ stop: () => {
99
+ stop()
100
+ el.removeEventListener('click', block, true)
101
+ el.removeEventListener('keydown', block, true)
102
+ restore()
103
+ }
104
+ })
105
+ },
106
+ beforeUpdate(el) {
107
+ states.get(el)?.restore()
108
+ },
109
+ updated(el, binding) {
110
+ const state = states.get(el)
111
+ if (state) {
112
+ state.capture()
113
+ state.binding.value = {
114
+ value: binding.value,
115
+ disabled: !!binding.modifiers.disabled,
116
+ all: !!binding.modifiers.all
117
+ }
118
+ }
119
+ },
120
+ unmounted(el) {
121
+ states.get(el)?.stop()
122
+ states.delete(el)
123
+ }
124
+ }
125
+ }
@@ -1,66 +1,11 @@
1
- /**
2
- * v-auth 权限指令
3
- *
4
- * 适用于后端权限控制模式,基于权限标识控制 DOM 元素的显示和隐藏。
5
- * 如果用户没有对应权限,元素将从 DOM 中移除。
6
- *
7
- * ## 主要功能
8
- *
9
- * - 权限验证 - 根据路由 meta 中的权限列表验证用户权限
10
- * - DOM 控制 - 无权限时自动移除元素,而非隐藏
11
- * - 响应式更新 - 权限变化时自动更新元素状态
12
- *
13
- * ## 使用示例
14
- *
15
- * ```vue
16
- * <!-- 只有拥有 'add' 权限的用户才能看到新增按钮 -->
17
- * <el-button v-auth="'add'">新增</el-button>
18
- *
19
- * <!-- 只有拥有 'edit' 权限的用户才能看到编辑按钮 -->
20
- * <el-button v-auth="'edit'">编辑</el-button>
21
- *
22
- * <!-- 只有拥有 'delete' 权限的用户才能看到删除按钮 -->
23
- * <el-button v-auth="'delete'">删除</el-button>
24
- * ```
25
- *
26
- * ## 注意事项
27
- *
28
- * - 该指令会直接移除 DOM 元素,而不是使用 v-if 隐藏
29
- * - 权限列表从当前路由的 meta.authList 中获取
30
- *
31
- * @module directives/auth
32
- * @author Art Design Pro Team
33
- */
1
+ import type { App, Directive } from 'vue'
2
+ import type { PermissionRequirement } from '@/utils/permission'
3
+ import { createAccessDirective } from './access'
34
4
 
35
- import { router } from '@/router'
36
- import { App, Directive, DirectiveBinding } from 'vue'
37
-
38
- export type AuthDirective = Directive<HTMLElement, string>
39
-
40
- function checkAuthPermission(el: HTMLElement, binding: DirectiveBinding<string>): void {
41
- // 获取当前路由的权限列表
42
- const authList = (router.currentRoute.value.meta.authList as Array<{ authMark: string }>) || []
43
-
44
- // 检查是否有对应的权限标识
45
- const hasPermission = authList.some((item) => item.authMark === binding.value)
46
-
47
- // 如果没有权限,移除元素
48
- if (!hasPermission) {
49
- removeElement(el)
50
- }
51
- }
52
-
53
- function removeElement(el: HTMLElement): void {
54
- if (el.parentNode) {
55
- el.parentNode.removeChild(el)
56
- }
57
- }
58
-
59
- const authDirective: AuthDirective = {
60
- mounted: checkAuthPermission,
61
- updated: checkAuthPermission
62
- }
5
+ export type AuthDirective = Directive<HTMLElement, PermissionRequirement>
63
6
 
7
+ /** v-permission 为标准入口,v-auth 保留兼容;支持 .all 与 .disabled。 */
64
8
  export function setupAuthDirective(app: App): void {
65
- app.directive('auth', authDirective)
9
+ app.directive('permission', createAccessDirective())
10
+ app.directive('auth', createAccessDirective())
66
11
  }
@@ -1,87 +1,9 @@
1
- /**
2
- * v-roles 角色权限指令
3
- *
4
- * 基于用户角色控制 DOM 元素的显示和隐藏。
5
- * 只要用户拥有指定角色中的任意一个,元素就会显示,否则从 DOM 中移除。
6
- *
7
- * ## 主要功能
8
- *
9
- * - 角色验证 - 检查用户是否拥有指定角色
10
- * - 多角色支持 - 支持单个角色或多个角色(满足其一即可)
11
- * - DOM 控制 - 无权限时自动移除元素,而非隐藏
12
- * - 响应式更新 - 角色变化时自动更新元素状态
13
- *
14
- * ## 使用示例
15
- *
16
- * ```vue
17
- * <template>
18
- * <!-- 单个角色 - 只有超级管理员可见 -->
19
- * <el-button v-roles="'R_SUPER'">超级管理员功能</el-button>
20
- *
21
- * <!-- 多个角色 - 超级管理员或普通管理员可见 -->
22
- * <el-button v-roles="['R_SUPER', 'R_ADMIN']">管理员功能</el-button>
23
- *
24
- * <!-- 应用到任意元素 -->
25
- * <div v-roles="['R_SUPER', 'R_ADMIN', 'R_USER']">
26
- * 所有登录用户可见的内容
27
- * </div>
28
- * </template>
29
- * ```
30
- *
31
- * ## 权限逻辑
32
- *
33
- * - 用户角色从 userStore.getUserInfo.roles 获取
34
- * - 只要用户拥有指定角色中的任意一个,元素就会显示
35
- * - 如果用户没有任何角色或不满足条件,元素将被移除
36
- *
37
- * ## 注意事项
38
- *
39
- * - 该指令会直接移除 DOM 元素,而不是使用 v-if 隐藏
40
- * - 适用于基于角色的粗粒度权限控制
41
- * - 如需基于具体操作的细粒度权限控制,请使用 v-auth 指令
42
- *
43
- * @module directives/roles
44
- * @author Art Design Pro Team
45
- */
1
+ import type { App, Directive } from 'vue'
2
+ import type { PermissionRequirement } from '@/utils/permission'
3
+ import { createAccessDirective } from './access'
46
4
 
47
- import { useUserStore } from '@/store/modules/user'
48
- import { App, Directive, DirectiveBinding } from 'vue'
49
-
50
- export type RolesDirective = Directive<HTMLElement, string | string[]>
51
-
52
- function checkRolePermission(el: HTMLElement, binding: DirectiveBinding<string | string[]>): void {
53
- const userStore = useUserStore()
54
- const userRoles = userStore.getUserInfo.roles
55
-
56
- // 如果用户角色为空或未定义,移除元素
57
- if (!userRoles?.length) {
58
- removeElement(el)
59
- return
60
- }
61
-
62
- // 确保指令值为数组格式
63
- const requiredRoles = Array.isArray(binding.value) ? binding.value : [binding.value]
64
-
65
- // 检查用户是否具有所需角色之一
66
- const hasPermission = requiredRoles.some((role: string) => userRoles.includes(role))
67
-
68
- // 如果没有权限,安全地移除元素
69
- if (!hasPermission) {
70
- removeElement(el)
71
- }
72
- }
73
-
74
- function removeElement(el: HTMLElement): void {
75
- if (el.parentNode) {
76
- el.parentNode.removeChild(el)
77
- }
78
- }
79
-
80
- const rolesDirective: RolesDirective = {
81
- mounted: checkRolePermission,
82
- updated: checkRolePermission
83
- }
5
+ export type RolesDirective = Directive<HTMLElement, PermissionRequirement>
84
6
 
85
7
  export function setupRolesDirective(app: App): void {
86
- app.directive('roles', rolesDirective)
8
+ app.directive('roles', createAccessDirective(true))
87
9
  }
@@ -30,3 +30,4 @@ declare module 'qrcode.vue' {
30
30
 
31
31
  // 全局变量声明
32
32
  declare const __APP_VERSION__: string // 版本号
33
+ declare const __BUILD_ID__: string // 每次构建的唯一标识,可由 CI 注入
@@ -1,74 +1,2 @@
1
- /**
2
- * useAuth - 权限验证管理
3
- *
4
- * 提供统一的权限验证功能,支持前端和后端两种权限模式。
5
- * 用于控制页面按钮、操作等功能的显示和访问权限。
6
- *
7
- * ## 主要功能
8
- *
9
- * 1. 权限检查 - 检查用户是否拥有指定的权限标识
10
- * 2. 双模式支持 - 自动适配前端模式和后端模式的权限验证
11
- * 3. 前端模式 - 从用户信息中获取按钮权限列表(如 ['add', 'edit', 'delete'])
12
- * 4. 后端模式 - 从路由 meta 配置中获取权限列表(如 [{ authMark: 'add' }])
13
- *
14
- * ## 使用示例
15
- *
16
- * ```typescript
17
- * const { hasAuth } = useAuth()
18
- *
19
- * // 检查是否有新增权限
20
- * if (hasAuth('add')) {
21
- * // 显示新增按钮
22
- * }
23
- *
24
- * // 在模板中使用
25
- * <el-button v-if="hasAuth('edit')">编辑</el-button>
26
- * <el-button v-if="hasAuth('delete')">删除</el-button>
27
- * ```
28
- *
29
- * @module useAuth
30
- * @author Art Design Pro Team
31
- */
32
-
33
- import { useRoute } from 'vue-router'
34
- import { storeToRefs } from 'pinia'
35
- import { useUserStore } from '@/store/modules/user'
36
- import { useAppMode } from '@/hooks/core/useAppMode'
37
- import type { AppRouteRecord } from '@/types/router'
38
-
39
- type AuthItem = NonNullable<AppRouteRecord['meta']['authList']>[number]
40
-
41
- const userStore = useUserStore()
42
-
43
- export const useAuth = () => {
44
- const route = useRoute()
45
- const { isFrontendMode } = useAppMode()
46
- const { info } = storeToRefs(userStore)
47
-
48
- // 前端按钮权限(例如:['add', 'edit'])
49
- const frontendAuthList = info.value?.buttons ?? []
50
-
51
- // 后端路由 meta 配置的权限列表(例如:[{ authMark: 'add' }])
52
- const backendAuthList: AuthItem[] = Array.isArray(route.meta.authList)
53
- ? (route.meta.authList as AuthItem[])
54
- : []
55
-
56
- /**
57
- * 检查是否拥有某权限标识(前后端模式通用)
58
- * @param auth 权限标识
59
- * @returns 是否有权限
60
- */
61
- const hasAuth = (auth: string): boolean => {
62
- // 前端模式
63
- if (isFrontendMode.value) {
64
- return frontendAuthList.includes(auth)
65
- }
66
-
67
- // 后端模式
68
- return backendAuthList.some((item) => item?.authMark === auth)
69
- }
70
-
71
- return {
72
- hasAuth
73
- }
74
- }
1
+ /** 兼容原有 hasAuth 调用;新页面优先使用 usePermission。 */
2
+ export { usePermission as useAuth } from './usePermission'
@@ -100,6 +100,12 @@ export function useGuide() {
100
100
  prevBtnText: t('guide.buttons.prev'),
101
101
  doneBtnText: t('guide.buttons.done'),
102
102
  closeBtnLabel: t('guide.buttons.close'),
103
+ // 欢迎步骤尚在动画中时,driver.js 可能不触发 onDestroyed。
104
+ // 用户主动结束引导时先记录完成,再执行无拦截的实例销毁。
105
+ onDestroyStarted: () => {
106
+ settingStore.completeGuide()
107
+ destroy()
108
+ },
103
109
  onDestroyed: () => {
104
110
  settingStore.completeGuide()
105
111
  driverInstance = null
@@ -0,0 +1,41 @@
1
+ import { computed } from 'vue'
2
+ import { useUserStore } from '@/store/modules/user'
3
+ import AppConfig from '@/config'
4
+ import {
5
+ matchesGrants,
6
+ warnInvalidRequirement,
7
+ type PermissionRequirement,
8
+ type PermissionMode
9
+ } from '@/utils/permission'
10
+
11
+ /** 所有 UI 权限入口共用此处,与菜单数据来源无关。 */
12
+ export function usePermission() {
13
+ const userStore = useUserStore()
14
+ const permissions = computed(() => userStore.permissions)
15
+ const roles = computed(() => userStore.roles)
16
+ const ready = computed(() => userStore.permissionsReady)
17
+ const check = (required: PermissionRequirement, mode: PermissionMode, role = false) => {
18
+ warnInvalidRequirement(required)
19
+ return (
20
+ ready.value &&
21
+ matchesGrants(
22
+ role ? roles.value : permissions.value,
23
+ required,
24
+ mode,
25
+ role ? false : AppConfig.accessControl.wildcardPermission
26
+ )
27
+ )
28
+ }
29
+
30
+ const hasPermission = (required: PermissionRequirement) => check(required, 'any')
31
+ return {
32
+ ready,
33
+ permissions,
34
+ roles,
35
+ hasPermission,
36
+ hasAuth: hasPermission,
37
+ hasAllPermissions: (required: PermissionRequirement) => check(required, 'all'),
38
+ hasRole: (required: PermissionRequirement) => check(required, 'any', true),
39
+ hasAllRoles: (required: PermissionRequirement) => check(required, 'all', true)
40
+ }
41
+ }
@@ -6,6 +6,7 @@ export { useAppMode } from './core/useAppMode'
6
6
 
7
7
  // 权限控制
8
8
  export { useAuth } from './core/useAuth'
9
+ export { usePermission } from './core/usePermission'
9
10
 
10
11
  // 表格列配置管理
11
12
  export { useTableColumns } from './core/useTableColumns'
@@ -255,7 +255,11 @@
255
255
  "403": "Sorry, you do not have permission to access this page",
256
256
  "404": "Sorry, the page you are trying to access does not exist",
257
257
  "500": "Sorry, there was an error on the server",
258
- "gohome": "Go Home"
258
+ "gohome": "Go Home",
259
+ "retryDescription": "The page could not be loaded. Retry initialization, or contact your administrator if the problem continues.",
260
+ "retry": "Retry loading",
261
+ "resourceFailure": "Page resources could not be loaded. A new version may have been deployed. Reload to fetch the latest resources.",
262
+ "reload": "Reload and retry"
259
263
  },
260
264
  "menus": {
261
265
  "login": {
@@ -340,5 +344,11 @@
340
344
  "zebra": "Zebra",
341
345
  "border": "Border",
342
346
  "headerBackground": "Header BG"
347
+ },
348
+ "access": {
349
+ "noAccessTitle": "No access assigned",
350
+ "noAccessDescription": "You are signed in. Ask an administrator to assign access, then check again.",
351
+ "checkAgain": "Check again",
352
+ "checking": "Checking…"
343
353
  }
344
354
  }
@@ -255,7 +255,11 @@
255
255
  "403": "抱歉,您无权访问该页面",
256
256
  "404": "抱歉,您访问的页面不存在",
257
257
  "500": "抱歉,服务器出错了",
258
- "gohome": "返回首页"
258
+ "gohome": "返回首页",
259
+ "retryDescription": "页面加载失败,可以重试初始化。若仍无法恢复,请联系管理员。",
260
+ "retry": "重新加载页面",
261
+ "resourceFailure": "页面资源加载失败,可能刚刚发布了新版本。刷新后将重新加载资源。",
262
+ "reload": "刷新并重试"
259
263
  },
260
264
  "menus": {
261
265
  "login": {
@@ -340,5 +344,11 @@
340
344
  "zebra": "斑马纹",
341
345
  "border": "边框",
342
346
  "headerBackground": "表头背景"
347
+ },
348
+ "access": {
349
+ "noAccessTitle": "尚未分配访问权限",
350
+ "noAccessDescription": "当前账号已登录,请联系管理员分配访问权限后重新检查。",
351
+ "checkAgain": "重新检查",
352
+ "checking": "正在检查…"
343
353
  }
344
354
  }