index.vue 17 KB

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