index.vue 8.3 KB

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