绿满眶商城微信小程序-uniapp
xiangpei
2025-06-03 d92ead2d480779d3226e898c5827271795e21562
视频发布封面
2个文件已修改
36 ■■■■■ 已修改文件
api/common.js 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/tabbar/video/video.vue 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/common.js
@@ -36,6 +36,17 @@
}
/**
 * 获取文件访问地址
 */
 export function getFilePreviewUrl(fileKey) {
  return http.request({
    url: `${api.common}/lmk/file/preview`,
    method: Method.POST,
    data: {fileKey: fileKey}
  });
}
/**
 * 文件上传地址
 * @type {string}
 */
pages/tabbar/video/video.vue
@@ -179,7 +179,7 @@
import USearch from '@/uview-components/uview-ui/components/u-search/u-search.vue';
import UPopup from '@/uview-components/uview-ui/components/u-popup/u-popup.vue';
import MyTag from "@/components/my-tag.vue"
import { getSTSToken } from "@/api/common.js";
import { getSTSToken, getFilePreviewUrl } from "@/api/common.js";
import { publish } from "@/api/video.js";
import { getRecommendTag3 } from "@/api/video-tag.js";
import { getFileKey } from "@/utils/file.js";
@@ -389,7 +389,30 @@
        sizeType: ['compressed'],
        sourceType: ['album'],
        success: (res) => {
          let fileName = res.tempFilePaths[0].substring(res.tempFilePaths[0].lastIndexOf('/') + 1);
          // 处理安卓可能的URI编码
          if(fileName.indexOf('%') > -1) {
                fileName = decodeURIComponent(fileName);
          }
          const fileKey = getFileKey(fileName);
          this.videoInfo.cover = res.tempFilePaths[0];
          this.cosClient.uploadFile({
               Bucket: this.bucket,
               Region: this.region,
               Key: fileKey,
               FilePath: res.tempFilePaths[0],
               SliceSize: 1024 * 1024 * 5     /* 触发分块上传的阈值,5M */
           }, (err, data) => {
               if (err) {
                 console.log('上传失败', err);
               } else {
                   // 获取封面的访问地址
                   getFilePreviewUrl(fileKey).then(res => {
                   this.videoInfo.cover = res.data.data
                   this.formData.cover = fileKey
                   })
               }
           });
        }
      });
    },