index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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: 'createTime',
  150. label: '创建时间',
  151. search: {
  152. el: 'input'
  153. }
  154. },
  155. // {
  156. // prop: 'status',
  157. // label: '任务状态',
  158. // tag: true,
  159. // enum: () => getDictsApi('biz_task_status'),
  160. // search: {
  161. // el: 'tree-select'
  162. // },
  163. // fieldNames: { label: 'dictLabel', value: 'dictValue' }
  164. // },
  165. // {
  166. // prop: 'type',
  167. // label: '任务类型',
  168. // tag: true,
  169. // enum: () => getDictsApi('biz_ag_type'),
  170. // fieldNames: { label: 'dictLabel', value: 'dictValue' }
  171. // },
  172. // {
  173. // prop: 'parameters',
  174. // label: '调用算法时所用的参数'
  175. // },
  176. // {
  177. // prop: 'startTime',
  178. // label: '开始时间',
  179. // search: {
  180. // el: 'date-picker',
  181. // props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  182. // },
  183. // width: 120
  184. // },
  185. // {
  186. // prop: 'endTime',
  187. // label: '结束时间',
  188. // search: {
  189. // el: 'date-picker',
  190. // props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  191. // },
  192. // width: 120
  193. // },
  194. // {
  195. // prop: 'costSecond',
  196. // label: '耗时'
  197. // },
  198. { prop: 'operation', label: '操作', width: 270, fixed: 'right' }
  199. ])
  200. // 表单配置项
  201. let itemsOptions: ProForm.ItemsOptions[] = []
  202. const setItemsOptions = () => {
  203. itemsOptions = [
  204. {
  205. label: '任务ID',
  206. prop: 'taskId',
  207. compOptions: {
  208. placeholder: '请输入任务ID'
  209. }
  210. },
  211. {
  212. label: '任务名称',
  213. prop: 'name',
  214. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  215. compOptions: {
  216. placeholder: '请输入任务名称'
  217. }
  218. },
  219. {
  220. label: '任务状态',
  221. prop: 'status',
  222. rules: [{ required: true, message: '任务状态不能为空', trigger: 'change' }],
  223. compOptions: {
  224. elTagName: 'select',
  225. labelKey: 'dictLabel',
  226. valueKey: 'dictValue',
  227. enum: () => getDictsApi('biz_task_status'),
  228. placeholder: '请选择任务状态'
  229. }
  230. },
  231. {
  232. label: '任务类型',
  233. prop: 'type',
  234. rules: [{ required: true, message: '任务类型不能为空', trigger: 'blur' }],
  235. compOptions: {
  236. placeholder: '请输入任务类型'
  237. }
  238. },
  239. {
  240. label: '调用算法时所用的参数',
  241. prop: 'parameters',
  242. compOptions: {
  243. type: 'textarea',
  244. clearable: true,
  245. placeholder: '请输入内容'
  246. }
  247. },
  248. {
  249. label: '开始时间',
  250. prop: 'startTime',
  251. compOptions: {
  252. elTagName: 'date-picker',
  253. type: 'date',
  254. placeholder: '请选择开始时间'
  255. }
  256. },
  257. {
  258. label: '结束时间',
  259. prop: 'endTime',
  260. compOptions: {
  261. elTagName: 'date-picker',
  262. type: 'date',
  263. placeholder: '请选择结束时间'
  264. }
  265. },
  266. {
  267. label: '耗时',
  268. prop: 'costSecond',
  269. compOptions: {
  270. placeholder: '请输入耗时'
  271. }
  272. },
  273. {
  274. label: '日志',
  275. prop: 'log',
  276. compOptions: {
  277. type: 'textarea',
  278. clearable: true,
  279. placeholder: '请输入内容'
  280. }
  281. },
  282. {
  283. label: '序号',
  284. prop: 'index',
  285. compOptions: {
  286. placeholder: '请输入序号'
  287. }
  288. }
  289. ]
  290. }
  291. </script>