index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. if (row.name === '数据扩增') {
  84. router.push({ path: `/task/amplify/`, query: { id: row.id } })
  85. } else {
  86. router.push({ path: `/task/bizProcess/`, query: { id: row.id } })
  87. }
  88. }
  89. // 删除算法子任务信息
  90. const deleteSubtask = async (params: any) => {
  91. await useHandleData(delSubtaskApi, params.id, '删除【' + params.id + '】算法子任务')
  92. proTable.value?.getTableList()
  93. }
  94. // 批量删除算法子任务信息
  95. const batchDelete = async (ids: string[]) => {
  96. await useHandleData(delSubtaskApi, ids, '删除所选算法子任务信息')
  97. proTable.value?.clearSelection()
  98. proTable.value?.getTableList()
  99. }
  100. // 导出算法子任务列表
  101. const downloadFile = async () => {
  102. ElMessageBox.confirm('确认导出算法子任务数据?', '温馨提示', { type: 'warning' }).then(() =>
  103. useDownload(exportSubtaskApi, '算法子任务列表', proTable.value?.searchParam)
  104. )
  105. }
  106. // 批量添加算法子任务
  107. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  108. // const batchAdd = () => {
  109. // const params = {
  110. // title: '算法子任务',
  111. // tempApi: importTemplateApi,
  112. // importApi: importSubtaskDataApi,
  113. // getTableList: proTable.value?.getTableList
  114. // }
  115. // dialogRef.value?.acceptParams(params)
  116. // }
  117. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  118. // 打开弹框的功能
  119. const openDialog = async (type: number, title: string, row?: any) => {
  120. let res = { data: {} }
  121. if (row?.id) {
  122. res = await getSubtaskApi(row?.id || null)
  123. }
  124. // 重置表单
  125. setItemsOptions()
  126. const params = {
  127. title,
  128. width: 580,
  129. isEdit: type !== 3,
  130. itemsOptions: itemsOptions,
  131. model: type == 1 ? {} : res.data,
  132. api: type == 1 ? addSubtaskApi : updateSubtaskApi,
  133. getTableList: proTable.value?.getTableList
  134. }
  135. formDialogRef.value?.openDialog(params)
  136. }
  137. onUnmounted(() => {
  138. clearInterval(timer.value)
  139. timer.value = null
  140. })
  141. // 表格配置项
  142. const columns = reactive<ColumnProps<any>[]>([
  143. { type: 'selection', fixed: 'left', width: 70 },
  144. { prop: 'id', label: '主键ID' },
  145. {
  146. prop: 'name',
  147. label: '任务类型',
  148. search: {
  149. el: 'input'
  150. }
  151. },
  152. {
  153. prop: 'createTime',
  154. label: '创建时间',
  155. search: {
  156. el: 'input'
  157. }
  158. },
  159. // {
  160. // prop: 'status',
  161. // label: '任务状态',
  162. // tag: true,
  163. // enum: () => getDictsApi('biz_task_status'),
  164. // search: {
  165. // el: 'tree-select'
  166. // },
  167. // fieldNames: { label: 'dictLabel', value: 'dictValue' }
  168. // },
  169. // {
  170. // prop: 'type',
  171. // label: '任务类型',
  172. // tag: true,
  173. // enum: () => getDictsApi('biz_ag_type'),
  174. // fieldNames: { label: 'dictLabel', value: 'dictValue' }
  175. // },
  176. // {
  177. // prop: 'parameters',
  178. // label: '调用算法时所用的参数'
  179. // },
  180. // {
  181. // prop: 'startTime',
  182. // label: '开始时间',
  183. // search: {
  184. // el: 'date-picker',
  185. // props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  186. // },
  187. // width: 120
  188. // },
  189. // {
  190. // prop: 'endTime',
  191. // label: '结束时间',
  192. // search: {
  193. // el: 'date-picker',
  194. // props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  195. // },
  196. // width: 120
  197. // },
  198. // {
  199. // prop: 'costSecond',
  200. // label: '耗时'
  201. // },
  202. { prop: 'operation', label: '操作', width: 270, fixed: 'right' }
  203. ])
  204. // 表单配置项
  205. let itemsOptions: ProForm.ItemsOptions[] = []
  206. const setItemsOptions = () => {
  207. itemsOptions = [
  208. {
  209. label: '任务ID',
  210. prop: 'taskId',
  211. compOptions: {
  212. placeholder: '请输入任务ID'
  213. }
  214. },
  215. {
  216. label: '任务名称',
  217. prop: 'name',
  218. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  219. compOptions: {
  220. placeholder: '请输入任务名称'
  221. }
  222. },
  223. {
  224. label: '任务状态',
  225. prop: 'status',
  226. rules: [{ required: true, message: '任务状态不能为空', trigger: 'change' }],
  227. compOptions: {
  228. elTagName: 'select',
  229. labelKey: 'dictLabel',
  230. valueKey: 'dictValue',
  231. enum: () => getDictsApi('biz_task_status'),
  232. placeholder: '请选择任务状态'
  233. }
  234. },
  235. {
  236. label: '任务类型',
  237. prop: 'type',
  238. rules: [{ required: true, message: '任务类型不能为空', trigger: 'blur' }],
  239. compOptions: {
  240. placeholder: '请输入任务类型'
  241. }
  242. },
  243. {
  244. label: '调用算法时所用的参数',
  245. prop: 'parameters',
  246. compOptions: {
  247. type: 'textarea',
  248. clearable: true,
  249. placeholder: '请输入内容'
  250. }
  251. },
  252. {
  253. label: '开始时间',
  254. prop: 'startTime',
  255. compOptions: {
  256. elTagName: 'date-picker',
  257. type: 'date',
  258. placeholder: '请选择开始时间'
  259. }
  260. },
  261. {
  262. label: '结束时间',
  263. prop: 'endTime',
  264. compOptions: {
  265. elTagName: 'date-picker',
  266. type: 'date',
  267. placeholder: '请选择结束时间'
  268. }
  269. },
  270. {
  271. label: '耗时',
  272. prop: 'costSecond',
  273. compOptions: {
  274. placeholder: '请输入耗时'
  275. }
  276. },
  277. {
  278. label: '日志',
  279. prop: 'log',
  280. compOptions: {
  281. type: 'textarea',
  282. clearable: true,
  283. placeholder: '请输入内容'
  284. }
  285. },
  286. {
  287. label: '序号',
  288. prop: 'index',
  289. compOptions: {
  290. placeholder: '请输入序号'
  291. }
  292. }
  293. ]
  294. }
  295. </script>