index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <!--
  2. @Date: 2024-10-29
  3. @Author: ©WANGKANG
  4. @Email: 1686617586@qq.com
  5. -->
  6. <template>
  7. <div class="table-box">
  8. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listTargetDetectionApi">
  9. <!-- 表格 header 按钮 -->
  10. <template #tableHeader="scope">
  11. <el-button type="primary" v-auth="['demo:TargetDetection:add']" icon="CirclePlus" @click="openDialog(1, '目标检测新增')"> 新增 </el-button>
  12. <!-- <el-button type="primary" v-auth="['demo:TargetDetection:import']" icon="Upload" plain @click="batchAdd">-->
  13. <!-- 导入-->
  14. <!-- </el-button>-->
  15. <!-- <el-button type="primary" v-auth="['demo:TargetDetection:export']" icon="Download" plain @click="downloadFile">-->
  16. <!-- 导出-->
  17. <!-- </el-button>-->
  18. <el-button
  19. type="danger"
  20. v-auth="['demo:TargetDetection:remove']"
  21. icon="Delete"
  22. plain
  23. :disabled="!scope.isSelected"
  24. @click="batchDelete(scope.selectedListIds)"
  25. >
  26. 批量删除
  27. </el-button>
  28. </template>
  29. <!-- 表格操作 -->
  30. <template #operation="scope">
  31. <el-button type="primary" link icon="View" v-if="scope.row.algorithmModelId != null" @click="openModelDialog(scope.row)">
  32. <!--@click="openStartDialog(scope.row)" -->
  33. 详情
  34. </el-button>
  35. <el-button
  36. type="primary"
  37. link
  38. icon="View"
  39. v-auth="['demo:trackSequence:start']"
  40. v-if="scope.row.status == '0' || scope.row.status == '3' || scope.row.status == '4'"
  41. @click="startTargetDetection(scope.row)"
  42. >
  43. 开始
  44. </el-button>
  45. <el-popconfirm title="确定终止此任务吗?" v-if="scope.row.status == '1'" @confirm="stopTargetDetect(scope.row)">
  46. <template #reference>
  47. <el-button type="primary" link icon="Delete">终止</el-button>
  48. </template>
  49. </el-popconfirm>
  50. <el-button
  51. type="primary"
  52. link
  53. icon="View"
  54. v-auth="['demo:toInfrared:query']"
  55. @click="viewLogRef.handleOpen(scope.row.id)"
  56. v-if="scope.row.status != '0'"
  57. >
  58. 日志
  59. </el-button>
  60. <el-button
  61. type="primary"
  62. link
  63. icon="View"
  64. v-auth="['demo:trackSequence:download']"
  65. v-if="scope.row.status == '2'"
  66. @click="dowloadTargetDetection(scope.row)"
  67. >
  68. 下载
  69. </el-button>
  70. <el-button
  71. type="primary"
  72. link
  73. icon="View"
  74. v-auth="['demo:ToInfrared:download']"
  75. v-if="scope.row.status == '2' && scope.row.type == AlgorithmType2['训练']"
  76. @click="showModelDialog(scope.row.id)"
  77. >
  78. 模型
  79. </el-button>
  80. <!-- <el-button-->
  81. <!-- type="primary"-->
  82. <!-- link-->
  83. <!-- icon="View"-->
  84. <!-- v-auth="['demo:TargetDetection:query']"-->
  85. <!-- @click="openDialog(3, '目标检测查看', scope.row)"-->
  86. <!-- >-->
  87. <!-- 查看-->
  88. <!-- </el-button>-->
  89. <!-- <el-button-->
  90. <!-- type="primary"-->
  91. <!-- link-->
  92. <!-- icon="EditPen"-->
  93. <!-- v-auth="['demo:TargetDetection:edit']"-->
  94. <!-- @click="openDialog(2, '目标检测编辑', scope.row)"-->
  95. <!-- >-->
  96. <!-- 编辑-->
  97. <!-- </el-button>-->
  98. <el-button type="primary" link icon="Delete" v-auth="['demo:TargetDetection:remove']" @click="deleteTargetDetection(scope.row)">
  99. 删除
  100. </el-button>
  101. </template>
  102. </ProTable>
  103. <FormDialog ref="formDialogRef" />
  104. <ImportExcel ref="dialogRef" />
  105. <ViewLog ref="viewLogRef" :get-log-api="getLogTargetDetectionApi" />
  106. <el-dialog v-model="showModelDialogVisible" title="模型列表" width="1000">
  107. <el-scrollbar ref="scrollbarRef" id="scrollbarRef1" height="500px">
  108. <template v-for="model in model_list" :key="model">
  109. <el-card style="width: 100%; margin-bottom: 10px">
  110. <el-form label-width="130px" label-position="left">
  111. <el-form-item label="Model Name">
  112. {{ model.name }}
  113. </el-form-item>
  114. <el-form-item label="Model Path">
  115. {{ model.path }}
  116. </el-form-item>
  117. <el-form-item label="Model Size">
  118. {{ model.size }}
  119. </el-form-item>
  120. <el-form-item label="操作">
  121. <el-link :href="model.url" type="primary" icon="Download" :underline="false" target="_blank" style="margin-right: 20px"
  122. >下载
  123. </el-link>
  124. <el-button type="success" link @click="addModel(model.path, model.name)">
  125. <el-icon>
  126. <Plus />
  127. </el-icon>
  128. 添加模型
  129. </el-button>
  130. </el-form-item>
  131. </el-form>
  132. </el-card>
  133. </template>
  134. </el-scrollbar>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script setup lang="tsx" name="TargetDetection">
  139. import { ref, reactive, onMounted, Ref } from 'vue'
  140. import { useHandleData } from '@/hooks/useHandleData'
  141. import { useDownload } from '@/hooks/useDownload'
  142. import { ElMessage, ElMessageBox } from 'element-plus'
  143. import ProTable from '@/components/ProTable/index.vue'
  144. import ImportExcel from '@/components/ImportExcel/index.vue'
  145. import FormDialog from '@/components/FormDialog/index.vue'
  146. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  147. import {
  148. listTargetDetectionApi,
  149. delTargetDetectionApi,
  150. addTargetDetectionApi,
  151. updateTargetDetectionApi,
  152. importTemplateApi,
  153. importTargetDetectionDataApi,
  154. exportTargetDetectionApi,
  155. getTargetDetectionApi,
  156. startTargetDetectionApi,
  157. dowloadTargetDetectionApi,
  158. stopTargetDetectionApi,
  159. getLogTargetDetectionApi,
  160. showTargetDetectionModelApi
  161. } from '@/api/modules/demo/TargetDetection'
  162. import { listDataSeqApi } from '@/api/modules/demo/DataSeq'
  163. import { enumAlgorithmModelTrackApi, getAlgorithmModelTrackApi } from '@/api/modules/demo/AlgorithmModelTrack'
  164. import { enumAlgorithmConfigTrackApi } from '@/api/modules/demo/AlgorithmConfigTrack'
  165. import { updateTrackSequenceApi } from '@/api/modules/demo/trackSequence'
  166. import ViewLog from '@/views/demo/components/ViewLog.vue'
  167. import { AlgorithmType2 } from '@/views/demo/utils'
  168. import { addAlgorithmModelTrackApi } from '@/api/modules/demo/AlgorithmModelTrack'
  169. import useWebSocketStore from '@/stores/modules/websocket'
  170. import { resetHeart } from '@/utils/websocket'
  171. onMounted(() => {
  172. const websocketStore = useWebSocketStore()
  173. websocketStore.websocket.onmessage = (e: any) => {
  174. if (e.data.indexOf('heartbeat') > 0) {
  175. resetHeart()
  176. }
  177. if (e.data.indexOf('ping') > 0) {
  178. return
  179. }
  180. // console.log(e)
  181. proTable.value?.getTableList(true)
  182. }
  183. })
  184. const enumsAlgorithmConfigTrack = ref<any>([])
  185. onMounted(async () => {
  186. const result = await enumAlgorithmConfigTrackApi()
  187. enumsAlgorithmConfigTrack.value = []
  188. const tmp_data: any = result['data']
  189. for (const item of tmp_data) {
  190. if (item.subsystem === SubSystem__['目标检测'] && item.type === AlgorithmType2['预测/推理']) {
  191. item['label'] = item['label'] + '-' + SubSystem[item['subsystem']] + '-' + AlgorithmType[item['type']]
  192. enumsAlgorithmConfigTrack.value.push(item)
  193. }
  194. }
  195. })
  196. const setItemsOptions222 = () => {
  197. itemsOptions = [
  198. {
  199. label: '算法',
  200. prop: 'algorithmId',
  201. rules: [{ required: true, message: '算法不能为空', trigger: 'blur' }],
  202. compOptions: {
  203. elTagName: 'select',
  204. placeholder: '请输入算法',
  205. enum: enumsAlgorithmConfigTrack
  206. }
  207. },
  208. {
  209. label: '子系统',
  210. prop: 'subSystem',
  211. rules: [{ required: true, message: '子系统不能为空', trigger: 'blur' }],
  212. compOptions: {
  213. disabled: true,
  214. elTagName: 'select',
  215. placeholder: '请输入子系统',
  216. enum: enumsSubSystem
  217. }
  218. },
  219. {
  220. label: '模型名称',
  221. prop: 'modelName',
  222. rules: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  223. compOptions: {
  224. disabled: true,
  225. placeholder: '请输入模型名称'
  226. }
  227. },
  228. {
  229. label: '模型路径',
  230. prop: 'modelPath',
  231. rules: [{ required: false, message: '模型文件不能为空', trigger: 'blur' }],
  232. compOptions: {
  233. placeholder: '请输入模型名称',
  234. disabled: true
  235. }
  236. },
  237. {
  238. label: '备注',
  239. prop: 'remarks',
  240. rules: [{ required: false, message: '备注不能为空', trigger: 'blur' }],
  241. compOptions: {
  242. placeholder: '请输入备注'
  243. }
  244. }
  245. ]
  246. }
  247. const addModel = async (modelPath: string, modelName: string) => {
  248. console.log(modelPath, modelName)
  249. let res = { data: { modelPath, subSystem: SubSystem__['目标检测'], type: AlgorithmType2['预测/推理'], modelName: modelName } }
  250. // 重置表单
  251. setItemsOptions222()
  252. const params = {
  253. title: '添加模型',
  254. width: 580,
  255. isEdit: true,
  256. itemsOptions: itemsOptions,
  257. model: res.data,
  258. api: addAlgorithmModelTrackApi,
  259. getTableList: proTable.value?.getTableList,
  260. closedEvent: async () => {
  261. await updateWnumsAlgorithmModelTrack()
  262. }
  263. }
  264. formDialogRef.value?.openDialog(params)
  265. }
  266. const showModelDialogVisible = ref(false)
  267. const model_list: Ref<any> = ref([])
  268. const showModelDialog = async (id: any) => {
  269. const res: any = await showTargetDetectionModelApi(id)
  270. model_list.value = res.data
  271. showModelDialogVisible.value = true
  272. }
  273. const viewLogRef = ref()
  274. const stopTargetDetect = async (params: any) => {
  275. const res: any = await stopTargetDetectionApi(params.id)
  276. if (res.code === 200) {
  277. ElMessage.success('终止任务成功!')
  278. } else {
  279. ElMessage.error('终止任务失败,请检查!')
  280. }
  281. proTable.value?.getTableList()
  282. }
  283. import statusEnums from '@/utils/status'
  284. import { AlgorithmType, SubSystem, SubSystem__, enumsAlgorithmType, enumsSubSystem } from '@/views/demo/utils'
  285. const dowloadTargetDetection = async (params: any) => {
  286. await useDownload(dowloadTargetDetectionApi, params.name, params.id, true, '.zip')
  287. }
  288. const startTargetDetection = async (params: any) => {
  289. const res: any = await startTargetDetectionApi(params.id)
  290. if (res.code === 200) {
  291. ElMessage.success('任务已开始,请等待完成!')
  292. } else {
  293. ElMessage.error('任务开始失败,请检查!')
  294. }
  295. proTable.value?.getTableList()
  296. }
  297. const openModelDialog = async row => {
  298. const algorithmModelId = row.algorithmModelId
  299. const result: any = await getAlgorithmModelTrackApi(algorithmModelId)
  300. // console.log(result.data)
  301. setItemsOptionsModel()
  302. const params = {
  303. title: '模型',
  304. width: 580,
  305. isEdit: false,
  306. itemsOptions: itemsOptions,
  307. model: result.data,
  308. api: updateTrackSequenceApi,
  309. getTableList: proTable.value?.getTableList
  310. }
  311. formDialogRef.value?.openDialog(params)
  312. }
  313. // ProTable 实例
  314. const proTable = ref<ProTableInstance>()
  315. // 删除目标检测信息
  316. const deleteTargetDetection = async (params: any) => {
  317. await useHandleData(delTargetDetectionApi, params.id, '删除【' + params.id + '】目标检测')
  318. proTable.value?.getTableList()
  319. }
  320. // 批量删除目标检测信息
  321. const batchDelete = async (ids: string[]) => {
  322. await useHandleData(delTargetDetectionApi, ids, '删除所选目标检测信息')
  323. proTable.value?.clearSelection()
  324. proTable.value?.getTableList()
  325. }
  326. // 导出目标检测列表
  327. const downloadFile = async () => {
  328. ElMessageBox.confirm('确认导出目标检测数据?', '温馨提示', { type: 'warning' }).then(() =>
  329. useDownload(exportTargetDetectionApi, '目标检测列表', proTable.value?.searchParam)
  330. )
  331. }
  332. // 批量添加目标检测
  333. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  334. const batchAdd = () => {
  335. const params = {
  336. title: '目标检测',
  337. tempApi: importTemplateApi,
  338. importApi: importTargetDetectionDataApi,
  339. getTableList: proTable.value?.getTableList
  340. }
  341. dialogRef.value?.acceptParams(params)
  342. }
  343. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  344. // 打开弹框的功能
  345. const openDialog = async (type: number, title: string, row?: any) => {
  346. let res = { data: {} }
  347. if (row?.id) {
  348. res = await getTargetDetectionApi(row?.id || null)
  349. }
  350. // 重置表单
  351. setItemsOptions()
  352. const params = {
  353. title,
  354. width: 580,
  355. isEdit: type !== 3,
  356. itemsOptions: itemsOptions,
  357. model: type == 1 ? {} : res.data,
  358. api: type == 1 ? addTargetDetectionApi : updateTargetDetectionApi,
  359. getTableList: proTable.value?.getTableList
  360. }
  361. formDialogRef.value?.openDialog(params)
  362. }
  363. // 表格配置项
  364. const columns = reactive<ColumnProps<any>[]>([
  365. { type: 'selection', fixed: 'left', width: 70 },
  366. { prop: 'id', label: '主键ID', width: 180 },
  367. {
  368. prop: 'name',
  369. label: '任务名称',
  370. search: {
  371. el: 'input'
  372. },
  373. width: 150
  374. },
  375. {
  376. prop: 'status',
  377. label: '任务状态',
  378. search: {
  379. el: 'select'
  380. },
  381. tag: true,
  382. enum: statusEnums,
  383. width: 150
  384. },
  385. {
  386. prop: 'type',
  387. label: '类型',
  388. tag: true,
  389. enum: enumsAlgorithmType,
  390. width: 120
  391. },
  392. {
  393. prop: 'subsystem',
  394. label: '分系统',
  395. tag: true,
  396. enum: enumsSubSystem,
  397. width: 200
  398. },
  399. {
  400. prop: 'algorithmName',
  401. label: '算法名称',
  402. width: 200
  403. },
  404. {
  405. prop: 'modelName',
  406. label: '模型名称',
  407. width: 200
  408. },
  409. // {
  410. // prop: 'algorithmModelId',
  411. // label: '模型',
  412. // search: {
  413. // el: 'input'
  414. // },
  415. // width: 150
  416. // },
  417. {
  418. prop: 'startTime',
  419. label: '开始时间',
  420. width: 180
  421. },
  422. {
  423. prop: 'endTime',
  424. label: '结束时间',
  425. width: 180
  426. },
  427. {
  428. prop: 'costSecond',
  429. label: '耗时',
  430. width: 120
  431. },
  432. {
  433. prop: 'log',
  434. label: '日志',
  435. width: 120
  436. },
  437. {
  438. prop: 'outputPath',
  439. label: '输出路径',
  440. width: 120
  441. },
  442. {
  443. prop: 'remarks',
  444. label: '备注',
  445. search: {
  446. el: 'input'
  447. },
  448. width: 120
  449. },
  450. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  451. ])
  452. const imageUrlList________ = ref<any>([])
  453. const getImageData = async (subsystem: string) => {
  454. const qyery = {
  455. subsystem: SubSystem__[subsystem],
  456. pageNum: 1,
  457. pageSize: 1000
  458. }
  459. const result: any = await listDataSeqApi(qyery)
  460. const data = result['data']['list']
  461. for (const item of data) {
  462. imageUrlList________.value.push({
  463. value: item['inputOssId'],
  464. label: item['name'] + '-' + subsystem
  465. })
  466. }
  467. }
  468. onMounted(async () => {
  469. await getImageData('可见光转红外')
  470. await getImageData('目标检测')
  471. await getImageData('注释轨迹序列')
  472. })
  473. const enumsAlgorithmModelTrack = ref<any>([])
  474. const updateWnumsAlgorithmModelTrack = async () => {
  475. const result: any = await enumAlgorithmModelTrackApi()
  476. // console.log(result.data);
  477. enumsAlgorithmModelTrack.value = []
  478. for (const item of result.data) {
  479. if (SubSystem[item['subsystem']] === '目标检测') {
  480. item['label'] =
  481. item.value + '_' + item['label'] + '-' + SubSystem[item['subsystem']] + '-' + AlgorithmType[item['type']] + '-' + item['algorithmName']
  482. enumsAlgorithmModelTrack.value.push(item)
  483. }
  484. }
  485. }
  486. onMounted(async () => {
  487. updateWnumsAlgorithmModelTrack()
  488. })
  489. // 表单配置项
  490. let itemsOptions: ProForm.ItemsOptions[] = []
  491. const setItemsOptions = () => {
  492. itemsOptions = [
  493. {
  494. label: '任务名称',
  495. prop: 'name',
  496. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  497. compOptions: {
  498. placeholder: '请输入任务名称'
  499. }
  500. },
  501. {
  502. label: '选择数据集',
  503. prop: 'inputOssId',
  504. rules: [{ required: false, message: '数据集不能为空', trigger: 'blur' }],
  505. compOptions: {
  506. elTagName: 'select',
  507. placeholder: '请选择或者上传数据集',
  508. enum: imageUrlList________,
  509. clearable: true
  510. }
  511. },
  512. {
  513. label: '上传数据集',
  514. prop: 'inputOssId',
  515. rules: [{ required: true, message: '数据集不能为空', trigger: 'blur' }],
  516. compOptions: {
  517. elTagName: 'file-upload',
  518. fileSize: 4096,
  519. fileType: ['zip'],
  520. placeholder: '请上传数据集'
  521. }
  522. },
  523. {
  524. label: '选择模型',
  525. prop: 'algorithmModelId',
  526. rules: [{ required: true, message: '模型不能为空', trigger: 'blur' }],
  527. compOptions: {
  528. elTagName: 'select',
  529. placeholder: '请选择模型',
  530. enum: enumsAlgorithmModelTrack
  531. }
  532. },
  533. {
  534. label: '备注',
  535. prop: 'remarks',
  536. rules: [],
  537. compOptions: {
  538. placeholder: '请输入备注'
  539. }
  540. }
  541. ]
  542. }
  543. const setItemsOptionsModel = () => {
  544. itemsOptions = [
  545. {
  546. label: '算法ID',
  547. prop: 'algorithmId',
  548. rules: [{ required: true, message: '算法不能为空', trigger: 'blur' }],
  549. compOptions: {
  550. disabled: true,
  551. placeholder: '请输入算法'
  552. }
  553. },
  554. {
  555. label: '算法类型',
  556. prop: 'algorithmType',
  557. rules: [{ required: true, message: '算法不能为空', trigger: 'blur' }],
  558. compOptions: {
  559. disabled: true,
  560. elTagName: 'select',
  561. placeholder: '请输入算法',
  562. enum: enumsAlgorithmConfigTrack
  563. }
  564. },
  565. {
  566. label: '算法参数',
  567. prop: 'parameterConfig',
  568. rules: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  569. compOptions: {
  570. placeholder: '请输入模型名称'
  571. }
  572. },
  573. {
  574. label: '模型ID',
  575. prop: 'id',
  576. rules: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  577. compOptions: {
  578. placeholder: '请输入模型名称'
  579. }
  580. },
  581. {
  582. label: '模型名称',
  583. prop: 'modelName',
  584. rules: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  585. compOptions: {
  586. placeholder: '请输入模型名称'
  587. }
  588. },
  589. {
  590. label: '模型保存路径',
  591. prop: 'modelAddress',
  592. rules: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  593. compOptions: {
  594. placeholder: '请输入模型名称'
  595. }
  596. },
  597. {
  598. label: '备注',
  599. prop: 'remarks',
  600. rules: [{ required: false, message: '备注不能为空', trigger: 'blur' }],
  601. compOptions: {
  602. placeholder: '请输入备注'
  603. }
  604. }
  605. ]
  606. }
  607. </script>