@kevairy/template 0.1.5 → 0.1.7

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 (68) hide show
  1. package/package.json +1 -1
  2. package/template/.agents/skills/kevairy-ui/SKILL.md +4 -0
  3. package/template/.agents/skills/kevairy-ui/references/component-catalog.md +1 -0
  4. package/template/.agents/skills/kevairy-ui/references/form-drawer.md +22 -0
  5. package/template/AGENTS.md +12 -0
  6. package/template/README.md +14 -0
  7. package/template/package.json +3 -2
  8. package/template/public/licenses/noto-sans-sc-OFL.txt +93 -0
  9. package/template/src/assets/images/common/logo.webp +0 -0
  10. package/template/src/assets/images/favicon.ico +0 -0
  11. package/template/src/assets/styles/core/el-ui.scss +0 -3
  12. package/template/src/assets/styles/core/router-transition.scss +36 -4
  13. package/template/src/assets/styles/core/tailwind.css +3 -0
  14. package/template/src/assets/styles/custom/search-table.scss +8 -0
  15. package/template/src/assets/styles/custom/typography.scss +88 -0
  16. package/template/src/components/core/feedback/art-page-loading/index.vue +1 -1
  17. package/template/src/components/core/layouts/art-chat-window/index.vue +15 -24
  18. package/template/src/components/core/layouts/art-header-bar/index.vue +21 -1
  19. package/template/src/components/core/layouts/art-header-bar/widget/ArtUserMenu.vue +17 -8
  20. package/template/src/components/core/layouts/art-menus/art-horizontal-menu/widget/HorizontalSubmenu.vue +7 -1
  21. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/index.vue +1 -0
  22. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/style.scss +2 -1
  23. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/theme.scss +7 -0
  24. package/template/src/components/core/layouts/art-menus/art-sidebar-menu/widget/SidebarSubmenu.vue +2 -2
  25. package/template/src/components/core/layouts/art-notification/index.vue +11 -21
  26. package/template/src/components/core/layouts/art-screen-lock/index.vue +6 -2
  27. package/template/src/components/core/layouts/art-work-tab/index.vue +8 -15
  28. package/template/src/components/core/views/exception/ArtException.vue +8 -5
  29. package/template/src/config/index.ts +1 -2
  30. package/template/src/hooks/core/useChart.ts +22 -2
  31. package/template/src/locales/langs/en.json +1 -1
  32. package/template/src/locales/langs/zh.json +1 -1
  33. package/template/src/main.ts +3 -0
  34. package/template/src/router/core/access.ts +11 -0
  35. package/template/src/types/config/index.ts +1 -1
  36. package/template/src/types/router/index.ts +2 -0
  37. package/template/src/utils/ui/loading.ts +7 -1
  38. package/template/src/views/examples/crud-workspace/index.vue +103 -30
  39. package/template/src/views/examples/search-table/index.vue +1 -1
  40. package/template/src/views/exception/500/index.vue +35 -32
  41. package/template/src/views/index/index.vue +58 -2
  42. package/template/src/views/index/style.scss +91 -13
  43. package/template/tests/e2e/drawer.spec.ts +85 -0
  44. package/template/tests/e2e/form-drawer.spec.ts +128 -0
  45. package/template/tests/e2e/layout-motion.spec.ts +189 -0
  46. package/template/tests/e2e/search-table.spec.ts +6 -5
  47. package/template/tests/e2e/session-recovery.spec.ts +6 -8
  48. package/template/tests/e2e/typography.spec.ts +118 -0
  49. package/template/tests/unit/permissions/rules.spec.ts +29 -0
  50. package/template/vite.config.ts +2 -0
  51. package/template/src/assets/images/avatar/avatar.webp +0 -0
  52. package/template/src/assets/images/avatar/avatar1.webp +0 -0
  53. package/template/src/assets/images/avatar/avatar10.webp +0 -0
  54. package/template/src/assets/images/avatar/avatar2.webp +0 -0
  55. package/template/src/assets/images/avatar/avatar3.webp +0 -0
  56. package/template/src/assets/images/avatar/avatar4.webp +0 -0
  57. package/template/src/assets/images/avatar/avatar5.webp +0 -0
  58. package/template/src/assets/images/avatar/avatar6.webp +0 -0
  59. package/template/src/assets/images/avatar/avatar7.webp +0 -0
  60. package/template/src/assets/images/avatar/avatar8.webp +0 -0
  61. package/template/src/assets/images/avatar/avatar9.webp +0 -0
  62. package/template/src/assets/images/ceremony/xc.png +0 -0
  63. package/template/src/assets/images/draw/draw1.png +0 -0
  64. package/template/src/assets/images/lock/bg_dark.webp +0 -0
  65. package/template/src/assets/images/lock/bg_light.webp +0 -0
  66. package/template/src/assets/images/login/lf_icon2.webp +0 -0
  67. package/template/src/assets/images/user/avatar.webp +0 -0
  68. package/template/src/assets/images/user/bg.webp +0 -0
@@ -2,7 +2,7 @@
2
2
  <template v-for="(item, index) in filteredMenuItems" :key="getUniqueKey(item, index)">
3
3
  <ElSubMenu v-if="hasChildren(item)" :index="item.path || item.meta.title" :level="level">
4
4
  <template #title>
5
- <div class="menu-icon flex-cc">
5
+ <div v-if="level === 0 && item.meta.icon" class="menu-icon flex-cc">
6
6
  <ArtSvgIcon
7
7
  :icon="item.meta.icon"
8
8
  :color="theme?.iconColor"
@@ -30,7 +30,7 @@
30
30
  :level-item="level + 1"
31
31
  @click="goPage(item)"
32
32
  >
33
- <div class="menu-icon flex-cc">
33
+ <div v-if="level === 0 && item.meta.icon" class="menu-icon flex-cc">
34
34
  <ArtSvgIcon
35
35
  :icon="item.meta.icon"
36
36
  :color="theme?.iconColor"
@@ -58,7 +58,9 @@
58
58
  class="box-border flex-c px-3.5 py-3.5 c-p last:border-b-0 hover:bg-g-200/60"
59
59
  >
60
60
  <div class="w-9 h-9">
61
- <img :src="item.avatar" class="w-full h-full rounded-lg" />
61
+ <ElAvatar :size="36" :src="item.avatar" shape="square" class="rounded-lg">
62
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-xl" />
63
+ </ElAvatar>
62
64
  </div>
63
65
  <div class="w-[calc(100%-45px)] ml-3.5">
64
66
  <h4 class="text-xs font-normal leading-5.5">{{ item.title }}</h4>
@@ -106,13 +108,7 @@
106
108
  import { computed, ref, watch, type Ref, type ComputedRef } from 'vue'
107
109
  import { useI18n } from 'vue-i18n'
108
110
 
109
- // 导入头像图片
110
- import avatar1 from '@/assets/images/avatar/avatar1.webp'
111
- import avatar2 from '@/assets/images/avatar/avatar2.webp'
112
- import avatar3 from '@/assets/images/avatar/avatar3.webp'
113
- import avatar4 from '@/assets/images/avatar/avatar4.webp'
114
- import avatar5 from '@/assets/images/avatar/avatar5.webp'
115
- import avatar6 from '@/assets/images/avatar/avatar6.webp'
111
+ import AppConfig from '@/config'
116
112
 
117
113
  defineOptions({ name: 'ArtNotification' })
118
114
 
@@ -131,7 +127,7 @@
131
127
  /** 时间 */
132
128
  time: string
133
129
  /** 头像 */
134
- avatar: string
130
+ avatar?: string
135
131
  }
136
132
 
137
133
  interface PendingItem {
@@ -210,33 +206,27 @@
210
206
  const msgList = ref<MessageItem[]>([
211
207
  {
212
208
  title: '池不胖 关注了你',
213
- time: '2021-2-26 23:50',
214
- avatar: avatar1
209
+ time: '2021-2-26 23:50'
215
210
  },
216
211
  {
217
212
  title: '唐不苦 关注了你',
218
- time: '2021-2-21 8:05',
219
- avatar: avatar2
213
+ time: '2021-2-21 8:05'
220
214
  },
221
215
  {
222
216
  title: '中小鱼 关注了你',
223
- time: '2020-1-17 21:12',
224
- avatar: avatar3
217
+ time: '2020-1-17 21:12'
225
218
  },
226
219
  {
227
220
  title: '何小荷 关注了你',
228
- time: '2021-01-14 0:20',
229
- avatar: avatar4
221
+ time: '2021-01-14 0:20'
230
222
  },
231
223
  {
232
224
  title: '誶誶淰 关注了你',
233
- time: '2020-12-20 0:15',
234
- avatar: avatar5
225
+ time: '2020-12-20 0:15'
235
226
  },
236
227
  {
237
228
  title: '冷月呆呆 关注了你',
238
- time: '2020-12-17 22:06',
239
- avatar: avatar6
229
+ time: '2020-12-17 22:06'
240
230
  }
241
231
  ])
242
232
 
@@ -12,9 +12,13 @@
12
12
  <div class="screen-lock__panel">
13
13
  <ElAvatar
14
14
  :size="72"
15
- :src="userInfo.avatar || AppConfig.assets.defaultAvatar"
15
+ :src="userInfo.avatar"
16
16
  class="screen-lock__avatar"
17
- />
17
+ role="img"
18
+ :aria-label="userInfo.userName || '用户头像'"
19
+ >
20
+ <ArtSvgIcon :icon="AppConfig.assets.defaultAvatarIcon" class="text-[40px]" />
21
+ </ElAvatar>
18
22
  <div class="screen-lock__name">{{ userInfo.userName || 'User' }}</div>
19
23
 
20
24
  <!-- 已设置密码:输入密码解锁 -->
@@ -2,7 +2,7 @@
2
2
  <template>
3
3
  <div
4
4
  v-if="showWorkTab"
5
- class="box-border flex-b w-full px-5 mb-3 select-none max-sm:px-[15px]"
5
+ class="art-work-tab box-border flex-b w-full select-none"
6
6
  :class="[
7
7
  tabStyle === 'tab-card' ? 'py-1 border-b border-[var(--art-card-border)]' : '',
8
8
  tabStyle === 'tab-google' ? 'pt-1 pb-0 border-b border-[var(--art-card-border)]' : ''
@@ -19,9 +19,11 @@
19
19
  }"
20
20
  >
21
21
  <li
22
- class="art-card-xs inline-flex flex-cc h-8 mr-1.5 text-xs c-p hover:text-theme group"
22
+ class="art-card-xs inline-flex flex-cc h-8 mr-1.5 text-sm c-p hover:text-theme group"
23
23
  :class="[
24
- item.path === activeTab ? 'activ-tab !text-theme' : 'text-g-600 dark:text-g-800',
24
+ item.path === activeTab
25
+ ? 'activ-tab !text-theme font-medium'
26
+ : 'text-g-600 dark:text-g-800',
25
27
  tabStyle === 'tab-google' ? 'google-tab relative !h-8 !leading-8 !border-none' : ''
26
28
  ]"
27
29
  :style="{
@@ -568,17 +570,8 @@
568
570
  background: var(--art-gray-300);
569
571
  }
570
572
 
571
- @media only screen and (width <= 768px) {
572
- .box-border.flex.justify-between {
573
- padding-right: 0.625rem;
574
- padding-left: 0.625rem;
575
- }
576
- }
577
-
578
- @media only screen and (width <= 640px) {
579
- .box-border.flex.justify-between {
580
- padding-right: 0.9375rem;
581
- padding-left: 0.9375rem;
582
- }
573
+ .art-work-tab {
574
+ padding-inline: var(--art-page-gutter, 12px);
575
+ margin-bottom: 8px;
583
576
  }
584
577
  </style>
@@ -1,12 +1,15 @@
1
1
  <template>
2
2
  <div class="page-content !border-0 !bg-transparent min-h-screen flex-cc">
3
- <div class="flex-cc max-md:!block max-md:text-center">
4
- <ThemeSvg :src="data.imgUrl" size="100%" class="!w-100" />
3
+ <div class="flex-cc max-w-full max-md:!block max-md:text-center">
4
+ <ThemeSvg :src="data.imgUrl" size="100%" class="!w-100 max-w-full" aria-hidden="true" />
5
5
  <div class="ml-15 w-75 max-md:mx-auto max-md:mt-10 max-md:w-full max-md:text-center">
6
+ <slot name="title" />
6
7
  <p class="text-xl leading-7 text-g-600 max-md:text-lg">{{ data.desc }}</p>
7
- <ElButton type="primary" size="large" @click="backHome" v-ripple class="mt-5">{{
8
- data.btnText
9
- }}</ElButton>
8
+ <slot name="action">
9
+ <ElButton type="primary" size="large" @click="backHome" v-ripple class="mt-5">{{
10
+ data.btnText
11
+ }}</ElButton>
12
+ </slot>
10
13
  </div>
11
14
  </div>
12
15
  </div>
@@ -34,7 +34,6 @@ import { configImages } from './assets/images'
34
34
  import fastEnterConfig from './modules/fastEnter'
35
35
  import logo from '@imgs/common/logo.webp'
36
36
  import favicon from '@imgs/favicon.ico'
37
- import defaultAvatar from '@imgs/user/avatar.webp'
38
37
 
39
38
  const appConfig: SystemConfig = {
40
39
  // 系统信息
@@ -78,7 +77,7 @@ const appConfig: SystemConfig = {
78
77
  namespace: 'admin-template'
79
78
  },
80
79
  assets: {
81
- defaultAvatar
80
+ defaultAvatarIcon: 'ri:user-3-line'
82
81
  },
83
82
  links: {
84
83
  documentation: '',
@@ -97,6 +97,24 @@ export function useChart(options: UseChartOptions = {}) {
97
97
  let isDestroyed = false
98
98
  let emptyStateDiv: HTMLElement | null = null
99
99
 
100
+ // Canvas 不继承 DOM 字体,需要在初始化、更新及字体加载完成时同步排版。
101
+ const withTypography = (options: EChartsOption): EChartsOption => ({
102
+ ...options,
103
+ textStyle: {
104
+ fontFamily: getCssVar('--app-font-family') || 'sans-serif',
105
+ fontSize: useChartOps().fontSize,
106
+ fontWeight: 400,
107
+ ...options.textStyle
108
+ }
109
+ })
110
+
111
+ const handleFontsLoaded = () => {
112
+ if (chart && !isDestroyed) {
113
+ chart.setOption(withTypography(chart.getOption() as EChartsOption))
114
+ chart.resize()
115
+ }
116
+ }
117
+
100
118
  // 清理定时器的统一方法
101
119
  const clearTimers = () => {
102
120
  if (resizeTimeoutId) {
@@ -442,7 +460,7 @@ export function useChart(options: UseChartOptions = {}) {
442
460
  setupThemeWatcher()
443
461
  }
444
462
  if (chart && !isDestroyed) {
445
- chart.setOption(options)
463
+ chart.setOption(withTypography(options))
446
464
  pendingOptions = null
447
465
  }
448
466
  }
@@ -541,7 +559,7 @@ export function useChart(options: UseChartOptions = {}) {
541
559
  initChart(options)
542
560
  return
543
561
  }
544
- chart.setOption(options)
562
+ chart.setOption(withTypography(options))
545
563
  } catch (error) {
546
564
  console.error('图表更新失败:', error)
547
565
  }
@@ -590,10 +608,12 @@ export function useChart(options: UseChartOptions = {}) {
590
608
 
591
609
  onMounted(() => {
592
610
  window.addEventListener('resize', debouncedResize)
611
+ document.fonts?.addEventListener('loadingdone', handleFontsLoaded)
593
612
  })
594
613
 
595
614
  onBeforeUnmount(() => {
596
615
  window.removeEventListener('resize', debouncedResize)
616
+ document.fonts?.removeEventListener('loadingdone', handleFontsLoaded)
597
617
  })
598
618
 
599
619
  onUnmounted(() => {
@@ -257,7 +257,7 @@
257
257
  "500": "Sorry, there was an error on the server",
258
258
  "gohome": "Go Home",
259
259
  "retryDescription": "The page could not be loaded. Retry initialization, or contact your administrator if the problem continues.",
260
- "retry": "Retry loading",
260
+ "retry": "Retry",
261
261
  "resourceFailure": "Page resources could not be loaded. A new version may have been deployed. Reload to fetch the latest resources.",
262
262
  "reload": "Reload and retry"
263
263
  },
@@ -257,7 +257,7 @@
257
257
  "500": "抱歉,服务器出错了",
258
258
  "gohome": "返回首页",
259
259
  "retryDescription": "页面加载失败,可以重试初始化。若仍无法恢复,请联系管理员。",
260
- "retry": "重新加载页面",
260
+ "retry": "重试访问",
261
261
  "resourceFailure": "页面资源加载失败,可能刚刚发布了新版本。刷新后将重新加载资源。",
262
262
  "reload": "刷新并重试"
263
263
  },
@@ -3,10 +3,13 @@ import { createApp } from 'vue'
3
3
  import { initStore } from './store' // Store
4
4
  import { initRouter } from './router' // Router
5
5
  import language from './locales' // 国际化
6
+ import '@fontsource-variable/noto-sans-sc' // 本地中文可变字体
6
7
  import '@styles/core/tailwind.css' // tailwind
7
8
  import 'element-plus/dist/index.css' // Element Plus 基础样式(覆盖组件包内部依赖)
8
9
  import '@styles/index.scss' // 样式
9
10
  import '@kevairy/components/style.css' // 公共组件样式
11
+ import '@styles/custom/search-table.scss' // 应用表格配色
12
+ import '@styles/custom/typography.scss' // 统一字体排版
10
13
  import '@utils/sys/console.ts' // 控制台输出内容
11
14
  import { setupGlobDirectives } from './directives'
12
15
  import { setupErrorHandle, setupGlobalErrorHandlers } from './utils/sys/error-handle'
@@ -67,6 +67,17 @@ export function filterAccessibleRoutes(
67
67
  (!route.component || route.component === '/index/index')
68
68
  )
69
69
  return []
70
+ // 先完成父子权限校验,再折叠仅用于路由和权限组织的单页菜单容器。
71
+ // 访问守卫仍基于原始路由树校验全部祖先限制。
72
+ if (
73
+ route.meta.isMenuWrapper &&
74
+ !route.meta.isHide &&
75
+ children?.length === 1 &&
76
+ !children[0].meta.isHide
77
+ ) {
78
+ const child = children[0]
79
+ return [{ ...child, path: child.path.startsWith('/') ? child.path : `/${child.path}` }]
80
+ }
70
81
  let redirect = route.redirect
71
82
  if (
72
83
  children?.length &&
@@ -124,7 +124,7 @@ export interface AppStorageConfig {
124
124
  }
125
125
 
126
126
  export interface AppAssetConfig {
127
- defaultAvatar: string
127
+ defaultAvatarIcon: string
128
128
  }
129
129
 
130
130
  export interface AppLinkConfig {
@@ -54,6 +54,8 @@ export interface RouteMeta extends Record<string | number | symbol, unknown> {
54
54
  }>
55
55
  /** 是否为一级菜单 */
56
56
  isFirstLevel?: boolean
57
+ /** 单页菜单容器;授权过滤后折叠显示,访问仍校验原始祖先权限。 */
58
+ isMenuWrapper?: boolean
57
59
  /** 角色权限 */
58
60
  roles?: string[]
59
61
  /** 进入页面所需的操作权限,与 authList 的动作描述分离。 */
@@ -28,7 +28,7 @@
28
28
  * @module utils/ui/loading
29
29
  * @author Art Design Pro Team
30
30
  */
31
- import { createVNode, render } from 'vue'
31
+ import { createVNode, readonly, render, shallowRef } from 'vue'
32
32
  import ArtPageLoading from '@/components/core/feedback/art-page-loading/index.vue'
33
33
  import AppConfig from '@/config'
34
34
 
@@ -45,6 +45,7 @@ let previousBodyOverflow = ''
45
45
  let loadingStartedAt = 0
46
46
  let hideTimer: number | null = null
47
47
  let isLeaving = false
48
+ const isVisible = shallowRef(false)
48
49
 
49
50
  const prefersReducedMotion = (): boolean =>
50
51
  window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false
@@ -95,6 +96,7 @@ const closeLoadingImmediately = (): void => {
95
96
  loadingInstance = null
96
97
  loadingStartedAt = 0
97
98
  isLeaving = false
99
+ isVisible.value = false
98
100
  }
99
101
  }
100
102
 
@@ -114,6 +116,9 @@ const startLoadingExit = (): void => {
114
116
  }
115
117
 
116
118
  export const loadingService = {
119
+ // 布局在遮罩移除后开始入场,避免动画在加载层下提前播放。
120
+ isVisible: readonly(isVisible),
121
+
117
122
  /**
118
123
  * 显示 loading
119
124
  * @returns 关闭 loading 的函数
@@ -125,6 +130,7 @@ export const loadingService = {
125
130
  if (!loadingInstance) {
126
131
  loadingStartedAt = Date.now()
127
132
  loadingInstance = createLoading()
133
+ isVisible.value = true
128
134
  } else if (wasLeaving) {
129
135
  isLeaving = false
130
136
  loadingStartedAt = Date.now()
@@ -15,7 +15,7 @@
15
15
  <section class="table-shell" aria-label="资源列表">
16
16
  <KvSearchTablePage
17
17
  ref="tableRef"
18
- title="资源目录"
18
+ aria-label="资源目录搜索表格"
19
19
  row-key="id"
20
20
  :search-items="searchItems"
21
21
  :columns="columns"
@@ -39,6 +39,7 @@
39
39
  </template>
40
40
  <template #operation="{ row }">
41
41
  <div class="row-actions">
42
+ <ElButton link type="primary" @click="openDetails(row)">查看</ElButton>
42
43
  <ElButton link type="primary" @click="openEdit(row)">编辑</ElButton>
43
44
  <ElButton link type="danger" @click="removeOne(row)">删除</ElButton>
44
45
  </div>
@@ -46,16 +47,50 @@
46
47
  </KvSearchTablePage>
47
48
  </section>
48
49
 
49
- <KvDialog
50
- v-model="dialogVisible"
50
+ <KvDrawer v-model="detailsVisible" title="资源详情" @closed="selectedResource = undefined">
51
+ <section v-if="selectedResource" class="resource-details art-card">
52
+ <KvSectionTitle title="基本信息" />
53
+ <dl class="resource-details__fields">
54
+ <div
55
+ ><dt>资源名称</dt><dd>{{ selectedResource.name }}</dd></div
56
+ >
57
+ <div
58
+ ><dt>资源编码</dt><dd>{{ selectedResource.code }}</dd></div
59
+ >
60
+ <div
61
+ ><dt>负责人</dt><dd>{{ selectedResource.owner }}</dd></div
62
+ >
63
+ <div>
64
+ <dt>状态</dt>
65
+ <dd
66
+ ><ElTag :type="getStatusMeta(selectedResource.status).type">{{
67
+ getStatusMeta(selectedResource.status).label
68
+ }}</ElTag></dd
69
+ >
70
+ </div>
71
+ <div
72
+ ><dt>更新时间</dt><dd>{{ selectedResource.updatedAt }}</dd></div
73
+ >
74
+ </dl>
75
+ </section>
76
+ </KvDrawer>
77
+
78
+ <KvFormDrawer
79
+ v-model="drawerVisible"
51
80
  :title="editingId ? '编辑资源' : '新增资源'"
52
- width="min(560px, calc(100vw - 24px))"
53
- draggable
54
- resizable
55
- destroy-on-close
81
+ :submitting="saving"
82
+ :dirty="dirty"
83
+ @submit="saveResource"
56
84
  @closed="resetForm"
57
85
  >
58
- <ElForm ref="formRef" :model="form" :rules="rules" label-position="top">
86
+ <ElForm
87
+ ref="formRef"
88
+ :model="form"
89
+ :rules="rules"
90
+ :disabled="saving"
91
+ label-position="top"
92
+ @submit.prevent="saveResource"
93
+ >
59
94
  <div class="form-grid">
60
95
  <ElFormItem label="资源名称" prop="name">
61
96
  <ElInput v-model.trim="form.name" placeholder="例如:事件中心" autocomplete="off" />
@@ -78,16 +113,12 @@
78
113
  </ElFormItem>
79
114
  </div>
80
115
  </ElForm>
81
- <template #footer>
82
- <ElButton @click="dialogVisible = false">取消</ElButton>
83
- <ElButton type="primary" :loading="saving" @click="saveResource">保存</ElButton>
84
- </template>
85
- </KvDialog>
116
+ </KvFormDrawer>
86
117
  </main>
87
118
  </template>
88
119
 
89
120
  <script setup lang="ts">
90
- import { KvDialog, KvSearchTablePage } from '@kevairy/components'
121
+ import { KvDrawer, KvFormDrawer, KvSearchTablePage, KvSectionTitle } from '@kevairy/components'
91
122
  import type { ColumnOption, PagedTableRequest, SearchFormItem } from '@kevairy/components'
92
123
  import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
93
124
 
@@ -192,7 +223,7 @@
192
223
  { prop: 'owner', label: '负责人', minWidth: 130 },
193
224
  { prop: 'status', label: '状态', width: 100, useSlot: true },
194
225
  { prop: 'updatedAt', label: '更新时间', minWidth: 170 },
195
- { prop: 'operation', label: '操作', width: 130, fixed: 'right', disabled: true, useSlot: true }
226
+ { prop: 'operation', label: '操作', width: 170, fixed: 'right', disabled: true, useSlot: true }
196
227
  ]
197
228
 
198
229
  const fetchPage = async ({ query, current, size, signal }: PagedTableRequest<ResourceQuery>) => {
@@ -218,11 +249,23 @@
218
249
 
219
250
  const tableRef = ref<{ refresh: () => Promise<void> | void }>()
220
251
  const formRef = ref<FormInstance>()
221
- const dialogVisible = ref(false)
252
+ const drawerVisible = ref(false)
253
+ const detailsVisible = ref(false)
254
+ const selectedResource = ref<ResourceRecord>()
255
+ const openDetails = (row: ResourceRecord) => {
256
+ selectedResource.value = row
257
+ detailsVisible.value = true
258
+ }
222
259
  const saving = ref(false)
223
260
  const editingId = ref<number>()
224
261
  const createForm = () => ({ name: '', code: '', owner: '', status: 'draft' as ResourceStatus })
225
262
  const form = reactive(createForm())
263
+ const initialForm = ref(createForm())
264
+ const dirty = computed(() =>
265
+ (Object.keys(initialForm.value) as (keyof typeof form)[]).some(
266
+ (key) => form[key] !== initialForm.value[key]
267
+ )
268
+ )
226
269
  const rules: FormRules = {
227
270
  name: [{ required: true, message: '请输入资源名称', trigger: 'blur' }],
228
271
  code: [
@@ -237,31 +280,39 @@
237
280
  }
238
281
  const resetForm = () => {
239
282
  editingId.value = undefined
240
- Object.assign(form, createForm())
283
+ initialForm.value = createForm()
284
+ Object.assign(form, initialForm.value)
241
285
  formRef.value?.clearValidate()
242
286
  }
243
287
  const openCreate = () => {
244
288
  resetForm()
245
- dialogVisible.value = true
289
+ drawerVisible.value = true
246
290
  }
247
291
  const openEdit = (row: ResourceRecord) => {
248
292
  editingId.value = row.id
249
- Object.assign(form, row)
250
- dialogVisible.value = true
293
+ initialForm.value = { name: row.name, code: row.code, owner: row.owner, status: row.status }
294
+ Object.assign(form, initialForm.value)
295
+ drawerVisible.value = true
251
296
  }
252
297
  const saveResource = async () => {
253
- if (!(await formRef.value?.validate().catch(() => false))) return
298
+ if (saving.value) return
254
299
  saving.value = true
255
- await new Promise((resolve) => window.setTimeout(resolve, 420))
256
- if (editingId.value) {
257
- const index = records.value.findIndex((item) => item.id === editingId.value)
258
- if (index >= 0) records.value[index] = { ...records.value[index], ...form, updatedAt: '刚刚' }
259
- } else {
260
- records.value.unshift({ id: Date.now(), ...form, updatedAt: '刚刚' })
300
+ try {
301
+ if (!(await formRef.value?.validate().catch(() => false))) return
302
+ await new Promise((resolve) => window.setTimeout(resolve, 420))
303
+ if (editingId.value) {
304
+ const index = records.value.findIndex((item) => item.id === editingId.value)
305
+ if (index >= 0)
306
+ records.value[index] = { ...records.value[index], ...form, updatedAt: '刚刚' }
307
+ } else {
308
+ records.value.unshift({ id: Date.now(), ...form, updatedAt: '刚刚' })
309
+ }
310
+ // Programmatic closing after a successful save skips the discard confirmation.
311
+ drawerVisible.value = false
312
+ ElMessage.success(editingId.value ? '资源已更新' : '资源已创建')
313
+ } finally {
314
+ saving.value = false
261
315
  }
262
- saving.value = false
263
- dialogVisible.value = false
264
- ElMessage.success(editingId.value ? '资源已更新' : '资源已创建')
265
316
  await tableRef.value?.refresh()
266
317
  }
267
318
  const confirmRemove = (count: number) =>
@@ -295,6 +346,28 @@
295
346
  </script>
296
347
 
297
348
  <style scoped lang="scss">
349
+ .resource-details {
350
+ padding: 22px;
351
+ }
352
+
353
+ .resource-details__fields {
354
+ display: grid;
355
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
356
+ gap: 24px 36px;
357
+ margin: 24px 0 0;
358
+
359
+ dt {
360
+ margin-bottom: 8px;
361
+ font-size: 12px;
362
+ color: var(--el-text-color-secondary);
363
+ }
364
+
365
+ dd {
366
+ margin: 0;
367
+ overflow-wrap: anywhere;
368
+ }
369
+ }
370
+
298
371
  .crud-page {
299
372
  display: flex;
300
373
  flex-direction: column;
@@ -11,7 +11,7 @@
11
11
  <section class="table-shell" aria-label="服务目录">
12
12
  <KvSearchTablePage
13
13
  data-testid="service-search-table"
14
- title="服务目录"
14
+ aria-label="服务目录搜索表格"
15
15
  row-key="id"
16
16
  :search-items="searchItems"
17
17
  :columns="serviceTableColumns"