wangguoyu il y a 1 semaine
Parent
commit
07a4219c4c
2 fichiers modifiés avec 66 ajouts et 62 suppressions
  1. 26 23
      App.vue
  2. 40 39
      pages/admin/Jiazheng/common/jiazhengUpload.vue

+ 26 - 23
App.vue

@@ -34,18 +34,18 @@
 					uni.reLaunch({
 						url: `/pages/admin/ShouYe/shouye`,
 						success() {
-							
+
 						}
 					})
 				} else {
 					uni.reLaunch({
 						url: `/pages/client/ShouYe/shouye`,
 						success() {
-					
+
 						}
 					})
 				}
-			
+
 			}
 			// #endif
 		},
@@ -63,26 +63,29 @@
 				}
 			});
 			// #endif
-			// #ifdef H5
-			if (cacheManager.get('auth')) {
-				if (cacheManager.get('auth').type === 2 || cacheManager.get('auth').type == 5) {
-					uni.reLaunch({
-						url: `/pages/admin/ShouYe/shouye`,
-						success() {
-					
-						}
-					})
-				} else {
-					uni.reLaunch({
-						url: `/pages/client/ShouYe/shouye`,
-						success() {
-					
-						}
-					})
-				}
-			
-			} 
-			// #endif
+			// // #ifdef H5	
+
+			// alert(cacheManager.get('auth'))
+			// alert(123123123)
+			// if (cacheManager.get('auth')) {
+			// 	if (cacheManager.get('auth').type === 2 || cacheManager.get('auth').type == 5) {
+			// 		uni.reLaunch({
+			// 			url: `/pages/admin/ShouYe/shouye`,
+			// 			success() {
+
+			// 			}
+			// 		})
+			// 	} else {
+			// 		uni.reLaunch({
+			// 			url: `/pages/client/ShouYe/shouye`,
+			// 			success() {
+
+			// 			}
+			// 		})
+			// 	}
+
+			// }
+			// // #endif
 		},
 		onHide: function() {
 

+ 40 - 39
pages/admin/Jiazheng/common/jiazhengUpload.vue

@@ -17,9 +17,11 @@
 </template>
 
 <script>
+	import axios from 'axios';
 	import {
 		getAliyunPolicy
 	} from "@/api/jiazheng.js"
+		import cacheManager from "@/utils/cacheManager.js";
 	export default {
 		emits: ['getFileUrl'], // 声明自定义事件
 		data() {
@@ -75,31 +77,49 @@
 					count: 1, // 只能选择一张图片
 					sourceType: [sourceType], // 'camera' 或 'album'
 					success: (res) => {
+						console.log('res', res);
+
+						// #ifndef H5
 						const filePath = res.tempFilePaths[0];
 						this.uploadFileToAliyun(filePath);
+						// #endif
+						// #ifdef H5
+						const filePath = res.tempFiles[0];
+						this.uploadFileToAliyun(filePath);
+						// #endif
 					}
 				});
 			},
 			uploadFileToAliyun(filePath) {
 				console.log('filePath', filePath);
+
 				const loading = uni.showLoading({
 					title: '上传中...',
 					mask: true
 				});
-			
 				try {
+
+					// #ifdef H5
+					const suffixList = filePath.name.split('.');
+					let req = {
+						prefix: 'resource/',
+						suffix: suffixList[suffixList.length - 1],
+					}
+					// #endif
+					// #ifndef H5
 					const suffix = filePath.split('.').pop();
 					let req = {
 						prefix: 'resource/',
 						suffix: suffix
 					}
-			
+					// #endif
+
 					getAliyunPolicy(req).then(res => {
 						let that = this;
 						if (res.code == 0) {
 							const policyData = res.data;
 							console.log('policyData', policyData);
-			
+
 							// #ifdef H5
 							const formData = new FormData();
 							formData.append('key', policyData.key);
@@ -107,47 +127,28 @@
 							formData.append('OSSAccessKeyId', policyData.accessid);
 							formData.append('signature', policyData.signature);
 							formData.append('success_action_status', '200');
-		
-							fetch(filePath)
-								.then(response => response.blob())
-								.then(blob => {
-									formData.append('file', blob, policyData.key);
-									fetch(policyData.uploadUrl, {
-										method: 'POST',
-										body: formData
-									})
-									.then(response => {
-										if (response.ok) {
-											that.imageUrl = `${policyData.downloadUrl}/${policyData.key}`;
-											uni.showToast({
-												title: '上传成功',
-												icon: 'success'
-											});
-											that.$emit('getFileUrl', that.imageUrl);
-										} else {
-											uni.showToast({
-												title: '上传失败',
-											});
-										}
-									})
-									.catch(error => {
-										console.error('上传失败:', error);
+							formData.append('file', filePath);
+
+							axios.post(policyData.uploadUrl, formData)
+								.then(alRes => {
+									if (alRes.status === 200) {
+										that.imageUrl =
+											`${policyData.downloadUrl}/${policyData.key}`;
+										uni.showToast({
+											title: '上传成功',
+											icon: 'success'
+										});
+										that.$emit('getFileUrl', that.imageUrl);
+									} else {
 										uni.showToast({
 											title: '上传失败',
-											icon: 'none'
 										});
-									});
+									}
 								})
-								.catch(error => {
-									console.error('文件转换失败:', error);
-									uni.showToast({
-										title: '文件转换失败',
-										icon: 'none'
-									});
-								});
 							// #endif
-			
+
 							// #ifndef H5
+							console.log('appappappappappapp');
 							// 非 H5 环境下使用 uni.uploadFile 上传
 							uni.uploadFile({
 								url: policyData.uploadUrl,
@@ -183,7 +184,7 @@
 								}
 							});
 							// #endif
-			
+
 						} else {
 							uni.showToast({
 								title: '获取凭证失败',