Ver código fonte

Merge branch 'dev_wk' into develop

WANGKANG 10 meses atrás
pai
commit
e3b8057397

+ 171 - 0
src/api/interface/demo/video2image.ts

@@ -0,0 +1,171 @@
+import { PageQuery, BaseEntity } from '@/api/interface/index'
+export interface Video2imageVO extends BaseEntity {
+  /**
+   * 主键ID
+   */
+  id: string | number
+
+  /**
+   * 视频名称
+   */
+  name: string
+
+  /**
+   * 任务状态
+   */
+  status: string
+
+  /**
+   * 切割好的图片的保存路径
+   */
+  outPath: string
+
+  /**
+   * 开始时间
+   */
+  startTime: string
+
+  /**
+   * 结束时间
+   */
+  endTime: string
+
+  /**
+   * 耗时
+   */
+  costSecond: number
+
+  /**
+   * 日志
+   */
+  log: string
+
+  /**
+   * 备注
+   */
+  remarks: string
+
+  /**
+   * 视频本身保存路径
+   */
+  path: string
+
+  /**
+   * 切割帧率,默认1
+   */
+  fps: number
+}
+
+export interface Video2imageForm {
+  /**
+   * 主键ID
+   */
+  id?: string | number
+
+  /**
+   * 视频名称
+   */
+  name?: string
+
+  /**
+   * 任务状态
+   */
+  status?: string
+
+  /**
+   * 切割好的图片的保存路径
+   */
+  outPath?: string
+
+  /**
+   * 开始时间
+   */
+  startTime?: string
+
+  /**
+   * 结束时间
+   */
+  endTime?: string
+
+  /**
+   * 耗时
+   */
+  costSecond?: number
+
+  /**
+   * 日志
+   */
+  log?: string
+
+  /**
+   * 备注
+   */
+  remarks?: string
+
+  /**
+   * 视频本身保存路径
+   */
+  path?: string
+
+  /**
+   * 切割帧率,默认1
+   */
+  fps?: number
+}
+
+export interface Video2imageQuery extends PageQuery {
+  /**
+   * 视频名称
+   */
+  name?: string
+
+  /**
+   * 任务状态
+   */
+  status?: string
+
+  /**
+   * 切割好的图片的保存路径
+   */
+  outPath?: string
+
+  /**
+   * 开始时间
+   */
+  startTime?: string
+
+  /**
+   * 结束时间
+   */
+  endTime?: string
+
+  /**
+   * 耗时
+   */
+  costSecond?: number
+
+  /**
+   * 日志
+   */
+  log?: string
+
+  /**
+   * 备注
+   */
+  remarks?: string
+
+  /**
+   * 视频本身保存路径
+   */
+  path?: string
+
+  /**
+   * 切割帧率,默认1
+   */
+  fps?: number
+
+  /**
+   * 日期范围参数
+   */
+  params?: any
+}

+ 94 - 0
src/api/modules/demo/video2image.ts

@@ -0,0 +1,94 @@
+import http from '@/api'
+import { Video2imageVO, Video2imageForm, Video2imageQuery } from '@/api/interface/demo/video2image'
+/**
+ * @name 查询视频转图片列表
+ * @param query 参数
+ * @returns 返回列表
+ */
+export const listVideo2imageApi = (query: Video2imageQuery) => {
+  return http.get<Video2imageVO[]>('/demo/video2image/list', query, { loading: true })
+}
+
+/**
+ * @name 查询视频转图片详细
+ * @param id id
+ * @returns returns
+ */
+export const getVideo2imageApi = (id: string | number) => {
+  return http.get<Video2imageVO>(`/demo/video2image/${id}`)
+}
+
+/**
+ * @name 新增视频转图片
+ * @param data data
+ * @returns returns
+ */
+export const addVideo2imageApi = (data: Video2imageForm) => {
+  return http.post<any>('/demo/video2image', data, { loading: false })
+}
+
+/**
+ * @name 修改视频转图片
+ * @param data data
+ * @returns returns
+ */
+export const updateVideo2imageApi = (data: Video2imageForm) => {
+  return http.put<any>('/demo/video2image', data, { loading: false })
+}
+
+/**
+ * @name 删除视频转图片
+ * @param id id
+ * @returns returns
+ */
+export const delVideo2imageApi = (id: string | number | Array<string | number>) => {
+  return http.delete<any>(`/demo/video2image/${id}`)
+}
+
+/**
+ * @name 下载模板
+ * @returns returns
+ */
+export const importTemplateApi = () => {
+  return http.downloadPost('/demo/video2image/importTemplate', {})
+}
+
+/**
+ * @name 导入数据
+ * @returns returns
+ */
+export const importVideo2imageDataApi = (data: any) => {
+  return http.post('/demo/video2image/importData', data)
+}
+
+/**
+ * @name 导出数据
+ * @returns returns
+ */
+export const exportVideo2imageApi = (data: any) => {
+  return http.downloadPost('/demo/video2image/export', data)
+}
+
+/**
+ * @name 上传视频
+ * @returns returns
+ */
+export const uploadVideoApi = (data: any) => {
+  return http.post('/demo/video2image/upload', data)
+}
+
+/**
+ * @name 开始视频转图片
+ * @returns returns
+ */
+export const startVideo2imageApi = (id: string | number) => {
+  return http.get('/demo/video2image/start/' + id)
+}
+
+/**
+ * @name 下载压缩包
+ * @returns returns
+ */
+export const downloadVideo2imageApi = (id: string | number): Promise<any> => {
+  return http.downloadGet('/demo/video2image/zip/' + id)
+}

+ 38 - 2
src/components/FormDialog/index.vue

@@ -13,6 +13,9 @@
         <FileUpload :file-size="4096" :file-type="['pt']" />
       </template>
     </ProFrom>
+    <div class="upload-video-box" v-if="parameter.showVideoUpload">
+      <FileUpload ref="videoUploadRef" :limit="1" :file-size="4096" :file-type="['mp4']" />
+    </div>
     <template #footer>
       <span class="dialog-footer">
         <el-button type="primary" v-if="parameter.isEdit" :loading="butLoading" @click="handleSubmit">确认</el-button>
@@ -28,6 +31,8 @@ import ProFrom from '@/components/ProForm/index.vue'
 import { ElMessage } from 'element-plus'
 import FileUpload from '@/components/Upload/File.vue'
 
+const videoUploadRef = ref<InstanceType<typeof FileUpload> | null>(null)
+
 export interface FormParameterProps {
   title: string // 标题
   width?: number // 弹框宽度
@@ -39,7 +44,9 @@ export interface FormParameterProps {
   itemsOptions: ProForm.ItemsOptions[] // 动态表单字段配置
   model?: Record<ProForm.FormItem['prop'], ProForm.FormItem['value']> // 表单数据对象
   getTableList?: () => void // 获取表格数据的Api
+  showVideoUpload: boolean // 是否显示视频上传
 }
+
 // dialog状态
 const dialogVisible = ref(false)
 const butLoading = ref(false)
@@ -50,7 +57,8 @@ const parameter = ref<FormParameterProps>({
   top: '10vh',
   itemsOptions: [],
   formOptions: {},
-  isEdit: true
+  isEdit: true,
+  showVideoUpload: false
 })
 const _options: ComputedRef<ProForm.FormOptions> = computed(() => {
   const form = {
@@ -65,11 +73,17 @@ const proFormRef = ref<InstanceType<typeof ProFrom> | null>(null)
 const handleSubmit = () => {
   const formEl = proFormRef.value?.proFormRef
   const formModel = proFormRef.value?.formModel
+
+  let urlModel = {}
+  if (parameter.value.showVideoUpload) {
+    console.log(videoUploadRef.value.uploadFileListExport)
+    urlModel = { url: videoUploadRef.value?.uploadFileListExport[0].url }
+  }
   butLoading.value = true
   if (!formEl) return
   formEl.validate(valid => {
     if (valid) {
-      parameter.value.api!({ ...formModel, ...parameter.value.model }).then(res => {
+      parameter.value.api!({ ...formModel, ...parameter.value.model, ...urlModel }).then(res => {
         if (res.code == 200) {
           proFormRef.value?.resetForm(formEl)
           ElMessage.success('操作成功')
@@ -111,3 +125,25 @@ defineExpose({
   openDialog
 })
 </script>
+
+<style scoped>
+.upload-video-box {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  width: 100%;
+  height: 200px;
+  margin-top: 20px;
+  border: 1px dashed #cccccc;
+  :deep(.upload-file-uploader) {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    width: 100%;
+    height: 100%;
+    font-size: 18px;
+    text-align: center;
+    cursor: pointer;
+  }
+}
+</style>

+ 19 - 4
src/components/Upload/File.vue

@@ -16,7 +16,7 @@
       :accept="fileType.join(',')"
       :headers="headers"
     >
-      <el-button icon="icon" type="primary">{{ text }}</el-button>
+      <el-button :icon="icon" type="primary">{{ text }}</el-button>
     </el-upload>
     <!-- 上传提示 -->
     <div class="el-upload__tip" v-if="showTip">
@@ -54,6 +54,7 @@ import { globalHeaders } from '@/api'
 import { OssVO } from '@/api/interface/system/oss'
 import { getListByIdsApi, delOssApi } from '@/api/modules/system/oss'
 import { listToString } from '@/utils/common'
+
 interface UploadFileProps {
   modelValue?: string | number
   disabled?: boolean // 是否禁用上传组件 ==> 非必传(默认为 false)
@@ -64,7 +65,9 @@ interface UploadFileProps {
   text?: string // 按钮文字
   icon?: string
   fileType?: Array<string>
+  uploadApiPath: string // 上传文件服务器地址
 }
+
 // 默认值
 const props = withDefaults(defineProps<UploadFileProps>(), {
   modelValue: () => '',
@@ -72,18 +75,21 @@ const props = withDefaults(defineProps<UploadFileProps>(), {
   disabled: false,
   limit: 1,
   fileSize: 5,
-  fileType: () => ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'txt', 'pdf'],
+  fileType: () => ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'txt', 'pdf', 'mp4'],
   text: '文件上传',
-  isShowTip: true
+  isShowTip: true,
+  uploadApiPath: '/common/upload',
+  icon: 'upload-filled'
 })
 
 const baseUrl = import.meta.env.VITE_API_URL
-const uploadFileUrl = ref(baseUrl + '/common/upload') // 上传文件服务器地址
+const uploadFileUrl = ref(baseUrl + props.uploadApiPath)
 const headers = ref(globalHeaders())
 const uploadRef = ref<UploadInstance>()
 const number = ref(0)
 const showTip = computed(() => props.isShowTip && (props.fileType || props.fileSize))
 const uploadList = ref<any[]>([])
+const uploadFileListExport = ref<any[]>([])
 const emit = defineEmits<{
   'update:modelValue': [value: any]
 }>()
@@ -170,6 +176,11 @@ const uploadSuccess = (response: any | undefined, uploadFile: UploadFile) => {
     return
   }
   uploadList.value.push({ name: response.data.fileName, url: response.data.url, ossId: response.data.ossId })
+  uploadFileListExport.value = []
+  uploadFileListExport.value.push({ name: response.data.fileName, url: response.data.url, ossId: response.data.ossId })
+
+  console.log(uploadList.value)
+
   uploadedSuccessfully()
 }
 
@@ -210,6 +221,10 @@ const uploadError = () => {
 const handleExceed = () => {
   ElMessage.warning(`当前最多只能上传 ${props.limit} 个文件 ,请移除后上传!`)
 }
+
+defineExpose({
+  uploadFileListExport
+})
 </script>
 
 <style scoped lang="scss">

+ 274 - 0
src/views/demo/video2image/index.vue

@@ -0,0 +1,274 @@
+<template>
+  <div class="table-box">
+    <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listVideo2imageApi">
+      <!-- 表格 header 按钮 -->
+      <template #tableHeader="scope">
+        <el-button type="primary" v-auth="['demo:video2image:add']" icon="CirclePlus" @click="openDialog(1, '新增')"> 新增 </el-button>
+        <el-button type="primary" v-auth="['demo:video2image:import']" icon="Upload" plain @click="batchAdd" v-if="false"> 导入 </el-button>
+        <el-button type="primary" v-auth="['demo:video2image:export']" icon="Download" plain @click="downloadFile" v-if="false"> 导出 </el-button>
+        <el-button
+          type="danger"
+          v-auth="['demo:video2image:remove']"
+          icon="Delete"
+          plain
+          :disabled="!scope.isSelected"
+          @click="batchDelete(scope.selectedListIds)"
+        >
+          批量删除
+        </el-button>
+      </template>
+      <!-- 表格操作 -->
+      <template #operation="scope">
+        <el-button
+          type="primary"
+          link
+          icon="View"
+          v-auth="['demo:video2image:start']"
+          @click="startVideo2image(scope.row)"
+          v-if="scope.row.status !== '2'"
+        >
+          图片提取
+        </el-button>
+        <el-button
+          type="primary"
+          link
+          icon="View"
+          v-auth="['demo:video2image:download']"
+          @click="dowloadVideo2image(scope.row)"
+          v-if="scope.row.status == '2'"
+        >
+          下载图片
+        </el-button>
+        <el-button type="primary" link icon="View" v-auth="['demo:video2image:query']" @click="openDialog(3, '查看', scope.row)"> 查看 </el-button>
+        <el-button type="primary" link icon="EditPen" v-auth="['demo:video2image:edit']" @click="openDialog(2, '编辑', scope.row)"> 编辑 </el-button>
+        <el-button type="primary" link icon="Delete" v-auth="['demo:video2image:remove']" @click="deleteVideo2image(scope.row)"> 删除 </el-button>
+      </template>
+    </ProTable>
+    <FormDialog ref="formDialogRef"></FormDialog>
+  </div>
+</template>
+
+<script setup lang="tsx" name="Video2image">
+import { ref, reactive } from 'vue'
+import { useHandleData } from '@/hooks/useHandleData'
+import { useDownload } from '@/hooks/useDownload'
+import { ElMessageBox, ElMessage } from 'element-plus'
+import ProTable from '@/components/ProTable/index.vue'
+import ImportExcel from '@/components/ImportExcel/index.vue'
+import FormDialog from '@/components/FormDialog/index.vue'
+import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
+import {
+  listVideo2imageApi,
+  delVideo2imageApi,
+  addVideo2imageApi,
+  updateVideo2imageApi,
+  importTemplateApi,
+  importVideo2imageDataApi,
+  exportVideo2imageApi,
+  getVideo2imageApi,
+  startVideo2imageApi,
+  downloadVideo2imageApi
+} from '@/api/modules/demo/video2image'
+import FileUpload from '@/components/Upload/File.vue'
+
+const startVideo2image = async (params: any) => {
+  const res = await startVideo2imageApi(params.id)
+  if (res.code === 200) {
+    ElMessage.success('开始视频转图片已经开始,请等待完成!')
+  } else {
+    ElMessage.error('开始视频转图片开始失败,请检查!')
+  }
+}
+
+const dowloadVideo2image = async (params: any) => {
+  await useDownload(downloadVideo2imageApi, params.name, params.id, true, '.zip')
+}
+
+// ProTable 实例
+const proTable = ref<ProTableInstance>()
+
+// 删除视频转图片信息
+const deleteVideo2image = async (params: any) => {
+  await useHandleData(delVideo2imageApi, params.id, '删除【' + params.id + '】视频转图片')
+  proTable.value?.getTableList()
+}
+
+// 批量删除视频转图片信息
+const batchDelete = async (ids: string[]) => {
+  await useHandleData(delVideo2imageApi, ids, '删除所选视频转图片信息')
+  proTable.value?.clearSelection()
+  proTable.value?.getTableList()
+}
+
+// 导出视频转图片列表
+const downloadFile = async () => {
+  ElMessageBox.confirm('确认导出视频转图片数据?', '温馨提示', { type: 'warning' }).then(() =>
+    useDownload(exportVideo2imageApi, '视频转图片列表', proTable.value?.searchParam)
+  )
+}
+
+// 批量添加视频转图片
+const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
+const batchAdd = () => {
+  const params = {
+    title: '视频转图片',
+    tempApi: importTemplateApi,
+    importApi: importVideo2imageDataApi,
+    getTableList: proTable.value?.getTableList
+  }
+  dialogRef.value?.acceptParams(params)
+}
+
+const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
+// 打开弹框的功能
+const openDialog = async (type: number, title: string, row?: any) => {
+  let res = { data: {} }
+  if (row?.id) {
+    res = await getVideo2imageApi(row?.id || null)
+  }
+  // 重置表单
+  setItemsOptions()
+  const params = {
+    title,
+    width: 580,
+    isEdit: type !== 3,
+    itemsOptions: itemsOptions,
+    model: type == 1 ? {} : res.data,
+    api: type == 1 ? addVideo2imageApi : updateVideo2imageApi,
+    getTableList: proTable.value?.getTableList,
+    showVideoUpload: type == 1 ? true : false
+  }
+  formDialogRef.value?.openDialog(params)
+}
+
+// 表格配置项
+const columns = reactive<ColumnProps<any>[]>([
+  { type: 'selection', fixed: 'left', width: 70 },
+  { prop: 'id', label: '主键ID' },
+  {
+    prop: 'name',
+    label: '视频名称',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'status',
+    label: '任务状态',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'outPath',
+    label: '切割好的图片的保存路径',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'startTime',
+    label: '开始时间',
+    search: {
+      el: 'date-picker',
+      props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
+    },
+    width: 120
+  },
+  {
+    prop: 'endTime',
+    label: '结束时间',
+    search: {
+      el: 'date-picker',
+      props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
+    },
+    width: 120
+  },
+  {
+    prop: 'costSecond',
+    label: '耗时',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'log',
+    label: '日志',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'remarks',
+    label: '备注',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'path',
+    label: '视频本身保存路径',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  {
+    prop: 'fps',
+    label: '切割帧率,默认1',
+    search: {
+      el: 'input'
+    },
+    width: 120
+  },
+  { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
+])
+// 表单配置项
+let itemsOptions: ProForm.ItemsOptions[] = []
+const setItemsOptions = () => {
+  itemsOptions = [
+    {
+      label: '视频名称',
+      prop: 'name',
+      rules: [{ required: true, message: '视频名称不能为空', trigger: 'blur' }],
+      compOptions: {
+        placeholder: '请输入视频名称'
+      }
+    },
+    {
+      label: '备注',
+      prop: 'remarks',
+      rules: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
+      compOptions: {
+        placeholder: '请输入备注'
+      }
+    },
+    {
+      label: '切割帧率',
+      prop: 'fps',
+      rules: [
+        { required: true, message: '切割帧率不能为空', trigger: 'blur' }
+        // {
+        //   type: 'number',
+        //   message: '切割帧率必须为数字',
+        //   trigger: 'blur'
+        // },
+        // { min: 1, message: '切割帧率必须大于等于1', trigger: 'blur' },
+        // { max: 60, message: '切割帧率必须小于等于60', trigger: 'blur' }
+      ],
+      compOptions: {
+        type: 'number',
+        placeholder: '请输入切割帧率,范围:1-60'
+      }
+    }
+  ]
+}
+</script>
+
+<style scoped></style>