From bd3a7fe563cd5590109ae68d27ae747c1556f51e Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期三, 04 六月 2025 16:22:37 +0800 Subject: [PATCH] 视频管理页面-静态 --- config/api.js | 9 pages/video/video-edit.vue | 788 +++++++++++++++++++++++++++++++++++++++++++ pages/tabbar/video/video.vue | 2 components/dropdown-menu.vue | 204 +++++++++++ pages.json | 7 api/video.js | 14 pages/video/home-page.vue | 47 ++ 7 files changed, 1,055 insertions(+), 16 deletions(-) diff --git a/api/video.js b/api/video.js index 65b48e8..4d5e90d 100644 --- a/api/video.js +++ b/api/video.js @@ -130,3 +130,17 @@ data: data }); } + + +/** + * 鑾峰彇瑙嗛璇︽儏 + * + * @param params + */ + export function getVideoDetail(id) { + return http.request({ + url: "/lmk/video/wx/detail/" + id, + method: Method.GET, + needToken: true + }); +} \ No newline at end of file diff --git a/components/dropdown-menu.vue b/components/dropdown-menu.vue new file mode 100644 index 0000000..6dee7c9 --- /dev/null +++ b/components/dropdown-menu.vue @@ -0,0 +1,204 @@ +<template> + <view class="dropdown-container" :style="{ '--theme-color': themeColor }"> + <!-- 瑙﹀彂鎸夐挳 --> + <view class="dropdown-trigger" @click="toggleDropdown"> + <uni-icons type="more-filled" size="20" color="#666"></uni-icons> + <view class="dropdown-icon" :class="{ 'rotate': isOpen }"> + <uni-icons type="arrowdown" size="16" color="#666"></uni-icons> + </view> + </view> + + <!-- 涓嬫媺鑿滃崟 --> + <view + class="dropdown-menu" + :class="[placementClass]" + v-if="isOpen" + @click.stop + > + <scroll-view scroll-y class="dropdown-scroll" :style="{ maxHeight: maxHeight + 'px' }"> + <view + v-for="(item, index) in options" + :key="index" + class="dropdown-item" + @click="selectItem(item)" + > + <text>{{ item[labelKey] }}</text> + </view> + </scroll-view> + </view> + + <!-- 閬僵灞� --> + <view + class="dropdown-mask" + v-if="isOpen" + @click="closeDropdown" + ></view> + </view> +</template> + +<script> +export default { + name: 'DropdownMenu', + props: { + // 閫夐」鍒楄〃 + options: { + type: Array, + default: () => [] + }, + // 閫夐」瀵硅薄涓樉绀烘枃鏈殑key + labelKey: { + type: String, + default: 'label' + }, + // 閫夐」瀵硅薄涓�肩殑key + valueKey: { + type: String, + default: 'command' + }, + // 涓婚棰滆壊 + themeColor: { + type: String, + default: '#409EFF' + }, + // 涓嬫媺鑿滃崟鏈�澶ч珮搴� + maxHeight: { + type: Number, + default: 300 + }, + // 鑿滃崟寮瑰嚭浣嶇疆锛坱op/bottom锛� + placement: { + type: String, + default: 'bottom', + validator: (value) => ['top', 'bottom'].includes(value) + } + }, + data() { + return { + isOpen: false, + selectedItem: null + } + }, + computed: { + placementClass() { + return `placement-${this.placement}`; + } + }, + methods: { + toggleDropdown() { + this.isOpen = !this.isOpen + if (this.isOpen) { + this.$emit('open') + } else { + this.$emit('close') + } + }, + closeDropdown() { + this.isOpen = false + this.$emit('close') + }, + selectItem(item) { + this.selectedItem = item + this.closeDropdown() + + // 鏍规嵁閰嶇疆杩斿洖鏁翠釜瀵硅薄鎴杤alue鍊� + const emitValue = typeof item === 'object' ? item[this.valueKey] : item + this.$emit('input', emitValue) + this.$emit('change', emitValue) + } + } +} +</script> + +<style lang="scss" scoped> +.dropdown-container { + position: relative; + display: inline-block; + z-index: 10; +} + +.dropdown-trigger { + height: 70rpx; + line-height: 70rpx; + border-radius: 8rpx; + background-color: #fff; + box-sizing: border-box; + cursor: pointer; + + &:active { + opacity: 0.8; + } +} + +.dropdown-text { + flex: 1; + font-size: 28rpx; + color: #333; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.dropdown-icon { + transition: transform 0.3s; + margin-left: 10rpx; + + &.rotate { + transform: rotate(180deg); + } +} + +.dropdown-menu { + position: absolute; + left: 0; + display: inline-block; + white-space: nowrap; + background-color: #fff; + border: 1rpx solid #EBEEF5; + border-radius: 8rpx; + // box-shadow: 0 2rpx 12rpx 0 rgba(0, 0, 0, 0.1); + z-index: 100; + overflow: hidden; + + &.placement-bottom { + top: 80rpx; + } + + &.placement-top { + bottom: 80rpx; + } +} + +.dropdown-scroll { + width: 100%; +} + +.dropdown-item { + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 20rpx; + height: 80rpx; + line-height: 80rpx; + font-size: 28rpx; + color: #606266; + + &:active { + background-color: #f5f7fa; + } + + &.active { + color: var(--theme-color); + font-weight: bold; + } +} + +.dropdown-mask { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: transparent; + z-index: 99; +} +</style> \ No newline at end of file diff --git a/config/api.js b/config/api.js index 769e179..de87b6c 100644 --- a/config/api.js +++ b/config/api.js @@ -4,12 +4,9 @@ */ // 寮�鍙戠幆澧� const dev = { - // im: "http://192.168.0.4:8885", - // common: "http://192.168.0.4:8890", - // buyer: "http://192.168.0.4:8888", - im: "http://127.0.0.1:8885", - common: "http://127.0.0.1:8890", - buyer: "http://127.0.0.1:8888", + im: "http://192.168.0.4:8885", + common: "http://192.168.0.4:8890", + buyer: "http://192.168.0.4:8888", // common: "http://192.168.0.113:8890", // buyer: "http://192.168.0.113:8888", // im: "http://192.168.0.113:8885", diff --git a/pages.json b/pages.json index 9bbcf07..fd6db8b 100644 --- a/pages.json +++ b/pages.json @@ -820,6 +820,13 @@ { "navigationBarTitleText" : "涓婚〉淇℃伅淇敼" } + }, + { + "path" : "video-edit", + "style" : + { + "navigationBarTitleText" : "瑙嗛缂栬緫" + } } ] }, diff --git a/pages/tabbar/video/video.vue b/pages/tabbar/video/video.vue index cc04f4e..18d38ae 100644 --- a/pages/tabbar/video/video.vue +++ b/pages/tabbar/video/video.vue @@ -207,6 +207,7 @@ formData: { id: '', title: '', + cover: '', videoFileKey: '', videoDuration: 0, videoFit: 'cover', @@ -519,6 +520,7 @@ id: '', title: '', videoFileKey: '', + cover: '', videoFit: 'cover', videoDuration: 0, goodsId: '', diff --git a/pages/video/home-page.vue b/pages/video/home-page.vue index 10be23c..1e29861 100644 --- a/pages/video/home-page.vue +++ b/pages/video/home-page.vue @@ -61,23 +61,28 @@ <!-- 瑙嗛鍒楄〃 --> <scroll-view class="video-list" scroll-y :show-scrollbar="false" @scrolltolower="getPage" v-show="currentTab === 'works' && videoList.length > 0"> - <view class="video-container"> <view class="video-item" v-for="(item, index) in videoList" :key="item.id" - @click="playAuthorVideo(index)" > - <image class="video-cover" :src="item.coverUrl" mode="aspectFill"></image> + <image class="video-cover" @click="playAuthorVideo(index)" :src="item.coverUrl" mode="aspectFill"></image> <view class="video-info"> <view class="video-stats"> <view class="stat"> <uni-icons type="heart" size="16" color="#fff"></uni-icons> <text>{{item.collectNum}}</text> + <view class="more-op"> + <dropdown-menu + :options="item.options" + placement="top" + theme-color="#07C160" + @change="handleChange" + ></dropdown-menu> + </view> </view> </view> </view> - </view> </view> </scroll-view> <scroll-view class="video-list" scroll-y :show-scrollbar="false" @scrolltolower="getPage" v-show="currentTab === 'likes' && collectVideoList.length > 0"> @@ -115,11 +120,19 @@ </template> <script> +import DropdownMenu from '@/components/dropdown-menu.vue' + import {getAuthorInfo, getAuthorVideoPage, getAuthorCollectVideoPage} from '@/api/user.js' import {subscribe, unSubscribe} from '@/api/video.js' export default { + components: {DropdownMenu}, data() { return { + options: [ + { command: 1, label: '鍖椾含' }, + { command: 2, label: '涓婃捣' }, + { command: 3, label: '骞垮窞' } + ], currentTab: 'works', // works: 浣滃搧, likes: 鍠滄 authorId: '', userInfo: { @@ -159,6 +172,9 @@ this.getAuthorVideoPage(); }, methods: { + handleChange(value) { + console.log('閫変腑鍊�:', value) + }, getPage() { if(this.currentTab === 'works') { if(this.nomoreVideo) { @@ -465,12 +481,15 @@ } .video-info { + display: flex; + height: 60rpx; + align-items: center; + font-size: 24rpx; + width: 100%; + padding-right: 20rpx; + box-sizing: border-box; position: absolute; bottom: 20rpx; - left: 20rpx; - right: 20rpx; - color: #fff; - font-size: 24rpx; } .video-title { @@ -484,17 +503,25 @@ .video-stats { display: flex; + width: 100%; } .stat { display: flex; + width: 100%; align-items: center; - margin-right: 20rpx; - text-shadow: 0 0 5rpx rgba(0, 0, 0, 0.5); + position: relative; +} + +.more-op { + position: absolute; + right: 0; } .stat text { margin-left: 5rpx; + color: #fff; + font-size: 14px; } .empty-state { diff --git a/pages/video/video-edit.vue b/pages/video/video-edit.vue new file mode 100644 index 0000000..a6e2f37 --- /dev/null +++ b/pages/video/video-edit.vue @@ -0,0 +1,788 @@ +<template> + <view class="publish-container"> + <!-- 瑙嗛涓婁紶鍖哄煙 --> + <view class="upload-section"> + <view class="upload-btn" @click="chooseVideo" v-if="!videoInfo.url"> + <u-icon name="plus" size="40" color="#999"></u-icon> + <text class="upload-text">鐐瑰嚮涓婁紶瑙嗛</text> + <text class="upload-tips">鏀寔MP4鏍煎紡锛屾渶闀�60绉�</text> + </view> + + <view class="video-preview" v-else> + <video + :src="videoInfo.url" + :object-fit="formData.videoFit" + class="video-player" + :poster="videoInfo.cover || ''" + ></video> + <view class="progress-box"> + <progress style="width: 100%;" :percent="videoUploadProgress" active-mode="forwards" show-info stroke-width="6" :active="true" active-color="#ff573e" /> + </view> + <view class="video-actions"> + <u-button type="error" size="mini" @click="reUpload">閲嶆柊涓婁紶</u-button> + <u-button type="primary" size="mini" @click="chooseCover" v-if="videoInfo.url">{{formData.cover ? '鏇存崲灏侀潰' : '璇烽�夋嫨灏侀潰'}}</u-button> + </view> + </view> + </view> + + <!-- 瑙嗛淇℃伅琛ㄥ崟 --> + <view class="form-section"> + <u-form :model="formData" ref="formRef" labelWidth="80"> + <!-- 鏍囬杈撳叆 --> + <u-form-item label="鏍囬" prop="title" borderBottom> + <u-input + v-model="formData.title" + placeholder="璇疯緭鍏ヨ棰戞爣棰�,20瀛椾互鍐�" + maxlength="20" + show-word-limit + clearable + /> + </u-form-item> + + <!-- 璇濋杈撳叆 --> + <u-form-item label="璇濋" prop="tags" borderBottom> + <view class="tags-input-container"> + <u-input + v-model="tagInput" + placeholder="杈撳叆璇濋锛屽洖杞︾‘璁�" + clearable + @confirm="addTag" + @blur="addTag" + @input="searchTags" + ></u-input> + <!-- 宸查�夎瘽棰樺睍绀� --> + <view class="tags-display" v-if="formData.tags.length > 0"> + <my-tag + v-for="(tag, index) in formData.tags" + :key="index" + :text="tag.tagName" + :index="index" + type="success" + @close="removeTag(index)" + /> + </view> + <text class="tags-count" v-if="formData.tags.length > 0"> + 宸查�� {{ formData.tags.length }}/5 + </text> + </view> + <!-- 璇濋鎺ㄨ崘 --> + <view class="hot-topics" v-if="showTopicRecommendations"> + <text class="section-title">{{ tagInput ? '鎺ㄨ崘璇濋' : '鐑棬璇濋' }}</text> + <view class="topic-list"> + <my-tag + v-for="(tag, index) in recommendedTags" + :key="index" + :text="tag.tagName" + :index="index" + type="success" + :closeable="false" + @click="selectTopic(index)" + /> + </view> + </view> + </u-form-item> + + + <!-- 鍟嗗搧閾炬帴 --> + <u-form-item label="鍟嗗搧" prop="goodsId" borderBottom> + <view class="goods-link-container"> + <u-input + placeholder="鍙�夋嫨鎺ㄨ崘鍟嗗搧" + clearable + v-if="!selectedGoods" + @click="chooseGoods" + disabled + > + <u-icon + slot="right" + name="search" + size="24" + @click="chooseGoods" + ></u-icon> + </u-input> + <view class="goods-preview" v-if="selectedGoods"> + <image :src="selectedGoods.image" class="goods-image"></image> + <view class="goods-info"> + <text class="goods-name">{{ selectedGoods.name }}</text> + <text class="goods-price">楼{{ selectedGoods.price }}</text> + </view> + <u-icon + name="close" + size="20" + @click="clearGoods" + ></u-icon> + </view> + </view> + </u-form-item> + </u-form> + </view> + + <!-- 鍙戝竷鎸夐挳 --> + <view class="publish-btn"> + <u-button + type="primary" + shape="circle" + :loading="loading" + @click="handlePublish" + :disabled="!canPublish" + > + {{ loading ? '鍙戝竷涓�...' : '绔嬪嵆鍙戝竷' }} + </u-button> + </view> + + <!-- 鍟嗗搧閫夋嫨寮圭獥 --> + <u-popup v-model="showGoodsPicker" mode="bottom" round="20" height="70%"> + <view class="goods-picker"> + <view class="picker-header"> + <text class="picker-title">閫夋嫨鍟嗗搧</text> + <u-icon name="close" size="24" @click="showGoodsPicker = false"></u-icon> + </view> + <view class="search-bar"> + <u-search + v-model="goodsSearch" + placeholder="鎼滅储鍟嗗搧鍚嶇О" + :showAction="false" + ></u-search> + </view> + <scroll-view class="goods-list" scroll-y> + <view + class="goods-item" + v-for="goods in filteredGoods" + :key="goods.id" + @click="selectGoods(goods)" + > + <image :src="goods.image" class="goods-image"></image> + <view class="goods-info"> + <text class="goods-name">{{ goods.name }}</text> + <text class="goods-price">楼{{ goods.price }}</text> + </view> + <u-icon + name="checkmark" + size="24" + :color="selectedGoods && selectedGoods.id === goods.id ? '#2979ff' : '#ccc'" + ></u-icon> + </view> + </scroll-view> + </view> + </u-popup> + + <custom-tabbar bgColor="#ffffff" selected="video"></custom-tabbar> + </view> +</template> + +<script> +import UIcon from '@/uview-components/uview-ui/components/u-icon/u-icon.vue'; +import UButton from '@/uview-components/uview-ui/components/u-button/u-button.vue'; +import UForm from '@/uview-components/uview-ui/components/u-form/u-form.vue'; +import UFormItem from '@/uview-components/uview-ui/components/u-form-item/u-form-item.vue'; +import UInput from '@/uview-components/uview-ui/components/u-input/u-input.vue'; +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, getFilePreviewUrl } from "@/api/common.js"; +import { publish, getVideoDetail } from "@/api/video.js"; +import { getRecommendTag3 } from "@/api/video-tag.js"; +import { getFileKey } from "@/utils/file.js"; +export default { + components: {MyTag,UIcon,UButton,UForm,UFormItem,UInput,USearch,UPopup}, + data() { + return { + cosClient: null, + bucket: '', + region: '', + videoUploadProgress: 0, + loading: false, + showGoodsPicker: false, + goodsSearch: '', + tagInput: '', + videoInfo: { + url: '', + fileKey: '', + fileType: '', + fileSize: 0, + originalFileName: '', + cover: '' + }, + formData: { + id: '', + title: '', + cover: '', + videoFileKey: '', + videoDuration: 0, + videoFit: 'cover', + goodsId: '', + tags: [], + fileInfo: {} + }, + selectedGoods: null, + goodsList: [ + { + id: '1', + name: '鏂版鏃犵嚎钃濈墮鑰虫満', + price: '199.00', + image: 'https://via.placeholder.com/100' + }, + { + id: '2', + name: '鏅鸿兘鎵嬬幆杩愬姩鎵嬭〃', + price: '299.00', + image: 'https://via.placeholder.com/100' + } + ], + recommendedTags: [], + rules: { + title: [ + { required: true, message: '璇疯緭鍏ヨ棰戞爣棰�', trigger: 'blur' }, + { min: 1, max: 20, message: '鏍囬闀垮害鍦�1鍒�20涓瓧绗�', trigger: 'blur' } + ] + } + }; + }, + computed: { + canPublish() { + return this.formData.videoFileKey && this.formData.title && this.formData.cover; + }, + filteredGoods() { + if (!this.goodsSearch) return this.goodsList; + return this.goodsList.filter(goods => + goods.name.toLowerCase().includes(this.goodsSearch.toLowerCase()) + ); + }, + showTopicRecommendations() { + return (this.tagInput === '' || this.recommendedTags.length > 0) && this.formData.tags.length < 5; + } + }, + onLoad(option) { + this.getVideoDetail(option.id) + }, + onShow() { + this.initCOS() + // 鍒濆鍖栨帹鑽愭爣绛� + this.getRecommendTags() + }, + methods: { + getVideoDetail(id) { + getVideoDetail(id).then(res => { + this.fileInfo.cover = res.data.data.coverUrl + this.fileInfo.url = res.data.data.videoUrl + this.formData.cover = res.data.data.coverFileKey + this.formData.id = res.data.data.id + this.formData.title = res.data.data.title + this.formData.videoFileKey = res.data.data.videoFileKey + this.formData.videoFit = res.data.data.videoFit + this.formData.videoDuration = res.data.data.videoDuration + this.formData.goodsId = res.data.data.goodsId + this.formData.tags = res.data.data.tags + }).catch(() => { + uni.navigateBack({ + delta: 1 + }); + }) + }, + // 鑾峰彇鎺ㄨ崘鏍囩 + async getRecommendTags(type) { + const params = { + tagName: this.tagInput.trim(), + searchType: type + } + getRecommendTag3(params).then(res => { + this.recommendedTags = res.data.data + }) + }, + // 鍒濆鍖栬吘璁簯cos瀹㈡埛绔� + initCOS() { + // 璋冪敤鍚庣鑾峰彇sts涓存椂璁块棶鍑瘉 + getSTSToken().then(res => { + const COS = require('@/lib/cos-wx-sdk-v5.js'); // 寮�鍙戞椂浣跨敤 + // const COS = require('./lib/cos-wx-sdk-v5.min.js'); // 涓婄嚎鏃朵娇鐢ㄥ帇缂╁寘 + + // console.log(COS.version); sdk 鐗堟湰闇�瑕佷笉浣庝簬 1.7.2 + this.cosClient = new COS({ + SecretId: res.data.data.tmpSecretId, // sts 鏈嶅姟涓嬪彂鐨勪复鏃� secretId + SecretKey: res.data.data.tmpSecretKey, // sts 鏈嶅姟涓嬪彂鐨勪复鏃� secretKey + SecurityToken: res.data.data.sessionToken, // sts 鏈嶅姟涓嬪彂鐨勪复鏃� SessionToken + StartTime: res.data.data.stsStartTime, // 寤鸿浼犲叆鏈嶅姟绔椂闂达紝鍙伩鍏嶅鎴风鏃堕棿涓嶅噯瀵艰嚧鐨勭鍚嶉敊璇� + ExpiredTime: res.data.data.stsEndTime, // 涓存椂瀵嗛挜杩囨湡鏃堕棿 + SimpleUploadMethod: 'putObject', // 寮虹儓寤鸿锛岄珮绾т笂浼犮�佹壒閲忎笂浼犲唴閮ㄥ灏忔枃浠跺仛绠�鍗曚笂浼犳椂浣跨敤 putObject,sdk 鐗堟湰鑷冲皯闇�瑕乿1.3.0 + }); + this.bucket = res.data.data.bucket + this.region = res.data.data.region + }) + + }, + // 閫夋嫨瑙嗛 + chooseVideo() { + uni.chooseVideo({ + sourceType: ['album', 'camera'], + maxDuration: 60, + camera: 'back', + success: (res) => { + this.videoUploadProgress = 0 + // 鑾峰彇鏂囦欢鍚� + const tempPath = res.tempFilePath; + let fileName = tempPath.substring(tempPath.lastIndexOf('/') + 1); + + // 澶勭悊瀹夊崜鍙兘鐨刄RI缂栫爜 + 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.videoDuration = res.duration; + // 鍒ゆ柇瑙嗛鐨勫~鍏呮ā寮� + this.formData.videoFit = this.calculateVideoFit(res.width, res.height) + + this.cosClient.uploadFile({ + Bucket: this.bucket, + Region: this.region, + Key: fileKey, + FilePath: res.tempFilePath, + SliceSize: 1024 * 1024 * 5, /* 瑙﹀彂鍒嗗潡涓婁紶鐨勯槇鍊�,5M */ + onProgress: (progressData) => { + console.log(progressData.percent); + this.videoUploadProgress = progressData.percent * 100 + } + }, (err, data) => { + if (err) { + console.log('涓婁紶澶辫触', err); + this.videoInfo = { + url: '', + fileKey: '', + fileType: '', + fileSize: 0, + originalFileName: '', + cover: '' + } + } else { + console.log(this.videoInfo); + } + }); + }, + fail: (err) => { + uni.showToast({ + title: '鏈�夋嫨瑙嗛', + icon: 'none' + }); + console.error(err); + } + }); + }, + // 鏍规嵁瀹介珮姣旈�夋嫨瑙嗛濉厖妯″紡 + calculateVideoFit(width, height) { + const viewportRatio = uni.getSystemInfoSync().windowWidth / uni.getSystemInfoSync().windowHeight; + const videoRatio = width / height; + + // 瑙勫垯1锛氳秴瀹借棰戯紙濡傜數褰�21:9锛� + if (videoRatio > 2) return 'contain'; + + // 瑙勫垯2锛氱珫灞忚棰戯紙濡�9:16锛� + if (videoRatio < 0.8) return 'cover'; + + // 瑙勫垯3锛氭帴杩戝睆骞曟瘮渚嬬殑妯睆瑙嗛 + return Math.abs(videoRatio - viewportRatio) > 0.3 ? 'contain' : 'cover'; + }, + // 閲嶆柊涓婁紶 + reUpload() { + this.videoInfo = { + url: '', + cover: '', + duration: 0, + size: 0 + }; + this.chooseVideo(); + }, + + // 閫夋嫨灏侀潰 + chooseCover() { + uni.chooseImage({ + count: 1, + 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 + }) + } + }); + } + }); + }, + + // 閫夋嫨鍟嗗搧 + chooseGoods() { + this.showGoodsPicker = true; + }, + + // 閫夋嫨鍏蜂綋鍟嗗搧 + selectGoods(goods) { + this.selectedGoods = goods; + this.formData.goodsId = goods.id; + this.showGoodsPicker = false; + }, + + // 娓呴櫎鍟嗗搧 + clearGoods() { + this.selectedGoods = null; + this.formData.goodsId = ''; + }, + + // 鎼滅储鐑棬璇濋 + searchTags() { + if (this.tagInput.trim() !== '') { + this.getRecommendTags("SEARCH") + } + }, + // 娣诲姞鏍囩 + addTag() { + if(!this.tagInput.trim()) { + return + } + const newTag = {'id': '', 'tagName': this.tagInput.trim()}; + if (newTag && this.formData.tags.length < 5) { + if (this.formData.tags.filter(item => item.tagName === newTag.tagName).length < 1) { + this.formData.tags.push(newTag); + this.tagInput = ''; + this.getRecommendTags() // 閲嶇疆鎺ㄨ崘 + } else { + uni.showToast({ + title: '璇ヨ瘽棰樺凡娣诲姞杩囦簡~', + icon: 'none' + }); + } + } else if (this.formData.tags.length >= 5) { + uni.showToast({ + title: '鏈�澶氭坊鍔�5涓瘽棰榽', + icon: 'none' + }); + } + }, + + // 閫夋嫨鎺ㄨ崘璇濋 + selectTopic(index) { + const tag = this.recommendedTags[index] + if (this.formData.tags.length >= 5) { + uni.showToast({ + title: '鏈�澶氭坊鍔�5涓瘽棰榽', + icon: 'none' + }); + return; + } + + if (this.formData.tags.filter(item => item.tagName === tag.tagName).length < 1) { + this.formData.tags.push(tag); + this.tagInput = ''; + } else { + uni.showToast({ + title: '璇ヨ瘽棰樺凡娣诲姞杩囦簡~', + icon: 'none' + }); + } + }, + + // 绉婚櫎鏍囩 + removeTag(index) { + this.formData.tags.splice(index, 1); + }, + + // 澶勭悊鍙戝竷 + handlePublish() { + this.$refs.formRef.validate(valid => { + if (valid && this.canPublish) { + this.loading = true; + this.formData.fileInfo = this.videoInfo; + console.log(this.formData); + publish(this.formData).then(res => { + uni.showToast({ + title: '瑙嗛宸叉彁浜ゅ鏍竳', + icon: 'success' + }); + this.loading = false + // 閲嶇疆琛ㄥ崟 + this.videoInfo = { + url: '', + fileKey: '', + fileType: '', + fileSize: 0, + originalFileName: '', + cover: '' + }; + this.formData = { + id: '', + title: '', + videoFileKey: '', + cover: '', + videoFit: 'cover', + videoDuration: 0, + goodsId: '', + tags: [], + fileInfo: {} + }; + this.selectedGoods = null; + this.tagInput = ''; + this.recommendedTags = []; + + // TODO 鍏堣烦棣栭〉,鍚庨潰璺虫垜鐨勮棰戦〉闈� + setTimeout(() => { + uni.switchTab({ + url: '/pages/tabbar/index/home' + }); + }, 1500); + }) + } else { + uni.showToast({ + title: '璇峰畬鍠勮棰戜俊鎭瘇', + icon: 'none' + }); + } + }); + } + } +}; +</script> + +<style scoped> +.publish-container { + padding: 20rpx; + padding-bottom: 120rpx; +} + +.upload-section { + background-color: #f8f8f8; + border-radius: 16rpx; + padding: 40rpx; + margin-bottom: 30rpx; + display: flex; + justify-content: center; + align-items: center; + min-height: 400rpx; +} + +.upload-btn { + display: flex; + flex-direction: column; + align-items: center; + color: #999; +} + +.upload-text { + font-size: 32rpx; + margin: 20rpx 0 10rpx; +} + +.upload-tips { + font-size: 24rpx; + color: #ccc; +} + +.video-preview { + width: 100%; + display: flex; + flex-direction: column; + align-items: center; +} + +.video-player { + width: 100%; + height: 400rpx; + border-radius: 12rpx; + background-color: #000; +} + +.video-actions { + margin-top: 20rpx; + display: flex; + justify-content: center; + gap: 20rpx; +} + +.form-section { + background-color: #fff; + border-radius: 16rpx; + padding: 0 20rpx; +} + +.goods-link-container { + width: 100%; +} + +.goods-preview { + display: flex; + align-items: center; + padding: 15rpx; + background-color: #f9f9f9; + border-radius: 8rpx; + margin-top: 15rpx; +} + +.goods-preview .goods-image { + width: 80rpx; + height: 80rpx; + border-radius: 8rpx; + margin-right: 15rpx; +} + +.goods-preview .goods-info { + flex: 1; + display: flex; + flex-direction: column; +} + +.goods-preview .goods-info .goods-name { + font-size: 26rpx; + color: #333; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.goods-preview .goods-info .goods-price { + font-size: 28rpx; + color: #f44; + font-weight: bold; +} + +.topic-list { + display: flex; + flex-direction: row; + flex-wrap: wrap; + line-height: 22px; +} + +.tags-input-container { + width: 100%; +} + +.tags-display { + display: flex; + flex-wrap: wrap; + margin-top: 15rpx; + line-height: 22px; +} + +.hot-topics { + display: flex; + flex-direction: column; + margin-top: 15rpx; + margin-bottom: 15rpx; +} + +.section-title { + font-size: 12px; + color: #999; + line-height: 12px; + margin-bottom: 6rpx; +} + +.tags-count { + display: block; + font-size: 12px; + line-height: 12px; + color: #999; + margin-top: 10rpx; + text-align: right; +} + +.publish-btn { + position: fixed; + bottom: 100rpx; + left: 20rpx; + right: 20rpx; +} + +.goods-picker { + padding: 30rpx; + height: 100%; + display: flex; + flex-direction: column; +} + +.goods-picker .picker-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 30rpx; +} + +.goods-picker .picker-header .picker-title { + font-size: 36rpx; + font-weight: bold; +} + +.goods-picker .search-bar { + margin-bottom: 20rpx; +} + +.goods-picker .goods-list { + flex: 1; + overflow: hidden; +} + +.goods-picker .goods-list .goods-item { + display: flex; + align-items: center; + padding: 20rpx 0; + border-bottom: 1rpx solid #f5f5f5; +} + +.goods-picker .goods-list .goods-item .goods-image { + width: 100rpx; + height: 100rpx; + border-radius: 8rpx; + margin-right: 20rpx; +} + +.goods-picker .goods-list .goods-item .goods-info { + flex: 1; +} + +.goods-picker .goods-list .goods-item .goods-info .goods-name { + font-size: 28rpx; + color: #333; + margin-bottom: 10rpx; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; +} + +.goods-picker .goods-list .goods-item .goods-info .goods-price { + font-size: 28rpx; + color: #f44; + font-weight: bold; +} + +.progress-box { + width: 100%; + display: flex; + height: 25px; + margin-top: 10px; +} +</style> \ No newline at end of file -- Gitblit v1.8.0