From d7b8298e174d39256beb3803d120de191b60621f Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期五, 04 七月 2025 15:32:21 +0800 Subject: [PATCH] 上传调整 --- pages/order/complain/complain.vue | 2 api/common.js | 3 pages/tabbar/user/my.vue | 17 +++++ pages/tabbar/video/video.vue | 4 pages/goods-manager/addGoods/addGoods.vue | 5 + pages/order/afterSales/afterSalesDetail.vue | 2 pages/passport/entry/seller/step1.vue | 3 pages/mine/set/feedBack.vue | 2 pages/mine/set/personMsg.vue | 79 +++++++++++++++++++------- pages/passport/entry/seller/step3.vue | 2 pages/order/evaluate/releaseEvaluate.vue | 2 11 files changed, 86 insertions(+), 35 deletions(-) diff --git a/api/common.js b/api/common.js index 023c24b..0a56d73 100644 --- a/api/common.js +++ b/api/common.js @@ -50,4 +50,5 @@ * 鏂囦欢涓婁紶鍦板潃 * @type {string} */ -export const upload = api.common + "/common/upload/file"; +export const upload = api.common + "/lmk/file/upload"; +export const multiUpload = api.common + "/lmk/file/multi/upload"; diff --git a/pages/goods-manager/addGoods/addGoods.vue b/pages/goods-manager/addGoods/addGoods.vue index 0dfd68a..403106a 100644 --- a/pages/goods-manager/addGoods/addGoods.vue +++ b/pages/goods-manager/addGoods/addGoods.vue @@ -77,12 +77,13 @@ <script> import '@/components/uview-components/uview-ui'; - +import { upload } from "@/api/common.js"; import storage from "@/utils/storage.js"; import * as API_GOODS from "@/api/goods.js"; export default { data() { return { + action: upload, c_index: 0, b_index: 0, u_index: 0, @@ -101,7 +102,7 @@ let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.form.images = images; }, diff --git a/pages/mine/set/feedBack.vue b/pages/mine/set/feedBack.vue index fc4a67a..94a2915 100644 --- a/pages/mine/set/feedBack.vue +++ b/pages/mine/set/feedBack.vue @@ -67,7 +67,7 @@ onUploaded(lists) { let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.feedBack.images = images.join(","); }, diff --git a/pages/mine/set/personMsg.vue b/pages/mine/set/personMsg.vue index aa80980..9441176 100644 --- a/pages/mine/set/personMsg.vue +++ b/pages/mine/set/personMsg.vue @@ -1,7 +1,8 @@ <template> <view class="person-msg"> <view class="head c-content" @click="changeFace"> - <image :src="form.face || '/static/missing-face.png'" mode=""></image> + <image v-if="form.face" :src="endpoint + '/' + form.face" mode=""></image> + <image v-else :src="'/static/missing-face.png'" mode=""></image> <view>鐐瑰嚮淇敼澶村儚</view> </view> <u-form :model="form" ref="uForm" class="form"> @@ -42,20 +43,25 @@ </template> <script> import '@/components/uview-components/uview-ui'; - +import { getSTSToken } from "@/api/common.js"; import { saveUserInfo, getUserInfo } from "@/api/members.js"; import { upload } from "@/api/common.js"; +import { getFileKey } from "@/utils/file.js"; import storage from "@/utils/storage.js"; import city from "@/components/m-city/m-city.vue"; export default { components: { "m-city": city }, data() { return { + cosClient: null, + bucket: '', + region: '', + endpoint: '', lightColor: this.$lightColor, //楂樹寒棰滆壊 form: { nickName: storage.getUserInfo().nickName || "", birthday: storage.getUserInfo().birthday || "", - face: storage.getUserInfo().face || "/static/missing-face.png", //榛樿澶村儚 + face: storage.getUserInfo().face, //榛樿澶村儚 regionId: [], //鍦板潃Id region: storage.getUserInfo().region || [], //鍦板潃 sex: storage.getUserInfo().sex, //鎬у埆 @@ -79,7 +85,31 @@ showBirthday: false, //鏄剧ず鐢熸棩鏃ユ湡 }; }, + onLoad() { + this.initCOS() + }, methods: { + // 鍒濆鍖栬吘璁簯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 + this.endpoint = res.data.data.endpoint + }) + }, /** * 閫�鍑虹櫥褰� */ @@ -135,21 +165,30 @@ */ changeFace(index) { uni.chooseImage({ + count: 1, + sizeType: ['compressed'], + sourceType: ['album'], success: (chooseImageRes) => { - const tempFilePaths = chooseImageRes.tempFilePaths; - uni.uploadFile({ - url: upload, - filePath: tempFilePaths[0], - name: "file", - header: { - accessToken: storage.getAccessToken(), - }, - success: (uploadFileRes) => { - let data = JSON.parse(uploadFileRes.data); - - this.form.face = data.result; - }, - }); + const tempFilePath = chooseImageRes.tempFilePaths[0]; + let fileName = tempFilePath.substring(tempFilePath.lastIndexOf('/') + 1); + // 澶勭悊瀹夊崜鍙兘鐨刄RI缂栫爜 + if(fileName.indexOf('%') > -1) { + fileName = decodeURIComponent(fileName); + } + const fileKey = getFileKey(fileName); + this.cosClient.uploadFile({ + Bucket: this.bucket, + Region: this.region, + Key: fileKey, + FilePath: tempFilePath, + SliceSize: 1024 * 1024 * 5 /* 瑙﹀彂鍒嗗潡涓婁紶鐨勯槇鍊�,5M */ + }, (err, data) => { + if (err) { + console.log('涓婁紶澶辫触', err); + } else { + this.form.face = fileKey; + } + }); }, }); }, @@ -178,12 +217,8 @@ url: '/pages/mine/set/securityCenter/bindMobile' + '?username=' + username, }); }, - }, + } - /** - * 鍔犺浇鏁版嵁 - */ - onLoad() {}, }; </script> <style> diff --git a/pages/order/afterSales/afterSalesDetail.vue b/pages/order/afterSales/afterSalesDetail.vue index be2efa9..f839e2b 100644 --- a/pages/order/afterSales/afterSalesDetail.vue +++ b/pages/order/afterSales/afterSalesDetail.vue @@ -269,7 +269,7 @@ let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.form.images = images; }, diff --git a/pages/order/complain/complain.vue b/pages/order/complain/complain.vue index 06ed4b8..9023226 100644 --- a/pages/order/complain/complain.vue +++ b/pages/order/complain/complain.vue @@ -103,7 +103,7 @@ onUploaded(lists) { let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.images = images; }, diff --git a/pages/order/evaluate/releaseEvaluate.vue b/pages/order/evaluate/releaseEvaluate.vue index c2a9cd0..cdb6d8c 100644 --- a/pages/order/evaluate/releaseEvaluate.vue +++ b/pages/order/evaluate/releaseEvaluate.vue @@ -160,7 +160,7 @@ onUploaded(lists) { let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.form.images = images; }, diff --git a/pages/passport/entry/seller/step1.vue b/pages/passport/entry/seller/step1.vue index e2a0d73..09bb81e 100644 --- a/pages/passport/entry/seller/step1.vue +++ b/pages/passport/entry/seller/step1.vue @@ -315,9 +315,10 @@ methods: { // 鍥剧墖涓婁紶 onUploaded(lists, key) { + console.log("涓婁紶缁撴灉",lists); let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.form[key] = images; }, diff --git a/pages/passport/entry/seller/step3.vue b/pages/passport/entry/seller/step3.vue index fcbf32a..33c78ec 100644 --- a/pages/passport/entry/seller/step3.vue +++ b/pages/passport/entry/seller/step3.vue @@ -288,7 +288,7 @@ onUploaded(lists, key) { let images = []; lists.forEach((item) => { - images.push(item.response.result); + images.push(item.response.data.fileKey); }); this.form[key] = images; }, diff --git a/pages/tabbar/user/my.vue b/pages/tabbar/user/my.vue index 2bbfdd4..12d9de8 100644 --- a/pages/tabbar/user/my.vue +++ b/pages/tabbar/user/my.vue @@ -6,7 +6,8 @@ </view> <view class="header" @click="userDetail"> <view class="head-1"> - <image :src="userInfo.face || userImage"></image> + <image v-if="userInfo.face" :src="endpoint + '/' + userInfo.face"></image> + <image v-else :src="userImage"></image> </view> <view class="head-2" v-if="userInfo.id"> <view class="user-name">{{ userInfo.nickName }}</view> @@ -111,6 +112,7 @@ <script> import '@/components/uview-components/uview-ui'; import tool from "@/pages/tabbar/user/utils/tool.vue"; +import { getSTSToken } from "@/api/common.js"; import { getCouponsNum, getFootprintNum } from "@/api/members.js"; import { getUserWallet } from "@/api/members"; import configs from '@/config/config' @@ -121,6 +123,7 @@ }, data() { return { + endpoint: '', configs, userImage:configs.defaultUserPhoto, coverTransform: "translateY(0px)", @@ -132,7 +135,9 @@ walletNum: "", }; }, - onLoad() { }, + onLoad() { + this.initCOS() + }, onShow() { this.userInfo = this.$options.filters.isLogin() || {}; if (this.$options.filters.isLogin("auth")) { @@ -158,6 +163,14 @@ mounted() { }, methods: { + // 鍒濆鍖栬吘璁簯cos瀹㈡埛绔� + initCOS() { + // 璋冪敤鍚庣鑾峰彇sts涓存椂璁块棶鍑瘉 + getSTSToken().then(res => { + this.endpoint = res.data.data.endpoint + }) + }, + // 璺宠浆瑙嗛涓婚〉 jumpToVideoHome() { uni.navigateTo({ url: '/pages/video/home-page?authorId=' + storage.getUserInfo().id diff --git a/pages/tabbar/video/video.vue b/pages/tabbar/video/video.vue index c70a040..c601704 100644 --- a/pages/tabbar/video/video.vue +++ b/pages/tabbar/video/video.vue @@ -208,7 +208,7 @@ import '@/components/uview-components/uview-ui'; import MyTag from '@/components/my-tag.vue' -import { getSTSToken, getFilePreviewUrl } from "@/api/common.js"; +import { getSTSToken } from "@/api/common.js"; import { publish } from "@/api/video.js"; import { getRecommendTag3 } from "@/api/video-tag.js"; import { getFileKey } from "@/utils/file.js"; @@ -488,7 +488,7 @@ let fileName = tmpImg.substring(tmpImg.lastIndexOf('/') + 1); // 澶勭悊瀹夊崜鍙兘鐨刄RI缂栫爜 if(fileName.indexOf('%') > -1) { - fileName = decodeURIComponent(fileName); + fileName = decodeURIComponent(fileName); } const fileKey = getFileKey(fileName); this.cosClient.uploadFile({ -- Gitblit v1.8.0