index.vue 17 KB

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