index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :is-show-search="false" :columns="columns" row-key="id" :data="subTaskList">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['task:subtask:add']" icon="CirclePlus" @click="openDialog(1, '算法子任务新增')"> 新增 </el-button>
  7. <el-button type="primary" v-auth="['task:subtask:import']" icon="Upload" plain @click="batchAdd"> 导入 </el-button>
  8. <el-button type="primary" v-auth="['task:subtask:export']" icon="Download" plain @click="downloadFile"> 导出 </el-button>
  9. <el-button
  10. type="danger"
  11. v-auth="['task:subtask:remove']"
  12. icon="Delete"
  13. plain
  14. :disabled="!scope.isSelected"
  15. @click="batchDelete(scope.selectedListIds)"
  16. >
  17. 批量删除
  18. </el-button>
  19. </template>
  20. <!-- 表格操作 -->
  21. <template #operation="scope">
  22. <el-button type="primary" link icon="View" v-auth="['task:subtask:query']" @click="viewDetails(scope.row)"> 查看详情 </el-button>
  23. <el-button type="primary" link icon="EditPen" v-auth="['task:subtask:edit']" @click="openDialog(2, '算法子任务编辑', scope.row)">
  24. 编辑
  25. </el-button>
  26. <el-button type="primary" link icon="Delete" v-auth="['task:subtask:remove']" @click="deleteSubtask(scope.row)"> 删除 </el-button>
  27. </template>
  28. </ProTable>
  29. <FormDialog ref="formDialogRef" />
  30. <ImportExcel ref="dialogRef" />
  31. </div>
  32. </template>
  33. <script setup lang="tsx" name="Subtask">
  34. import { ref, reactive, onUnmounted, onMounted } from 'vue'
  35. import { useHandleData } from '@/hooks/useHandleData'
  36. import { useDownload } from '@/hooks/useDownload'
  37. import { ElMessageBox } from 'element-plus'
  38. import ProTable from '@/components/ProTable/index.vue'
  39. import ImportExcel from '@/components/ImportExcel/index.vue'
  40. import FormDialog from '@/components/FormDialog/index.vue'
  41. import { useRoute, useRouter } from 'vue-router'
  42. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  43. import {
  44. listSubtaskApi,
  45. delSubtaskApi,
  46. addSubtaskApi,
  47. updateSubtaskApi,
  48. importTemplateApi,
  49. importSubtaskDataApi,
  50. exportSubtaskApi,
  51. getSubtaskApi
  52. } from '@/api/modules/task/subtask'
  53. import { getDictsApi } from '@/api/modules/system/dictData'
  54. const router = useRouter()
  55. const route = useRoute()
  56. const taskId = route.query.id as string
  57. // ProTable 实例
  58. const proTable = ref<ProTableInstance>()
  59. let subTaskList = ref()
  60. // 每隔10秒请求一下列表
  61. const timer = ref() // 定时器
  62. const refreshList = () => {
  63. setTimeout(() => {
  64. listSubtaskApi({
  65. pageNum: 1,
  66. pageSize: 100,
  67. taskId: taskId
  68. }).then(res => {
  69. subTaskList.value = res.data['list']
  70. })
  71. }, 0)
  72. }
  73. onMounted(() => {
  74. // timer
  75. refreshList()
  76. timer.value = setInterval(() => {
  77. refreshList()
  78. }, 10000)
  79. })
  80. // 查看详情
  81. const viewDetails = row => {
  82. router.push({ path: `/task/bizProcess/`, query: { id: row.id } })
  83. }
  84. // 删除算法子任务信息
  85. const deleteSubtask = async (params: any) => {
  86. await useHandleData(delSubtaskApi, params.id, '删除【' + params.id + '】算法子任务')
  87. proTable.value?.getTableList()
  88. }
  89. // 批量删除算法子任务信息
  90. const batchDelete = async (ids: string[]) => {
  91. await useHandleData(delSubtaskApi, ids, '删除所选算法子任务信息')
  92. proTable.value?.clearSelection()
  93. proTable.value?.getTableList()
  94. }
  95. // 导出算法子任务列表
  96. const downloadFile = async () => {
  97. ElMessageBox.confirm('确认导出算法子任务数据?', '温馨提示', { type: 'warning' }).then(() =>
  98. useDownload(exportSubtaskApi, '算法子任务列表', proTable.value?.searchParam)
  99. )
  100. }
  101. // 批量添加算法子任务
  102. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  103. const batchAdd = () => {
  104. const params = {
  105. title: '算法子任务',
  106. tempApi: importTemplateApi,
  107. importApi: importSubtaskDataApi,
  108. getTableList: proTable.value?.getTableList
  109. }
  110. dialogRef.value?.acceptParams(params)
  111. }
  112. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  113. // 打开弹框的功能
  114. const openDialog = async (type: number, title: string, row?: any) => {
  115. let res = { data: {} }
  116. if (row?.id) {
  117. res = await getSubtaskApi(row?.id || null)
  118. }
  119. // 重置表单
  120. setItemsOptions()
  121. const params = {
  122. title,
  123. width: 580,
  124. isEdit: type !== 3,
  125. itemsOptions: itemsOptions,
  126. model: type == 1 ? {} : res.data,
  127. api: type == 1 ? addSubtaskApi : updateSubtaskApi,
  128. getTableList: proTable.value?.getTableList
  129. }
  130. formDialogRef.value?.openDialog(params)
  131. }
  132. onUnmounted(() => {
  133. clearInterval(timer.value)
  134. timer.value = null
  135. })
  136. // 表格配置项
  137. const columns = reactive<ColumnProps<any>[]>([
  138. { type: 'selection', fixed: 'left', width: 70 },
  139. { prop: 'id', label: '主键ID' },
  140. {
  141. prop: 'name',
  142. label: '任务名称',
  143. search: {
  144. el: 'input'
  145. }
  146. },
  147. {
  148. prop: 'status',
  149. label: '任务状态',
  150. tag: true,
  151. enum: () => getDictsApi('biz_task_status'),
  152. search: {
  153. el: 'tree-select'
  154. },
  155. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  156. },
  157. {
  158. prop: 'type',
  159. label: '任务类型',
  160. tag: true,
  161. enum: () => getDictsApi('biz_ag_type'),
  162. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  163. },
  164. {
  165. prop: 'parameters',
  166. label: '调用算法时所用的参数'
  167. },
  168. {
  169. prop: 'startTime',
  170. label: '开始时间',
  171. search: {
  172. el: 'date-picker',
  173. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  174. },
  175. width: 120
  176. },
  177. {
  178. prop: 'endTime',
  179. label: '结束时间',
  180. search: {
  181. el: 'date-picker',
  182. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  183. },
  184. width: 120
  185. },
  186. {
  187. prop: 'costSecond',
  188. label: '耗时'
  189. },
  190. { prop: 'operation', label: '操作', width: 270, fixed: 'right' }
  191. ])
  192. // 表单配置项
  193. let itemsOptions: ProForm.ItemsOptions[] = []
  194. const setItemsOptions = () => {
  195. itemsOptions = [
  196. {
  197. label: '任务ID',
  198. prop: 'taskId',
  199. compOptions: {
  200. placeholder: '请输入任务ID'
  201. }
  202. },
  203. {
  204. label: '任务名称',
  205. prop: 'name',
  206. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  207. compOptions: {
  208. placeholder: '请输入任务名称'
  209. }
  210. },
  211. {
  212. label: '任务状态',
  213. prop: 'status',
  214. rules: [{ required: true, message: '任务状态不能为空', trigger: 'change' }],
  215. compOptions: {
  216. elTagName: 'select',
  217. labelKey: 'dictLabel',
  218. valueKey: 'dictValue',
  219. enum: () => getDictsApi('biz_task_status'),
  220. placeholder: '请选择任务状态'
  221. }
  222. },
  223. {
  224. label: '任务类型',
  225. prop: 'type',
  226. rules: [{ required: true, message: '任务类型不能为空', trigger: 'blur' }],
  227. compOptions: {
  228. placeholder: '请输入任务类型'
  229. }
  230. },
  231. {
  232. label: '调用算法时所用的参数',
  233. prop: 'parameters',
  234. compOptions: {
  235. type: 'textarea',
  236. clearable: true,
  237. placeholder: '请输入内容'
  238. }
  239. },
  240. {
  241. label: '开始时间',
  242. prop: 'startTime',
  243. compOptions: {
  244. elTagName: 'date-picker',
  245. type: 'date',
  246. placeholder: '请选择开始时间'
  247. }
  248. },
  249. {
  250. label: '结束时间',
  251. prop: 'endTime',
  252. compOptions: {
  253. elTagName: 'date-picker',
  254. type: 'date',
  255. placeholder: '请选择结束时间'
  256. }
  257. },
  258. {
  259. label: '耗时',
  260. prop: 'costSecond',
  261. compOptions: {
  262. placeholder: '请输入耗时'
  263. }
  264. },
  265. {
  266. label: '日志',
  267. prop: 'log',
  268. compOptions: {
  269. type: 'textarea',
  270. clearable: true,
  271. placeholder: '请输入内容'
  272. }
  273. },
  274. {
  275. label: '序号',
  276. prop: 'index',
  277. compOptions: {
  278. placeholder: '请输入序号'
  279. }
  280. }
  281. ]
  282. }
  283. </script>