sys hace 1 año
padre
commit
e4fd4fcf99
Se han modificado 3 ficheros con 24 adiciones y 15 borrados
  1. 5 2
      main.js
  2. 3 5
      pages/perfect/cards.vue
  3. 16 8
      service/txOssSts.js

+ 5 - 2
main.js

@@ -6,9 +6,12 @@ import {
 	RouterMount
 } from './service/router.js' //路径换成自己的
 import cosServe from "@/service/txOssSts";
-Vue.prototype.getCosPath = (urlName) => {
+Vue.prototype.getCosPath =async (urlName) => {
 	console.log('getCosPath:路径转换调用')
-	return cosServe.getSignUrl(urlName);
+	console.log(urlName)
+	let  url=await cosServe.getSignUrl(urlName);
+	console.log(url)
+	return url;
 };
 Vue.use(router)
 // #ifndef VUE3

+ 3 - 5
pages/perfect/cards.vue

@@ -11,7 +11,7 @@
           <text class="sys-color-green">真实照片</text>
           <text class="sys-color-gray-9">,否则部分功能可能会受限</text>
         </view>
-        <view class="card-img" :class="{'open-img':imgBg}" @click="openPopup" :style="{'height':'calc(100vh - '+navHeight+'px  - 278rpx - 270rpx - env(safe-area-inset-bottom)','background-image':'url('+getCosPath(imgBg)+')'}">
+        <view class="card-img" :class="{'open-img':imgBg}" @click="openPopup" :style="{'height':'calc(100vh - '+navHeight+'px  - 278rpx - 270rpx - env(safe-area-inset-bottom)','background-image':'url('+imgBg+')'}">
           <view class="add-box" v-if="!imgBg">
             <image class="add-img" src="/static/img/common/add.png" mode="aspectFill"></image>
           </view>
@@ -99,12 +99,10 @@ export default {
           if(res.tempFiles.length>0){
             console.log(res.tempFiles)
             res.tempFiles.forEach((item,key)=>{
-              cosServe.txUploadFile(item,'gallery').then((res)=>{
+              cosServe.txUploadFile(item,'gallery').then(async (res)=>{
                 if(key===0){
                   this.imgBg=res.Location
-                  console.log('this.imgBg:'+this.imgBg)
-                  this.imgBg=cosServe.getSignUrl(this.imgBg)
-                  console.log(this.imgBg)
+                  this.imgBg=await cosServe.getSignUrl(this.imgBg)
                 }
                 this.imgList.push(res.Location)
               })

+ 16 - 8
service/txOssSts.js

@@ -113,7 +113,7 @@ cosServe.txUploadFile=function (file,folder){
 }
 
 
-cosServe.getSignUrl=function (url){
+cosServe.getSignUrl=  function (url){
     if(!url){
         return  ''
     }
@@ -131,14 +131,22 @@ cosServe.getSignUrl=function (url){
         Region: Region,
         Key: url, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),支持中文,必须字段 */
     })
-    let newUrl= cos.getObjectUrl({
-        Bucket: Bucket,
-        Region: Region,
-        Key: url, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),支持中文,必须字段 */
+    return new Promise((resolve, reject) => {
+        cos.getObjectUrl({
+                Bucket: Bucket,
+                Region: Region,
+                Key: url, /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),支持中文,必须字段 */
+            },
+            function (err, data) {
+                console.log(err || data.Url);
+                if(err){
+                    resolve('')
+                }else {
+                    resolve(data.Url)
+                }
+            })
     })
-    console.log('签名完成----------------------------'+newUrl)
-    console.log(newUrl)
-    return newUrl
+
 }