From 12af499e64f38b7ff3a79fcc5bf527855cf359f3 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期二, 03 六月 2025 16:41:49 +0800 Subject: [PATCH] 视频主页基本信息接口对接 --- pages/tabbar/video/video.vue | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 41 insertions(+), 16 deletions(-) diff --git a/pages/tabbar/video/video.vue b/pages/tabbar/video/video.vue index d003daf..103a3ff 100644 --- a/pages/tabbar/video/video.vue +++ b/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"; @@ -207,6 +207,7 @@ id: '', title: '', videoFileKey: '', + videoDuration: 0, videoFit: 'cover', goodsId: '', tags: [], @@ -260,7 +261,7 @@ }, methods: { // 鑾峰彇鎺ㄨ崘鏍囩 - getRecommendTags(type) { + async getRecommendTags(type) { const params = { tagName: this.tagInput.trim(), searchType: type @@ -274,7 +275,6 @@ console.log("鎵ц浜�"); // 璋冪敤鍚庣鑾峰彇sts涓存椂璁块棶鍑瘉 getSTSToken().then(res => { - console.log(res, "sts缁撴瀯"); const COS = require('@/lib/cos-wx-sdk-v5.js'); // 寮�鍙戞椂浣跨敤 // const COS = require('./lib/cos-wx-sdk-v5.min.js'); // 涓婄嚎鏃朵娇鐢ㄥ帇缂╁寘 @@ -308,20 +308,21 @@ if(fileName.indexOf('%') > -1) { fileName = decodeURIComponent(fileName); } - const fileKey = getFileKey(fileName); - this.videoInfo = { - url: res.tempFilePath, - fileKey: fileKey, - fileType: fileKey.split('/')[0], - fileSize: res.size, - originalFileName: fileName, - cover: '' - }; - this.formData.videoFileKey = fileKey; - // 鍒ゆ柇瑙嗛鐨勫~鍏呮ā寮� - this.formData.videoFit = this.calculateVideoFit(res.width, res.height) + const fileKey = getFileKey(fileName); + this.videoInfo = { + url: res.tempFilePath, + fileKey: fileKey, + fileType: fileKey.split('/')[0], + fileSize: res.size, + originalFileName: fileName, + cover: '' + }; + this.formData.videoFileKey = fileKey; + this.formData.videoDuration = res.duration; + // 鍒ゆ柇瑙嗛鐨勫~鍏呮ā寮� + this.formData.videoFit = this.calculateVideoFit(res.width, res.height) - this.cosClient.uploadFile({ + this.cosClient.uploadFile({ Bucket: this.bucket, Region: this.region, Key: fileKey, @@ -388,7 +389,30 @@ sizeType: ['compressed'], sourceType: ['album'], success: (res) => { + let fileName = res.tempFilePaths[0].substring(res.tempFilePaths[0].lastIndexOf('/') + 1); + // 澶勭悊瀹夊崜鍙兘鐨刄RI缂栫爜 + 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 + }) + } + }); } }); }, @@ -496,6 +520,7 @@ title: '', videoFileKey: '', videoFit: 'cover', + videoDuration: 0, goodsId: '', tags: [], fileInfo: {} -- Gitblit v1.8.0