index.vue 14 KB

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