ソースを参照

feat(physical): 添加视频内容管理功能

- 新增视频内容API接口,包括查询、新增、修改、删除和上传视频功能
- 创建视频内容类型定义文件,包含VO、Form和Query接口
- 实现视频内容管理页面,支持视频上传、预览和基础CRUD操作
- 集成标签选择功能,关联视频与分类标签
- 更新商家项目页面中的标签字段显示文本
- 添加视频内容权限控制和表单验证规则
fugui001 1 週間 前
コミット
111e7c456d

+ 80 - 0
src/api/system/physical/videoContent/index.ts

@@ -0,0 +1,80 @@
+import request from '@/utils/request';
+import { AxiosPromise } from 'axios';
+import { VideoContentVO, VideoContentForm, VideoContentQuery } from '@/api/system/physical/videoContent/types';
+
+/**
+ * 查询视频内容信息列表
+ * @param query
+ * @returns {*}
+ */
+export const listVideoContent = (query?: VideoContentQuery): AxiosPromise<VideoContentVO[]> => {
+  return request({
+    url: '/physical/videoContent/list',
+    method: 'get',
+    params: query
+  });
+};
+
+/**
+ * 查询视频内容信息详细
+ * @param id
+ */
+export const getVideoContent = (id: string | number): AxiosPromise<VideoContentVO> => {
+  return request({
+    url: '/physical/videoContent/' + id,
+    method: 'get'
+  });
+};
+
+/**
+ * 新增视频内容信息
+ * @param data
+ */
+export const addVideoContent = (data: VideoContentForm) => {
+  return request({
+    url: '/physical/videoContent',
+    method: 'post',
+    data: data
+  });
+};
+
+/**
+ * 修改视频内容信息
+ * @param data
+ */
+export const updateVideoContent = (data: VideoContentForm) => {
+  return request({
+    url: '/physical/videoContent',
+    method: 'put',
+    data: data
+  });
+};
+
+/**
+ * 删除视频内容信息
+ * @param id
+ */
+export const delVideoContent = (id: string | number | Array<string | number>) => {
+  return request({
+    url: '/physical/videoContent/' + id,
+    method: 'delete'
+  });
+};
+/**
+ * 上传视频
+ * @param file 文件
+ */
+export const uploadVideo = async (file: File) => {
+  const formData = new FormData();
+  formData.append('file', file); // 后端接收的参数名是 "file"
+  const res = await request({
+    url: '/physical/videoContent/uploadVideo',
+    method: 'POST',
+    data: formData,
+    headers: {
+      'Content-Type': 'multipart/form-data'
+    }
+  });
+
+  return res;
+};

+ 174 - 0
src/api/system/physical/videoContent/types.ts

@@ -0,0 +1,174 @@
+export interface VideoContentVO {
+  /**
+   * 主键ID
+   */
+  id: string | number;
+
+  /**
+   * 视频标题
+   */
+  title: string;
+
+  /**
+   * 观看完整视频所需消耗的视频点数(积分)
+   */
+  requiredPoints: number;
+
+  /**
+   * 视频总时长,单位:秒
+   */
+  durationSeconds: number;
+
+  /**
+   * 免费试看时长,单位:秒
+   */
+  previewDurationSeconds: number;
+
+  /**
+   * 订阅后可观看的有效期,单位:小时(如24=1天,720=30天)
+   */
+  subscriptionValidHours: string | number;
+
+  /**
+   * 视频文件在阿里云OSS上的完整访问URL
+   */
+  ossVideoUrl: string | number;
+
+  videoTempUrl: string | number;
+
+  /**
+   * 视频状态:up=已上架(可被用户查看/购买),down=已下架(不可见)
+   */
+  status: string;
+
+  /**
+   * 创建时间
+   */
+  createdAt: string;
+
+  /**
+   * 最后更新时间
+   */
+  updatedAt: string;
+
+  /**
+   * 视频oss_id
+   */
+  ossId: string | number;
+}
+
+export interface VideoContentForm extends BaseEntity {
+  /**
+   * 主键ID
+   */
+  id?: string | number;
+
+  /**
+   * 视频标题
+   */
+  title?: string;
+
+  /**
+   * 观看完整视频所需消耗的视频点数(积分)
+   */
+  requiredPoints?: number;
+
+  /**
+   * 视频总时长,单位:秒
+   */
+  durationSeconds?: number;
+
+  /**
+   * 免费试看时长,单位:秒
+   */
+  previewDurationSeconds?: number;
+
+  /**
+   * 订阅后可观看的有效期,单位:小时(如24=1天,720=30天)
+   */
+  subscriptionValidHours?: string | number;
+
+  /**
+   * 视频文件在阿里云OSS上的完整访问URL
+   */
+  ossVideoUrl?: string | number;
+
+  /**
+   * 视频状态:up=已上架(可被用户查看/购买),down=已下架(不可见)
+   */
+  status?: string;
+
+  /**
+   * 创建时间
+   */
+  createdAt?: string;
+
+  /**
+   * 最后更新时间
+   */
+  updatedAt?: string;
+
+  /**
+   * 视频oss_id
+   */
+  ossId?: string | number;
+
+  categoryTagId?: string | number;
+}
+
+export interface VideoContentQuery extends PageQuery {
+  /**
+   * 视频标题
+   */
+  title?: string;
+
+  /**
+   * 观看完整视频所需消耗的视频点数(积分)
+   */
+  requiredPoints?: number;
+
+  /**
+   * 视频总时长,单位:秒
+   */
+  durationSeconds?: number;
+
+  /**
+   * 免费试看时长,单位:秒
+   */
+  previewDurationSeconds?: number;
+
+  /**
+   * 订阅后可观看的有效期,单位:小时(如24=1天,720=30天)
+   */
+  subscriptionValidHours?: string | number;
+
+  /**
+   * 视频文件在阿里云OSS上的完整访问URL
+   */
+  ossVideoUrl?: string | number;
+
+  /**
+   * 视频状态:up=已上架(可被用户查看/购买),down=已下架(不可见)
+   */
+  status?: string;
+
+  /**
+   * 创建时间
+   */
+  createdAt?: string;
+
+  /**
+   * 最后更新时间
+   */
+  updatedAt?: string;
+
+  /**
+   * 视频oss_id
+   */
+  ossId?: string | number;
+
+  /**
+   * 日期范围参数
+   */
+  params?: any;
+}

+ 3 - 2
src/views/system/physical/merchantItem/index.vue

@@ -160,8 +160,8 @@
             </el-form-item>
           </el-col>
           <el-col :span="12">
-            <el-form-item label="所属签" prop="serviceTabId">
-              <el-select v-model="form.categoryTagId" placeholder="请选择所属签" filterable clearable style="width: 100%">
+            <el-form-item label="所属签" prop="serviceTabId">
+              <el-select v-model="form.categoryTagId" placeholder="请选择所属签" filterable clearable style="width: 100%">
                 <el-option v-for="item in serviceTabOptions" :key="item.id" :label="item.name" :value="item.id" />
               </el-select>
             </el-form-item>
@@ -769,6 +769,7 @@ const loadMerchantOptions = async () => {
     proxy?.$modal.msgError('加载商家列表失败');
   }
 };
+
 /** 加载页签选项列表 */
 const loadServiceTabOptions = async () => {
   try {

+ 403 - 0
src/views/system/physical/videoContent/index.vue

@@ -0,0 +1,403 @@
+<template>
+  <div class="p-2">
+    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
+      <div v-show="showSearch" class="mb-[10px]">
+        <el-card shadow="hover">
+          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
+            <el-form-item label="视频标题" prop="title">
+              <el-input v-model="queryParams.title" placeholder="请输入视频标题" clearable @keyup.enter="handleQuery" />
+            </el-form-item>
+            <el-form-item label="状态" prop="status">
+              <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
+                <el-option label="上架" value="up" />
+                <el-option label="下架" value="down" />
+              </el-select>
+            </el-form-item>
+            <el-form-item>
+              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
+              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
+            </el-form-item>
+          </el-form>
+        </el-card>
+      </div>
+    </transition>
+
+    <el-card shadow="never">
+      <template #header>
+        <el-row :gutter="10" class="mb8">
+          <el-col :span="1.5">
+            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['physical:videoContent:add']">新增</el-button>
+          </el-col>
+          <el-col :span="1.5">
+            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['physical:videoContent:edit']"
+              >修改</el-button
+            >
+          </el-col>
+          <el-col :span="1.5">
+            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['physical:videoContent:remove']"
+              >删除</el-button
+            >
+          </el-col>
+          <el-col :span="1.5">
+            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['physical:videoContent:export']">导出</el-button>
+          </el-col>
+          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
+        </el-row>
+      </template>
+
+      <el-table v-loading="loading" border :data="videoContentList" @selection-change="handleSelectionChange">
+        <el-table-column type="selection" width="55" align="center" />
+        <el-table-column label="编号" align="center" prop="id" v-if="true" />
+        <el-table-column label="视频标题" align="center" prop="title" />
+        <el-table-column label="观看人数" align="center" prop="title" />
+        <el-table-column label="所需视频点" align="center" prop="requiredPoints" />
+        <el-table-column label="所属标签" align="center" prop="title" />
+        <el-table-column label="视频时长(秒)" align="center" prop="durationSeconds" />
+        <el-table-column label="试看时长(秒)" align="center" prop="previewDurationSeconds" />
+        <el-table-column label="订阅时效(时)" align="center" prop="subscriptionValidHours" />
+        <!--        <el-table-column label="视频文件在阿里云OSS上的完整访问URL" align="center" prop="ossVideoUrl" />-->
+        <el-table-column label="视频状态" align="center">
+          <template #default="{ row }">
+            <el-tag :type="row.status === 'up' ? 'success' : 'info'">
+              {{ row.status === 'up' ? '已上架' : '未上架' }}
+            </el-tag>
+          </template>
+        </el-table-column>
+        <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
+          <template #default="scope">
+            <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
+          </template>
+        </el-table-column>
+        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+          <template #default="scope">
+            <el-tooltip content="修改" placement="top">
+              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['physical:videoContent:edit']"></el-button>
+            </el-tooltip>
+            <el-tooltip content="删除" placement="top">
+              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['physical:videoContent:remove']"></el-button>
+            </el-tooltip>
+          </template>
+        </el-table-column>
+      </el-table>
+
+      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
+    </el-card>
+    <!-- 添加或修改视频内容信息对话框 -->
+    <el-dialog :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body>
+      <el-form ref="videoContentFormRef" :model="form" :rules="rules" label-width="120px">
+        <el-form-item label="视频标题" prop="title">
+          <el-input v-model="form.title" placeholder="请输入视频标题" />
+        </el-form-item>
+        <el-form-item label="视频文件" prop="ossVideoUrl">
+          <div class="upload-container">
+            <el-upload
+              class="upload-icon"
+              action="#"
+              :on-change="handleOssVideoUrlChange"
+              :on-remove="handleOssVideoUrlRemove"
+              :file-list="ossVideoUrlFileList"
+              :auto-upload="false"
+              :limit="1"
+              accept="video/*"
+            >
+              <template #trigger>
+                <el-button type="primary">点击选择视频</el-button>
+              </template>
+
+              <template #default>
+                <div class="preview-area">
+                  <video
+                    v-if="ossVideoUrlPreviewUrl || form.ossVideoUrl"
+                    :src="ossVideoUrlPreviewUrl || String(form.ossVideoUrl || '')"
+                    controls
+                    style="max-width: 300px; max-height: 200px; margin-top: 10px"
+                  />
+                  <div v-else style="margin-top: 10px; color: #999">无视频</div>
+                  <el-button
+                    v-if="ossVideoUrlPreviewUrl || form.ossVideoUrl"
+                    type="danger"
+                    size="small"
+                    icon="Delete"
+                    @click="handleOssVideoUrlRemove"
+                    style="margin-top: 10px"
+                  >
+                    删除视频
+                  </el-button>
+                </div>
+              </template>
+
+              <template #tip>
+                <div class="el-upload__tip">
+                  <span v-if="ossVideoUrlFileList.length > 0">当前已选文件:{{ ossVideoUrlFileList[0].name }}</span>
+                </div>
+              </template>
+            </el-upload>
+          </div>
+        </el-form-item>
+        <el-form-item label="所需视频点" prop="requiredPoints">
+          <el-input v-model="form.requiredPoints" placeholder="请输入所需视频点" />
+        </el-form-item>
+        <el-form-item label="视频时长(秒)">
+          <el-input v-model="form.durationSeconds" disabled />
+        </el-form-item>
+        <el-form-item label="试看时长(秒)" prop="previewDurationSeconds">
+          <el-input v-model="form.previewDurationSeconds" placeholder="请输入试看时长(秒)" />
+        </el-form-item>
+        <el-form-item label="订阅时效(时)" prop="subscriptionValidHours">
+          <el-input v-model="form.subscriptionValidHours" placeholder="请输入订阅时效(时)" />
+        </el-form-item>
+        <el-form-item label="所属标签" prop="categoryTagId">
+          <el-select v-model="form.categoryTagId" placeholder="请选择所属标签" filterable clearable style="width: 100%">
+            <el-option v-for="item in serviceTabOptions" :key="item.id" :label="item.name" :value="item.id" />
+          </el-select>
+        </el-form-item>
+        <el-form-item label="状态" prop="status">
+          <el-select v-model="form.status" placeholder="请选择状态">
+            <el-option label="上架" value="up" />
+            <el-option label="下架" value="down" />
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
+          <el-button @click="cancel">取 消</el-button>
+        </div>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+
+<script setup name="VideoContent" lang="ts">
+import {
+  listVideoContent,
+  getVideoContent,
+  delVideoContent,
+  addVideoContent,
+  updateVideoContent,
+  uploadVideo
+} from '@/api/system/physical/videoContent';
+import { VideoContentVO, VideoContentQuery, VideoContentForm } from '@/api/system/physical/videoContent/types';
+import { ServiceTabVO } from '@/api/system/physical/serviceTab/types';
+import { selectEnabledTabsByCategoryList } from '@/api/system/physical/serviceTab';
+
+const { proxy } = getCurrentInstance() as ComponentInternalInstance;
+
+const videoContentList = ref<VideoContentVO[]>([]);
+const buttonLoading = ref(false);
+const loading = ref(true);
+const showSearch = ref(true);
+const ids = ref<Array<string | number>>([]);
+const single = ref(true);
+const multiple = ref(true);
+const total = ref(0);
+
+const queryFormRef = ref<ElFormInstance>();
+const videoContentFormRef = ref<ElFormInstance>();
+
+const dialog = reactive<DialogOption>({
+  visible: false,
+  title: ''
+});
+
+const initFormData: VideoContentForm = {
+  id: undefined,
+  title: undefined,
+  requiredPoints: undefined,
+  durationSeconds: undefined,
+  previewDurationSeconds: undefined,
+  subscriptionValidHours: undefined,
+  ossVideoUrl: undefined,
+  status: 'up',
+  createdAt: undefined,
+  updatedAt: undefined,
+  ossId: undefined
+};
+const data = reactive<PageData<VideoContentForm, VideoContentQuery>>({
+  form: { ...initFormData },
+  queryParams: {
+    pageNum: 1,
+    pageSize: 10,
+    title: undefined,
+    requiredPoints: undefined,
+    durationSeconds: undefined,
+    previewDurationSeconds: undefined,
+    subscriptionValidHours: undefined,
+    ossVideoUrl: undefined,
+    status: undefined,
+    createdAt: undefined,
+    updatedAt: undefined,
+    ossId: undefined,
+    params: {}
+  },
+  rules: {
+    id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
+    title: [{ required: true, message: '视频标题不能为空', trigger: 'blur' }],
+    requiredPoints: [{ required: true, message: '观看完整视频所需消耗的视频点数不能为空', trigger: 'blur' }],
+    durationSeconds: [{ required: true, message: '视频总时长,单位:秒不能为空', trigger: 'blur' }],
+    previewDurationSeconds: [{ required: true, message: '免费试看时长,单位:秒不能为空', trigger: 'blur' }],
+    subscriptionValidHours: [{ required: true, message: '订阅后可观看的有效期,单位:小时不能为空', trigger: 'blur' }],
+    ossVideoUrl: [{ required: true, message: '视频文件在阿里云OSS上的完整访问URL不能为空', trigger: 'blur' }],
+    status: [{ required: true, message: '视频状态:up=已上架不能为空', trigger: 'change' }],
+    categoryTagId: [{ required: true, message: '不能为空', trigger: 'blur' }]
+  }
+});
+
+const { queryParams, form, rules } = toRefs(data);
+
+/** 查询视频内容信息列表 */
+const getList = async () => {
+  loading.value = true;
+  const res = await listVideoContent(queryParams.value);
+  videoContentList.value = res.rows;
+  total.value = res.total;
+  loading.value = false;
+};
+
+/** 取消按钮 */
+const cancel = () => {
+  reset();
+  dialog.visible = false;
+};
+
+/** 表单重置 */
+const reset = () => {
+  form.value = { ...initFormData };
+  videoContentFormRef.value?.resetFields();
+  ossVideoUrlFileList.value = [];
+  ossVideoUrlPreviewUrl.value = '';
+};
+
+/** 搜索按钮操作 */
+const handleQuery = () => {
+  queryParams.value.pageNum = 1;
+  getList();
+};
+
+/** 重置按钮操作 */
+const resetQuery = () => {
+  queryFormRef.value?.resetFields();
+  handleQuery();
+};
+
+/** 多选框选中数据 */
+const handleSelectionChange = (selection: VideoContentVO[]) => {
+  ids.value = selection.map((item) => item.id);
+  single.value = selection.length != 1;
+  multiple.value = !selection.length;
+};
+
+/** 新增按钮操作 */
+const handleAdd = () => {
+  reset();
+  dialog.visible = true;
+  dialog.title = '添加';
+};
+
+/** 修改按钮操作 */
+const handleUpdate = async (row?: VideoContentVO) => {
+  reset();
+  const _id = row?.id || ids.value[0];
+  const res = await getVideoContent(_id);
+  Object.assign(form.value, res.data);
+  const videoTempUrl2 = res.data?.videoTempUrl || res.data?.ossVideoUrl || '';
+  ossVideoUrlPreviewUrl.value = String(videoTempUrl2);
+  dialog.visible = true;
+  dialog.title = '修改';
+};
+
+/** 提交按钮 */
+const submitForm = () => {
+  videoContentFormRef.value?.validate(async (valid: boolean) => {
+    if (valid) {
+      buttonLoading.value = true;
+      if (form.value.id) {
+        await updateVideoContent(form.value).finally(() => (buttonLoading.value = false));
+      } else {
+        await addVideoContent(form.value).finally(() => (buttonLoading.value = false));
+      }
+      proxy?.$modal.msgSuccess('操作成功');
+      dialog.visible = false;
+      await getList();
+    }
+  });
+};
+
+/** 删除按钮操作 */
+const handleDelete = async (row?: VideoContentVO) => {
+  const _ids = row?.id || ids.value;
+  await proxy?.$modal.confirm('是否确认删除视频内容信息编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
+  await delVideoContent(_ids);
+  proxy?.$modal.msgSuccess('删除成功');
+  await getList();
+};
+
+/** 导出按钮操作 */
+const handleExport = () => {
+  proxy?.download(
+    'physical/videoContent/export',
+    {
+      ...queryParams.value
+    },
+    `videoContent_${new Date().getTime()}.xlsx`
+  );
+};
+
+onMounted(() => {
+  getList();
+  loadServiceTabOptions();
+});
+const serviceTabOptions = ref<ServiceTabVO[]>([]);
+/** 加载页签选项列表 */
+const loadServiceTabOptions = async () => {
+  try {
+    const res = await selectEnabledTabsByCategoryList('video');
+    if (res.code === 200 && Array.isArray(res.data)) {
+      serviceTabOptions.value = res.data;
+    } else if (Array.isArray(res)) {
+      serviceTabOptions.value = res;
+    }
+  } catch (error) {
+    console.error('加载页签列表失败:', error);
+    proxy?.$modal.msgError('加载页签列表失败');
+  }
+};
+// 视频文件列表
+const ossVideoUrlFileList = ref<any[]>([]);
+const ossVideoUrlPreviewUrl = ref('');
+
+// ... existing code ...
+// 视频文件改变事件
+async function handleOssVideoUrlChange(file: any) {
+  // 清空文件列表,确保每次选择文件都能触发 change 事件
+  ossVideoUrlFileList.value = [];
+  const fileObj = file.raw || file;
+  if (fileObj) {
+    try {
+      // 立即上传视频
+      const uploadRes = await uploadVideo(fileObj);
+      const videoTempUrl = uploadRes.data?.tempUrl || uploadRes.data?.ossVideoUrl || uploadRes.data;
+      const videoUrl = uploadRes.data?.url || uploadRes.data?.ossVideoUrl || uploadRes.data;
+      const ossId = uploadRes.data?.ossId;
+      const duration = uploadRes.data?.duration;
+      form.value.ossVideoUrl = videoUrl;
+      form.value.ossId = ossId;
+      form.value.durationSeconds = duration;
+      ossVideoUrlPreviewUrl.value = videoTempUrl;
+      proxy?.$modal.msgSuccess('视频上传成功');
+    } catch (error) {
+      console.error('视频上传失败:', error);
+      proxy?.$modal.msgError('视频上传失败');
+      form.value.ossVideoUrl = '';
+      form.value.ossId = undefined;
+      form.value.durationSeconds = undefined;
+    }
+  }
+}
+// 视频文件移除事件
+function handleOssVideoUrlRemove() {
+  ossVideoUrlFileList.value = [];
+  ossVideoUrlPreviewUrl.value = '';
+  form.value.ossVideoUrl = '';
+}
+</script>