index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listDataAugmentationApi3">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['demo:DataAugmentation:add']" icon="CirclePlus" @click="openDialog(1, '任务新增')"> 新增 </el-button>
  7. <!-- <el-button type="primary" v-auth="['demo:DataAugmentation:import']" icon="Upload" plain @click="batchAdd"> 导入</el-button> -->
  8. <!-- <el-button type="primary" v-auth="['demo:DataAugmentation:export']" icon="Download" plain @click="downloadFile"> 导出 </el-button> -->
  9. <el-button
  10. type="danger"
  11. v-auth="['demo:DataAugmentation: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" @click="startDataAugmentation(scope.row)" v-if="scope.row.status == '0'"> 开始 </el-button>
  23. <el-popconfirm title="确定终止此任务吗?" @confirm="stopDataAugmentation(scope.row)" v-if="scope.row.status == '1'">
  24. <template #reference>
  25. <el-button type="primary" link icon="View"> 终止 </el-button>
  26. </template>
  27. </el-popconfirm>
  28. <el-popconfirm title="确定暂停此任务吗?" @confirm="pauseDataAugmentation(scope.row)" v-if="scope.row.status == '1'">
  29. <template #reference>
  30. <el-button type="primary" link icon="View"> 暂停 </el-button>
  31. </template>
  32. </el-popconfirm>
  33. <el-button type="primary" link icon="View" @click="preview(scope.row)" v-if="scope.row.status == '2'"> 预览 </el-button>
  34. <el-button type="primary" link icon="View" @click="downloadFile(scope.row)" v-if="scope.row.status == '2'"> 导出 </el-button>
  35. <el-button type="primary" link icon="View" @click="openMetricDialog(scope.row.id)" v-if="scope.row.status == '2'"> 指标 </el-button>
  36. <el-button type="primary" link icon="View" v-auth="['demo:DataAugmentation:query']" @click="openDialog(3, '任务查看', scope.row)">
  37. 查看
  38. </el-button>
  39. <el-button
  40. type="primary"
  41. link
  42. icon="View"
  43. v-auth="['demo:DataAugmentation:query']"
  44. @click="viewLogRef.handleOpen(scope.row.id)"
  45. v-if="scope.row.status != '0' && scope.row.status != '1'"
  46. >
  47. 日志
  48. </el-button>
  49. <el-button type="primary" link icon="Delete" v-auth="['demo:DataAugmentation:remove']" @click="deleteDataAugmentation(scope.row)">
  50. 删除
  51. </el-button>
  52. </template>
  53. </ProTable>
  54. <DataAugmentationFormDialog ref="formDialogRef" />
  55. <ImportExcel ref="dialogRef" />
  56. <!-- <el-dialog v-model="dialogVisible" title="结果预览" width="80%">
  57. <div style="display: flex; text-align: center">
  58. <div style="width: 50%" v-if="inputVideoUrl">
  59. <video controls width="90%">
  60. <source :src="inputVideoUrl" />
  61. Your browser does not support the video tag.
  62. </video>
  63. </div>
  64. <div style="width: 50%" v-if="outputVideoUrl">
  65. <video controls width="90%">
  66. <source :src="outputVideoUrl" />
  67. Your browser does not support the video tag.
  68. </video>
  69. </div>
  70. </div>
  71. </el-dialog> -->
  72. <el-dialog v-model="dialogVisible" :title="dialogTitle" width="80%" @close="handleClose">
  73. <el-select v-model="imageFps" placeholder="选择帧率" style="width: 200px" @change="changeFps">
  74. <el-option label="0" value="0"></el-option>
  75. <el-option label="5" value="5"></el-option>
  76. <el-option label="15" value="15"></el-option>
  77. <el-option label="30" value="30"></el-option>
  78. </el-select>
  79. <div class="image-dialog" v-if="imageIdx >= 0 && cacheImages[imageIdx]">
  80. <div style="width: 50%">
  81. <el-image :src="cacheImages[imageIdx].origin[0]"></el-image>
  82. </div>
  83. <div style="width: 50%">
  84. <el-image :src="cacheImages[imageIdx].stable[0]"></el-image>
  85. </div>
  86. </div>
  87. <div class="image-dialog-btn" v-if="imageFps == 0">
  88. <el-button type="primary" @click="pre_picture" :disabled="imageIdx <= 0">上一个</el-button>
  89. <el-button type="primary" @click="next_picture" :disabled="imageIdx >= fileCount - 1">下一个</el-button>
  90. </div>
  91. </el-dialog>
  92. <ViewLog ref="viewLogRef" :get-log-api="getDialogApi" />
  93. <PreviewCompareImages ref="previewCompareImagesRef" />
  94. <el-dialog v-model="metricDialogVisible" title="算法结果指标" width="500px" style="text-align: center">
  95. <el-table :data="metricList" style="width: 100%; margin-left: 10%; text-align: left">
  96. <el-table-column prop="name" label="name" width="200px" />
  97. <el-table-column prop="value" label="value" width="200px" />
  98. </el-table>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script setup lang="tsx" name="DataAugmentation">
  103. import { ref, reactive, onMounted, computed, onUnmounted, onBeforeMount, watch, nextTick } from 'vue'
  104. import { useHandleData } from '@/hooks/useHandleData'
  105. import { useDownload } from '@/hooks/useDownload'
  106. import { ElMessageBox, ElMessage } from 'element-plus'
  107. import ProTable from '@/components/ProTable/index.vue'
  108. import ImportExcel from '@/components/ImportExcel/index.vue'
  109. import ViewLog from '@/views/demo/components/ViewLog.vue'
  110. import PreviewCompareImages from '@/views/demo/components/PreviewCompareImages.vue'
  111. import DataAugmentationFormDialog from '@/components/DataAugmentationFormDialog/index.vue'
  112. import { ProTableInstance, ColumnProps, EnumProps } from '@/components/ProTable/interface'
  113. import {
  114. listDataAugmentationApi3,
  115. delDataAugmentationApi,
  116. addDataAugmentationApi,
  117. updateDataAugmentationApi,
  118. importTemplateApi,
  119. importDataAugmentationDataApi,
  120. exportDataAugmentationApi,
  121. getDataAugmentationApi,
  122. startDataAugmentationApi,
  123. stopDataAugmentationApi,
  124. getCompareImageApi,
  125. getCompareImageCountApi,
  126. getDialogApi,
  127. getTaskDictData,
  128. getMetricApi,
  129. getVideoUrl,
  130. getCompareImageApiNew,
  131. pauseDataAugmentationApi
  132. } from '@/api/modules/demo/dataAugmentation'
  133. // import { VideoPlayer } from 'vue-video-player'
  134. // import 'vue-video-player/dist/simple.css'
  135. // const playerOptions = ref({})
  136. // const videoPlayer = ref<InstanceType<typeof VideoPlayer> | null>(null);
  137. // const playVideo = () => {
  138. // if (videoPlayer.value) {
  139. // videoPlayer.value.player.play();
  140. // }
  141. // };
  142. // const pauseVideo = () => {
  143. // if (videoPlayer.value) {
  144. // videoPlayer.value.player.pause();
  145. // }
  146. // };
  147. // const onPlay = () => {
  148. // console.log('视频开始播放');
  149. // };
  150. // const onPause = () => {
  151. // console.log('视频暂停播放');
  152. // };
  153. // const setPlayerOptions = (url) => {
  154. // playerOptions.value = {
  155. // sources: [{
  156. // type: "video/mp4",
  157. // src: url
  158. // }],
  159. // poster: "", // 视频封面图
  160. // autoplay: false,
  161. // controls: true,
  162. // fluid: true // 响应式布局
  163. // }
  164. // }
  165. const previewCompareImagesRef = ref()
  166. const preview = async row => {
  167. // console.log(row)
  168. await previewCompareImagesRef.value.handleOpen(getCompareImageApiNew, row.id)
  169. }
  170. const handleClose = () => {
  171. if (intervalChangeFps.value) {
  172. clearInterval(intervalChangeFps.value)
  173. }
  174. }
  175. const changeFps = () => {
  176. console.log('changeFps')
  177. if (intervalChangeFps.value) {
  178. clearInterval(intervalChangeFps.value)
  179. }
  180. if (imageFps.value == 0) {
  181. return
  182. }
  183. imageIdx.value = 1
  184. intervalChangeFps.value = setInterval(() => {
  185. next_picture()
  186. }, 1000 / imageFps.value)
  187. }
  188. const dialogVisible = ref(false)
  189. const taskId = ref('')
  190. const imageIdx = ref(0)
  191. const imageBase64List = ref({
  192. origin: '',
  193. stable: ''
  194. })
  195. const inFileCount = ref(0)
  196. const outFileCount = ref(0)
  197. const cacheImages = ref({})
  198. const dialogTitle = ref('')
  199. const fileCount = ref(0)
  200. const imageFps = ref(0)
  201. const intervalChangeFps: any = ref()
  202. const loadImageData = async (taskId: string, imageIdx: number) => {
  203. const res: any = await getCompareImageApi(taskId, imageIdx)
  204. // imageBase64List.value.origin = res.origin
  205. // imageBase64List.value.stable = res.stable
  206. cacheImages.value[imageIdx].origin = res.origin
  207. cacheImages.value[imageIdx].stable = res.stable
  208. }
  209. const task_type_view = ref('')
  210. const compareDataAugmentation = async (params: any) => {
  211. if (taskId.value !== '' && taskId.value !== null && taskId.value !== undefined && taskId.value == params.id) {
  212. dialogVisible.value = true
  213. return
  214. }
  215. task_type_view.value = params.taskType
  216. taskId.value = params.id
  217. imageIdx.value = 0
  218. cacheImages.value = {}
  219. const resCount: any = await getCompareImageCountApi(params.id)
  220. if (resCount.code === 200) {
  221. inFileCount.value = resCount.data.inFileCount
  222. outFileCount.value = resCount.data.outFileCount
  223. } else {
  224. ElMessage.error('获取图片对比数量失败')
  225. return
  226. }
  227. dialogVisible.value = true
  228. dialogTitle.value = '缓存图片中'
  229. fileCount.value = Math.min(inFileCount.value, outFileCount.value)
  230. const res: any = await getCompareImageApi(taskId.value)
  231. for (let idx = 1; idx <= fileCount.value; idx++) {
  232. dialogTitle.value = '缓存图片中: 第' + idx + '个样本 共' + fileCount.value + '个样本'
  233. if (cacheImages.value[idx - 1]) {
  234. continue
  235. }
  236. //const res: any = await getCompareImageApi(taskId.value, idx - 1)
  237. // console.log(res)
  238. cacheImages.value[idx - 1] = {
  239. origin: res.origin[idx - 1],
  240. stable: res.stable[idx - 1]
  241. }
  242. }
  243. // console.log(cacheImages.value[0])
  244. if (fileCount.value > 0) {
  245. dialogTitle.value = '预览: 第1个样本 共' + fileCount.value + '个样本'
  246. } else {
  247. dialogTitle.value = '无结果预览'
  248. }
  249. // next_picture()
  250. }
  251. const next_picture = async () => {
  252. if (imageIdx.value < fileCount.value - 1) {
  253. if (!cacheImages.value[imageIdx.value + 1]) {
  254. await loadImageData(taskId.value, imageIdx.value + 1)
  255. }
  256. imageIdx.value = imageIdx.value + 1
  257. }
  258. dialogTitle.value = '预览: 第' + (imageIdx.value + 1) + '个样本 共' + fileCount.value + '个样本'
  259. }
  260. const pre_picture = async () => {
  261. if (imageIdx.value > 0) {
  262. if (!cacheImages.value[imageIdx.value - 1]) {
  263. await loadImageData(taskId.value, imageIdx.value - 1)
  264. }
  265. imageIdx.value = imageIdx.value - 1
  266. }
  267. dialogTitle.value = '预览: 第' + (imageIdx.value + 1) + '个样本 共' + fileCount.value + '个样本'
  268. }
  269. //打开指标窗口查看算法指标信息
  270. const metricDialogVisible = ref(false)
  271. const metricList = reactive([])
  272. const openMetricDialog = async (id: string | number) => {
  273. const res: any = await getMetricApi(id)
  274. console.log(res.data)
  275. metricList.splice(0, metricList.length, ...res.data)
  276. metricDialogVisible.value = true
  277. }
  278. // const dialogVisible = ref(false)
  279. const inputVideoUrl = ref()
  280. const outputVideoUrl = ref()
  281. // const openResultDialog = async (id: string | number) => {
  282. // const res: any = await getVideoUrl(id)
  283. // inputVideoUrl.value = res.data.input
  284. // outputVideoUrl.value = res.data.output
  285. // //setPlayerOptions(inputVideoUrl.value)
  286. // // inputVideoUrl.value = '/api/public/video/input/' + id
  287. // // outputVideoUrl.value = '/api/public/video/output/' + id
  288. // console.log(inputVideoUrl)
  289. // dialogVisible.value = true
  290. // }
  291. const taskType = ref([])
  292. const modelType = ref([
  293. {
  294. label: 'yolov8_best.pt',
  295. value: 'yolov8_best.pt'
  296. },
  297. {
  298. label: 'yolov8_best_new.pt',
  299. value: 'yolov8_best_new.pt'
  300. },
  301. {
  302. label: 'yolov8__best.pt',
  303. value: 'yolov8__best.pt'
  304. },
  305. {
  306. label: 'yolov8__best_new.pt',
  307. value: 'yolov8__best_new.pt'
  308. }
  309. ])
  310. const trackingMethod = ref([
  311. {
  312. label: 'botsort',
  313. value: 'botsort'
  314. },
  315. {
  316. label: 'strongsort',
  317. value: 'strongsort'
  318. },
  319. {
  320. label: 'bytetrack',
  321. value: 'bytetrack'
  322. },
  323. {
  324. label: 'ocsort',
  325. value: 'ocsort'
  326. },
  327. {
  328. label: 'imprassoc',
  329. value: 'imprassoc'
  330. },
  331. {
  332. label: 'deepocsort',
  333. value: 'deepocsort'
  334. }
  335. ])
  336. const taskTypeEnums: EnumProps[] = []
  337. const hyperparameterConfiguration = []
  338. const viewLogRef = ref()
  339. const getTaskType = async () => {
  340. const res: any = await getTaskDictData('多目标跟踪')
  341. if (res.data.length != 0) {
  342. taskType.value = res.data
  343. .map(item => {
  344. return {
  345. label: item.taskType,
  346. value: item.taskType
  347. }
  348. })
  349. .filter(item => item !== null)
  350. res.data.forEach(item => {
  351. taskTypeEnums.push({
  352. label: item.taskType,
  353. value: item.taskType,
  354. disabled: false,
  355. tagType: 'default'
  356. })
  357. let obj = {}
  358. obj[item.taskType] = item.hyperparameterConfiguration
  359. hyperparameterConfiguration.push(obj)
  360. })
  361. }
  362. }
  363. let intervalId: NodeJS.Timeout | null = null
  364. onUnmounted(() => {
  365. // 组件卸载时清除定时器
  366. if (intervalId !== null) {
  367. clearInterval(intervalId)
  368. }
  369. })
  370. onMounted(() => {
  371. intervalId = setInterval(async () => {
  372. proTable.value?.getTableList()
  373. }, 5000)
  374. getTaskType()
  375. })
  376. const startDataAugmentation = async (params: any) => {
  377. const res = await startDataAugmentationApi(params.id)
  378. if (res.code === 200) {
  379. ElMessage.success('任务已经开始,请等待')
  380. } else {
  381. ElMessage.error('任务开始失败,请检查!')
  382. }
  383. proTable.value?.getTableList()
  384. }
  385. const stopDataAugmentation = async (params: any) => {
  386. const res = await stopDataAugmentationApi(params.id)
  387. if (res.code === 200) {
  388. ElMessage.success('任务终止成功')
  389. } else {
  390. ElMessage.error('任务终止失败!')
  391. }
  392. proTable.value?.getTableList()
  393. }
  394. const pauseDataAugmentation = async (params: any) => {
  395. const res = await pauseDataAugmentationApi(params.id)
  396. if (res.code === 200) {
  397. ElMessage.success('任务暂停成功')
  398. } else {
  399. ElMessage.error('任务暂停失败!')
  400. }
  401. proTable.value?.getTableList()
  402. }
  403. // ProTable 实例
  404. const proTable = ref<ProTableInstance>()
  405. // 删除视频去抖动信息
  406. const deleteDataAugmentation = async (params: any) => {
  407. await useHandleData(delDataAugmentationApi, params.id, '删除任务【' + params.name + '】?')
  408. proTable.value?.getTableList()
  409. }
  410. // 批量删除视频去抖动信息
  411. const batchDelete = async (ids: string[]) => {
  412. await useHandleData(delDataAugmentationApi, ids, '删除所选任务?')
  413. proTable.value?.clearSelection()
  414. proTable.value?.getTableList()
  415. }
  416. // 导出视频去抖动列表
  417. const downloadFile = async task => {
  418. ElMessageBox.confirm('确认导出任务数据?', '温馨提示', { type: 'warning' }).then(() =>
  419. useDownload(exportDataAugmentationApi, 'export', task.outputPath)
  420. )
  421. }
  422. // 批量添加视频去抖动
  423. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  424. const formDialogRef = ref<InstanceType<typeof DataAugmentationFormDialog> | null>(null)
  425. // 打开弹框的功能
  426. const openDialog = async (type: number, title: string, row?: any) => {
  427. // hyperparameter.value = ''
  428. let res = { data: {} }
  429. if (row?.id) {
  430. res = await getDataAugmentationApi(row?.id || null)
  431. // hyperparameter.value = res.data?.hyperparameterConfiguration
  432. }
  433. // console.log(itemsOptions[1].compOptions?.value)
  434. // 重置表单
  435. // setItemsOptions()
  436. const params = {
  437. title,
  438. width: 580,
  439. isEdit: type !== 3,
  440. itemsOptions: itemsOptions,
  441. model: type == 1 ? model : res.data,
  442. api: type == 1 ? addDataAugmentationApi : updateDataAugmentationApi,
  443. getTableList: proTable.value?.getTableList
  444. }
  445. formDialogRef.value?.openDialog(params)
  446. }
  447. const statusEnums: EnumProps[] = [
  448. {
  449. label: '未开始',
  450. value: '0',
  451. disabled: false,
  452. tagType: 'default'
  453. },
  454. {
  455. label: '进行中',
  456. value: '1',
  457. disabled: false,
  458. tagType: 'primary'
  459. },
  460. {
  461. label: '完成',
  462. value: '2',
  463. disabled: false,
  464. tagType: 'success'
  465. },
  466. {
  467. label: '失败',
  468. value: '3',
  469. disabled: false,
  470. tagType: 'danger'
  471. },
  472. {
  473. label: '已中断',
  474. value: '4',
  475. disabled: false,
  476. tagType: 'default'
  477. }
  478. ]
  479. // 表格配置项
  480. const columns = reactive<ColumnProps<any>[]>([
  481. { type: 'selection', fixed: 'left', width: 70 },
  482. { prop: 'id', label: '主键ID', width: 180 },
  483. {
  484. prop: 'name',
  485. label: '任务名称',
  486. search: {
  487. el: 'input'
  488. },
  489. width: 150
  490. },
  491. {
  492. prop: 'taskType',
  493. label: '任务类型',
  494. search: {
  495. el: 'select'
  496. },
  497. width: 100,
  498. tag: true,
  499. enum: taskTypeEnums
  500. },
  501. {
  502. prop: 'status',
  503. label: '任务状态',
  504. search: {
  505. el: 'select'
  506. },
  507. width: 100,
  508. tag: true,
  509. enum: statusEnums
  510. },
  511. {
  512. prop: 'startTime',
  513. label: '开始时间',
  514. width: 180
  515. },
  516. {
  517. prop: 'endTime',
  518. label: '结束时间',
  519. width: 180
  520. },
  521. {
  522. prop: 'costSecond',
  523. label: '耗时',
  524. search: {
  525. el: 'input'
  526. },
  527. width: 80
  528. },
  529. {
  530. prop: 'log',
  531. label: '日志',
  532. width: 120
  533. },
  534. {
  535. prop: 'algorithmPath',
  536. label: '日志路径',
  537. width: 120
  538. },
  539. {
  540. prop: 'hyperparameterConfiguration',
  541. label: '超参配置',
  542. width: 120
  543. },
  544. {
  545. prop: 'remarks',
  546. label: '备注',
  547. search: {
  548. el: 'input'
  549. },
  550. width: 120
  551. },
  552. {
  553. prop: 'operation',
  554. label: '操作',
  555. width: 230,
  556. fixed: 'right'
  557. }
  558. ])
  559. // 表单配置项
  560. let itemsOptions: ProForm.ItemsOptions[] = [
  561. {
  562. label: '任务名称',
  563. prop: 'name',
  564. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  565. compOptions: {
  566. placeholder: '请输入任务名称'
  567. }
  568. },
  569. {
  570. label: '任务类型',
  571. prop: 'taskType',
  572. rules: [{ required: true, message: '任务类型不能为空', trigger: 'change' }],
  573. compOptions: {
  574. elTagName: 'select', // 指定使用 el-select 组件
  575. placeholder: '请选择任务类型',
  576. enum: taskType,
  577. onChange: (value: string) => {
  578. model.value['taskType'] = value
  579. hyperparameterConfiguration.forEach(obj => {
  580. if (value in obj) {
  581. // console.log(obj[value])
  582. addParams(obj[value], value)
  583. openDialog(1, '任务新增')
  584. }
  585. })
  586. }
  587. }
  588. },
  589. {
  590. label: '图片集压缩包',
  591. prop: 'inputOssId',
  592. rules: [{ required: true, message: '数据压缩包不能为空', trigger: 'change' }],
  593. compOptions: {
  594. elTagName: 'file-upload',
  595. fileSize: 4096,
  596. fileType: ['zip'],
  597. placeholder: '请上传图片集压缩包'
  598. }
  599. },
  600. {
  601. label: '备注',
  602. prop: 'remarks',
  603. rules: [
  604. {
  605. required: false,
  606. trigger: 'blur'
  607. }
  608. ],
  609. compOptions: {
  610. placeholder: '请输入备注'
  611. }
  612. }
  613. ]
  614. const model = ref({})
  615. const setItemsOptions = () => {
  616. if (itemsOptions.length > 4) {
  617. itemsOptions.splice(4) // 如果里面有新增参数,删除,重新添加
  618. }
  619. }
  620. const addParams = (params, task_Type) => {
  621. setItemsOptions()
  622. if (params == 'null') {
  623. return
  624. }
  625. let validJsonString = params.replace(/'/g, '"')
  626. // if (task_Type === '多目标跟踪') {
  627. // itemsOptions.push({
  628. // label: '模型',
  629. // prop: 'yolo_model',
  630. // rules: [{ trigger: 'blur' }],
  631. // compOptions: {
  632. // elTagName: 'select',
  633. // enum: modelType,
  634. // placeholder: '默认值为' + 'yolov8__best.pt'
  635. // }
  636. // })
  637. // itemsOptions.push({
  638. // label: '跟踪方法',
  639. // prop: 'tracking_method',
  640. // rules: [{ trigger: 'blur' }],
  641. // compOptions: {
  642. // elTagName: 'select',
  643. // enum: trackingMethod,
  644. // placeholder: '默认值为' + 'bytetrack'
  645. // }
  646. // })
  647. // }
  648. // model.value['tracking_method'] = 'bytetrack'
  649. model.value['yolo_model'] = 'yolov8__best.pt'
  650. try {
  651. const obj = JSON.parse(validJsonString)
  652. obj.forEach(param => {
  653. model.value[param.agName] = param.defaultValue
  654. itemsOptions.push({
  655. tooltip: param.prompt,
  656. label: param.name,
  657. prop: param.agName,
  658. rules: [],
  659. compOptions: {
  660. type: 'input',
  661. clearable: true,
  662. placeholder: '默认值为' + param.defaultValue
  663. }
  664. })
  665. })
  666. // const obj: { [key: string]: number } = JSON.parse(validJsonString)
  667. // Object.keys(obj).forEach(key => {
  668. // model.value[key] = obj[key]
  669. // if (key === 'conf' || key === 'iou') {
  670. // itemsOptions.push({
  671. // label: key,
  672. // prop: key,
  673. // rules: [
  674. // {
  675. // trigger: 'change',
  676. // validator: (rule, value, callback) => {
  677. // if (value === '' || value === undefined) {
  678. // return callback()
  679. // }
  680. // if (!value) {
  681. // return callback(new Error('请输入一个0到1之间的浮点数'))
  682. // }
  683. // const regex = /^(0(\.\d+)?|1(\.0+)?)$/
  684. // if (!regex.test(value)) {
  685. // return callback(new Error('请输入一个0到1之间的浮点数'))
  686. // }
  687. // callback()
  688. // }
  689. // }
  690. // ],
  691. // compOptions: {
  692. // type: 'input',
  693. // clearable: true,
  694. // placeholder: '默认值为' + obj[key]
  695. // }
  696. // })
  697. // } else if (key === 'imgsz') {
  698. // itemsOptions.push({
  699. // label: key,
  700. // prop: key,
  701. // rules: [
  702. // {
  703. // trigger: 'change',
  704. // validator: (rule, value, callback) => {
  705. // //console.log(value)
  706. // if (value === '' || value === undefined) {
  707. // return callback()
  708. // }
  709. // if (!value) {
  710. // return callback(new Error('请输入一个大于0的整数'))
  711. // }
  712. // const regex = /^[1-9]\d*$/
  713. // if (!regex.test(value)) {
  714. // return callback(new Error('请输入一个大于0的整数'))
  715. // }
  716. // callback()
  717. // }
  718. // }
  719. // ],
  720. // compOptions: {
  721. // type: 'input',
  722. // clearable: true,
  723. // placeholder: '默认值为' + obj[key]
  724. // }
  725. // })
  726. // }
  727. // })
  728. } catch (error) {
  729. console.error('解析 JSON 字符串时出错:', error)
  730. }
  731. }
  732. </script>
  733. <style lang="scss" scoped>
  734. .image-dialog {
  735. display: flex;
  736. align-items: center;
  737. justify-content: center;
  738. .el-image {
  739. margin-right: 20px;
  740. margin-bottom: 20px;
  741. }
  742. }
  743. .image-dialog-btn {
  744. display: flex;
  745. justify-content: center;
  746. margin-top: 20px;
  747. }
  748. </style>