@origen-ui/admin-cli 1.1.0 → 2.0.1

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 (159) hide show
  1. package/README.md +11 -7
  2. package/package.json +18 -2
  3. package/templates/current/clean/CHANGELOG.md +103 -0
  4. package/templates/current/clean/component-catalog.json +58 -17
  5. package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
  6. package/templates/current/clean/e2e/demo-shell.spec.ts +90 -46
  7. package/templates/current/clean/package.json +35 -21
  8. package/templates/current/clean/playwright.config.ts +1 -0
  9. package/templates/current/clean/playwright.demo.config.ts +1 -1
  10. package/templates/current/clean/scaffold.lock.json +2 -2
  11. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  12. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  13. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  14. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  15. package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
  16. package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  17. package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  18. package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  19. package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
  20. package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  21. package/templates/current/clean/scripts/demo-api.ts +84 -8
  22. package/templates/current/clean/scripts/generate-api.ts +87 -3
  23. package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
  24. package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
  25. package/templates/current/clean/src/api/generated/http-client.ts +28 -26
  26. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
  27. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
  28. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
  29. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
  30. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
  31. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
  32. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
  33. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
  34. package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
  35. package/templates/current/clean/src/app/errorMessage.ts +53 -0
  36. package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
  37. package/templates/current/clean/src/app/menu.spec.ts +39 -0
  38. package/templates/current/clean/src/app/menu.ts +48 -12
  39. package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
  40. package/templates/current/clean/src/demo-api.spec.ts +311 -0
  41. package/templates/current/clean/src/features/auth/pages/Login.vue +8 -2
  42. package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
  43. package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
  44. package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
  45. package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
  46. package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
  47. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
  48. package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
  49. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  50. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  51. package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
  52. package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
  53. package/templates/current/clean/src/layouts/TopBar.vue +37 -6
  54. package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
  55. package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
  56. package/templates/current/clean/src/locales/en-US.json +30 -3
  57. package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
  58. package/templates/current/clean/src/locales/index.ts +39 -26
  59. package/templates/current/clean/src/locales/zh-CN.json +30 -3
  60. package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
  61. package/templates/current/clean/src/locales/zh-TW.json +30 -3
  62. package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
  63. package/templates/current/clean/src/main.ts +23 -14
  64. package/templates/current/clean/src/router/bootstrap.ts +10 -16
  65. package/templates/current/clean/src/router/componentCache.ts +12 -0
  66. package/templates/current/clean/src/router/componentRegistry.ts +2 -13
  67. package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
  68. package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
  69. package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
  70. package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
  71. package/templates/current/clean/src/router/paths.spec.ts +50 -0
  72. package/templates/current/clean/src/router/paths.ts +21 -0
  73. package/templates/current/clean/src/router/staticRoutes.ts +6 -6
  74. package/templates/current/clean/src/templates/og-table.ts +2 -4
  75. package/templates/current/clean/tsconfig.json +0 -1
  76. package/templates/current/clean/vite.build-policy.ts +55 -8
  77. package/templates/current/clean/vite.config.ts +30 -0
  78. package/templates/current/examples/CHANGELOG.md +103 -0
  79. package/templates/current/examples/component-catalog.json +58 -17
  80. package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
  81. package/templates/current/examples/e2e/demo-shell.spec.ts +90 -46
  82. package/templates/current/examples/package.json +35 -21
  83. package/templates/current/examples/playwright.config.ts +1 -0
  84. package/templates/current/examples/playwright.demo.config.ts +1 -1
  85. package/templates/current/examples/scaffold.lock.json +2 -2
  86. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  87. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  88. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  89. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  90. package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
  91. package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  92. package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  93. package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  94. package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
  95. package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  96. package/templates/current/examples/scripts/demo-api.ts +84 -8
  97. package/templates/current/examples/scripts/generate-api.ts +87 -3
  98. package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
  99. package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
  100. package/templates/current/examples/src/api/generated/http-client.ts +28 -26
  101. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
  102. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
  103. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
  104. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
  105. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
  106. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
  107. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
  108. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
  109. package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
  110. package/templates/current/examples/src/app/errorMessage.ts +53 -0
  111. package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
  112. package/templates/current/examples/src/app/menu.spec.ts +39 -0
  113. package/templates/current/examples/src/app/menu.ts +48 -12
  114. package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
  115. package/templates/current/examples/src/demo-api.spec.ts +311 -0
  116. package/templates/current/examples/src/features/auth/pages/Login.vue +8 -2
  117. package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
  118. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
  119. package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
  120. package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
  121. package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
  122. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
  123. package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
  124. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  125. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  126. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
  127. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
  128. package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
  129. package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
  130. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
  131. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
  132. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
  133. package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
  134. package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
  135. package/templates/current/examples/src/layouts/TopBar.vue +37 -6
  136. package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
  137. package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
  138. package/templates/current/examples/src/locales/en-US.json +30 -3
  139. package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
  140. package/templates/current/examples/src/locales/index.ts +39 -26
  141. package/templates/current/examples/src/locales/zh-CN.json +30 -3
  142. package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
  143. package/templates/current/examples/src/locales/zh-TW.json +30 -3
  144. package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
  145. package/templates/current/examples/src/main.ts +24 -22
  146. package/templates/current/examples/src/router/bootstrap.ts +10 -16
  147. package/templates/current/examples/src/router/componentCache.ts +18 -0
  148. package/templates/current/examples/src/router/componentRegistry.ts +1 -18
  149. package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
  150. package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
  151. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
  152. package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
  153. package/templates/current/examples/src/router/paths.spec.ts +50 -0
  154. package/templates/current/examples/src/router/paths.ts +21 -0
  155. package/templates/current/examples/src/router/staticRoutes.ts +3 -3
  156. package/templates/current/examples/src/templates/og-table.ts +2 -4
  157. package/templates/current/examples/tsconfig.json +0 -1
  158. package/templates/current/examples/vite.build-policy.ts +55 -8
  159. package/templates/current/examples/vite.config.ts +30 -0
@@ -36,6 +36,7 @@ interface DemoMenu {
36
36
  kind: MenuKind
37
37
  code: string
38
38
  title: string
39
+ titleKey?: string
39
40
  path?: string
40
41
  componentKey?: string
41
42
  icon?: string
@@ -46,6 +47,7 @@ interface DemoMenu {
46
47
  cache: boolean
47
48
  tabHidden: boolean
48
49
  redirect?: string
50
+ version: number
49
51
  createdAt: string
50
52
  updatedAt: string
51
53
  }
@@ -108,6 +110,40 @@ function failure(message: string, code = 40001): DemoApiResponse {
108
110
  return envelope(null, message, code)
109
111
  }
110
112
 
113
+ /**
114
+ * 菜单写路径的结构完整性校验:父级必须存在、不得指向自身或后代(成环后行从
115
+ * 树中不可达),button 必须挂页面且不能拥有子级,带 button 子级的行不能改出 page。
116
+ * 版本冲突业务码 40901 须与 rbac.ts 的 MENU_VERSION_CONFLICT_CODE 保持一致。
117
+ */
118
+ function menuStructureError(
119
+ menus: readonly DemoMenu[],
120
+ selfId: string | undefined,
121
+ parentId: string | undefined,
122
+ kind: MenuKind,
123
+ ): string | undefined {
124
+ if (kind === 'button' && !parentId) return 'Button permission requires a parent menu.'
125
+ if (kind === 'button' && selfId && menus.some((menu) => menu.parentId === selfId))
126
+ return 'Menus with children cannot become button permissions.'
127
+ if (kind !== 'page' && menus.some((menu) => menu.parentId === selfId && menu.kind === 'button'))
128
+ return 'Menus with button children must remain pages.'
129
+ if (!parentId) return undefined
130
+ const parent = menus.find((menu) => menu.id === parentId)
131
+ if (!parent) return 'Menu parent not found.'
132
+ if (parent.kind === 'button') return 'Button permission menus cannot have child menus.'
133
+ if (selfId) {
134
+ if (parentId === selfId) return 'Menu parent cannot be the menu itself.'
135
+ const visited = new Set<string>([parentId])
136
+ let cursorId: string | undefined = parent.parentId
137
+ while (cursorId && !visited.has(cursorId)) {
138
+ visited.add(cursorId)
139
+ if (cursorId === selfId) return 'Menu parent cannot be one of its descendants.'
140
+ cursorId = menus.find((item) => item.id === cursorId)?.parentId
141
+ }
142
+ }
143
+ if (kind === 'button' && parent.kind !== 'page') return 'Button permission must attach to a page menu.'
144
+ return undefined
145
+ }
146
+
111
147
  function asRecord(value: unknown): Record<string, unknown> {
112
148
  return typeof value === 'object' && value !== null && !Array.isArray(value)
113
149
  ? (value as Record<string, unknown>)
@@ -243,6 +279,7 @@ function initialState() {
243
279
  kind: 'page',
244
280
  code: 'dashboard',
245
281
  title: 'Dashboard',
282
+ titleKey: 'menu.dashboard',
246
283
  path: '/dashboard',
247
284
  componentKey: 'dashboard',
248
285
  icon: 'dashboard',
@@ -252,6 +289,7 @@ function initialState() {
252
289
  visible: true,
253
290
  cache: true,
254
291
  tabHidden: false,
292
+ version: 1,
255
293
  createdAt: NOW,
256
294
  updatedAt: NOW,
257
295
  },
@@ -260,6 +298,7 @@ function initialState() {
260
298
  kind: 'directory',
261
299
  code: 'system',
262
300
  title: 'System',
301
+ titleKey: 'menu.system',
263
302
  path: '/system',
264
303
  componentKey: 'outlet',
265
304
  icon: 'system',
@@ -269,6 +308,7 @@ function initialState() {
269
308
  cache: false,
270
309
  tabHidden: false,
271
310
  redirect: '/system/users',
311
+ version: 1,
272
312
  createdAt: NOW,
273
313
  updatedAt: NOW,
274
314
  },
@@ -278,6 +318,7 @@ function initialState() {
278
318
  kind: 'page',
279
319
  code: 'users',
280
320
  title: 'Users',
321
+ titleKey: 'menu.users',
281
322
  path: 'users',
282
323
  componentKey: 'user-list',
283
324
  permission: 'system:user:read',
@@ -286,6 +327,7 @@ function initialState() {
286
327
  visible: true,
287
328
  cache: true,
288
329
  tabHidden: false,
330
+ version: 1,
289
331
  createdAt: NOW,
290
332
  updatedAt: NOW,
291
333
  },
@@ -295,6 +337,7 @@ function initialState() {
295
337
  kind: 'page',
296
338
  code: 'roles',
297
339
  title: 'Roles',
340
+ titleKey: 'menu.roles',
298
341
  path: 'roles',
299
342
  componentKey: 'role-list',
300
343
  permission: 'system:role:read',
@@ -303,6 +346,7 @@ function initialState() {
303
346
  visible: true,
304
347
  cache: true,
305
348
  tabHidden: false,
349
+ version: 1,
306
350
  createdAt: NOW,
307
351
  updatedAt: NOW,
308
352
  },
@@ -312,6 +356,7 @@ function initialState() {
312
356
  kind: 'page',
313
357
  code: 'menus',
314
358
  title: 'Menus',
359
+ titleKey: 'menu.menus',
315
360
  path: 'menus',
316
361
  componentKey: 'menu-list',
317
362
  permission: 'system:menu:read',
@@ -320,6 +365,7 @@ function initialState() {
320
365
  visible: true,
321
366
  cache: true,
322
367
  tabHidden: false,
368
+ version: 1,
323
369
  createdAt: NOW,
324
370
  updatedAt: NOW,
325
371
  },
@@ -329,6 +375,7 @@ function initialState() {
329
375
  kind: 'page',
330
376
  code: 'audit',
331
377
  title: 'Audit log',
378
+ titleKey: 'menu.audit',
332
379
  path: 'audit',
333
380
  componentKey: 'audit-list',
334
381
  permission: 'system:audit:read',
@@ -337,6 +384,7 @@ function initialState() {
337
384
  visible: true,
338
385
  cache: false,
339
386
  tabHidden: false,
387
+ version: 1,
340
388
  createdAt: NOW,
341
389
  updatedAt: NOW,
342
390
  },
@@ -654,13 +702,23 @@ export function createDemoApi(): DemoApi {
654
702
  }
655
703
 
656
704
  if (method === 'POST' && path === '/system/menus') {
705
+ const kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
706
+ const parentId =
707
+ typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined
708
+ const code = String(body.code ?? '').trim()
709
+ const title = String(body.title ?? '').trim()
710
+ if (!code) return failure('Menu code is required.', 40001)
711
+ if (!title) return failure('Menu title is required.', 40001)
712
+ const structureError = menuStructureError(state.menus, undefined, parentId, kind)
713
+ if (structureError) return failure(structureError, 40001)
657
714
  const id = `menu-${state.nextId++}`
658
715
  const menu: DemoMenu = {
659
716
  id,
660
- parentId: typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined,
661
- kind: body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page',
662
- code: String(body.code ?? '').trim(),
663
- title: String(body.title ?? '').trim(),
717
+ parentId,
718
+ kind,
719
+ code,
720
+ title,
721
+ titleKey: typeof body.titleKey === 'string' && body.titleKey ? body.titleKey : undefined,
664
722
  path: typeof body.path === 'string' && body.path ? body.path : undefined,
665
723
  componentKey:
666
724
  typeof body.componentKey === 'string' && body.componentKey
@@ -675,6 +733,7 @@ export function createDemoApi(): DemoApi {
675
733
  cache: body.cache !== false,
676
734
  tabHidden: body.tabHidden === true,
677
735
  redirect: typeof body.redirect === 'string' && body.redirect ? body.redirect : undefined,
736
+ version: 1,
678
737
  createdAt: NOW,
679
738
  updatedAt: NOW,
680
739
  }
@@ -709,6 +768,7 @@ export function createDemoApi(): DemoApi {
709
768
  const next = status(body.status)
710
769
  for (const menu of state.menus.filter((item) => ids.has(item.id))) {
711
770
  menu.status = next
771
+ menu.version += 1
712
772
  menu.updatedAt = new Date().toISOString()
713
773
  revise('menu.status', 'menu', menu.id, menu.title || menu.code, `Set status to ${next}.`)
714
774
  }
@@ -720,11 +780,26 @@ export function createDemoApi(): DemoApi {
720
780
  if (!menu) return failure('Menu not found.', 40401)
721
781
  if (method === 'GET') return envelope(cloneMenu(menu))
722
782
  if (method === 'PUT') {
723
- menu.parentId =
783
+ const kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
784
+ const parentId =
724
785
  typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined
725
- menu.kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
726
- menu.code = String(body.code ?? menu.code).trim()
727
- menu.title = String(body.title ?? menu.title).trim()
786
+ const code = String(body.code ?? menu.code).trim()
787
+ const title = String(body.title ?? menu.title).trim()
788
+ if (!code) return failure('Menu code is required.', 40001)
789
+ if (!title) return failure('Menu title is required.', 40001)
790
+ const structureError = menuStructureError(state.menus, menu.id, parentId, kind)
791
+ if (structureError) return failure(structureError, 40001)
792
+ if (body.version !== undefined) {
793
+ const clientVersion = Number(body.version)
794
+ if (!Number.isInteger(clientVersion) || clientVersion !== menu.version)
795
+ return failure('Menu was modified by someone else. Refresh and retry.', 40901)
796
+ }
797
+ menu.parentId = parentId
798
+ menu.kind = kind
799
+ menu.code = code
800
+ menu.title = title
801
+ menu.titleKey =
802
+ typeof body.titleKey === 'string' && body.titleKey ? body.titleKey : undefined
728
803
  menu.path = typeof body.path === 'string' && body.path ? body.path : undefined
729
804
  menu.componentKey =
730
805
  typeof body.componentKey === 'string' && body.componentKey ? body.componentKey : undefined
@@ -738,6 +813,7 @@ export function createDemoApi(): DemoApi {
738
813
  menu.tabHidden = body.tabHidden === true
739
814
  menu.redirect =
740
815
  typeof body.redirect === 'string' && body.redirect ? body.redirect : undefined
816
+ menu.version += 1
741
817
  menu.updatedAt = new Date().toISOString()
742
818
  revise('menu.update', 'menu', menu.id, menu.title || menu.code, 'Updated demo menu.')
743
819
  return envelope(cloneMenu(menu))
@@ -1,3 +1,4 @@
1
+ import { readdir, readFile, writeFile } from 'node:fs/promises'
1
2
  import path from 'node:path'
2
3
  import { fileURLToPath } from 'node:url'
3
4
  // 使用 swagger-typescript-api 从 OpenAPI 规范生成 API 客户端
@@ -6,10 +7,11 @@ import { generateApi } from 'swagger-typescript-api'
6
7
  /* eslint-disable node/prefer-global/process */
7
8
 
8
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const outputDirectory = path.resolve(__dirname, '../src/api/generated')
9
11
 
10
12
  generateApi({
11
13
  name: 'Api.ts',
12
- output: path.resolve(__dirname, '../src/api/generated'),
14
+ output: outputDirectory,
13
15
  input: path.resolve(__dirname, '../openapi.json'),
14
16
  modular: true,
15
17
  moduleNameFirstTag: true,
@@ -18,10 +20,92 @@ generateApi({
18
20
  singleHttpClient: true,
19
21
  cleanOutput: true,
20
22
  })
23
+ .then(() => normalizeGeneratedApi(outputDirectory))
21
24
  .then(() => {
22
25
  process.stdout.write('API client generated successfully!\n')
23
26
  })
24
- .catch((e) => {
25
- console.error('Failed to generate API client:', e)
27
+ .catch((error) => {
28
+ console.error('Failed to generate API client:', error)
26
29
  process.exit(1)
27
30
  })
31
+
32
+ async function normalizeGeneratedApi(directory: string) {
33
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
34
+ if (!entry.isFile() || !entry.name.endsWith('.ts')) continue
35
+ const filePath = path.join(directory, entry.name)
36
+ const source = await readFile(filePath, 'utf8')
37
+ const normalized = normalizeGeneratedSource(source, entry.name)
38
+ if (normalized !== source) await writeFile(filePath, normalized, 'utf8')
39
+ }
40
+ }
41
+
42
+ function normalizeGeneratedSource(source: string, fileName: string) {
43
+ let normalized = source
44
+ .replace(/^\/\* eslint-disable \*\/\r?\n/u, '')
45
+ .replace(/^\/\* tslint:disable \*\/\r?\n/u, '')
46
+ .replace(/^\/\/ @ts-nocheck\r?\n/u, '')
47
+ .replace(/\bany\b/gu, 'unknown')
48
+
49
+ if (fileName === 'http-client.ts') normalized = normalizeHttpClient(normalized)
50
+ return normalized
51
+ }
52
+
53
+ function normalizeHttpClient(source: string) {
54
+ let normalized = source.replace(
55
+ ' return value.map((v: unknown) => this.encodeQueryParam(key, v)).join("&");',
56
+ ' if (!Array.isArray(value)) return "";\n return value.map((v) => this.encodeQueryParam(key, v)).join("&");',
57
+ )
58
+
59
+ const formatterStart = normalized.indexOf(' private contentFormatters:')
60
+ const formatterEnd = normalized.indexOf('\n\n protected mergeRequestParams', formatterStart)
61
+ if (formatterStart < 0 || formatterEnd < 0)
62
+ throw new Error('Generated HTTP client formatters changed unexpectedly.')
63
+
64
+ const formatter = ` private contentFormatters: Record<ContentType, (input: unknown) => BodyInit | null> = {
65
+ [ContentType.Json]: (input: unknown) =>
66
+ input === null || typeof input === "undefined"
67
+ ? null
68
+ : JSON.stringify(input) ?? null,
69
+ [ContentType.JsonApi]: (input: unknown) =>
70
+ input === null || typeof input === "undefined"
71
+ ? null
72
+ : JSON.stringify(input) ?? null,
73
+ [ContentType.Text]: (input: unknown) =>
74
+ typeof input === "string" ? input : JSON.stringify(input) ?? null,
75
+ [ContentType.FormData]: (input: unknown) => {
76
+ if (input instanceof FormData) {
77
+ return input;
78
+ }
79
+
80
+ const record = isRecord(input) ? input : {};
81
+ return Object.keys(record).reduce((formData, key) => {
82
+ const property = record[key];
83
+ formData.append(
84
+ key,
85
+ property instanceof Blob
86
+ ? property
87
+ : typeof property === "object" && property !== null
88
+ ? JSON.stringify(property) ?? ""
89
+ : String(property),
90
+ );
91
+ return formData;
92
+ }, new FormData());
93
+ },
94
+ [ContentType.UrlEncoded]: (input: unknown) =>
95
+ this.toQueryString(isRecord(input) ? input : {}),
96
+ };`
97
+ normalized = `${normalized.slice(0, formatterStart)}${formatter}${normalized.slice(formatterEnd)}`
98
+
99
+ const classMarker = 'export class HttpClient<SecurityDataType = unknown> {'
100
+ if (!normalized.includes('function isRecord(value: unknown): value is Record<string, unknown>')) {
101
+ normalized = normalized.replace(
102
+ classMarker,
103
+ `function isRecord(value: unknown): value is Record<string, unknown> {
104
+ return typeof value === "object" && value !== null;
105
+ }
106
+
107
+ ${classMarker}`,
108
+ )
109
+ }
110
+ return normalized
111
+ }
@@ -23,6 +23,7 @@ describe('admin build chunk policy', () => {
23
23
  'vendor-vue-i18n',
24
24
  'vendor-vueuse',
25
25
  'vendor-positioning',
26
+ 'vendor-async-validator',
26
27
  'vendor-table-suite',
27
28
  'vendor-initial',
28
29
  ]),
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
2
- /* tslint:disable */
3
- // @ts-nocheck
4
1
  /*
5
2
  * ---------------------------------------------------------------
6
3
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -11,7 +8,7 @@
11
8
  */
12
9
 
13
10
  export interface LoginCredentials {
14
- /** 用户�?*/
11
+ /** 用户名 */
15
12
  username: string;
16
13
  /** 密码 */
17
14
  password: string;
@@ -27,7 +24,7 @@ export interface LoginResponse {
27
24
  permissions?: string[];
28
25
  /** 角色ID列表 */
29
26
  roleIds?: string[];
30
- /** 授权版本�?*/
27
+ /** 授权版本号 */
31
28
  authorizationRevision?: number;
32
29
  }
33
30
 
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
2
- /* tslint:disable */
3
- // @ts-nocheck
4
1
  /*
5
2
  * ---------------------------------------------------------------
6
3
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -10,7 +7,7 @@
10
7
  * ---------------------------------------------------------------
11
8
  */
12
9
 
13
- export type QueryParamsType = Record<string | number, any>;
10
+ export type QueryParamsType = Record<string | number, unknown>;
14
11
  export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
15
12
 
16
13
  export interface FullRequestParams extends Omit<RequestInit, "body"> {
@@ -62,6 +59,10 @@ export enum ContentType {
62
59
  Text = "text/plain",
63
60
  }
64
61
 
62
+ function isRecord(value: unknown): value is Record<string, unknown> {
63
+ return typeof value === "object" && value !== null;
64
+ }
65
+
65
66
  export class HttpClient<SecurityDataType = unknown> {
66
67
  public baseUrl: string = "/api";
67
68
  private securityData: SecurityDataType | null = null;
@@ -85,7 +86,7 @@ export class HttpClient<SecurityDataType = unknown> {
85
86
  this.securityData = data;
86
87
  };
87
88
 
88
- protected encodeQueryParam(key: string, value: any) {
89
+ protected encodeQueryParam(key: string, value: unknown) {
89
90
  const encodedKey = encodeURIComponent(key);
90
91
  return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
91
92
  }
@@ -96,7 +97,8 @@ export class HttpClient<SecurityDataType = unknown> {
96
97
 
97
98
  protected addArrayQueryParam(query: QueryParamsType, key: string) {
98
99
  const value = query[key];
99
- return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
100
+ if (!Array.isArray(value)) return "";
101
+ return value.map((v) => this.encodeQueryParam(key, v)).join("&");
100
102
  }
101
103
 
102
104
  protected toQueryString(rawQuery?: QueryParamsType): string {
@@ -118,38 +120,38 @@ export class HttpClient<SecurityDataType = unknown> {
118
120
  return queryString ? `?${queryString}` : "";
119
121
  }
120
122
 
121
- private contentFormatters: Record<ContentType, (input: any) => any> = {
122
- [ContentType.Json]: (input: any) =>
123
- input !== null && (typeof input === "object" || typeof input === "string")
124
- ? JSON.stringify(input)
125
- : input,
126
- [ContentType.JsonApi]: (input: any) =>
127
- input !== null && (typeof input === "object" || typeof input === "string")
128
- ? JSON.stringify(input)
129
- : input,
130
- [ContentType.Text]: (input: any) =>
131
- input !== null && typeof input !== "string"
132
- ? JSON.stringify(input)
133
- : input,
134
- [ContentType.FormData]: (input: any) => {
123
+ private contentFormatters: Record<ContentType, (input: unknown) => BodyInit | null> = {
124
+ [ContentType.Json]: (input: unknown) =>
125
+ input === null || typeof input === "undefined"
126
+ ? null
127
+ : JSON.stringify(input) ?? null,
128
+ [ContentType.JsonApi]: (input: unknown) =>
129
+ input === null || typeof input === "undefined"
130
+ ? null
131
+ : JSON.stringify(input) ?? null,
132
+ [ContentType.Text]: (input: unknown) =>
133
+ typeof input === "string" ? input : JSON.stringify(input) ?? null,
134
+ [ContentType.FormData]: (input: unknown) => {
135
135
  if (input instanceof FormData) {
136
136
  return input;
137
137
  }
138
138
 
139
- return Object.keys(input || {}).reduce((formData, key) => {
140
- const property = input[key];
139
+ const record = isRecord(input) ? input : {};
140
+ return Object.keys(record).reduce((formData, key) => {
141
+ const property = record[key];
141
142
  formData.append(
142
143
  key,
143
144
  property instanceof Blob
144
145
  ? property
145
146
  : typeof property === "object" && property !== null
146
- ? JSON.stringify(property)
147
- : `${property}`,
147
+ ? JSON.stringify(property) ?? ""
148
+ : String(property),
148
149
  );
149
150
  return formData;
150
151
  }, new FormData());
151
152
  },
152
- [ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
153
+ [ContentType.UrlEncoded]: (input: unknown) =>
154
+ this.toQueryString(isRecord(input) ? input : {}),
153
155
  };
154
156
 
155
157
  protected mergeRequestParams(
@@ -193,7 +195,7 @@ export class HttpClient<SecurityDataType = unknown> {
193
195
  }
194
196
  };
195
197
 
196
- public request = async <T = any, E = any>({
198
+ public request = async <T = unknown, E = unknown>({
197
199
  body,
198
200
  secure,
199
201
  path,
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
2
- /* tslint:disable */
3
- // @ts-nocheck
4
1
  /*
5
2
  * ---------------------------------------------------------------
6
3
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -47,7 +44,7 @@ export class 系统管理内容文章<SecurityDataType = unknown> {
47
44
  },
48
45
  params: RequestParams = {},
49
46
  ) =>
50
- this.http.request<PageResultContentArticle, any>({
47
+ this.http.request<PageResultContentArticle, unknown>({
51
48
  path: `/system/content-articles`,
52
49
  method: "GET",
53
50
  query: query,
@@ -69,7 +66,7 @@ export class 系统管理内容文章<SecurityDataType = unknown> {
69
66
  data: ContentArticleDraft,
70
67
  params: RequestParams = {},
71
68
  ) =>
72
- this.http.request<ContentArticle, any>({
69
+ this.http.request<ContentArticle, unknown>({
73
70
  path: `/system/content-articles`,
74
71
  method: "POST",
75
72
  body: data,
@@ -94,7 +91,7 @@ export class 系统管理内容文章<SecurityDataType = unknown> {
94
91
  },
95
92
  params: RequestParams = {},
96
93
  ) =>
97
- this.http.request<void, any>({
94
+ this.http.request<void, unknown>({
98
95
  path: `/system/content-articles`,
99
96
  method: "DELETE",
100
97
  body: data,
@@ -113,7 +110,7 @@ export class 系统管理内容文章<SecurityDataType = unknown> {
113
110
  * @response `200` `ContentArticle` 成功
114
111
  */
115
112
  contentArticlesDetail = (id: string, params: RequestParams = {}) =>
116
- this.http.request<ContentArticle, any>({
113
+ this.http.request<ContentArticle, unknown>({
117
114
  path: `/system/content-articles/${id}`,
118
115
  method: "GET",
119
116
  secure: true,
@@ -135,7 +132,7 @@ export class 系统管理内容文章<SecurityDataType = unknown> {
135
132
  data: ContentArticleDraft,
136
133
  params: RequestParams = {},
137
134
  ) =>
138
- this.http.request<ContentArticle, any>({
135
+ this.http.request<ContentArticle, unknown>({
139
136
  path: `/system/content-articles/${id}`,
140
137
  method: "PUT",
141
138
  body: data,
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
2
- /* tslint:disable */
3
- // @ts-nocheck
4
1
  /*
5
2
  * ---------------------------------------------------------------
6
3
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -42,7 +39,7 @@ export class 系统管理审计<SecurityDataType = unknown> {
42
39
  },
43
40
  params: RequestParams = {},
44
41
  ) =>
45
- this.http.request<PageResultRbacAuditEvent, any>({
42
+ this.http.request<PageResultRbacAuditEvent, unknown>({
46
43
  path: `/system/audit`,
47
44
  method: "GET",
48
45
  query: query,
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
2
- /* tslint:disable */
3
- // @ts-nocheck
4
1
  /*
5
2
  * ---------------------------------------------------------------
6
3
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -37,7 +34,7 @@ export class 系统管理文件上传<SecurityDataType = unknown> {
37
34
  },
38
35
  params: RequestParams = {},
39
36
  ) =>
40
- this.http.request<UploadResponse, any>({
37
+ this.http.request<UploadResponse, unknown>({
41
38
  path: `/system/uploads`,
42
39
  method: "POST",
43
40
  body: data,
@@ -57,7 +54,7 @@ export class 系统管理文件上传<SecurityDataType = unknown> {
57
54
  * @response `204` `void` 删除成功
58
55
  */
59
56
  uploadsDelete = (id: string, params: RequestParams = {}) =>
60
- this.http.request<void, any>({
57
+ this.http.request<void, unknown>({
61
58
  path: `/system/uploads/${id}`,
62
59
  method: "DELETE",
63
60
  secure: true,
@@ -1,6 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
2
- /* tslint:disable */
3
- // @ts-nocheck
4
1
  /*
5
2
  * ---------------------------------------------------------------
6
3
  * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
@@ -50,7 +47,7 @@ export class 系统管理用户<SecurityDataType = unknown> {
50
47
  },
51
48
  params: RequestParams = {},
52
49
  ) =>
53
- this.http.request<PageResultAdminUser, any>({
50
+ this.http.request<PageResultAdminUser, unknown>({
54
51
  path: `/system/users`,
55
52
  method: "GET",
56
53
  query: query,
@@ -69,7 +66,7 @@ export class 系统管理用户<SecurityDataType = unknown> {
69
66
  * @response `200` `AdminUser` 创建成功
70
67
  */
71
68
  usersCreate = (data: AdminUserDraft, params: RequestParams = {}) =>
72
- this.http.request<AdminUser, any>({
69
+ this.http.request<AdminUser, unknown>({
73
70
  path: `/system/users`,
74
71
  method: "POST",
75
72
  body: data,
@@ -94,7 +91,7 @@ export class 系统管理用户<SecurityDataType = unknown> {
94
91
  },
95
92
  params: RequestParams = {},
96
93
  ) =>
97
- this.http.request<void, any>({
94
+ this.http.request<void, unknown>({
98
95
  path: `/system/users`,
99
96
  method: "DELETE",
100
97
  body: data,
@@ -113,7 +110,7 @@ export class 系统管理用户<SecurityDataType = unknown> {
113
110
  * @response `200` `AdminUser` 成功
114
111
  */
115
112
  usersDetail = (id: string, params: RequestParams = {}) =>
116
- this.http.request<AdminUser, any>({
113
+ this.http.request<AdminUser, unknown>({
117
114
  path: `/system/users/${id}`,
118
115
  method: "GET",
119
116
  secure: true,
@@ -135,7 +132,7 @@ export class 系统管理用户<SecurityDataType = unknown> {
135
132
  data: AdminUserDraft,
136
133
  params: RequestParams = {},
137
134
  ) =>
138
- this.http.request<AdminUser, any>({
135
+ this.http.request<AdminUser, unknown>({
139
136
  path: `/system/users/${id}`,
140
137
  method: "PUT",
141
138
  body: data,
@@ -149,7 +146,8 @@ export class 系统管理用户<SecurityDataType = unknown> {
149
146
  *
150
147
  * @tags 系统管理-用户
151
148
  * @name UsersStatusPartialUpdate
152
- * @summary 批量更新用户状�? * @request PATCH:/system/users/status
149
+ * @summary 批量更新用户状态
150
+ * @request PATCH:/system/users/status
153
151
  * @secure
154
152
  * @response `204` `void` 更新成功
155
153
  */
@@ -160,7 +158,7 @@ export class 系统管理用户<SecurityDataType = unknown> {
160
158
  },
161
159
  params: RequestParams = {},
162
160
  ) =>
163
- this.http.request<void, any>({
161
+ this.http.request<void, unknown>({
164
162
  path: `/system/users/status`,
165
163
  method: "PATCH",
166
164
  body: data,