Browse Source

商城评价图片改为cos直传

zhuxiuping 2 years ago
parent
commit
4725bad41f
3 changed files with 26 additions and 58 deletions
  1. 2 1
      manifest.json
  2. 23 56
      packageShang/components/use-upload/use-upload.vue
  3. 1 1
      util/cos.js

+ 2 - 1
manifest.json

@@ -57,7 +57,8 @@
 			"postcss": true,
 			"postcss": true,
 			"minified": true
 			"minified": true
 		},
 		},
-		"usingComponents": true,
+		"usingComponents": true,
+		"lazyCodeLoading": "requiredComponents",
 		"permission": {
 		"permission": {
 			"scope.userLocation": {
 			"scope.userLocation": {
 				"desc": "获取用户位置已展示距离民宿的距离"
 				"desc": "获取用户位置已展示距离民宿的距离"

+ 23 - 56
packageShang/components/use-upload/use-upload.vue

@@ -14,6 +14,7 @@
 
 
 <script>
 <script>
 	import common from '../../../static/comon.js'
 	import common from '../../../static/comon.js'
+	import { cos } from '@/util/cos.js'
 	export default {
 	export default {
 		props: {
 		props: {
 			limit: {
 			limit: {
@@ -46,71 +47,37 @@
 					// 可以指定是原图|压缩图,默认二者都有
 					// 可以指定是原图|压缩图,默认二者都有
 					sizeType: ['original', 'compressed'],
 					sizeType: ['original', 'compressed'],
 					success: (res) => {
 					success: (res) => {
-						console.log(JSON.stringify(res.tempFilePaths));
 						// _this.imgs.push((res.tempFilePaths)[0])
 						// _this.imgs.push((res.tempFilePaths)[0])
 						// console.log(_this.imgs)
 						// console.log(_this.imgs)
 						const file = res.tempFilePaths[0];
 						const file = res.tempFilePaths[0];
-						
-						// 文件上传
-						uni.uploadFile({
-							url:getApp().globalData.baseurl+ '/file/open/', //自己的后端接口(默认发送post请求)
-							filePath:file,
-							name:"file",  //这里应为自己后端文件形参的名字
-							data:{
-		//                     
-							},
-							header:{
-								'Content-type' : 'multipart/form-data'
+						let Key = file.substr(file.lastIndexOf('/') + 1)
+						cos.postObject(
+							{
+								Bucket: 'jinganminsu-1320402385',
+								Region: 'ap-nanjing',
+								Key: Key,
+								FilePath: file,
+								onProgress: (info) => {
+									// console.log(info)
+								}
 							},
 							},
-							success(res) {
-								res = res.data
-								console.log(JSON.parse(res).success)
-								if(JSON.parse(res).success){
-									_this.imgs.push(JSON.parse(res).data)
+							(err, data) => {
+								if (err) {
+									console.log('上传失败', err)
+								} else {
+									console.log('上传成功', data)
+						
+									uni.hideLoading()
+									let imgUrl = 'https://' + data.Location
+									// this.form.img =imgUrl
+									_this.imgs.push(imgUrl)
 									_this.sendData()
 									_this.sendData()
+									
 								}
 								}
 							}
 							}
-						})
-						
-						// uni.showLoading({
-						// 	title: '上传中',
-						// 	mask: true
-						// });
+						)
 						
 						
 						for (var i = 0; i < res.tempFilePaths.length; i++) {
 						for (var i = 0; i < res.tempFilePaths.length; i++) {
-							console.log(i,'41')
-							//解决跨越问题,让通过微信上传的图片你能够展示在浏览器前端
-							// uni.getImageInfo({
-							// 	src: res.tempFilePaths[0],
-							// 	success: (path) => {
-							// 		pathToBase64(path.path).then(base64 => {
-							// 				console.log("base64="+base64); // 这就是转为base64格式的图片
-							// 				_this.imgs=base64
-							// 			})
-							// 			.catch(error => {
-							// 				console.error(error)
-							// 			})
-							// 	}
-							// })
-							// const result = uni.uploadFile({
-							// 	filePath: res.tempFilePaths[i],
-							// 	cloudPath: _this.$api.getFileName(res.tempFilePaths[i]),
-							// 	onUploadProgress: function(progressEvent) {
-							// 		console.log(progressEvent,'0p1')
-							// 		var percentCompleted = Math.round((progressEvent.loaded *
-							// 			100) / progressEvent.total);
-							// 	}
-							// }).then(uRes => {
-							// 	console.log(uRes, res.tempFiles[i],'0p')
-							// 	uRes.url = uRes.fileID;
-							// 	uRes.type = res.tempFiles[i].type || '';
-							// 	uRes.size = res.tempFiles[i].size;
-								
-							// 	_this.imgs.push(uRes);
-							// 	_this.sendData()
-							// }).catch(err => {
-							// 	console.log('use-upload', err);
-							// });
 						}
 						}
 
 
 						uni.hideLoading();
 						uni.hideLoading();

+ 1 - 1
util/cos.js

@@ -2,5 +2,5 @@ let COS = require('cos-wx-sdk-v5')
 export const cos = new COS({
 export const cos = new COS({
 	SecretId: 'AKIDJSP9gz469yZv77tQjotsgHguvjIgtvkL',
 	SecretId: 'AKIDJSP9gz469yZv77tQjotsgHguvjIgtvkL',
 	SecretKey: 'b3MVRD1g8RYS9g195oMkvukQvDKZfbOz',
 	SecretKey: 'b3MVRD1g8RYS9g195oMkvukQvDKZfbOz',
-	SimpleUploadMethod: 'putObject'
+	SimpleUploadMethod: 'putObject',
 })
 })