index.vue 13 KB

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