index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listTraceMergeApi">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['demo:traceMerge:add']" icon="CirclePlus" @click="createTask"> 新增 </el-button>
  7. <el-button type="primary" v-auth="['demo:traceMerge:import']" icon="Upload" plain @click="batchAdd"> 导入 </el-button>
  8. <el-button type="primary" v-auth="['demo:traceMerge:export']" icon="Download" plain @click="downloadFile"> 导出 </el-button>
  9. <el-button
  10. type="danger"
  11. v-auth="['demo:traceMerge: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="['demo:traceMerge:query']" @click="openDialog(3, '多物体融合轨迹识别查看', scope.row)">
  23. 查看
  24. </el-button>
  25. <!-- <el-button type="primary" link icon="EditPen" v-auth="['demo:traceMerge:edit']" @click="openDialog(2, '多物体融合轨迹识别编辑', scope.row)">-->
  26. <!-- 编辑-->
  27. <!-- </el-button>-->
  28. <!-- <el-button type="primary" link icon="Delete" v-auth="['demo:traceMerge:remove']" @click="deleteTraceMerge(scope.row)"> 删除 </el-button>-->
  29. <el-button type="primary" link icon="View" @click="execute(scope.row)"> 执行任务 </el-button>
  30. <el-button type="primary" link icon="View" @click="display(scope.row)"> 展示结果 </el-button>
  31. </template>
  32. </ProTable>
  33. <FormDialog ref="formDialogRef" />
  34. <ImportExcel ref="dialogRef" />
  35. <el-dialog v-model="createTaskDialogVisible" title="新增任务">
  36. <el-container style="display: flex; flex-direction: column; justify-content: center">
  37. <el-container>
  38. <span style="min-width: 80px">任务名称</span>
  39. <el-input v-model="params.name" placeholder="请输入任务名称"></el-input>
  40. </el-container>
  41. <el-container style="margin-top: 20px">
  42. <span style="min-width: 80px">任务文件</span>
  43. <file @update:model-value="updateFiles" :file-size="20" :file-type="['mat']"></file>
  44. </el-container>
  45. </el-container>
  46. <span class="dialog-footer">
  47. <el-button type="primary" @click="submitCreateTask">确 定</el-button>
  48. <el-button @click="createTaskDialogVisible = false">取 消</el-button>
  49. </span>
  50. </el-dialog>
  51. <el-dialog v-model="displayDialogVisible" title="执行结果">
  52. <el-container direction="vertical">
  53. <el-container v-for="(item, index) in resultData" :key="index">
  54. <el-image :src="'/api/profile' + item" style="max-width: 300px; max-height: 300px"></el-image>
  55. </el-container>
  56. </el-container>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script setup lang="tsx" name="TraceMerge">
  61. import { ref, reactive } from 'vue'
  62. import { useHandleData } from '@/hooks/useHandleData'
  63. import { useDownload } from '@/hooks/useDownload'
  64. import { ElMessage, ElMessageBox } from 'element-plus'
  65. import ProTable from '@/components/ProTable/index.vue'
  66. import ImportExcel from '@/components/ImportExcel/index.vue'
  67. import FormDialog from '@/components/FormDialog/index.vue'
  68. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  69. import {
  70. listTraceMergeApi,
  71. delTraceMergeApi,
  72. addTraceMergeApi,
  73. updateTraceMergeApi,
  74. importTemplateApi,
  75. importTraceMergeDataApi,
  76. exportTraceMergeApi,
  77. getTraceMergeApi,
  78. executeApi,
  79. getResApi
  80. } from '@/api/modules/demo/traceMerge'
  81. import File from '@/components/Upload/File.vue'
  82. import { getDictsApi } from '@/api/modules/system/dictData'
  83. const createTaskDialogVisible = ref(false)
  84. const params = ref({
  85. preprocessPath: null,
  86. name: ''
  87. })
  88. const resultData = ref([])
  89. const displayDialogVisible = ref(false)
  90. const display = function (row) {
  91. // console.log(row)
  92. getResApi({ taskId: row.id }).then(res => {
  93. if (res.code !== 200) {
  94. ElMessage.error(res.msg)
  95. return
  96. }
  97. let arr = row.resultPath.split('ObjectDetection_Web')
  98. let pathPrefix = arr[arr.length - 1]
  99. resultData.value = []
  100. for (let i = 0; i < res.data.length; i++) {
  101. resultData.value.push(pathPrefix + '/' + res.data[i])
  102. }
  103. console.log('resultData', resultData.value)
  104. displayDialogVisible.value = true
  105. })
  106. }
  107. const execute = function (row) {
  108. executeApi({ taskId: row.id }).then(res => {
  109. console.log(res)
  110. if (res.code == 200) {
  111. ElMessage.success('开始执行!')
  112. } else {
  113. ElMessage.error('执行失败: ' + res.msg)
  114. }
  115. })
  116. }
  117. const createTask = function () {
  118. createTaskDialogVisible.value = true
  119. }
  120. const submitCreateTask = function () {
  121. if (params.value.preprocessPath == null || params.value.preprocessPath === '') {
  122. ElMessage.error('请上传mat文件!')
  123. return
  124. } else if (params.value.name == null || params.value.name === '') {
  125. ElMessage.error('请输入任务名称!')
  126. return
  127. }
  128. addTraceMergeApi(params.value)
  129. .then(res => {
  130. console.log(res)
  131. if (res.code === 200) {
  132. ElMessage.success('创建成功!')
  133. createTaskDialogVisible.value = false
  134. } else {
  135. ElMessage.error(res.msg)
  136. }
  137. })
  138. .catch(err => {
  139. console.log(err)
  140. ElMessage.error('创建错误!')
  141. })
  142. }
  143. const updateFiles = function (filePath) {
  144. console.log('filepath', filePath)
  145. params.value.preprocessPath = filePath
  146. }
  147. // ProTable 实例
  148. const proTable = ref<ProTableInstance>()
  149. // 删除多物体融合轨迹识别信息
  150. const deleteTraceMerge = async (params: any) => {
  151. await useHandleData(delTraceMergeApi, params.id, '删除【' + params.id + '】多物体融合轨迹识别')
  152. proTable.value?.getTableList()
  153. }
  154. // 批量删除多物体融合轨迹识别信息
  155. const batchDelete = async (ids: string[]) => {
  156. await useHandleData(delTraceMergeApi, ids, '删除所选多物体融合轨迹识别信息')
  157. proTable.value?.clearSelection()
  158. proTable.value?.getTableList()
  159. }
  160. // 导出多物体融合轨迹识别列表
  161. const downloadFile = async () => {
  162. ElMessageBox.confirm('确认导出多物体融合轨迹识别数据?', '温馨提示', { type: 'warning' }).then(() =>
  163. useDownload(exportTraceMergeApi, '多物体融合轨迹识别列表', proTable.value?.searchParam)
  164. )
  165. }
  166. // 批量添加多物体融合轨迹识别
  167. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  168. const batchAdd = () => {
  169. const params = {
  170. title: '多物体融合轨迹识别',
  171. tempApi: importTemplateApi,
  172. importApi: importTraceMergeDataApi,
  173. getTableList: proTable.value?.getTableList
  174. }
  175. dialogRef.value?.acceptParams(params)
  176. }
  177. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  178. // 打开弹框的功能
  179. const openDialog = async (type: number, title: string, row?: any) => {
  180. let res = { data: {} }
  181. if (row?.id) {
  182. res = await getTraceMergeApi(row?.id || null)
  183. }
  184. // 重置表单
  185. setItemsOptions()
  186. const params = {
  187. title,
  188. width: 580,
  189. isEdit: type !== 3,
  190. itemsOptions: itemsOptions,
  191. model: type == 1 ? {} : res.data,
  192. api: type == 1 ? addTraceMergeApi : updateTraceMergeApi,
  193. getTableList: proTable.value?.getTableList
  194. }
  195. formDialogRef.value?.openDialog(params)
  196. }
  197. // 表格配置项
  198. const columns = reactive<ColumnProps<any>[]>([
  199. { type: 'selection', fixed: 'left', width: 70 },
  200. { prop: 'id', label: '主键ID' },
  201. {
  202. prop: 'name',
  203. label: '任务名称',
  204. search: {
  205. el: 'input'
  206. },
  207. width: 120
  208. },
  209. {
  210. prop: 'status',
  211. label: '任务状态',
  212. search: {
  213. el: 'input'
  214. },
  215. width: 120,
  216. tag: true,
  217. enum: () => getDictsApi('biz_task_status'),
  218. fieldNames: { label: 'dictLabel', value: 'dictValue' }
  219. },
  220. {
  221. prop: 'parameters',
  222. label: '调用算法时所用的参数',
  223. search: {
  224. el: 'input'
  225. },
  226. width: 120
  227. },
  228. {
  229. prop: 'preprocessPath',
  230. label: '预处理数据路径',
  231. search: {
  232. el: 'input'
  233. },
  234. width: 120
  235. },
  236. {
  237. prop: 'resultPath',
  238. label: '结果数据路径',
  239. search: {
  240. el: 'input'
  241. },
  242. width: 120
  243. },
  244. {
  245. prop: 'startTime',
  246. label: '开始时间',
  247. search: {
  248. el: 'date-picker',
  249. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  250. },
  251. width: 120
  252. },
  253. {
  254. prop: 'endTime',
  255. label: '结束时间',
  256. search: {
  257. el: 'date-picker',
  258. props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
  259. },
  260. width: 120
  261. },
  262. {
  263. prop: 'costSecond',
  264. label: '耗时',
  265. search: {
  266. el: 'input'
  267. },
  268. width: 120
  269. },
  270. {
  271. prop: 'remarks',
  272. label: '备注',
  273. search: {
  274. el: 'input'
  275. },
  276. width: 120
  277. },
  278. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  279. ])
  280. // 表单配置项
  281. let itemsOptions: ProForm.ItemsOptions[] = []
  282. const setItemsOptions = () => {
  283. itemsOptions = [
  284. {
  285. label: '任务名称',
  286. prop: 'name',
  287. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  288. compOptions: {
  289. placeholder: '请输入任务名称'
  290. }
  291. },
  292. {
  293. label: '任务状态',
  294. prop: 'status',
  295. rules: [{ required: true, message: '任务状态不能为空', trigger: 'blur' }],
  296. compOptions: {
  297. placeholder: '请输入任务状态'
  298. }
  299. },
  300. {
  301. label: '调用算法时所用的参数',
  302. prop: 'parameters',
  303. rules: [{ required: true, message: '调用算法时所用的参数不能为空', trigger: 'blur' }],
  304. compOptions: {
  305. type: 'textarea',
  306. clearable: true,
  307. placeholder: '请输入内容'
  308. }
  309. },
  310. {
  311. label: '预处理数据路径',
  312. prop: 'preprocessPath',
  313. rules: [{ required: true, message: '预处理数据路径不能为空', trigger: 'blur' }],
  314. compOptions: {
  315. placeholder: '请输入预处理数据路径'
  316. }
  317. },
  318. {
  319. label: '结果数据路径',
  320. prop: 'resultPath',
  321. rules: [{ required: true, message: '结果数据路径不能为空', trigger: 'blur' }],
  322. compOptions: {
  323. placeholder: '请输入结果数据路径'
  324. }
  325. },
  326. {
  327. label: '开始时间',
  328. prop: 'startTime',
  329. rules: [{ required: true, message: '开始时间不能为空', trigger: 'change' }],
  330. compOptions: {
  331. elTagName: 'date-picker',
  332. type: 'date',
  333. placeholder: '请选择开始时间'
  334. }
  335. },
  336. {
  337. label: '结束时间',
  338. prop: 'endTime',
  339. rules: [{ required: true, message: '结束时间不能为空', trigger: 'change' }],
  340. compOptions: {
  341. elTagName: 'date-picker',
  342. type: 'date',
  343. placeholder: '请选择结束时间'
  344. }
  345. },
  346. {
  347. label: '耗时',
  348. prop: 'costSecond',
  349. rules: [{ required: true, message: '耗时不能为空', trigger: 'blur' }],
  350. compOptions: {
  351. placeholder: '请输入耗时'
  352. }
  353. },
  354. {
  355. label: '备注',
  356. prop: 'remarks',
  357. rules: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
  358. compOptions: {
  359. placeholder: '请输入备注'
  360. }
  361. }
  362. ]
  363. }
  364. </script>