index.vue 18 KB

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