Browse Source

分享朋友圈图片压缩

xhj 2 năm trước cách đây
mục cha
commit
5b1c9dd6d8
1 tập tin đã thay đổi với 36 bổ sung2 xóa
  1. 36 2
      topic/content/content.vue

+ 36 - 2
topic/content/content.vue

@@ -77,7 +77,9 @@ export default {
 			query:{},
 			id:null,
 			
-			webUrl:''
+			webUrl:'',
+			
+			tempFilePath:''
 		};
 	},
 
@@ -118,12 +120,43 @@ export default {
 		req.saveBehaviorNew(this.id,3,6)
 		return {
 			title: this.detaile.title,
-			imageUrl: this.detaile.pic,
+			imageUrl: this.tempFilePath?this.tempFilePath:this.detaile.pic,
 			path: '/topic/content/content',
 			query:'id=' + this.id+'&isSharePYQ=' + true +'&isShare=' + true+(this.userInfo.userType==1?('&shareId='+this.userInfo.saleNo):'')
 		};
 	},
 	methods: {
+		/*获取分享图 */
+		async getShareImg(){
+			let tempFilePath = await new Promise((r,j)=>{
+				try{
+					uni.getImageInfo({
+						src:this.detaile.pic,
+						success: (data) => {
+							uni.compressImage({
+								src:data.path,
+								quality:0.5,
+								success:(res)=>{
+									console.log('压缩成功',res.tempFilePath)
+									r(res.tempFilePath)
+								},
+								fail: (error) => {
+									console.log('压缩失败',error)
+									r('')
+								}
+							})
+						},
+						fail: () => {
+							r('')
+						}
+					})
+				}catch(e){
+					//TODO handle the exception
+					r('')
+				}
+			})
+			this.tempFilePath = tempFilePath
+		},
 		getConfig() {
 			var _this = this;
 			return new Promise((res, rej) => {
@@ -176,6 +209,7 @@ export default {
 						res.productCategory = res.productCategory.split(',')
 					}
 					that.detaile = res;
+					that.getShareImg()
 					that.webUrl = that.detaile.linkUrl?that.detaile.linkUrl:''
 					let arr = [];
 					if(res.productCategory && res.productCategory.length > 0){