index.vue 13 KB

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