Browse Source

个人资料接口联调

htc 2 ngày trước cách đây
mục cha
commit
565fd0e53e
3 tập tin đã thay đổi với 42 bổ sung16 xóa
  1. 5 2
      common/stores/user.js
  2. 7 2
      pages/my.vue
  3. 30 12
      pagesMy/information.vue

+ 5 - 2
common/stores/user.js

@@ -47,9 +47,12 @@ export const useUserStore = defineStore('user', {
 			await new Promise(resolve => {
 				api.get('/wx/login',loginDto).then(({data:res})=>{
 					if(res.code !== 0){
-						return uni.showToast({
-							title: res.msg
+						uni.showModal({
+							title:'温馨提示',
+							content:res.msg,
+							showCancel:false
 						})
+						return
 					}  
 					
 					this.showLoginModal = false;

+ 7 - 2
pages/my.vue

@@ -122,8 +122,13 @@
 	}
 	
 	const getUserInfo = () => {
-		if(uni.getStorageSync('userInfo')){
-			userInfo.value = JSON.parse(uni.getStorageSync('userInfo'));
+		try{
+			proxy.$api.get(`/wx/${JSON.parse(uni.getStorageSync('userInfo')).id}`).then(({data:res})=>{
+				if(res.code!==0) return this.$showToast(res.msg)
+				userInfo.value = res.data;
+			})
+		}catch(e){
+			userInfo.value = null
 		}
 	}
 	

+ 30 - 12
pagesMy/information.vue

@@ -58,15 +58,28 @@
 	const userInfo = ref(null)
 	
 	const save = () => {
+		userInfo.value.avatarPath = fileList.value[0]?.url||''
 		if(!userInfo.value?.avatarPath) return proxy.$showToast('请上传用户头像')
 		if(!userInfo.value?.realName) return proxy.$showToast('请输入用户名')
 		// if(!proxy.$reg.mobile(userInfo.value.phone)) return proxy.$showToast('请输入正确的手机号')
 		if(!userInfo.value?.welfareName) return proxy.$showToast('请输入家庭公益名称')
 		if(!userInfo.value?.welfareSlogan) return proxy.$showToast('请输入家庭公益口号')
+		
+		userInfo.value.id = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
+		proxy.$api.put('/wx/update',userInfo.value).then(({data:res})=>{
+			if(res.code!==0) return proxy.$showToast(res.msg)
+			proxy.$showToast('保存成功')
+			setTimeout(()=>{
+				uni.reLaunch({
+					url:'/pages/my'
+				})
+			},1000)
+		})
 	}
 	
 	const deletePic = (event) => {
 	  fileList.value.splice(event.index, 1);
+	  userInfo.value.avatarPath = '';
 	};
 	
 	// 新增图片
@@ -83,13 +96,15 @@
 	  });
 	  for (let i = 0; i < lists.length; i++) {
 	    const result = await uploadFilePromise(lists[i].url);
-	    let item = fileList.value[fileListLen];
-	    fileList.value.splice(fileListLen, 1, {
-	      ...item,
-	      status: 'success',
-	      message: '',
-	      url: result,
-	    });
+		if(result){
+			let item = fileList.value[fileListLen];
+			fileList.value.splice(fileListLen, 1, {
+			  ...item,
+			  status: 'success',
+			  message: '',
+			  url: result,
+			});
+		}
 	    fileListLen++;
 	  }
 	};
@@ -97,17 +112,20 @@
 	const uploadFilePromise = (url) => {
 	  return new Promise((resolve, reject) => {
 	    let a = uni.uploadFile({
-	      url: BaseApi+'/uploadFile', // 仅为示例,非真实的接口地址
+	      url: BaseApi+'/uploadFile',
 	      filePath: url,
 	      name: 'file',
-	      formData: {
-	        user: 'test',
-	      },
 	      success: (res) => {
 	        setTimeout(() => {
-	          resolve(res.data.data);
+				let data = JSON.parse(res.data)
+				if(data&&data.code===0){
+					resolve(data.data);
+				}else proxy.$showToast(data?.msg)
 	        }, 1000);
 	      },
+		  fail: err =>{
+			resolve('');
+		  }
 	    });
 	  });
 	};