index.vue 23 KB

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