@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.
- package/package.json +1 -1
- package/template/.env +4 -0
- package/template/.env.production +6 -0
- package/template/.prettierignore +2 -0
- package/template/_gitignore +4 -1
- package/template/package.json +10 -0
- package/template/scripts/gen-offline-icons.mjs +84 -0
- package/template/src/adapters/auth/index.ts +1 -1
- package/template/src/adapters/auth/types.ts +6 -1
- package/template/src/api/auth.ts +3 -2
- package/template/src/components/core/forms/art-wang-editor/index.vue +0 -5
- package/template/src/components/core/layouts/art-guide/index.vue +131 -0
- package/template/src/components/core/layouts/art-header-bar/index.vue +26 -26
- package/template/src/components/core/layouts/art-header-bar/widget/ArtUserMenu.vue +17 -1
- package/template/src/components/core/layouts/art-page-content/index.vue +8 -1
- package/template/src/components/core/layouts/art-screen-lock/index.vue +325 -0
- package/template/src/components/core/layouts/art-settings-panel/widget/SettingActions.vue +0 -1
- package/template/src/components/core/media/art-cutter-img/index.vue +0 -1
- package/template/src/components/core/media/art-video-player/index.vue +0 -10
- package/template/src/config/index.ts +8 -1
- package/template/src/config/modules/component.ts +14 -0
- package/template/src/config/modules/guide.ts +122 -0
- package/template/src/config/modules/headerBar.ts +4 -0
- package/template/src/config/setting.ts +2 -2
- package/template/src/directives/core/access.ts +125 -0
- package/template/src/directives/core/auth.ts +7 -62
- package/template/src/directives/core/roles.ts +5 -83
- package/template/src/env.d.ts +1 -0
- package/template/src/hooks/core/useAuth.ts +2 -74
- package/template/src/hooks/core/useGuide.ts +122 -0
- package/template/src/hooks/core/useHeaderBar.ts +6 -0
- package/template/src/hooks/core/usePermission.ts +41 -0
- package/template/src/hooks/index.ts +1 -0
- package/template/src/locales/index.ts +0 -1
- package/template/src/locales/langs/en.json +77 -6
- package/template/src/locales/langs/zh.json +77 -6
- package/template/src/main.ts +19 -9
- package/template/src/router/core/IframeRouteManager.ts +4 -2
- package/template/src/router/core/MenuProcessor.ts +5 -40
- package/template/src/router/core/RoutePermissionValidator.ts +6 -149
- package/template/src/router/core/access.ts +79 -0
- package/template/src/router/guards/afterEach.ts +6 -10
- package/template/src/router/guards/beforeEach.ts +143 -100
- package/template/src/router/guards/error.ts +42 -0
- package/template/src/router/index.ts +2 -0
- package/template/src/router/modules/examples.ts +4 -3
- package/template/src/router/routes/staticRoutes.ts +5 -3
- package/template/src/services/auth.ts +32 -10
- package/template/src/services/permission.ts +21 -0
- package/template/src/store/modules/lock.ts +125 -0
- package/template/src/store/modules/menu.ts +28 -8
- package/template/src/store/modules/setting.ts +8 -15
- package/template/src/store/modules/user.ts +73 -33
- package/template/src/store/modules/worktab.ts +1 -1
- package/template/src/types/api/api.d.ts +4 -1
- package/template/src/types/config/index.ts +9 -0
- package/template/src/types/directive/directive.d.ts +1 -0
- package/template/src/types/import/components.d.ts +2 -0
- package/template/src/types/router/index.ts +6 -0
- package/template/src/utils/http/contract.ts +51 -19
- package/template/src/utils/http/error.ts +73 -26
- package/template/src/utils/http/index.ts +160 -165
- package/template/src/utils/http/request-manager.ts +124 -0
- package/template/src/utils/http/status.ts +1 -0
- package/template/src/utils/permission/index.ts +66 -0
- package/template/src/utils/session.ts +24 -0
- package/template/src/utils/socket/index.ts +27 -2
- package/template/src/utils/storage/storage-config.ts +15 -0
- package/template/src/utils/storage/storage.ts +5 -3
- package/template/src/utils/sys/diagnostics.ts +180 -0
- package/template/src/utils/sys/error-handle.ts +56 -126
- package/template/src/utils/sys/mittBus.ts +5 -0
- package/template/src/utils/sys/recovery.ts +31 -0
- package/template/src/utils/ui/iconify-loader.ts +32 -18
- package/template/src/utils/ui/offline-icons.json +77 -0
- package/template/src/views/examples/permissions/index.vue +69 -13
- package/template/src/views/examples/search-table/index.vue +2 -3
- package/template/src/views/exception/403/index.vue +33 -0
- package/template/src/views/exception/500/index.vue +52 -10
- package/template/tests/e2e/auth.spec.ts +24 -6
- package/template/tests/e2e/helpers/guide.ts +9 -0
- package/template/tests/e2e/permissions.spec.ts +53 -0
- package/template/tests/e2e/search-table.spec.ts +2 -0
- package/template/tests/e2e/session-recovery.spec.ts +49 -0
- package/template/tests/unit/diagnostics/diagnostics.spec.ts +132 -0
- package/template/tests/unit/diagnostics/router.spec.ts +84 -0
- package/template/tests/unit/http/auth-lifecycle.spec.ts +203 -0
- package/template/tests/unit/http/contract.spec.ts +46 -0
- package/template/tests/unit/http/request.spec.ts +487 -0
- package/template/tests/unit/permissions/guard.spec.ts +261 -0
- package/template/tests/unit/permissions/guide.spec.ts +30 -0
- package/template/tests/unit/permissions/rules.spec.ts +106 -0
- package/template/tests/unit/permissions/state-and-directives.spec.ts +176 -0
- package/template/tests/unit/router/examples.spec.ts +5 -1
- package/template/vite.config.ts +8 -2
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 离线图标加载器
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 内网 / 离线环境下,Iconify 无法从公共 CDN(api.iconify.design)拉取图标数据,会导致
|
|
5
|
+
* 图标空白。此模块在应用启动时预注册图标集数据,使 <ArtSvgIcon icon="ri:xxx" /> 等用法
|
|
6
|
+
* 完全离线可用。
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* 图标集策略(兼顾体积与覆盖):
|
|
9
|
+
* - ri(Remix Icon):全量注册。它是项目主力图标集,菜单 / 路由的动态图标名基本都来自它,
|
|
10
|
+
* 全量注册可让业务后续新增任意 ri 图标都开箱即用(约 1MB,gzip 后 ~280KB)。
|
|
11
|
+
* - 其余图标集:仅注册项目实际用到的图标(由 scripts/gen-offline-icons.mjs 精确提取,几 KB),
|
|
12
|
+
* 避免全量打包(如 fluent / solar 单集达 10MB+)。
|
|
13
|
+
*
|
|
14
|
+
* 新增“非 ri 图标集”图标的步骤:
|
|
15
|
+
* 1. 安装图标集:pnpm add -D @iconify-json/<prefix>
|
|
16
|
+
* 2. 重新生成精简数据:pnpm gen:icons
|
|
11
17
|
*
|
|
12
18
|
* @module utils/ui/iconify-loader
|
|
13
|
-
* @author Art Design Pro Team
|
|
14
19
|
*/
|
|
20
|
+
import { addCollection, type IconifyJSON } from '@iconify/vue'
|
|
15
21
|
|
|
16
|
-
//
|
|
22
|
+
// 主力图标集:全量数据
|
|
23
|
+
import riIcons from '@iconify-json/ri/icons.json'
|
|
24
|
+
// 其余图标集的精简数据(脚本生成,请勿手动编辑)
|
|
25
|
+
import offlineIcons from './offline-icons.json'
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
/** 幂等标记,避免重复注册 */
|
|
28
|
+
let registered = false
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
/**
|
|
31
|
+
* 注册离线图标集(幂等,重复调用只生效一次)
|
|
32
|
+
*/
|
|
33
|
+
export function setupOfflineIcons(): void {
|
|
34
|
+
if (registered) return
|
|
22
35
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
// import lineMd from '@iconify-json/line-md/icons.json'
|
|
36
|
+
// 主力图标集:全量注册,覆盖所有菜单动态图标与业务常用图标
|
|
37
|
+
addCollection(riIcons as unknown as IconifyJSON)
|
|
26
38
|
|
|
27
|
-
//
|
|
39
|
+
// 其余图标集:注册精确提取的子集
|
|
40
|
+
for (const collection of offlineIcons as unknown as IconifyJSON[]) {
|
|
41
|
+
addCollection(collection)
|
|
42
|
+
}
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// addCollection(lineMd)
|
|
44
|
+
registered = true
|
|
45
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"prefix": "fluent",
|
|
4
|
+
"icons": {
|
|
5
|
+
"arrow-enter-left-20-filled": {
|
|
6
|
+
"body": "<path fill=\"currentColor\" d=\"m4.641 12.5l2.873 2.704a.75.75 0 0 1-1.028 1.092l-4.25-4a.75.75 0 0 1 0-1.092l4.25-4a.75.75 0 1 1 1.028 1.092L4.641 11H14.75a1.75 1.75 0 0 0 1.75-1.75v-4.5a.75.75 0 0 1 1.5 0v4.5a3.25 3.25 0 0 1-3.25 3.25z\"/>"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"lastModified": 1790422098,
|
|
10
|
+
"width": 20,
|
|
11
|
+
"height": 20
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"prefix": "icon-park-outline",
|
|
15
|
+
"icons": {
|
|
16
|
+
"auto-width": {
|
|
17
|
+
"body": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M11.988 32L4 24.006L12 16m24.012 0L44 23.994L36 32M4 24h40\"/>"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"lastModified": 1754899616,
|
|
21
|
+
"width": 48,
|
|
22
|
+
"height": 48
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"prefix": "iconamoon",
|
|
26
|
+
"icons": {
|
|
27
|
+
"arrow-down-2-thin": {
|
|
28
|
+
"body": "<path fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"m7 10l5 5l5-5\"/>"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"lastModified": 1722794093,
|
|
32
|
+
"width": 24,
|
|
33
|
+
"height": 24
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"prefix": "ix",
|
|
37
|
+
"icons": {
|
|
38
|
+
"width": {
|
|
39
|
+
"body": "<path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M85.333 128H42.667v256h42.666V256l79.085 79.085l30.17-30.17l-27.582-27.582h178.017l-27.583 27.584l30.17 30.17l79.057-79.057V384h42.666V128h-42.666v127.973l-79.057-79.056l-30.17 30.17l27.58 27.58H167.006l27.582-27.582l-30.17-30.17l-79.085 79.084z\" clip-rule=\"evenodd\"/>"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"lastModified": 1790785405,
|
|
43
|
+
"width": 512,
|
|
44
|
+
"height": 512
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"prefix": "solar",
|
|
48
|
+
"icons": {
|
|
49
|
+
"double-alt-arrow-right-linear": {
|
|
50
|
+
"body": "<g fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"1.5\"><path d=\"M11 19L17 12L11 5\"/><path d=\"M7 19L13 12L7 5\"/></g>"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"lastModified": 1790422589,
|
|
54
|
+
"width": 24,
|
|
55
|
+
"height": 24
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"prefix": "system-uicons",
|
|
59
|
+
"icons": {
|
|
60
|
+
"inbox": {
|
|
61
|
+
"body": "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6.16 4.5h8.68a1 1 0 0 1 .92.606L18.5 11.5v4a2 2 0 0 1-2 2h-12a2 2 0 0 1-2-2v-4l2.74-6.394a1 1 0 0 1 .92-.606\"/><path d=\"M2.5 11.5h4a1 1 0 0 1 1 1v1a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h4\"/></g>"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"lastModified": 1754901428,
|
|
65
|
+
"width": 21,
|
|
66
|
+
"height": 21
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"prefix": "vaadin",
|
|
70
|
+
"icons": {
|
|
71
|
+
"ctrl-a": {
|
|
72
|
+
"body": "<path fill=\"currentColor\" d=\"M9 7V6H8V5H7v1h-.5v1H7v3.56a1.823 1.823 0 0 0 2.009 1.439L9 11a.9.9 0 0 1-.998-.495L8 7zm5-4h1v9h-1zm-1 3l-.085-.001c-.773 0-1.462.358-1.911.917L11 6.001h-1v6h1v-3a1.88 1.88 0 0 1 2.006-2l-.006-1zm-8.81 6C2.16 12 1 10.54 1 8s1.16-4 3.19-4h.029c.539 0 1.052.114 1.515.32l-.424.901a2.7 2.7 0 0 0-1.08-.22h-.042C2.38 5.001 2 6.631 2 8.001s.38 3 2.19 3c.497-.013.96-.145 1.366-.368l.444.898a3.94 3.94 0 0 1-1.806.47z\"/>"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"lastModified": 1722796111
|
|
76
|
+
}
|
|
77
|
+
]
|
|
@@ -4,13 +4,21 @@
|
|
|
4
4
|
<div>
|
|
5
5
|
<span>FOUNDATION / ACCESS CONTROL</span>
|
|
6
6
|
<h1 id="permission-title">权限演练场</h1>
|
|
7
|
-
<p
|
|
7
|
+
<p>路由、指令和组合式函数使用同一套用户授权,权限变化后立即更新。</p>
|
|
8
8
|
</div>
|
|
9
9
|
<div class="identity" aria-label="当前演示身份">
|
|
10
10
|
<ArtSvgIcon icon="ri:shield-user-line" aria-hidden="true" />
|
|
11
11
|
<div
|
|
12
12
|
><small>当前身份</small><strong>{{ userName }}</strong></div
|
|
13
13
|
>
|
|
14
|
+
<ElSelect v-if="isMock" v-model="demoProfile" aria-label="演示身份" style="width: 150px">
|
|
15
|
+
<ElOption
|
|
16
|
+
v-for="profile in profiles"
|
|
17
|
+
:key="profile.id"
|
|
18
|
+
:label="profile.name"
|
|
19
|
+
:value="profile.id"
|
|
20
|
+
/>
|
|
21
|
+
</ElSelect>
|
|
14
22
|
</div>
|
|
15
23
|
</section>
|
|
16
24
|
|
|
@@ -29,15 +37,24 @@
|
|
|
29
37
|
<div class="section-heading">
|
|
30
38
|
<div
|
|
31
39
|
><h2 id="operation-title">操作权限</h2
|
|
32
|
-
><p
|
|
40
|
+
><p>按钮根据用户授权显示或禁用;页面动作声明本身不会授予权限。</p></div
|
|
33
41
|
>
|
|
34
|
-
<ElTag
|
|
42
|
+
<ElTag effect="light">{{ availableCount }} 项可用</ElTag>
|
|
35
43
|
</div>
|
|
36
44
|
<div class="button-row">
|
|
37
|
-
<ElButton v-auth="'create'" type="primary" @click="notify('create')"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<ElButton v-
|
|
45
|
+
<ElButton v-auth="'example:resource:create'" type="primary" @click="notify('create')"
|
|
46
|
+
>新增资源</ElButton
|
|
47
|
+
>
|
|
48
|
+
<ElButton v-permission="'example:resource:edit'" @click="notify('edit')">编辑资源</ElButton>
|
|
49
|
+
<ElButton v-if="hasPermission('example:resource:export')" @click="notify('export')"
|
|
50
|
+
>导出数据</ElButton
|
|
51
|
+
>
|
|
52
|
+
<ElButton
|
|
53
|
+
v-permission.disabled="'example:resource:approve'"
|
|
54
|
+
type="warning"
|
|
55
|
+
@click="notify('approve')"
|
|
56
|
+
>审核资源</ElButton
|
|
57
|
+
>
|
|
41
58
|
</div>
|
|
42
59
|
<ElAlert title="安全提示" type="info" :closable="false" show-icon>
|
|
43
60
|
<template #default>前端权限只控制界面可见性,真实接口仍必须在服务端执行鉴权。</template>
|
|
@@ -48,7 +65,7 @@
|
|
|
48
65
|
<div class="section-heading"
|
|
49
66
|
><div
|
|
50
67
|
><h2 id="role-title">角色权限</h2
|
|
51
|
-
><p
|
|
68
|
+
><p>角色约束独立于操作权限;切换演示身份可观察区域的隐藏与恢复。</p></div
|
|
52
69
|
></div
|
|
53
70
|
>
|
|
54
71
|
<div class="role-cards">
|
|
@@ -60,7 +77,7 @@
|
|
|
60
77
|
<article v-roles="'R_AUDITOR'" class="role-card"><strong>审计员区域</strong></article>
|
|
61
78
|
<article class="role-card is-denied"
|
|
62
79
|
><ArtSvgIcon icon="ri:forbid-line" /><div
|
|
63
|
-
><strong>审计员区域</strong><p
|
|
80
|
+
><strong>审计员区域</strong><p>角色不匹配,受控区域会随当前角色更新。</p></div
|
|
64
81
|
></article
|
|
65
82
|
>
|
|
66
83
|
</div>
|
|
@@ -71,20 +88,58 @@
|
|
|
71
88
|
<script setup lang="ts">
|
|
72
89
|
import { ElMessage } from 'element-plus'
|
|
73
90
|
import { useUserStore } from '@/store/modules/user'
|
|
91
|
+
import { usePermission } from '@/hooks/core/usePermission'
|
|
92
|
+
import { authAdapter } from '@/adapters/auth'
|
|
74
93
|
defineOptions({ name: 'PermissionPlaygroundExample' })
|
|
75
94
|
const userStore = useUserStore()
|
|
76
95
|
const userName = computed(() => userStore.getUserInfo.userName || '模板管理员')
|
|
96
|
+
const { hasPermission } = usePermission()
|
|
97
|
+
const isMock = authAdapter.name === 'mock'
|
|
98
|
+
const actions = ['create', 'edit', 'export', 'approve']
|
|
99
|
+
const availableCount = computed(
|
|
100
|
+
() => actions.filter((action) => hasPermission(`example:resource:${action}`)).length
|
|
101
|
+
)
|
|
102
|
+
const profiles = [
|
|
103
|
+
{ id: 'admin', name: '模板管理员', roles: ['R_SUPER'], permissions: ['*:*:*'] },
|
|
104
|
+
{
|
|
105
|
+
id: 'member',
|
|
106
|
+
name: '普通成员',
|
|
107
|
+
roles: ['R_USER'],
|
|
108
|
+
permissions: [
|
|
109
|
+
'example:resource:create',
|
|
110
|
+
'example:resource:edit',
|
|
111
|
+
'example:resource:export',
|
|
112
|
+
'example:navigation:read'
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
{ id: 'empty', name: '无操作权限', roles: [], permissions: [] }
|
|
116
|
+
]
|
|
117
|
+
const demoProfile = computed({
|
|
118
|
+
get: () => profiles.find((profile) => profile.name === userName.value)?.id ?? 'admin',
|
|
119
|
+
set: (id: string) => {
|
|
120
|
+
const profile = profiles.find((item) => item.id === id)
|
|
121
|
+
if (profile && isMock)
|
|
122
|
+
userStore.setUserInfo({
|
|
123
|
+
...userStore.info,
|
|
124
|
+
userId: 'admin',
|
|
125
|
+
userName: profile.name,
|
|
126
|
+
email: 'admin@example.com',
|
|
127
|
+
roles: profile.roles,
|
|
128
|
+
permissions: profile.permissions
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
})
|
|
77
132
|
const permissionLayers = [
|
|
78
133
|
{
|
|
79
134
|
title: '路由层',
|
|
80
|
-
description: '
|
|
81
|
-
code: 'meta.roles',
|
|
135
|
+
description: '路由声明角色或权限要求,每次导航都执行校验。',
|
|
136
|
+
code: 'meta.roles / permissions',
|
|
82
137
|
icon: 'ri:route-line'
|
|
83
138
|
},
|
|
84
139
|
{
|
|
85
140
|
title: '操作层',
|
|
86
|
-
description: '
|
|
87
|
-
code: 'v-
|
|
141
|
+
description: '指令与 hasPermission 共用用户权限集合。',
|
|
142
|
+
code: 'v-permission / hasPermission',
|
|
88
143
|
icon: 'ri:cursor-line'
|
|
89
144
|
},
|
|
90
145
|
{
|
|
@@ -142,6 +197,7 @@
|
|
|
142
197
|
.identity {
|
|
143
198
|
display: flex;
|
|
144
199
|
flex: 0 0 auto;
|
|
200
|
+
flex-wrap: wrap;
|
|
145
201
|
gap: 12px;
|
|
146
202
|
align-items: center;
|
|
147
203
|
min-width: 190px;
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
<template #name="{ row }">
|
|
28
28
|
<div class="service-name">
|
|
29
29
|
<span class="service-name__icon" aria-hidden="true">
|
|
30
|
-
<
|
|
30
|
+
<ArtSvgIcon icon="ri:link" />
|
|
31
31
|
</span>
|
|
32
32
|
<div class="service-name__content">
|
|
33
33
|
<strong>{{ row.name }}</strong>
|
|
@@ -51,8 +51,7 @@
|
|
|
51
51
|
</template>
|
|
52
52
|
|
|
53
53
|
<script setup lang="ts">
|
|
54
|
-
import {
|
|
55
|
-
import { ElButton, ElIcon, ElMessage, ElTag } from 'element-plus'
|
|
54
|
+
import { ElButton, ElMessage, ElTag } from 'element-plus'
|
|
56
55
|
import { KvSearchTablePage } from '@kevairy/components'
|
|
57
56
|
import { searchItems, statusMeta } from './search.config'
|
|
58
57
|
import { serviceTableColumns } from './table.config'
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
<!-- 403页面 -->
|
|
2
2
|
<template>
|
|
3
|
+
<main v-if="hasNoAccess" class="page-content">
|
|
4
|
+
<KvStatus
|
|
5
|
+
:title="$t('access.noAccessTitle')"
|
|
6
|
+
:description="errorMessage || $t('access.noAccessDescription')"
|
|
7
|
+
:action-text="$t(refreshing ? 'access.checking' : 'access.checkAgain')"
|
|
8
|
+
@action="checkAgain"
|
|
9
|
+
/>
|
|
10
|
+
</main>
|
|
3
11
|
<ArtException
|
|
12
|
+
v-else
|
|
4
13
|
:data="{
|
|
5
14
|
title: '403',
|
|
6
15
|
desc: $t('exceptionPage.403'),
|
|
@@ -11,6 +20,30 @@
|
|
|
11
20
|
</template>
|
|
12
21
|
|
|
13
22
|
<script setup lang="ts">
|
|
23
|
+
import { ref, computed } from 'vue'
|
|
24
|
+
import { KvStatus } from '@kevairy/components'
|
|
25
|
+
import { useUserStore } from '@/store/modules/user'
|
|
26
|
+
import { useMenuStore } from '@/store/modules/menu'
|
|
27
|
+
import { refreshAccess } from '@/services/permission'
|
|
14
28
|
import imgUrl from '@imgs/svg/403.svg'
|
|
15
29
|
defineOptions({ name: 'Exception403' })
|
|
30
|
+
const user = useUserStore()
|
|
31
|
+
const menus = useMenuStore()
|
|
32
|
+
const hasNoAccess = computed(
|
|
33
|
+
() => user.isLogin && user.permissionsReady && menus.menuList.length === 0
|
|
34
|
+
)
|
|
35
|
+
const refreshing = ref(false)
|
|
36
|
+
const errorMessage = ref('')
|
|
37
|
+
const checkAgain = async () => {
|
|
38
|
+
if (refreshing.value) return
|
|
39
|
+
refreshing.value = true
|
|
40
|
+
errorMessage.value = ''
|
|
41
|
+
try {
|
|
42
|
+
await refreshAccess()
|
|
43
|
+
} catch (error) {
|
|
44
|
+
errorMessage.value = error instanceof Error ? error.message : String(error)
|
|
45
|
+
} finally {
|
|
46
|
+
refreshing.value = false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
16
49
|
</script>
|
|
@@ -1,16 +1,58 @@
|
|
|
1
|
-
<!-- 500页面 -->
|
|
2
1
|
<template>
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
<main class="page-content">
|
|
3
|
+
<KvStatus
|
|
4
|
+
type="error"
|
|
5
|
+
title="500"
|
|
6
|
+
:description="
|
|
7
|
+
errorMessage ||
|
|
8
|
+
$t(
|
|
9
|
+
resourceRecoveryNeeded
|
|
10
|
+
? 'exceptionPage.resourceFailure'
|
|
11
|
+
: 'exceptionPage.retryDescription'
|
|
12
|
+
)
|
|
13
|
+
"
|
|
14
|
+
:action-text="
|
|
15
|
+
$t(
|
|
16
|
+
retrying
|
|
17
|
+
? 'access.checking'
|
|
18
|
+
: resourceRecoveryNeeded
|
|
19
|
+
? 'exceptionPage.reload'
|
|
20
|
+
: 'exceptionPage.retry'
|
|
21
|
+
)
|
|
22
|
+
"
|
|
23
|
+
@action="retry"
|
|
24
|
+
/>
|
|
25
|
+
</main>
|
|
11
26
|
</template>
|
|
12
27
|
|
|
13
28
|
<script setup lang="ts">
|
|
14
|
-
import
|
|
29
|
+
import { ref } from 'vue'
|
|
30
|
+
import { KvStatus } from '@kevairy/components'
|
|
31
|
+
import { router } from '@/router'
|
|
32
|
+
import { resetRouterState } from '@/router/guards/beforeEach'
|
|
33
|
+
import { useUserStore } from '@/store/modules/user'
|
|
34
|
+
import { resourceRecoveryNeeded, reloadFailedPage } from '@/utils/sys/recovery'
|
|
35
|
+
import { isRequestCanceled } from '@/utils/http/error'
|
|
36
|
+
|
|
15
37
|
defineOptions({ name: 'Exception500' })
|
|
38
|
+
const retrying = ref(false)
|
|
39
|
+
const errorMessage = ref('')
|
|
40
|
+
const retry = async () => {
|
|
41
|
+
if (retrying.value) return
|
|
42
|
+
if (resourceRecoveryNeeded.value) {
|
|
43
|
+
reloadFailedPage()
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
retrying.value = true
|
|
47
|
+
errorMessage.value = ''
|
|
48
|
+
try {
|
|
49
|
+
resetRouterState(0)
|
|
50
|
+
await router.replace(useUserStore().isLogin ? '/' : '/auth/login')
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (!isRequestCanceled(error))
|
|
53
|
+
errorMessage.value = error instanceof Error ? error.message : String(error)
|
|
54
|
+
} finally {
|
|
55
|
+
retrying.value = false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
16
58
|
</script>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { expect, test } from '@playwright/test'
|
|
2
|
+
import { skipInitialGuide } from './helpers/guide'
|
|
2
3
|
|
|
3
|
-
test('redirects anonymous users
|
|
4
|
+
test('redirects anonymous users, signs in and supports skipping and replaying onboarding', async ({
|
|
5
|
+
page
|
|
6
|
+
}) => {
|
|
4
7
|
await page.goto('/#/dashboard/console')
|
|
5
8
|
|
|
6
9
|
await expect(page).toHaveURL(/#\/auth\/login\?redirect=/)
|
|
@@ -9,14 +12,27 @@ test('redirects anonymous users and signs in to the configured home page', async
|
|
|
9
12
|
await page.getByRole('button', { name: '进入系统(Mock)' }).click()
|
|
10
13
|
|
|
11
14
|
await expect(page).toHaveURL(/#\/dashboard\/console/)
|
|
12
|
-
|
|
15
|
+
const homeHeading = page.getByRole('heading', { name: __DISPLAY_NAME_LITERAL__ })
|
|
16
|
+
await expect(homeHeading).toBeVisible()
|
|
13
17
|
await expect(page).toHaveTitle(/__DISPLAY_NAME_REGEX__/)
|
|
18
|
+
|
|
19
|
+
await skipInitialGuide(page)
|
|
20
|
+
await page.reload()
|
|
21
|
+
await expect(homeHeading).toBeVisible()
|
|
22
|
+
await page.locator('.user-menu-avatar').hover()
|
|
23
|
+
await page.getByText('新手引导', { exact: true }).click()
|
|
24
|
+
await skipInitialGuide(page)
|
|
14
25
|
})
|
|
15
26
|
|
|
16
27
|
test('keeps the login form usable in a short compatibility viewport', async ({ page }) => {
|
|
17
28
|
await page.setViewportSize({ width: 1024, height: 600 })
|
|
18
29
|
await page.goto('/#/auth/login')
|
|
19
30
|
|
|
31
|
+
await expect(page.getByRole('button', { name: '进入系统(Mock)' })).toBeVisible()
|
|
32
|
+
await page.locator('.auth-right-wrap').evaluate(async (element) => {
|
|
33
|
+
await Promise.all(element.getAnimations().map((animation) => animation.finished))
|
|
34
|
+
})
|
|
35
|
+
|
|
20
36
|
const metrics = await page.evaluate(() => {
|
|
21
37
|
const pageRoot = document.querySelector<HTMLElement>('.auth-page')
|
|
22
38
|
const panel = document.querySelector<HTMLElement>('.auth-right-panel')
|
|
@@ -37,10 +53,12 @@ test('keeps the login form usable in a short compatibility viewport', async ({ p
|
|
|
37
53
|
})
|
|
38
54
|
|
|
39
55
|
expect(metrics.leftViewDisplay).toBe('none')
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect(metrics.
|
|
43
|
-
expect(metrics.
|
|
56
|
+
// 浏览器的子像素布局会带来浮点误差,边界测量允许 1px 容差。
|
|
57
|
+
const pixelTolerance = 1
|
|
58
|
+
expect(Math.abs(metrics.panelWidth - metrics.pageWidth)).toBeLessThanOrEqual(pixelTolerance)
|
|
59
|
+
expect(metrics.formWidth).toBeLessThanOrEqual(440 + pixelTolerance)
|
|
60
|
+
expect(metrics.formLeft).toBeGreaterThanOrEqual(-pixelTolerance)
|
|
61
|
+
expect(metrics.formRight).toBeLessThanOrEqual(metrics.pageWidth + pixelTolerance)
|
|
44
62
|
expect(metrics.scrollable).toBe(true)
|
|
45
63
|
await expect(page.getByRole('button', { name: '进入系统(Mock)' })).toBeVisible()
|
|
46
64
|
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { expect, type Page } from '@playwright/test'
|
|
2
|
+
|
|
3
|
+
/** 通过真实入口跳过首次引导,等待遮罩释放页面操作。 */
|
|
4
|
+
export async function skipInitialGuide(page: Page): Promise<void> {
|
|
5
|
+
const guide = page.getByRole('dialog').filter({ hasText: '欢迎使用' })
|
|
6
|
+
await expect(guide).toBeVisible()
|
|
7
|
+
await guide.getByRole('button', { name: '跳过', exact: true }).click()
|
|
8
|
+
await expect(page.locator('.driver-overlay')).toBeHidden()
|
|
9
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { expect, test, type Page } from '@playwright/test'
|
|
2
|
+
import { skipInitialGuide } from './helpers/guide'
|
|
3
|
+
|
|
4
|
+
async function selectProfile(page: Page, name: string) {
|
|
5
|
+
const select = page.getByRole('combobox', { name: '演示身份' })
|
|
6
|
+
await select.focus()
|
|
7
|
+
await select.press('ArrowDown')
|
|
8
|
+
await page.getByRole('option', { name, exact: true }).click()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
test('keeps hook and directive permissions consistent through grant, revoke, restore and protected detail navigation', async ({
|
|
12
|
+
page
|
|
13
|
+
}) => {
|
|
14
|
+
await page.goto('/#/examples/permissions')
|
|
15
|
+
await page.getByRole('button', { name: '进入系统(Mock)' }).click()
|
|
16
|
+
await skipInitialGuide(page)
|
|
17
|
+
const create = page.getByRole('button', { name: '新增资源', exact: true })
|
|
18
|
+
const edit = page.getByRole('button', { name: '编辑资源', exact: true })
|
|
19
|
+
const exportButton = page.getByRole('button', { name: '导出数据', exact: true })
|
|
20
|
+
const approve = page.getByRole('button', { name: '审核资源', exact: true })
|
|
21
|
+
await expect(approve).toBeEnabled()
|
|
22
|
+
await selectProfile(page, '普通成员')
|
|
23
|
+
await expect(create).toBeVisible()
|
|
24
|
+
await expect(edit).toBeVisible()
|
|
25
|
+
await expect(exportButton).toBeVisible()
|
|
26
|
+
await expect(approve).toBeDisabled()
|
|
27
|
+
await selectProfile(page, '无操作权限')
|
|
28
|
+
await expect(create).toBeHidden()
|
|
29
|
+
await expect(edit).toBeHidden()
|
|
30
|
+
await expect(exportButton).toBeHidden()
|
|
31
|
+
await expect(approve).toBeDisabled()
|
|
32
|
+
await expect(page.getByText('管理员区域', { exact: true })).toBeHidden()
|
|
33
|
+
await selectProfile(page, '模板管理员')
|
|
34
|
+
await expect(create).toBeVisible()
|
|
35
|
+
await expect(exportButton).toBeVisible()
|
|
36
|
+
await expect(approve).toBeEnabled()
|
|
37
|
+
await expect(page.getByText('管理员区域', { exact: true })).toBeVisible()
|
|
38
|
+
await selectProfile(page, '无操作权限')
|
|
39
|
+
await page.evaluate(() => {
|
|
40
|
+
location.hash = '/examples/navigation/detail/42'
|
|
41
|
+
})
|
|
42
|
+
await expect(page).toHaveURL(/#\/403$/)
|
|
43
|
+
await page.evaluate(() => {
|
|
44
|
+
location.hash = '/examples/permissions'
|
|
45
|
+
})
|
|
46
|
+
await expect(page.getByRole('heading', { name: '权限演练场' })).toBeVisible()
|
|
47
|
+
await selectProfile(page, '普通成员')
|
|
48
|
+
await page.evaluate(() => {
|
|
49
|
+
location.hash = '/examples/navigation/detail/42'
|
|
50
|
+
})
|
|
51
|
+
await expect(page).toHaveURL(/#\/examples\/navigation\/detail\/42$/)
|
|
52
|
+
await expect(page.getByText('42', { exact: true }).first()).toBeVisible()
|
|
53
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expect, test, type Page } from '@playwright/test'
|
|
2
|
+
import { skipInitialGuide } from './helpers/guide'
|
|
2
3
|
|
|
3
4
|
const openSearchTable = async (page: Page) => {
|
|
4
5
|
await page.goto('/#/examples/search-table')
|
|
@@ -9,6 +10,7 @@ const openSearchTable = async (page: Page) => {
|
|
|
9
10
|
await expect(page).toHaveURL(/#\/examples\/search-table/)
|
|
10
11
|
await expect(page.getByText('服务目录', { exact: true })).toBeVisible()
|
|
11
12
|
await expect(page.getByText('共 68 项')).toBeVisible()
|
|
13
|
+
await skipInitialGuide(page)
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
test('supports search, reset, pagination, errors, selection and keyboard toolbar actions', async ({
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expect, test } from '@playwright/test'
|
|
2
|
+
import { skipInitialGuide } from './helpers/guide'
|
|
3
|
+
|
|
4
|
+
test('discards cached page state on logout and reinitializes the same account', async ({
|
|
5
|
+
page
|
|
6
|
+
}) => {
|
|
7
|
+
await page.goto('/#/examples/search-table')
|
|
8
|
+
await page.getByRole('button', { name: '进入系统(Mock)' }).click()
|
|
9
|
+
await expect(page.getByText('共 68 项')).toBeVisible()
|
|
10
|
+
await skipInitialGuide(page)
|
|
11
|
+
await page.getByPlaceholder('服务名称或编码').fill('SERVICE_001')
|
|
12
|
+
await page.getByRole('button', { name: '查询', exact: true }).click()
|
|
13
|
+
await expect(page.getByText('共 1 项')).toBeVisible()
|
|
14
|
+
await page.locator('.user-menu-avatar').hover()
|
|
15
|
+
await page.getByText('退出登录', { exact: true }).click()
|
|
16
|
+
await page.getByRole('button', { name: '确定', exact: true }).click()
|
|
17
|
+
await expect(page).toHaveURL(/#\/auth\/login/)
|
|
18
|
+
await page.getByRole('button', { name: '进入系统(Mock)' }).click()
|
|
19
|
+
await expect(page).toHaveURL(/#\/examples\/search-table/)
|
|
20
|
+
await expect(page.getByText('共 68 项')).toBeVisible()
|
|
21
|
+
await expect(page.getByPlaceholder('服务名称或编码')).toHaveValue('')
|
|
22
|
+
// 引导完成属于偏好,重新登录不再次启动。
|
|
23
|
+
await expect(page.getByRole('dialog', { name: '欢迎使用 Admin Template' })).toBeHidden()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('offers explicit reload after a failed lazy chunk and recovers the requested page', async ({
|
|
27
|
+
page
|
|
28
|
+
}) => {
|
|
29
|
+
const diagnostics: string[] = []
|
|
30
|
+
page.on('console', (message) => {
|
|
31
|
+
if (message.type() === 'error') diagnostics.push(message.text())
|
|
32
|
+
})
|
|
33
|
+
await page.goto('/#/dashboard/console')
|
|
34
|
+
await page.getByRole('button', { name: '进入系统(Mock)' }).click()
|
|
35
|
+
await expect(page.getByRole('heading', { name: 'Admin Template' })).toBeVisible()
|
|
36
|
+
await skipInitialGuide(page)
|
|
37
|
+
// 登录后才阻断尚未加载的业务资源,恢复页应已随入口可用。
|
|
38
|
+
await page.route('**/assets/*.js', (route) => route.abort('failed'))
|
|
39
|
+
await page.evaluate(() => {
|
|
40
|
+
window.location.hash = '#/examples/search-table'
|
|
41
|
+
})
|
|
42
|
+
await expect(page).toHaveURL(/#\/500/)
|
|
43
|
+
await expect(page.getByRole('button', { name: '刷新并重试' })).toBeVisible()
|
|
44
|
+
expect(diagnostics.some((message) => message.includes('[Diagnostic]'))).toBe(true)
|
|
45
|
+
await page.unroute('**/assets/*.js')
|
|
46
|
+
await page.getByRole('button', { name: '刷新并重试' }).click()
|
|
47
|
+
await expect(page).toHaveURL(/#\/examples\/search-table/)
|
|
48
|
+
await expect(page.getByText('共 68 项')).toBeVisible()
|
|
49
|
+
})
|