index.vue 8.2 KB

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