index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listTrackSequenceApi">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['demo:trackSequence:add']" icon="CirclePlus" @click="openDialog(1, '注视轨迹序列新增')"> 新增 </el-button>
  7. <!-- <el-button type="primary" v-auth="['demo:trackSequence:import']" icon="Upload" plain @click="batchAdd"> 导入 </el-button>
  8. <el-button type="primary" v-auth="['demo:trackSequence:export']" icon="Download" plain @click="downloadFile"> 导出 </el-button> -->
  9. <el-button
  10. type="danger"
  11. v-auth="['demo:trackSequence: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
  23. type="primary"
  24. link
  25. icon="View"
  26. v-auth="['demo:trackSequence:start']"
  27. v-if="scope.row.status == '0' || scope.row.status == '3' || scope.row.status == '4'"
  28. @click="startTrackSequence(scope.row)"
  29. >
  30. 开始
  31. </el-button>
  32. <el-popconfirm title="确定终止此任务吗?" @confirm="stopTrackSequence(scope.row)" v-if="scope.row.status == '1'">
  33. <template #reference>
  34. <el-button type="primary" link icon="Delete"> 终止 </el-button>
  35. </template>
  36. </el-popconfirm>
  37. <el-button
  38. type="primary"
  39. link
  40. icon="View"
  41. v-auth="['demo:trackSequence:download']"
  42. v-if="scope.row.status == '2'"
  43. @click="dowloadtrackSequence(scope.row)"
  44. >
  45. 下载
  46. </el-button>
  47. <!-- <el-button type="primary" link icon="View" v-auth="['demo:toInfrared:query']" @click="openDialog(3, '查看', scope.row)"> 查看 </el-button> -->
  48. <!-- <el-button type="primary" link icon="EditPen"v-auth="['demo:toInfrared:edit']" @click="openDialog(2, '编辑', scope.row)"> 编辑 </el-button> -->
  49. <el-button
  50. type="primary"
  51. link
  52. icon="Delete"
  53. v-auth="['demo:toInfrared:remove']"
  54. @click="deleteTrackSequence(scope.row)"
  55. :disabled="scope.row.status == '1'"
  56. >
  57. 删除
  58. </el-button>
  59. </template>
  60. </ProTable>
  61. <FormDialog ref="formDialogRef" />
  62. <ImportExcel ref="dialogRef" />
  63. </div>
  64. </template>
  65. <script setup lang="tsx" name="TrackSequence">
  66. import { ref, reactive } from 'vue'
  67. import { useHandleData } from '@/hooks/useHandleData'
  68. import { useDownload } from '@/hooks/useDownload'
  69. import { ElMessage, ElMessageBox } from 'element-plus'
  70. import ProTable from '@/components/ProTable/index.vue'
  71. import ImportExcel from '@/components/ImportExcel/index.vue'
  72. import FormDialog from '@/components/FormDialog/index.vue'
  73. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  74. import {
  75. listTrackSequenceApi,
  76. delTrackSequenceApi,
  77. addTrackSequenceApi,
  78. updateTrackSequenceApi,
  79. importTemplateApi,
  80. importTrackSequenceDataApi,
  81. exportTrackSequenceApi,
  82. getTrackSequenceApi,
  83. startTrackSequenceApi,
  84. stopTrackSequenceApi,
  85. dowloadTrackSequenceApi
  86. } from '@/api/modules/demo/trackSequence'
  87. import statusEnums from '@/utils/status'
  88. const startTrackSequence = async (params: any) => {
  89. const res: any = await startTrackSequenceApi(params.id)
  90. if (res.code === 200) {
  91. ElMessage.success('任务已开始,请等待完成!')
  92. } else {
  93. ElMessage.error('任务开始失败,请检查!')
  94. }
  95. proTable.value?.getTableList()
  96. }
  97. const stopTrackSequence = async (params: any) => {
  98. const res: any = await stopTrackSequenceApi(params.id)
  99. if (res.code === 200) {
  100. ElMessage.success('终止任务成功!')
  101. } else {
  102. ElMessage.error('终止任务失败,请检查!')
  103. }
  104. proTable.value?.getTableList()
  105. }
  106. const dowloadToInfrared = async (params: any) => {
  107. await useDownload(dowloadTrackSequenceApi, params.name, params.id, true, '.zip')
  108. }
  109. // ProTable 实例
  110. const proTable = ref<ProTableInstance>()
  111. // 删除注视轨迹序列信息
  112. const deleteTrackSequence = async (params: any) => {
  113. await useHandleData(delTrackSequenceApi, params.id, '删除【' + params.id + '】注视轨迹序列')
  114. proTable.value?.getTableList()
  115. }
  116. // 批量删除注视轨迹序列信息
  117. const batchDelete = async (ids: string[]) => {
  118. await useHandleData(delTrackSequenceApi, ids, '删除所选注视轨迹序列信息')
  119. proTable.value?.clearSelection()
  120. proTable.value?.getTableList()
  121. }
  122. // 导出注视轨迹序列列表
  123. const downloadFile = async () => {
  124. ElMessageBox.confirm('确认导出注视轨迹序列数据?', '温馨提示', { type: 'warning' }).then(() =>
  125. useDownload(exportTrackSequenceApi, '注视轨迹序列列表', proTable.value?.searchParam)
  126. )
  127. }
  128. // 批量添加注视轨迹序列
  129. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  130. const batchAdd = () => {
  131. const params = {
  132. title: '注视轨迹序列',
  133. tempApi: importTemplateApi,
  134. importApi: importTrackSequenceDataApi,
  135. getTableList: proTable.value?.getTableList
  136. }
  137. dialogRef.value?.acceptParams(params)
  138. }
  139. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  140. // 打开弹框的功能
  141. const openDialog = async (type: number, title: string, row?: any) => {
  142. let res = { data: {} }
  143. if (row?.id) {
  144. res = await getTrackSequenceApi(row?.id || null)
  145. }
  146. // 重置表单
  147. setItemsOptions()
  148. const params = {
  149. title,
  150. width: 580,
  151. isEdit: type !== 3,
  152. itemsOptions: itemsOptions,
  153. model: type == 1 ? {} : res.data,
  154. api: type == 1 ? addTrackSequenceApi : updateTrackSequenceApi,
  155. getTableList: proTable.value?.getTableList
  156. }
  157. formDialogRef.value?.openDialog(params)
  158. }
  159. // 表格配置项
  160. const columns = reactive<ColumnProps<any>[]>([
  161. { type: 'selection', fixed: 'left', width: 70 },
  162. { prop: 'id', label: '主键ID', width: 180 },
  163. {
  164. prop: 'name',
  165. label: '任务名称',
  166. search: {
  167. el: 'input'
  168. },
  169. width: 150
  170. },
  171. {
  172. prop: 'status',
  173. label: '任务状态',
  174. search: {
  175. el: 'select'
  176. },
  177. tag: true,
  178. enum: statusEnums,
  179. width: 150
  180. },
  181. {
  182. prop: 'startTime',
  183. label: '开始时间',
  184. width: 180
  185. },
  186. {
  187. prop: 'endTime',
  188. label: '结束时间',
  189. width: 180
  190. },
  191. {
  192. prop: 'costSecond',
  193. label: '耗时',
  194. width: 120
  195. },
  196. {
  197. prop: 'log',
  198. label: '日志',
  199. width: 120
  200. },
  201. {
  202. prop: 'outputPath',
  203. label: '输出路径',
  204. width: 120
  205. },
  206. {
  207. prop: 'remarks',
  208. label: '备注',
  209. search: {
  210. el: 'input'
  211. },
  212. width: 120
  213. },
  214. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  215. ])
  216. // 表单配置项
  217. let itemsOptions: ProForm.ItemsOptions[] = []
  218. const setItemsOptions = () => {
  219. itemsOptions = [
  220. {
  221. label: '任务名称',
  222. prop: 'name',
  223. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  224. compOptions: {
  225. placeholder: '请输入任务名称'
  226. }
  227. },
  228. {
  229. label: '上传图片集',
  230. prop: 'inputOssId',
  231. rules: [{ required: true, message: '图片集不能为空', trigger: 'blur' }],
  232. compOptions: {
  233. elTagName: 'file-upload',
  234. fileSize: 4096,
  235. fileType: ['zip'],
  236. placeholder: '请上传图片集'
  237. }
  238. },
  239. {
  240. label: '备注',
  241. prop: 'remarks',
  242. rules: [],
  243. compOptions: {
  244. placeholder: '请输入备注'
  245. }
  246. }
  247. ]
  248. }
  249. </script>