Procházet zdrojové kódy

fix: 注册页面用户头像上传到OSS而非使用临时路径

Developer před 4 dny
rodič
revize
4828811a5a
1 změnil soubory, kde provedl 41 přidání a 6 odebrání
  1. 41 6
      components/pages/loginRegister/index.vue

+ 41 - 6
components/pages/loginRegister/index.vue

@@ -238,13 +238,48 @@
 		if(e.detail.code) getPhone(e.detail.code);
 	}
 
+	const userAvatarUploading = ref(false)
+
 	const onChooseAvatar = e => {
-		register.value.avatarPath = e.detail.avatarUrl;
-		// 更新 fileList 以显示头像
-		fileList.value = [{
-			url: e.detail.avatarUrl,
-			status: 'success'
-		}];
+		const avatarUrl = e.detail.avatarUrl;
+
+		// 内容安全检测
+		userAvatarUploading.value = true;
+		proxy.$api.detectionContent(avatarUrl, 2).then(res => {
+			if(res.code !== 0) {
+				userAvatarUploading.value = false;
+				return proxy.$showToast(res.msg)
+			}
+
+			// 上传到OSS
+			uni.uploadFile({
+				url: BaseApi2 + '/sys/oss/upload',
+				filePath: avatarUrl,
+				name: 'file',
+				success: (uploadRes) => {
+					setTimeout(() => {
+						userAvatarUploading.value = false;
+						let data = JSON.parse(uploadRes.data)
+						if(data && data.code === 0){
+							register.value.avatarPath = data.data;
+							// 更新 fileList 以显示头像
+							fileList.value = [{
+								url: data.data,
+								status: 'success'
+							}];
+						} else {
+							proxy.$showToast(data?.msg || '上传失败')
+						}
+					}, 1000);
+				},
+				fail: () => {
+					userAvatarUploading.value = false;
+					proxy.$showToast('上传失败');
+				}
+			});
+		}).catch(() => {
+			userAvatarUploading.value = false;
+		})
 	}
 
 	const getPhone = code => {