index.vue 21 KB

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