index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listDataAugmentationApi">
  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
  23. type="primary"
  24. link
  25. icon="View"
  26. @click="startDataAugmentation(scope.row)"
  27. v-if="scope.row.status == '0' || scope.row.status == '3' || scope.row.status == '4'"
  28. >
  29. 开始
  30. </el-button>
  31. <el-popconfirm title="确定终止此任务吗?" @confirm="stopDataAugmentation(scope.row)" v-if="scope.row.status == '1'">
  32. <template #reference>
  33. <el-button type="primary" link icon="View"> 终止 </el-button>
  34. </template>
  35. </el-popconfirm>
  36. <el-button type="primary" link icon="View" @click="compareDataAugmentation(scope.row)" v-if="scope.row.status == '2'"> 预览 </el-button>
  37. <el-button type="primary" link icon="View" @click="downloadFile(scope.row)" v-if="scope.row.status == '2'"> 导出 </el-button>
  38. <el-button type="primary" link icon="View" v-auth="['demo:DataAugmentation:query']" @click="openDialog(3, '任务查看', scope.row)">
  39. 查看
  40. </el-button>
  41. <el-button
  42. type="primary"
  43. link
  44. icon="View"
  45. v-auth="['demo:DataAugmentation:query']"
  46. @click="openLogDialog(scope.row.id)"
  47. v-if="scope.row.status != '0'"
  48. >
  49. 日志
  50. </el-button>
  51. <el-button type="primary" link icon="Delete" v-auth="['demo:DataAugmentation:remove']" @click="deleteDataAugmentation(scope.row)">
  52. 删除
  53. </el-button>
  54. </template>
  55. </ProTable>
  56. <DataAugmentationFormDialog ref="formDialogRef" />
  57. <ImportExcel ref="dialogRef" />
  58. <el-dialog v-model="dialogVisible" :title="dialogTitle" width="80%">
  59. <div class="image-dialog" v-if="imageIdx >= 0 && cacheImages[imageIdx]">
  60. <div style="width: 50%">
  61. <el-image v-for="(image, index) in cacheImages[imageIdx].origin" :key="index" :src="'data:image/png;base64,' + image"></el-image>
  62. <!-- <el-tag>结果:</el-tag> -->
  63. </div>
  64. <div v-if="task_type_view == '目标毁伤评估'" style="width: 50%">
  65. <ul v-infinite-scroll="load" class="list" :infinite-scroll-disabled="disabled">
  66. <li v-for="i in count" :key="i" style="list-style-type: none">
  67. <el-image :src="'data:image/png;base64,' + cacheImages[imageIdx].stable[i - 1]"></el-image>
  68. </li>
  69. </ul>
  70. <p v-if="loading">Loading...</p>
  71. <p v-if="noMore">No more</p>
  72. </div>
  73. <div v-else style="width: 50%">
  74. <el-image v-for="(image, index) in cacheImages[imageIdx].stable" :key="index" :src="'data:image/png;base64,' + image"></el-image>
  75. </div>
  76. </div>
  77. <div class="image-dialog-btn" v-if="imageFps == 0">
  78. <el-button type="primary" @click="pre_picture" :disabled="imageIdx <= 0">上一个</el-button>
  79. <el-button type="primary" @click="next_picture" :disabled="imageIdx >= fileCount - 1">下一个</el-button>
  80. </div>
  81. </el-dialog>
  82. <el-dialog v-model="logDialogVisible" title="日志" width="80%">
  83. <el-text class="mx-1">{{ logDialog }}</el-text>
  84. </el-dialog>
  85. </div>
  86. </template>
  87. <script setup lang="tsx" name="DataAugmentation">
  88. import { ref, reactive, onMounted, computed } from 'vue'
  89. import { useHandleData } from '@/hooks/useHandleData'
  90. import { useDownload } from '@/hooks/useDownload'
  91. import { ElMessageBox, ElMessage } from 'element-plus'
  92. import ProTable from '@/components/ProTable/index.vue'
  93. import ImportExcel from '@/components/ImportExcel/index.vue'
  94. import DataAugmentationFormDialog from '@/components/DataAugmentationFormDialog/index.vue'
  95. import { ProTableInstance, ColumnProps, EnumProps } from '@/components/ProTable/interface'
  96. import {
  97. listDataAugmentationApi,
  98. delDataAugmentationApi,
  99. addDataAugmentationApi,
  100. updateDataAugmentationApi,
  101. importTemplateApi,
  102. importDataAugmentationDataApi,
  103. exportDataAugmentationApi,
  104. getDataAugmentationApi,
  105. startDataAugmentationApi,
  106. stopDataAugmentationApi,
  107. getCompareImageApi,
  108. getCompareImageCountApi,
  109. getDialogApi
  110. } from '@/api/modules/demo/dataAugmentation'
  111. import { listDataApi } from '@/api/modules/system/dictData'
  112. import { S } from 'vite/dist/node/types.d-aGj9QkWt'
  113. import { servicesVersion } from 'typescript'
  114. const dialogVisible = ref(false)
  115. const taskId = ref('')
  116. const imageIdx = ref(0)
  117. const imageBase64List = ref({
  118. origin: '',
  119. stable: ''
  120. })
  121. const inFileCount = ref(0)
  122. const outFileCount = ref(0)
  123. // 直接缓存所有图片
  124. const cacheImages = ref({})
  125. const dialogTitle = ref('')
  126. const fileCount = ref(0)
  127. const imageFps = ref(0)
  128. const intervalChangeFps: any = ref()
  129. const taskType = ref([])
  130. const taskTypeEnums: EnumProps[] = []
  131. const hyperparameterConfiguration = []
  132. const logDialogVisible = ref(false)
  133. const logDialog = ref('')
  134. const count = ref(4)
  135. const loading = ref(false)
  136. const noMore = computed(() => count.value >= cacheImages.value[imageIdx.value].stable.length)
  137. const disabled = computed(() => loading.value || noMore.value)
  138. const load = () => {
  139. loading.value = true
  140. setTimeout(() => {
  141. count.value += 1
  142. loading.value = false
  143. }, 2000)
  144. }
  145. const openLogDialog = async (id: string | number) => {
  146. const res: any = await getDialogApi(id)
  147. logDialog.value = res.data
  148. logDialogVisible.value = true
  149. }
  150. const getTaskType = async () => {
  151. const res: any = await listDataApi({
  152. dictName: '',
  153. dictType: 'biz_data_augmentation',
  154. dictLabel: '任务类型',
  155. pageNum: 0,
  156. pageSize: 1000
  157. })
  158. if (res.data.list.length != 0) {
  159. taskType.value = res.data.list.map(item => ({
  160. label: item.dictValue,
  161. value: item.dictValue
  162. }))
  163. res.data.list.forEach(item => {
  164. taskTypeEnums.push({
  165. label: item.dictValue,
  166. value: item.dictValue,
  167. disabled: false,
  168. tagType: 'default'
  169. })
  170. })
  171. console.log(taskTypeEnums)
  172. for (let i = 0; i < taskType.value.length; i++) {
  173. let dictValue = taskType.value[i].value
  174. const res: any = await listDataApi({
  175. dictName: '',
  176. dictType: 'biz_data_augmentation',
  177. dictLabel: dictValue + '超参配置',
  178. pageNum: 0,
  179. pageSize: 1000
  180. })
  181. if (res.data.list.length != 0) {
  182. //console.log(res.data.list[0].dictValue)
  183. let obj = {}
  184. obj[dictValue] = res.data.list[0].dictValue
  185. hyperparameterConfiguration.push(obj)
  186. } else {
  187. ElMessage.error('${dictValue}未在数据字典中设置超参!')
  188. }
  189. }
  190. } else {
  191. ElMessage.error('task_type为空,请在数据字典中设置具体的任务类型!')
  192. }
  193. // console.log(taskType.value)
  194. }
  195. onMounted(() => {
  196. getTaskType()
  197. })
  198. const startDataAugmentation = async (params: any) => {
  199. const res = await startDataAugmentationApi(params.id)
  200. if (res.code === 200) {
  201. ElMessage.success('任务已经开始,请等待')
  202. } else {
  203. ElMessage.error('任务开始失败,请检查!')
  204. }
  205. proTable.value?.getTableList()
  206. }
  207. const stopDataAugmentation = async (params: any) => {
  208. const res = await stopDataAugmentationApi(params.id)
  209. if (res.code === 200) {
  210. ElMessage.success('任务终止成功')
  211. } else {
  212. ElMessage.error('任务终止失败!')
  213. }
  214. proTable.value?.getTableList()
  215. }
  216. const loadImageData = async (taskId: string, imageIdx: number) => {
  217. const res: any = await getCompareImageApi(taskId, imageIdx)
  218. // imageBase64List.value.origin = res.origin
  219. // imageBase64List.value.stable = res.stable
  220. cacheImages.value[imageIdx].origin = res.origin
  221. cacheImages.value[imageIdx].stable = res.stable
  222. }
  223. const task_type_view = ref('')
  224. const compareDataAugmentation = async (params: any) => {
  225. if (taskId.value !== '' && taskId.value !== null && taskId.value !== undefined && taskId.value == params.id) {
  226. dialogVisible.value = true
  227. return
  228. }
  229. task_type_view.value = params.taskType
  230. taskId.value = params.id
  231. imageIdx.value = 0
  232. cacheImages.value = {}
  233. const resCount: any = await getCompareImageCountApi(params.id)
  234. if (resCount.code === 200) {
  235. inFileCount.value = resCount.data.inFileCount
  236. outFileCount.value = resCount.data.outFileCount
  237. } else {
  238. ElMessage.error('获取图片对比数量失败')
  239. return
  240. }
  241. dialogVisible.value = true
  242. dialogTitle.value = '缓存图片中'
  243. fileCount.value = Math.min(inFileCount.value, outFileCount.value)
  244. for (let idx = 1; idx <= fileCount.value; idx++) {
  245. dialogTitle.value = '缓存图片中: 第' + idx + '个样本 共' + fileCount.value + '个样本'
  246. if (cacheImages.value[idx - 1]) {
  247. continue
  248. }
  249. const res: any = await getCompareImageApi(taskId.value, idx - 1)
  250. // console.log(res)
  251. cacheImages.value[idx - 1] = {
  252. origin: res.origin,
  253. stable: res.stable
  254. }
  255. }
  256. // console.log(cacheImages.value[0])
  257. dialogTitle.value = '预览: 第1个样本 共' + fileCount.value + '个样本'
  258. // next_picture()
  259. }
  260. const next_picture = async () => {
  261. if (imageIdx.value < fileCount.value - 1) {
  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. const pre_picture = async () => {
  270. if (imageIdx.value > 0) {
  271. if (!cacheImages.value[imageIdx.value - 1]) {
  272. await loadImageData(taskId.value, imageIdx.value - 1)
  273. }
  274. imageIdx.value = imageIdx.value - 1
  275. }
  276. dialogTitle.value = '预览: 第' + (imageIdx.value + 1) + '个样本 共' + fileCount.value + '个样本'
  277. }
  278. // ProTable 实例
  279. const proTable = ref<ProTableInstance>()
  280. // 删除视频去抖动信息
  281. const deleteDataAugmentation = async (params: any) => {
  282. await useHandleData(delDataAugmentationApi, params.id, '删除任务【' + params.name + '】?')
  283. proTable.value?.getTableList()
  284. }
  285. // 批量删除视频去抖动信息
  286. const batchDelete = async (ids: string[]) => {
  287. await useHandleData(delDataAugmentationApi, ids, '删除所选任务?')
  288. proTable.value?.clearSelection()
  289. proTable.value?.getTableList()
  290. }
  291. // 导出视频去抖动列表
  292. const downloadFile = async task => {
  293. ElMessageBox.confirm('确认导出任务数据?', '温馨提示', { type: 'warning' }).then(() =>
  294. useDownload(exportDataAugmentationApi, 'export', task.outputPath)
  295. )
  296. }
  297. // 批量添加视频去抖动
  298. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  299. const batchAdd = () => {
  300. const params = {
  301. title: '视频去抖动',
  302. tempApi: importTemplateApi,
  303. importApi: importDataAugmentationDataApi,
  304. getTableList: proTable.value?.getTableList
  305. }
  306. dialogRef.value?.acceptParams(params)
  307. }
  308. const formDialogRef = ref<InstanceType<typeof DataAugmentationFormDialog> | null>(null)
  309. // 打开弹框的功能
  310. const openDialog = async (type: number, title: string, row?: any) => {
  311. // hyperparameter.value = ''
  312. let res = { data: {} }
  313. if (row?.id) {
  314. res = await getDataAugmentationApi(row?.id || null)
  315. // hyperparameter.value = res.data?.hyperparameterConfiguration
  316. }
  317. // console.log(itemsOptions[1].compOptions?.value)
  318. // 重置表单
  319. // setItemsOptions()
  320. const params = {
  321. title,
  322. width: 580,
  323. isEdit: type !== 3,
  324. itemsOptions: itemsOptions,
  325. model: type == 1 ? model : res.data,
  326. api: type == 1 ? addDataAugmentationApi : updateDataAugmentationApi,
  327. getTableList: proTable.value?.getTableList
  328. }
  329. formDialogRef.value?.openDialog(params)
  330. }
  331. const statusEnums: EnumProps[] = [
  332. {
  333. label: '未开始',
  334. value: '0',
  335. disabled: false,
  336. tagType: 'default'
  337. },
  338. {
  339. label: '进行中',
  340. value: '1',
  341. disabled: false,
  342. tagType: 'primary'
  343. },
  344. {
  345. label: '完成',
  346. value: '2',
  347. disabled: false,
  348. tagType: 'success'
  349. },
  350. {
  351. label: '失败',
  352. value: '3',
  353. disabled: false,
  354. tagType: 'danger'
  355. },
  356. {
  357. label: '已中断',
  358. value: '4',
  359. disabled: false,
  360. tagType: 'default'
  361. }
  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: 'taskType',
  377. label: '任务类型',
  378. search: {
  379. el: 'select'
  380. },
  381. width: 100,
  382. tag: true,
  383. enum: taskTypeEnums
  384. },
  385. {
  386. prop: 'status',
  387. label: '任务状态',
  388. search: {
  389. el: 'select'
  390. },
  391. width: 100,
  392. tag: true,
  393. enum: statusEnums
  394. },
  395. {
  396. prop: 'startTime',
  397. label: '开始时间',
  398. width: 180
  399. },
  400. {
  401. prop: 'endTime',
  402. label: '结束时间',
  403. width: 180
  404. },
  405. {
  406. prop: 'costSecond',
  407. label: '耗时',
  408. search: {
  409. el: 'input'
  410. },
  411. width: 80
  412. },
  413. {
  414. prop: 'log',
  415. label: '日志',
  416. width: 120
  417. },
  418. {
  419. prop: 'algorithmPath',
  420. label: '日志路径',
  421. width: 120
  422. },
  423. {
  424. prop: 'hyperparameterConfiguration',
  425. label: '超参配置',
  426. width: 120
  427. },
  428. {
  429. prop: 'remarks',
  430. label: '备注',
  431. search: {
  432. el: 'input'
  433. },
  434. width: 120
  435. },
  436. {
  437. prop: 'operation',
  438. label: '操作',
  439. width: 230,
  440. fixed: 'right'
  441. }
  442. ])
  443. // 表单配置项
  444. let itemsOptions: ProForm.ItemsOptions[] = [
  445. {
  446. label: '任务名称',
  447. prop: 'name',
  448. rules: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
  449. compOptions: {
  450. placeholder: '请输入任务名称'
  451. }
  452. },
  453. {
  454. label: '任务类型',
  455. prop: 'taskType',
  456. rules: [{ required: true, message: '任务类型不能为空', trigger: 'change' }],
  457. compOptions: {
  458. elTagName: 'select', // 指定使用 el-select 组件
  459. placeholder: '请选择任务类型',
  460. enum: taskType,
  461. onChange: (value: string) => {
  462. model.value['taskType'] = value
  463. hyperparameterConfiguration.forEach(obj => {
  464. if (value in obj) {
  465. // console.log(obj[value])
  466. addParams(obj[value])
  467. openDialog(1, '任务新增')
  468. }
  469. })
  470. }
  471. }
  472. },
  473. {
  474. label: '图片集压缩包',
  475. prop: 'inputOssId',
  476. rules: [{ required: true, message: '数据压缩包不能为空', trigger: 'change' }],
  477. compOptions: {
  478. elTagName: 'file-upload',
  479. fileSize: 4096,
  480. fileType: ['zip'],
  481. placeholder: '请上传图片集压缩包'
  482. }
  483. },
  484. {
  485. label: '备注',
  486. prop: 'remarks',
  487. rules: [
  488. {
  489. required: false,
  490. trigger: 'blur'
  491. }
  492. ],
  493. compOptions: {
  494. placeholder: '请输入备注'
  495. }
  496. }
  497. ]
  498. const model = ref({})
  499. const setItemsOptions = () => {
  500. if (itemsOptions.length > 4) {
  501. itemsOptions.splice(4) // 如果里面有新增参数,删除,重新添加
  502. }
  503. }
  504. const hyperparameter = ref({})
  505. const addParams = params => {
  506. setItemsOptions()
  507. if (params == 'null') {
  508. return
  509. }
  510. let validJsonString = params.replace(/'/g, '"')
  511. try {
  512. const obj: { [key: string]: number } = JSON.parse(validJsonString)
  513. // hyperparameter.value = { ...obj };
  514. Object.keys(obj).forEach(key => {
  515. model.value[key] = obj[key]
  516. // hyperparameter[key] = obj[key]
  517. itemsOptions.push({
  518. label: key,
  519. prop: key,
  520. rules: [{ trigger: 'blur' }],
  521. compOptions: {
  522. type: 'input',
  523. clearable: true,
  524. placeholder: '默认值为' + obj[key]
  525. // value: hyperparameter.value[key],
  526. // onChange: (value) => {
  527. // hyperparameter.value[key] = value
  528. // console.log(hyperparameter)
  529. // // model.value[key] = value
  530. // }
  531. }
  532. })
  533. })
  534. } catch (error) {
  535. console.error('解析 JSON 字符串时出错:', error)
  536. }
  537. }
  538. </script>
  539. <style lang="scss" scoped>
  540. .image-dialog {
  541. display: flex;
  542. align-items: center;
  543. justify-content: center;
  544. .el-image {
  545. margin-right: 20px;
  546. margin-bottom: 20px;
  547. }
  548. }
  549. .image-dialog-btn {
  550. display: flex;
  551. justify-content: center;
  552. margin-top: 20px;
  553. }
  554. </style>