index.vue 8.0 KB

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