@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,535 @@
1
+ <!-- 定时任务 -->
2
+ <template>
3
+ <div class="table-box">
4
+ <ProTable ref="proTable" row-key="id" :columns="columns" :header-actions="headerActions" :request-api="requestBaseJobTable" />
5
+
6
+ <FormDialog
7
+ v-model="dialog.visible"
8
+ ref="formDialogRef"
9
+ :title="dialog.title"
10
+ width="1000px"
11
+ :model="formData"
12
+ :fields="formFields"
13
+ :rules="rules"
14
+ label-width="150px"
15
+ @confirm="handleSubmit"
16
+ @close="handleCloseDialog"
17
+ />
18
+ </div>
19
+ </template>
20
+
21
+ <script setup lang="ts">
22
+ import { computed, h, reactive, ref, type VNode } from "vue";
23
+ import { ElButton, ElMessage, ElMessageBox, ElTag } from "element-plus";
24
+ import { CirclePlus, Delete, EditPen, Promotion, Tickets, VideoPause, VideoPlay } from "@element-plus/icons-vue";
25
+ import type { ColumnProps, HeaderActionProps, ProTableInstance, RenderScope } from "@liujitcn/kratos-admin-core/components/ProTable/interface";
26
+ import FormDialog from "@liujitcn/kratos-admin-core/components/Dialog/FormDialog.vue";
27
+ import type { ProFormField, ProFormOption } from "@liujitcn/kratos-admin-core/components/ProForm/interface";
28
+ import ProTable from "@liujitcn/kratos-admin-core/components/ProTable";
29
+ import { useAuthButtons } from "@liujitcn/kratos-admin-core/auth";
30
+ import { defBaseJobService } from "@liujitcn/kratos-admin-system/api/system/base_job";
31
+ import type { BaseJob, BaseJobArgs, BaseJobForm, PageBaseJobRequest } from "@liujitcn/kratos-admin-system/rpc/system/admin/v1/base_job";
32
+ import router, { navigateTo } from "@liujitcn/kratos-admin-core/navigation";
33
+ import { Status } from "@liujitcn/kratos-admin-system/rpc/common/v1/enum";
34
+ import { buildPageRequest, normalizeSelectedIds } from "@liujitcn/kratos-admin-core/table";
35
+
36
+ defineOptions({
37
+ name: "BaseJob",
38
+ inheritAttrs: false
39
+ });
40
+
41
+ const { BUTTONS } = useAuthButtons();
42
+ const proTable = ref<ProTableInstance>();
43
+ const formDialogRef = ref<InstanceType<typeof FormDialog>>();
44
+
45
+ const dialog = reactive({
46
+ title: "",
47
+ visible: false
48
+ });
49
+
50
+ const formData = reactive<BaseJobForm>({
51
+ /** 定时任务ID */
52
+ id: 0,
53
+ /** 任务名称 */
54
+ name: "",
55
+ /** 调用目标 */
56
+ invoke_target: "",
57
+ /** 目标参数 */
58
+ args: [],
59
+ /** cron表达式 */
60
+ cron_expression: "",
61
+ /** 状态 */
62
+ status: Status.ENABLE
63
+ });
64
+
65
+ const rules = computed(() => ({
66
+ name: [
67
+ { required: true, message: "请输入任务名称", trigger: "blur" },
68
+ { max: 50, message: "任务名称不能超过 50 个字符", trigger: "blur" }
69
+ ],
70
+ cron_expression: [
71
+ { required: true, message: "请输入cron表达式", trigger: "blur" },
72
+ { max: 50, message: "cron表达式不能超过 50 个字符", trigger: "blur" }
73
+ ],
74
+ invoke_target: [
75
+ { required: true, message: "请输入调用目标", trigger: "blur" },
76
+ { max: 100, message: "调用目标不能超过 100 个字符", trigger: "blur" }
77
+ ],
78
+ args: {
79
+ validator: (rule: unknown, value: BaseJobArgs[], callback: (error?: Error) => void) => {
80
+ if (value.some(arg => !arg.key)) callback(new Error("所有参数必须填写key"));
81
+ else callback();
82
+ },
83
+ trigger: "blur"
84
+ },
85
+ status: [{ required: true, message: "状态不能为空", trigger: "blur" }]
86
+ }));
87
+
88
+ const statusOptions: ProFormOption[] = [
89
+ { label: "启用", value: Status.ENABLE },
90
+ { label: "禁用", value: Status.DISABLE }
91
+ ];
92
+
93
+ /**
94
+ * 渲染任务参数标签,便于在列表中快速查看键值对。
95
+ */
96
+ function renderArgsCell(scope: RenderScope<BaseJob>) {
97
+ const args = scope.row.args ?? [];
98
+ if (!args.length) return "--";
99
+ return h(
100
+ "div",
101
+ null,
102
+ args.map((arg, index) =>
103
+ h(
104
+ ElTag,
105
+ {
106
+ key: `${arg.key}-${arg.value}-${index}`,
107
+ class: "mr-5"
108
+ },
109
+ () => `${arg.key}=${arg.value}`
110
+ )
111
+ )
112
+ );
113
+ }
114
+
115
+ /**
116
+ * 渲染定时任务操作列。
117
+ */
118
+ function renderOperationCell(scope: RenderScope<BaseJob>) {
119
+ const row = scope.row;
120
+ const actionNodes: VNode[] = [];
121
+
122
+ if (BUTTONS.value["base:job:update"]) {
123
+ actionNodes.push(
124
+ h(
125
+ ElButton,
126
+ {
127
+ key: `edit-${row.id}`,
128
+ type: "primary",
129
+ link: true,
130
+ icon: EditPen,
131
+ onClick: () => handleOpenDialog(row.id)
132
+ },
133
+ () => "编辑"
134
+ )
135
+ );
136
+ }
137
+
138
+ if (BUTTONS.value["base:job:delete"]) {
139
+ actionNodes.push(
140
+ h(
141
+ ElButton,
142
+ {
143
+ key: `delete-${row.id}`,
144
+ type: "danger",
145
+ link: true,
146
+ icon: Delete,
147
+ onClick: () => handleDelete(row)
148
+ },
149
+ () => "删除"
150
+ )
151
+ );
152
+ }
153
+
154
+ if (row.status === Status.ENABLE && (row.entry_id === undefined || row.entry_id === 0) && BUTTONS.value["base:job:start"]) {
155
+ actionNodes.push(
156
+ h(
157
+ ElButton,
158
+ {
159
+ key: `start-${row.id}`,
160
+ type: "primary",
161
+ link: true,
162
+ icon: VideoPlay,
163
+ class: "job-action job-action--start",
164
+ onClick: () => handleStart(row.id, row.name)
165
+ },
166
+ () => "启动"
167
+ )
168
+ );
169
+ }
170
+
171
+ if (row.status === Status.ENABLE && row.entry_id > 0 && BUTTONS.value["base:job:stop"]) {
172
+ actionNodes.push(
173
+ h(
174
+ ElButton,
175
+ {
176
+ key: `stop-${row.id}`,
177
+ type: "warning",
178
+ link: true,
179
+ icon: VideoPause,
180
+ class: "job-action job-action--stop",
181
+ onClick: () => handleStop(row.id, row.name)
182
+ },
183
+ () => "停止"
184
+ )
185
+ );
186
+ }
187
+
188
+ if (row.status === Status.ENABLE && (row.entry_id === undefined || row.entry_id === 0) && BUTTONS.value["base:job:exec"]) {
189
+ actionNodes.push(
190
+ h(
191
+ ElButton,
192
+ {
193
+ key: `exec-${row.id}`,
194
+ type: "success",
195
+ link: true,
196
+ icon: Promotion,
197
+ class: "job-action job-action--exec",
198
+ onClick: () => handleExec(row.id, row.name)
199
+ },
200
+ () => "执行一次"
201
+ )
202
+ );
203
+ }
204
+
205
+ if (BUTTONS.value["base:job:log"]) {
206
+ actionNodes.push(
207
+ h(
208
+ ElButton,
209
+ {
210
+ key: `log-${row.id}`,
211
+ type: "primary",
212
+ link: true,
213
+ icon: Tickets,
214
+ class: "job-action job-action--log",
215
+ onClick: () => handleOpenBaseJob(row.id, row.name)
216
+ },
217
+ () => "日志"
218
+ )
219
+ );
220
+ }
221
+
222
+ if (!actionNodes.length) return "--";
223
+ return h(
224
+ "div",
225
+ {
226
+ class: "job-operation",
227
+ key: `job-operation-${row.id}`
228
+ },
229
+ actionNodes
230
+ );
231
+ }
232
+
233
+ /** 定时任务表单字段配置。 */
234
+ const formFields: ProFormField[] = [
235
+ { prop: "name", label: "任务名称", component: "input", props: { placeholder: "请输入任务名称" } },
236
+ { prop: "invoke_target", label: "调用目标", component: "input", props: { placeholder: "请输入调用目标" } },
237
+ { prop: "cron_expression", label: "cron表达式", component: "cron-expression", props: { placeholder: "0 0 0 * * *" } },
238
+ {
239
+ prop: "args",
240
+ label: "目标参数",
241
+ component: "kv-list",
242
+ props: {
243
+ keyInputProps: { placeholder: "参数" },
244
+ valueInputProps: { placeholder: "值" },
245
+ addText: "添加参数"
246
+ }
247
+ },
248
+ { prop: "status", label: "状态", component: "radio-group", options: statusOptions }
249
+ ];
250
+
251
+ /** 定时任务表格列配置。 */
252
+ const columns: ColumnProps[] = [
253
+ { type: "selection", width: 55 },
254
+ { prop: "name", label: "任务名称", minWidth: 140, search: { el: "input" } },
255
+ { prop: "invoke_target", label: "调用目标", minWidth: 180, search: { el: "input" } },
256
+ { prop: "args", label: "参数", minWidth: 140, render: scope => renderArgsCell(scope as unknown as RenderScope<BaseJob>) },
257
+ { prop: "cron_expression", label: "cron表达式", minWidth: 150 },
258
+ { prop: "entry_id", label: "任务id", minWidth: 100, align: "right" },
259
+ {
260
+ prop: "status",
261
+ label: "状态",
262
+ minWidth: 100,
263
+ search: { el: "select" },
264
+ cellType: "status",
265
+ statusProps: {
266
+ activeValue: Status.ENABLE,
267
+ inactiveValue: Status.DISABLE,
268
+ activeText: "启用",
269
+ inactiveText: "禁用",
270
+ disabled: scope => (scope.row as BaseJob).entry_id === 0 || !BUTTONS.value["base:job:status"],
271
+ beforeChange: scope => handleBeforeSetStatus(scope.row as BaseJob)
272
+ }
273
+ },
274
+ { prop: "created_at", label: "创建时间", minWidth: 180 },
275
+ { prop: "updated_at", label: "更新时间", minWidth: 180 },
276
+ {
277
+ prop: "operation",
278
+ label: "操作",
279
+ width: 380,
280
+ fixed: "right",
281
+ render: scope => renderOperationCell(scope as unknown as RenderScope<BaseJob>)
282
+ }
283
+ ];
284
+
285
+ /** 定时任务顶部按钮配置。 */
286
+ const headerActions: HeaderActionProps[] = [
287
+ {
288
+ label: "新增",
289
+ type: "success",
290
+ icon: CirclePlus,
291
+ hidden: () => !BUTTONS.value["base:job:create"],
292
+ onClick: () => handleOpenDialog()
293
+ },
294
+ {
295
+ label: "删除",
296
+ type: "danger",
297
+ icon: Delete,
298
+ hidden: () => !BUTTONS.value["base:job:delete"],
299
+ disabled: scope => !scope.selectedList.length,
300
+ onClick: scope => handleDelete(scope.selectedList as BaseJob[])
301
+ }
302
+ ];
303
+
304
+ /**
305
+ * 请求定时任务列表,并由 ProTable 统一维护分页与搜索参数。
306
+ */
307
+ async function requestBaseJobTable(params: PageBaseJobRequest) {
308
+ const data = await defBaseJobService.PageBaseJob(buildPageRequest(params));
309
+ return { data: { list: data.base_jobs ?? [], total: data.total } };
310
+ }
311
+
312
+ /**
313
+ * 刷新定时任务表格。
314
+ */
315
+ function refreshTable() {
316
+ proTable.value?.getTableList();
317
+ }
318
+
319
+ /**
320
+ * 打开定时任务弹窗。
321
+ */
322
+ function handleOpenDialog(jobId?: number) {
323
+ resetForm();
324
+ dialog.title = jobId ? "修改定时任务" : "新增定时任务";
325
+ dialog.visible = true;
326
+ if (!jobId) return;
327
+
328
+ defBaseJobService.GetBaseJob({ id: jobId }).then(data => {
329
+ Object.assign(formData, data);
330
+ });
331
+ }
332
+
333
+ /**
334
+ * 关闭定时任务弹窗并恢复默认表单值。
335
+ */
336
+ function handleCloseDialog() {
337
+ dialog.visible = false;
338
+ resetForm();
339
+ }
340
+
341
+ /**
342
+ * 重置定时任务表单。
343
+ */
344
+ function resetForm() {
345
+ formDialogRef.value?.resetFields();
346
+ formDialogRef.value?.clearValidate();
347
+ formData.id = 0;
348
+ formData.name = "";
349
+ formData.invoke_target = "";
350
+ formData.args = [];
351
+ formData.cron_expression = "";
352
+ formData.status = Status.ENABLE;
353
+ }
354
+
355
+ /**
356
+ * 提交定时任务表单。
357
+ */
358
+ function handleSubmit() {
359
+ formDialogRef.value?.validate()?.then(valid => {
360
+ if (!valid) return;
361
+
362
+ const submitData = JSON.parse(JSON.stringify(formData)) as BaseJobForm;
363
+ const request = submitData.id
364
+ ? defBaseJobService.UpdateBaseJob({ base_job: submitData })
365
+ : defBaseJobService.CreateBaseJob({ base_job: submitData });
366
+ request.then(() => {
367
+ ElMessage.success(submitData.id ? "修改定时任务成功" : "新增定时任务成功");
368
+ handleCloseDialog();
369
+ refreshTable();
370
+ });
371
+ });
372
+ }
373
+
374
+ /**
375
+ * 在定时任务状态切换前先完成确认与接口调用,避免首屏渲染触发误操作。
376
+ */
377
+ async function handleBeforeSetStatus(row: BaseJob) {
378
+ const nextStatus = row.status === Status.ENABLE ? Status.DISABLE : Status.ENABLE;
379
+ const text = nextStatus === Status.ENABLE ? "启用" : "禁用";
380
+ const jobName = row.name || row.invoke_target || `ID:${row.id}`;
381
+ try {
382
+ await ElMessageBox.confirm(`是否确定${text}定时任务?\n任务名称:${jobName}`, "提示", {
383
+ confirmButtonText: "确认",
384
+ cancelButtonText: "取消",
385
+ type: "warning"
386
+ });
387
+ await defBaseJobService.SetBaseJobStatus({ id: row.id, status: nextStatus });
388
+ ElMessage.success(`${text}成功`);
389
+ refreshTable();
390
+ return true;
391
+ } catch {
392
+ return false;
393
+ }
394
+ }
395
+
396
+ /**
397
+ * 删除定时任务,兼容单条删除与批量删除。
398
+ */
399
+ function handleDelete(selected?: number | string | Array<number | string> | BaseJob | BaseJob[]) {
400
+ const jobList = Array.isArray(selected)
401
+ ? (selected.filter(item => typeof item === "object") as BaseJob[])
402
+ : selected && typeof selected === "object"
403
+ ? [selected as BaseJob]
404
+ : [];
405
+ const jobIds = (
406
+ jobList.length ? jobList.map(item => item.id) : normalizeSelectedIds(selected as number | string | Array<number | string>)
407
+ ).join(",");
408
+ if (!jobIds) {
409
+ ElMessage.warning("请勾选删除项");
410
+ return;
411
+ }
412
+
413
+ const singleJobName = jobList[0]?.name || jobList[0]?.invoke_target || `ID:${jobList[0]?.id ?? ""}`;
414
+ const confirmMessage = jobList.length
415
+ ? jobList.length === 1
416
+ ? `是否确定删除定时任务?\n任务名称:${singleJobName}`
417
+ : `确认删除已选中的 ${jobList.length} 个定时任务吗?`
418
+ : "确认删除已选中的定时任务吗?";
419
+
420
+ ElMessageBox.confirm(confirmMessage, "警告", {
421
+ confirmButtonText: "确定",
422
+ cancelButtonText: "取消",
423
+ type: "warning"
424
+ }).then(
425
+ () => {
426
+ defBaseJobService.DeleteBaseJob({ id: jobIds }).then(() => {
427
+ ElMessage.success("删除定时任务成功");
428
+ refreshTable();
429
+ });
430
+ },
431
+ () => {
432
+ ElMessage.info("已取消删除定时任务");
433
+ }
434
+ );
435
+ }
436
+
437
+ /**
438
+ * 启动定时任务。
439
+ */
440
+ function handleStart(id: number, name: string) {
441
+ ElMessageBox.confirm(`是否确定启动定时任务?\n任务名称:${name}`, "警告", {
442
+ confirmButtonText: "确定",
443
+ cancelButtonText: "取消",
444
+ type: "warning"
445
+ }).then(
446
+ () => {
447
+ defBaseJobService.StartBaseJob({ id }).then(() => {
448
+ ElMessage.success("启动成功");
449
+ refreshTable();
450
+ });
451
+ },
452
+ () => {
453
+ ElMessage.info("已取消启动定时任务");
454
+ }
455
+ );
456
+ }
457
+
458
+ /**
459
+ * 停止定时任务。
460
+ */
461
+ function handleStop(id: number, name: string) {
462
+ ElMessageBox.confirm(`是否确定停止定时任务?\n任务名称:${name}`, "警告", {
463
+ confirmButtonText: "确定",
464
+ cancelButtonText: "取消",
465
+ type: "warning"
466
+ }).then(
467
+ () => {
468
+ defBaseJobService.StopBaseJob({ id }).then(() => {
469
+ ElMessage.success("停止成功");
470
+ refreshTable();
471
+ });
472
+ },
473
+ () => {
474
+ ElMessage.info("已取消停止定时任务");
475
+ }
476
+ );
477
+ }
478
+
479
+ /**
480
+ * 执行一次定时任务。
481
+ */
482
+ function handleExec(id: number, name: string) {
483
+ ElMessageBox.confirm(`是否确定执行一次定时任务?\n任务名称:${name}`, "警告", {
484
+ confirmButtonText: "确定",
485
+ cancelButtonText: "取消",
486
+ type: "warning"
487
+ }).then(
488
+ () => {
489
+ defBaseJobService.ExecuteBaseJob({ id }).then(() => {
490
+ ElMessage.success("执行成功");
491
+ refreshTable();
492
+ });
493
+ },
494
+ () => {
495
+ ElMessage.info("已取消执行定时任务");
496
+ }
497
+ );
498
+ }
499
+
500
+ /**
501
+ * 打开定时任务日志页面。
502
+ */
503
+ function handleOpenBaseJob(id: number, name: string) {
504
+ navigateTo(router, "/base/job/log", { jobId: id, title: `【${name}】定时任务日志` });
505
+ }
506
+ </script>
507
+
508
+ <style scoped>
509
+ .job-operation {
510
+ display: flex;
511
+ flex-wrap: wrap;
512
+ gap: 4px 10px;
513
+ align-items: center;
514
+ white-space: nowrap;
515
+ }
516
+ .job-action {
517
+ margin-left: 0;
518
+ font-weight: 500;
519
+ }
520
+ .job-action:deep(.el-icon) {
521
+ margin-right: 4px;
522
+ }
523
+ .job-action--start {
524
+ --el-button-text-color: var(--el-color-primary);
525
+ }
526
+ .job-action--stop {
527
+ --el-button-text-color: var(--el-color-warning);
528
+ }
529
+ .job-action--exec {
530
+ --el-button-text-color: var(--el-color-success);
531
+ }
532
+ .job-action--log {
533
+ --el-button-text-color: var(--el-color-info);
534
+ }
535
+ </style>