index.vue 15 KB

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