@liujitcn/kratos-admin-system 0.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 (208) hide show
  1. package/README.md +137 -0
  2. package/dist/package/declarations/index.d.ts +1 -0
  3. package/dist/package/declarations/src/ai.d.ts +10 -0
  4. package/dist/package/declarations/src/api/base/ai_message.d.ts +27 -0
  5. package/dist/package/declarations/src/api/base/ai_session.d.ts +17 -0
  6. package/dist/package/declarations/src/api/base/ai_tool.d.ts +7 -0
  7. package/dist/package/declarations/src/api/base/oauth.d.ts +13 -0
  8. package/dist/package/declarations/src/api/base/sse.d.ts +31 -0
  9. package/dist/package/declarations/src/api/system/auth.d.ts +17 -0
  10. package/dist/package/declarations/src/api/system/base_api.d.ts +22 -0
  11. package/dist/package/declarations/src/api/system/base_area.d.ts +19 -0
  12. package/dist/package/declarations/src/api/system/base_config.d.ts +20 -0
  13. package/dist/package/declarations/src/api/system/base_dept.d.ts +21 -0
  14. package/dist/package/declarations/src/api/system/base_dict.d.ts +32 -0
  15. package/dist/package/declarations/src/api/system/base_job.d.ts +28 -0
  16. package/dist/package/declarations/src/api/system/base_log.d.ts +9 -0
  17. package/dist/package/declarations/src/api/system/base_menu.d.ts +21 -0
  18. package/dist/package/declarations/src/api/system/base_migration.d.ts +10 -0
  19. package/dist/package/declarations/src/api/system/base_post.d.ts +21 -0
  20. package/dist/package/declarations/src/api/system/base_role.d.ts +23 -0
  21. package/dist/package/declarations/src/api/system/base_tenant.d.ts +21 -0
  22. package/dist/package/declarations/src/api/system/base_user.d.ts +23 -0
  23. package/dist/package/declarations/src/api/system/code_gen.d.ts +14 -0
  24. package/dist/package/declarations/src/api/system/code_gen_column.d.ts +12 -0
  25. package/dist/package/declarations/src/api/system/code_gen_proto.d.ts +10 -0
  26. package/dist/package/declarations/src/api/system/code_gen_sse.d.ts +8 -0
  27. package/dist/package/declarations/src/api/system/code_gen_table.d.ts +18 -0
  28. package/dist/package/declarations/src/api/system/project_document.d.ts +9 -0
  29. package/dist/package/declarations/src/components/Ai.vue.d.ts +3 -0
  30. package/dist/package/declarations/src/index.d.ts +3 -0
  31. package/dist/package/declarations/src/module.d.ts +2 -0
  32. package/dist/package/declarations/src/rpc/base/v1/ai_message.d.ts +82 -0
  33. package/dist/package/declarations/src/rpc/base/v1/ai_session.d.ts +176 -0
  34. package/dist/package/declarations/src/rpc/base/v1/ai_tool.d.ts +59 -0
  35. package/dist/package/declarations/src/rpc/base/v1/oauth.d.ts +167 -0
  36. package/dist/package/declarations/src/rpc/base/v1/sse.d.ts +13 -0
  37. package/dist/package/declarations/src/rpc/common/v1/common.d.ts +57 -0
  38. package/dist/package/declarations/src/rpc/common/v1/enum.d.ts +58 -0
  39. package/dist/package/declarations/src/rpc/common/v1/types.d.ts +60 -0
  40. package/dist/package/declarations/src/rpc/google/protobuf/empty.d.ts +11 -0
  41. package/dist/package/declarations/src/rpc/google/protobuf/timestamp.d.ts +107 -0
  42. package/dist/package/declarations/src/rpc/system/admin/v1/auth.d.ts +156 -0
  43. package/dist/package/declarations/src/rpc/system/admin/v1/base_api.d.ts +193 -0
  44. package/dist/package/declarations/src/rpc/system/admin/v1/base_area.d.ts +82 -0
  45. package/dist/package/declarations/src/rpc/system/admin/v1/base_config.d.ts +112 -0
  46. package/dist/package/declarations/src/rpc/system/admin/v1/base_dept.d.ts +112 -0
  47. package/dist/package/declarations/src/rpc/system/admin/v1/base_dict.d.ts +215 -0
  48. package/dist/package/declarations/src/rpc/system/admin/v1/base_job.d.ts +177 -0
  49. package/dist/package/declarations/src/rpc/system/admin/v1/base_log.d.ts +87 -0
  50. package/dist/package/declarations/src/rpc/system/admin/v1/base_menu.d.ts +151 -0
  51. package/dist/package/declarations/src/rpc/system/admin/v1/base_migration.d.ts +64 -0
  52. package/dist/package/declarations/src/rpc/system/admin/v1/base_post.d.ts +112 -0
  53. package/dist/package/declarations/src/rpc/system/admin/v1/base_role.d.ts +128 -0
  54. package/dist/package/declarations/src/rpc/system/admin/v1/base_tenant.d.ts +112 -0
  55. package/dist/package/declarations/src/rpc/system/admin/v1/base_user.d.ts +161 -0
  56. package/dist/package/declarations/src/rpc/system/admin/v1/code_gen.d.ts +155 -0
  57. package/dist/package/declarations/src/rpc/system/admin/v1/code_gen_column.d.ts +143 -0
  58. package/dist/package/declarations/src/rpc/system/admin/v1/code_gen_proto.d.ts +86 -0
  59. package/dist/package/declarations/src/rpc/system/admin/v1/code_gen_table.d.ts +149 -0
  60. package/dist/package/declarations/src/rpc/system/admin/v1/project_document.d.ts +64 -0
  61. package/dist/package/declarations/src/rpc/system/common/v1/enum.d.ts +67 -0
  62. package/dist/package/declarations/src/views/ai/chat/attachment.d.ts +14 -0
  63. package/dist/package/declarations/src/views/ai/chat/components/AiMarkdown.vue.d.ts +13 -0
  64. package/dist/package/declarations/src/views/ai/chat/components/ChatPanel.vue.d.ts +45 -0
  65. package/dist/package/declarations/src/views/ai/chat/components/SessionPanel.vue.d.ts +34 -0
  66. package/dist/package/declarations/src/views/ai/chat/components/XSender.vue.d.ts +12 -0
  67. package/dist/package/declarations/src/views/ai/chat/index.vue.d.ts +4 -0
  68. package/dist/package/declarations/src/views/ai/chat/message.d.ts +59 -0
  69. package/dist/package/declarations/src/views/ai/chat/stream.d.ts +10 -0
  70. package/dist/package/declarations/src/views/ai/chat/types.d.ts +115 -0
  71. package/dist/package/declarations/src/views/base/api/index.vue.d.ts +3 -0
  72. package/dist/package/declarations/src/views/base/area/index.vue.d.ts +3 -0
  73. package/dist/package/declarations/src/views/base/config/index.vue.d.ts +3 -0
  74. package/dist/package/declarations/src/views/base/dept/index.vue.d.ts +3 -0
  75. package/dist/package/declarations/src/views/base/dict/index.vue.d.ts +3 -0
  76. package/dist/package/declarations/src/views/base/dict/item.vue.d.ts +3 -0
  77. package/dist/package/declarations/src/views/base/job/index.vue.d.ts +3 -0
  78. package/dist/package/declarations/src/views/base/job/log.vue.d.ts +3 -0
  79. package/dist/package/declarations/src/views/base/log/index.vue.d.ts +3 -0
  80. package/dist/package/declarations/src/views/base/menu/index.vue.d.ts +3 -0
  81. package/dist/package/declarations/src/views/base/migration/index.vue.d.ts +4 -0
  82. package/dist/package/declarations/src/views/base/post/index.vue.d.ts +3 -0
  83. package/dist/package/declarations/src/views/base/role/index.vue.d.ts +3 -0
  84. package/dist/package/declarations/src/views/base/tenant/index.vue.d.ts +3 -0
  85. package/dist/package/declarations/src/views/base/user/components/dept-tree.vue.d.ts +19 -0
  86. package/dist/package/declarations/src/views/base/user/index.vue.d.ts +3 -0
  87. package/dist/package/declarations/src/views/profile/components/base.vue.d.ts +13 -0
  88. package/dist/package/declarations/src/views/profile/components/password.vue.d.ts +3 -0
  89. package/dist/package/declarations/src/views/profile/components/security.vue.d.ts +15 -0
  90. package/dist/package/declarations/src/views/profile/index.vue.d.ts +3 -0
  91. package/dist/package/declarations/src/views/tool/api-doc/index.vue.d.ts +4 -0
  92. package/dist/package/declarations/src/views/tool/code-gen/code-preview/index.vue.d.ts +3 -0
  93. package/dist/package/declarations/src/views/tool/code-gen/columns/index.vue.d.ts +3 -0
  94. package/dist/package/declarations/src/views/tool/code-gen/columns/option-copy.d.ts +25 -0
  95. package/dist/package/declarations/src/views/tool/code-gen/components/CodeGenProgressDialog.vue.d.ts +16 -0
  96. package/dist/package/declarations/src/views/tool/code-gen/components/CodePreviewPane.vue.d.ts +9 -0
  97. package/dist/package/declarations/src/views/tool/code-gen/config.d.ts +32 -0
  98. package/dist/package/declarations/src/views/tool/code-gen/preview/capabilities.d.ts +20 -0
  99. package/dist/package/declarations/src/views/tool/code-gen/preview/data.d.ts +42 -0
  100. package/dist/package/declarations/src/views/tool/code-gen/preview/index.vue.d.ts +3 -0
  101. package/dist/package/declarations/src/views/tool/code-gen/proto/index.vue.d.ts +3 -0
  102. package/dist/package/declarations/src/views/tool/code-gen/table/index.vue.d.ts +3 -0
  103. package/dist/package/declarations/src/views/tool/project-doc/index.vue.d.ts +4 -0
  104. package/dist/package/src/ai.ts +16 -0
  105. package/dist/package/src/api/base/ai_message.ts +139 -0
  106. package/dist/package/src/api/base/ai_session.ts +77 -0
  107. package/dist/package/src/api/base/ai_tool.ts +22 -0
  108. package/dist/package/src/api/base/oauth.ts +47 -0
  109. package/dist/package/src/api/base/sse.ts +192 -0
  110. package/dist/package/src/api/system/auth.ts +65 -0
  111. package/dist/package/src/api/system/base_api.ts +95 -0
  112. package/dist/package/src/api/system/base_area.ts +73 -0
  113. package/dist/package/src/api/system/base_config.ts +82 -0
  114. package/dist/package/src/api/system/base_dept.ts +83 -0
  115. package/dist/package/src/api/system/base_dict.ts +144 -0
  116. package/dist/package/src/api/system/base_job.ts +125 -0
  117. package/dist/package/src/api/system/base_log.ts +32 -0
  118. package/dist/package/src/api/system/base_menu.ts +83 -0
  119. package/dist/package/src/api/system/base_migration.ts +35 -0
  120. package/dist/package/src/api/system/base_post.ts +83 -0
  121. package/dist/package/src/api/system/base_role.ts +93 -0
  122. package/dist/package/src/api/system/base_tenant.ts +83 -0
  123. package/dist/package/src/api/system/base_user.ts +93 -0
  124. package/dist/package/src/api/system/code_gen.ts +56 -0
  125. package/dist/package/src/api/system/code_gen_column.ts +43 -0
  126. package/dist/package/src/api/system/code_gen_proto.ts +32 -0
  127. package/dist/package/src/api/system/code_gen_sse.ts +33 -0
  128. package/dist/package/src/api/system/code_gen_table.ts +74 -0
  129. package/dist/package/src/api/system/project_document.ts +33 -0
  130. package/dist/package/src/components/Ai.vue +57 -0
  131. package/dist/package/src/index.ts +3 -0
  132. package/dist/package/src/module.ts +17 -0
  133. package/dist/package/src/rpc/base/v1/ai_message.ts +98 -0
  134. package/dist/package/src/rpc/base/v1/ai_session.ts +214 -0
  135. package/dist/package/src/rpc/base/v1/ai_tool.ts +74 -0
  136. package/dist/package/src/rpc/base/v1/oauth.ts +199 -0
  137. package/dist/package/src/rpc/base/v1/sse.ts +22 -0
  138. package/dist/package/src/rpc/common/v1/common.ts +71 -0
  139. package/dist/package/src/rpc/common/v1/enum.ts +71 -0
  140. package/dist/package/src/rpc/common/v1/types.ts +77 -0
  141. package/dist/package/src/rpc/google/protobuf/empty.ts +19 -0
  142. package/dist/package/src/rpc/google/protobuf/timestamp.ts +115 -0
  143. package/dist/package/src/rpc/system/admin/v1/auth.ts +208 -0
  144. package/dist/package/src/rpc/system/admin/v1/base_api.ts +241 -0
  145. package/dist/package/src/rpc/system/admin/v1/base_area.ts +105 -0
  146. package/dist/package/src/rpc/system/admin/v1/base_config.ts +140 -0
  147. package/dist/package/src/rpc/system/admin/v1/base_dept.ts +140 -0
  148. package/dist/package/src/rpc/system/admin/v1/base_dict.ts +249 -0
  149. package/dist/package/src/rpc/system/admin/v1/base_job.ts +206 -0
  150. package/dist/package/src/rpc/system/admin/v1/base_log.ts +101 -0
  151. package/dist/package/src/rpc/system/admin/v1/base_menu.ts +195 -0
  152. package/dist/package/src/rpc/system/admin/v1/base_migration.ts +81 -0
  153. package/dist/package/src/rpc/system/admin/v1/base_post.ts +134 -0
  154. package/dist/package/src/rpc/system/admin/v1/base_role.ts +151 -0
  155. package/dist/package/src/rpc/system/admin/v1/base_tenant.ts +134 -0
  156. package/dist/package/src/rpc/system/admin/v1/base_user.ts +190 -0
  157. package/dist/package/src/rpc/system/admin/v1/code_gen.ts +176 -0
  158. package/dist/package/src/rpc/system/admin/v1/code_gen_column.ts +170 -0
  159. package/dist/package/src/rpc/system/admin/v1/code_gen_proto.ts +104 -0
  160. package/dist/package/src/rpc/system/admin/v1/code_gen_table.ts +179 -0
  161. package/dist/package/src/rpc/system/admin/v1/project_document.ts +79 -0
  162. package/dist/package/src/rpc/system/common/v1/enum.ts +80 -0
  163. package/dist/package/src/typings/swagger-ui-dist.d.ts +28 -0
  164. package/dist/package/src/typings/x-markdown-vue.d.ts +1 -0
  165. package/dist/package/src/views/ai/chat/attachment.ts +65 -0
  166. package/dist/package/src/views/ai/chat/components/AiMarkdown.vue +162 -0
  167. package/dist/package/src/views/ai/chat/components/ChatPanel.vue +1861 -0
  168. package/dist/package/src/views/ai/chat/components/SessionPanel.vue +316 -0
  169. package/dist/package/src/views/ai/chat/components/XSender.vue +554 -0
  170. package/dist/package/src/views/ai/chat/index.vue +848 -0
  171. package/dist/package/src/views/ai/chat/message.ts +416 -0
  172. package/dist/package/src/views/ai/chat/stream.ts +115 -0
  173. package/dist/package/src/views/ai/chat/types.ts +126 -0
  174. package/dist/package/src/views/base/api/index.vue +455 -0
  175. package/dist/package/src/views/base/area/index.vue +269 -0
  176. package/dist/package/src/views/base/config/index.vue +530 -0
  177. package/dist/package/src/views/base/dept/index.vue +461 -0
  178. package/dist/package/src/views/base/dict/index.vue +304 -0
  179. package/dist/package/src/views/base/dict/item.vue +373 -0
  180. package/dist/package/src/views/base/job/index.vue +535 -0
  181. package/dist/package/src/views/base/job/log.vue +202 -0
  182. package/dist/package/src/views/base/log/index.vue +317 -0
  183. package/dist/package/src/views/base/menu/index.vue +944 -0
  184. package/dist/package/src/views/base/migration/index.vue +791 -0
  185. package/dist/package/src/views/base/post/index.vue +324 -0
  186. package/dist/package/src/views/base/role/index.vue +684 -0
  187. package/dist/package/src/views/base/tenant/index.vue +328 -0
  188. package/dist/package/src/views/base/user/components/dept-tree.vue +75 -0
  189. package/dist/package/src/views/base/user/index.vue +783 -0
  190. package/dist/package/src/views/profile/components/base.vue +320 -0
  191. package/dist/package/src/views/profile/components/password.vue +269 -0
  192. package/dist/package/src/views/profile/components/security.vue +443 -0
  193. package/dist/package/src/views/profile/index.vue +199 -0
  194. package/dist/package/src/views/tool/api-doc/index.vue +275 -0
  195. package/dist/package/src/views/tool/code-gen/code-preview/index.vue +233 -0
  196. package/dist/package/src/views/tool/code-gen/columns/index.vue +1456 -0
  197. package/dist/package/src/views/tool/code-gen/columns/option-copy.ts +125 -0
  198. package/dist/package/src/views/tool/code-gen/components/CodeGenProgressDialog.vue +328 -0
  199. package/dist/package/src/views/tool/code-gen/components/CodePreviewPane.vue +42 -0
  200. package/dist/package/src/views/tool/code-gen/config.ts +175 -0
  201. package/dist/package/src/views/tool/code-gen/preview/capabilities.ts +34 -0
  202. package/dist/package/src/views/tool/code-gen/preview/data.ts +331 -0
  203. package/dist/package/src/views/tool/code-gen/preview/index.vue +831 -0
  204. package/dist/package/src/views/tool/code-gen/proto/index.vue +703 -0
  205. package/dist/package/src/views/tool/code-gen/table/index.vue +864 -0
  206. package/dist/package/src/views/tool/project-doc/index.vue +561 -0
  207. package/package.json +60 -0
  208. package/tsconfig.json +13 -0
@@ -0,0 +1,34 @@
1
+ /** 预览能力判断所需的 Proto 检查项。 */
2
+ export interface CodeGenPreviewProtoCheck {
3
+ /** Proto 方法名。 */
4
+ method_name: string;
5
+ /** 接口是否已经存在。 */
6
+ exists: boolean;
7
+ /** 接口缺失时是否已选择生成。 */
8
+ generate_when_missing: boolean;
9
+ }
10
+
11
+ /** 代码生成页面预览支持的维护能力。 */
12
+ export interface CodeGenPreviewCapabilities {
13
+ /** 是否支持新增。 */
14
+ create: boolean;
15
+ /** 是否支持更新。 */
16
+ update: boolean;
17
+ /** 是否支持删除。 */
18
+ delete: boolean;
19
+ }
20
+
21
+ /** 根据当前实体可用的 Proto 方法解析预览维护能力。 */
22
+ export function resolveCodeGenPreviewCapabilities(
23
+ entityName: string,
24
+ protoChecks: CodeGenPreviewProtoCheck[]
25
+ ): CodeGenPreviewCapabilities {
26
+ const availableMethods = new Set(
27
+ protoChecks.filter(item => item.exists || item.generate_when_missing).map(item => item.method_name)
28
+ );
29
+ return {
30
+ create: availableMethods.has(`Create${entityName}`),
31
+ update: availableMethods.has(`Update${entityName}`),
32
+ delete: availableMethods.has(`Delete${entityName}`)
33
+ };
34
+ }
@@ -0,0 +1,331 @@
1
+ import previewAvatar from "@liujitcn/kratos-admin-core/assets/images/avatar.png";
2
+ import type { ProFormOption } from "@liujitcn/kratos-admin-core/components/ProForm/interface";
3
+ import type { OptionBaseDictResponse_BaseDict } from "@liujitcn/kratos-admin-system/rpc/system/admin/v1/base_dict";
4
+ import type { CodeGenColumn, CodeGenColumnOptionConfig, CodeGenColumnQueryConfig } from "@liujitcn/kratos-admin-system/rpc/system/admin/v1/code_gen_column";
5
+ import type { CodeGenLeftTreeConfig, CodeGenTableForm } from "@liujitcn/kratos-admin-system/rpc/system/admin/v1/code_gen_table";
6
+
7
+ /** 页面预览中的字段配置范围。 */
8
+ export type CodeGenPreviewScope = "query" | "list" | "form";
9
+
10
+ /** 页面预览模拟记录。 */
11
+ export type CodeGenPreviewRow = Record<string, any> & {
12
+ /** 树形表格子记录。 */
13
+ children?: CodeGenPreviewRow[];
14
+ /** 树形懒加载表格是否存在子记录。 */
15
+ has_children?: boolean;
16
+ };
17
+
18
+ /** 代码生成页面预览快照。 */
19
+ export interface CodeGenPagePreviewSnapshot {
20
+ /** 当前代码生成表配置。 */
21
+ table: CodeGenTableForm;
22
+ /** 当前已经保存的字段配置。 */
23
+ columns: CodeGenColumn[];
24
+ }
25
+
26
+ /** 页面预览中按字段和范围隔离的模拟选项。 */
27
+ export type CodeGenPreviewOptionMap = Record<string, ProFormOption[]>;
28
+
29
+ /** 创建字段指定配置范围的预览选项缓存键。 */
30
+ export function createCodeGenPreviewOptionKey(columnName: string, scope: CodeGenPreviewScope) {
31
+ return `${columnName}:${scope}`;
32
+ }
33
+
34
+ /** 根据当前字段配置和字典数据创建查询、列表和表单各自的模拟选项。 */
35
+ export function createCodeGenPreviewOptionMap(
36
+ columns: CodeGenColumn[],
37
+ dictionaries: OptionBaseDictResponse_BaseDict[]
38
+ ): CodeGenPreviewOptionMap {
39
+ const dictionaryMap = new Map(dictionaries.map(dictionary => [dictionary.code, dictionary]));
40
+ return columns.reduce<CodeGenPreviewOptionMap>((optionMap, column) => {
41
+ const label = column.comment || column.name;
42
+ const configs: Array<[CodeGenPreviewScope, CodeGenColumnOptionConfig | undefined, boolean]> = [
43
+ [
44
+ "query",
45
+ column.query_config?.option,
46
+ Boolean(column.query_config?.enabled && hasPreviewOptions(column.query_config.component))
47
+ ],
48
+ [
49
+ "list",
50
+ column.list_config?.option,
51
+ Boolean(column.list_config?.enabled && ["switch", "select", "tree-select"].includes(column.list_config.component))
52
+ ],
53
+ [
54
+ "form",
55
+ column.form_config?.option,
56
+ Boolean(column.form_config?.enabled && hasPreviewOptions(column.form_config.component))
57
+ ]
58
+ ];
59
+ configs.forEach(([scope, option, enabled]) => {
60
+ optionMap[createCodeGenPreviewOptionKey(column.name, scope)] = enabled
61
+ ? createCodeGenPreviewOptions(label, option, dictionaryMap)
62
+ : [];
63
+ });
64
+ return optionMap;
65
+ }, {});
66
+ }
67
+
68
+ /** 根据左树配置创建结构相符的模拟树节点。 */
69
+ export function createCodeGenLeftTreeOptions(config?: CodeGenLeftTreeConfig): ProFormOption[] {
70
+ if (!config?.table_name) return [];
71
+ const option: CodeGenColumnOptionConfig = {
72
+ kind: "tree",
73
+ source_type: "table",
74
+ source_value: config.table_name,
75
+ label_field: config.label_column,
76
+ value_field: config.value_column,
77
+ parent_field: config.parent_column,
78
+ active_value: "",
79
+ inactive_value: "",
80
+ lazy: config.lazy
81
+ };
82
+ return createCodeGenPreviewOptions(config.label_column || "分类", option, new Map());
83
+ }
84
+
85
+ /** 创建页面列表所需的模拟业务记录。 */
86
+ export function createCodeGenPreviewRows(
87
+ snapshot: CodeGenPagePreviewSnapshot,
88
+ optionMap: CodeGenPreviewOptionMap,
89
+ leftTreeOptions: ProFormOption[]
90
+ ) {
91
+ const { table, columns } = snapshot;
92
+ const primaryColumn = resolveCodeGenPrimaryColumn(columns);
93
+ const leftTreeValues = flattenCodeGenPreviewOptions(leftTreeOptions).map(option => option.value);
94
+ const rows = Array.from(
95
+ { length: table.page_type === "tree" || table.page_type === "tree_lazy" ? 12 : 18 },
96
+ (_, rowIndex) => {
97
+ const row: CodeGenPreviewRow = {};
98
+ columns.forEach(column => {
99
+ const options = resolveColumnPreviewOptions(optionMap, column);
100
+ row[column.name] = createCodeGenPreviewValue(column, rowIndex, options);
101
+ });
102
+ if (!(primaryColumn in row)) row[primaryColumn] = rowIndex + 1;
103
+ if (table.page_type === "left_tree" && table.left_tree_config?.filter_column && leftTreeValues.length) {
104
+ row[table.left_tree_config.filter_column] = leftTreeValues[rowIndex % leftTreeValues.length];
105
+ }
106
+ return row;
107
+ }
108
+ );
109
+
110
+ // 树形页面按照真实父节点字段构造层级,列表字段和值仍来自当前数据库配置。
111
+ if (
112
+ (table.page_type === "tree" || table.page_type === "tree_lazy") &&
113
+ table.parent_column &&
114
+ table.parent_column !== primaryColumn
115
+ ) {
116
+ rows.forEach((row, rowIndex) => {
117
+ if (rowIndex === 0 || rowIndex % 4 === 0) {
118
+ row[table.parent_column] = 0;
119
+ return;
120
+ }
121
+ const rootIndex = Math.floor(rowIndex / 4) * 4;
122
+ row[table.parent_column] = rows[rootIndex][primaryColumn];
123
+ });
124
+ }
125
+ if (table.page_type === "tree_lazy" && table.parent_column) {
126
+ rows.forEach(row => {
127
+ row.has_children = rows.some(child => String(child[table.parent_column!]) === String(row[primaryColumn]));
128
+ });
129
+ }
130
+ return rows;
131
+ }
132
+
133
+ /** 按查询配置过滤页面模拟记录。 */
134
+ export function filterCodeGenPreviewRows(rows: CodeGenPreviewRow[], columns: CodeGenColumn[], params: Record<string, any>) {
135
+ const queryColumns = columns.filter(column => column.query_config?.enabled);
136
+ return rows.filter(row =>
137
+ queryColumns.every(column => {
138
+ const queryValue = params[column.name];
139
+ if (isEmptyPreviewValue(queryValue)) return true;
140
+ return matchCodeGenPreviewValue(row[column.name], queryValue, column.query_config);
141
+ })
142
+ );
143
+ }
144
+
145
+ /** 将扁平模拟记录转换成 Element Plus 表格树。 */
146
+ export function buildCodeGenPreviewTree(rows: CodeGenPreviewRow[], primaryColumn: string, parentColumn: string) {
147
+ const rowMap = new Map<string, CodeGenPreviewRow>();
148
+ const roots: CodeGenPreviewRow[] = [];
149
+ rows.forEach(row => {
150
+ rowMap.set(String(row[primaryColumn]), { ...row, children: [] });
151
+ });
152
+ rowMap.forEach(row => {
153
+ const parent = rowMap.get(String(row[parentColumn]));
154
+ if (parent && parent !== row) {
155
+ parent.children?.push(row);
156
+ return;
157
+ }
158
+ roots.push(row);
159
+ });
160
+ return roots;
161
+ }
162
+
163
+ /** 将树形选项扁平化,供模拟记录赋值和标签匹配使用。 */
164
+ export function flattenCodeGenPreviewOptions(options: ProFormOption[]): ProFormOption[] {
165
+ return options.flatMap(option => [option, ...flattenCodeGenPreviewOptions(option.children ?? [])]);
166
+ }
167
+
168
+ /** 返回当前表的真实主键字段,缺少主键时使用预览内部编号。 */
169
+ export function resolveCodeGenPrimaryColumn(columns: CodeGenColumn[]) {
170
+ return columns.find(column => column.is_primary)?.name || "__preview_id";
171
+ }
172
+
173
+ /** 返回指定字段范围的模拟选项。 */
174
+ export function resolveCodeGenPreviewOptions(optionMap: CodeGenPreviewOptionMap, columnName: string, scope: CodeGenPreviewScope) {
175
+ return optionMap[createCodeGenPreviewOptionKey(columnName, scope)] ?? [];
176
+ }
177
+
178
+ /** 创建单个字段在下拉、树选择和开关展示中使用的模拟选项。 */
179
+ function createCodeGenPreviewOptions(
180
+ label: string,
181
+ option: CodeGenColumnOptionConfig | undefined,
182
+ dictionaryMap: Map<string, OptionBaseDictResponse_BaseDict>
183
+ ): ProFormOption[] {
184
+ if (option?.source_type === "static") {
185
+ const staticOptions = parseCodeGenStaticOptions(option.source_value);
186
+ if (staticOptions.length) return staticOptions;
187
+ }
188
+ if (option?.source_type === "dict") {
189
+ const dictionaryItems = dictionaryMap.get(option.source_value)?.items ?? [];
190
+ // 开关只使用用户明确选择的开启项和关闭项,避免模拟出第三种状态。
191
+ if (option.kind === "switch") {
192
+ return [option.active_value, option.inactive_value].flatMap(value => {
193
+ const item = dictionaryItems.find(dictionaryItem => dictionaryItem.value === value);
194
+ return item ? [{ label: item.label, value: item.value }] : [];
195
+ });
196
+ }
197
+ return dictionaryItems.map(item => ({ label: item.label, value: item.value }));
198
+ }
199
+ const sourceLabel = option?.source_value || label;
200
+ // 树形组件用两级节点表现最终布局,其字段名和来源标识均取当前真实配置。
201
+ if (option?.kind === "tree") {
202
+ return Array.from({ length: 3 }, (_, rootIndex) => {
203
+ const rootLabel = `${sourceLabel} ${rootIndex + 1}`;
204
+ const children = Array.from({ length: 2 }, (_, childIndex) => ({
205
+ label: `${rootLabel}/${option.label_field || label} ${rootIndex + 1}-${childIndex + 1}`,
206
+ value: `${sourceLabel}-${rootIndex + 1}-${childIndex + 1}`,
207
+ has_children: false
208
+ }));
209
+ return {
210
+ label: rootLabel,
211
+ value: `${sourceLabel}-${rootIndex + 1}`,
212
+ has_children: children.length > 0,
213
+ children
214
+ };
215
+ });
216
+ }
217
+ return Array.from({ length: 4 }, (_, optionIndex) => ({
218
+ label: `${sourceLabel}选项 ${optionIndex + 1}`,
219
+ value: `${sourceLabel}-${optionIndex + 1}`
220
+ }));
221
+ }
222
+
223
+ /** 判断组件是否需要模拟选项集合。 */
224
+ function hasPreviewOptions(component?: string) {
225
+ return ["segmented", "select", "dict", "radio-group", "checkbox-group", "tree-select", "transfer"].includes(component || "");
226
+ }
227
+
228
+ /** 解析字段配置中已经维护的静态选项和树形子节点。 */
229
+ function parseCodeGenStaticOptions(value: string): ProFormOption[] {
230
+ if (!value) return [];
231
+ try {
232
+ const options = JSON.parse(value) as unknown;
233
+ if (!Array.isArray(options)) return [];
234
+ return normalizeStaticOptions(options);
235
+ } catch {
236
+ return [];
237
+ }
238
+ }
239
+
240
+ /** 递归过滤不符合 ProForm 结构的静态选项。 */
241
+ function normalizeStaticOptions(options: unknown[]): ProFormOption[] {
242
+ return options.flatMap(option => {
243
+ if (!option || typeof option !== "object") return [];
244
+ const label = Reflect.get(option, "label");
245
+ const value = Reflect.get(option, "value");
246
+ if (
247
+ (typeof label !== "string" && typeof label !== "number") ||
248
+ (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
249
+ ) {
250
+ return [];
251
+ }
252
+ const children = Reflect.get(option, "children");
253
+ return [
254
+ {
255
+ label: String(label),
256
+ value,
257
+ disabled: Boolean(Reflect.get(option, "disabled")),
258
+ children: Array.isArray(children) ? normalizeStaticOptions(children) : undefined
259
+ }
260
+ ];
261
+ });
262
+ }
263
+
264
+ /** 按表单、列表、查询的优先级选择模拟记录使用的字段选项。 */
265
+ function resolveColumnPreviewOptions(optionMap: CodeGenPreviewOptionMap, column: CodeGenColumn) {
266
+ for (const scope of ["list", "query", "form"] as const) {
267
+ const options = resolveCodeGenPreviewOptions(optionMap, column.name, scope);
268
+ if (options.length) return flattenCodeGenPreviewOptions(options);
269
+ }
270
+ return [];
271
+ }
272
+
273
+ /** 根据数据库属性和组件配置创建单元格模拟值。 */
274
+ function createCodeGenPreviewValue(column: CodeGenColumn, rowIndex: number, options: ProFormOption[]) {
275
+ const sequence = rowIndex + 1;
276
+ const optionValue = options[rowIndex % Math.max(options.length, 1)]?.value;
277
+ if (optionValue !== undefined) return optionValue;
278
+ if (column.is_primary) return sequence;
279
+ if (column.name === "created_at" || column.name === "updated_at" || isDateTimeColumn(column)) {
280
+ return `2026-07-${String((rowIndex % 28) + 1).padStart(2, "0")} ${String(8 + (rowIndex % 10)).padStart(2, "0")}:30:00`;
281
+ }
282
+ if (["image", "image-upload", "images-upload"].includes(column.list_config?.component || column.form_config?.component || "")) {
283
+ return column.form_config?.component === "images-upload" ? [previewAvatar] : previewAvatar;
284
+ }
285
+ if (isBooleanColumn(column)) return rowIndex % 2 === 0;
286
+ if (isNumericColumn(column)) return column.list_config?.component === "money" ? 12000 + rowIndex * 1350 : sequence;
287
+ if (/phone|mobile/.test(column.name)) return `1380000${String(sequence).padStart(4, "0")}`;
288
+ if (column.name.includes("email")) return `preview${sequence}@example.com`;
289
+ if (column.name.includes("code")) return `CODE_${String(sequence).padStart(3, "0")}`;
290
+ const label = column.comment || column.name;
291
+ return `${label}${String(sequence).padStart(2, "0")}`;
292
+ }
293
+
294
+ /** 判断字段是否为日期时间类型。 */
295
+ function isDateTimeColumn(column: CodeGenColumn) {
296
+ const dbType = column.db_type.toLowerCase();
297
+ return dbType.includes("date") || dbType.includes("time") || column.form_config?.component === "date-picker";
298
+ }
299
+
300
+ /** 判断字段是否为布尔类型。 */
301
+ function isBooleanColumn(column: CodeGenColumn) {
302
+ const dbType = column.db_type.toLowerCase();
303
+ return column.go_type === "bool" || dbType === "bool" || dbType === "boolean" || dbType.includes("tinyint(1)");
304
+ }
305
+
306
+ /** 判断字段是否为数值类型。 */
307
+ export function isNumericColumn(column: CodeGenColumn) {
308
+ const dbType = column.db_type.toLowerCase();
309
+ return column.ts_type === "number" || ["int", "decimal", "float", "double"].some(type => dbType.includes(type));
310
+ }
311
+
312
+ /** 判断查询值是否为空。 */
313
+ function isEmptyPreviewValue(value: unknown) {
314
+ return value === undefined || value === null || value === "" || (Array.isArray(value) && !value.length);
315
+ }
316
+
317
+ /** 按等于、模糊和区间操作符匹配单个模拟字段。 */
318
+ function matchCodeGenPreviewValue(rowValue: unknown, queryValue: unknown, config?: CodeGenColumnQueryConfig) {
319
+ if (config?.operator === "between" && Array.isArray(queryValue) && queryValue.length === 2) {
320
+ const target = new Date(String(rowValue)).getTime();
321
+ const start = new Date(queryValue[0]).getTime();
322
+ const end = new Date(queryValue[1]).getTime();
323
+ return Number.isFinite(target) && target >= start && target <= end;
324
+ }
325
+ if (config?.operator === "like") {
326
+ return String(rowValue ?? "")
327
+ .toLowerCase()
328
+ .includes(String(queryValue).toLowerCase());
329
+ }
330
+ return String(rowValue ?? "") === String(queryValue);
331
+ }