zs před 1 rokem
rodič
revize
301f77926c
1 změnil soubory, kde provedl 32 přidání a 27 odebrání
  1. 32 27
      pagesHome/login/index.vue

+ 32 - 27
pagesHome/login/index.vue

@@ -108,40 +108,45 @@
 	// 查询
 	const search = async () => {
 		const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
-		if (res.errcode == '0') {
-			form.value = res.data
-			uni.setStorageSync('user', res.data);
-		}
+		if (res.errcode == '0') form.value = res.data
 	};
 	// 开始验证
 	const formSubmit = () => {
 		if (agree.value) {
 			if (openid.value) {
 				uForm.value.validate().then(async res => {
-					uni.getUserProfile({
-						desc: '用于展示',
-						success: async function (res) {
-							let parmas = {
-								openid: openid.value,
-								nickname: res.userInfo.nickName + moment().valueOf()
-							}
-							const arr = await $api(`user`, 'POST', { ...form.value, ...parmas });
-							if (arr.errcode == '0') {
-								uni.setStorageSync('user', arr.data);
-								uni.navigateBack({
-									delta: 1
-								})
-							} else {
-								uni.showToast({
-									title: arr.errmsg,
-									icon: 'error'
-								});
+					if (!form.value._id) {
+						uni.getUserProfile({
+							desc: '用于展示',
+							success: async function (res) {
+								let parmas = {
+									openid: openid.value,
+									nickname: res.userInfo.nickName + moment().valueOf()
+								}
+								const arr = await $api(`user`, 'POST', { ...form.value, ...parmas });
+								if (arr.errcode == '0') {
+									uni.setStorageSync('user', arr.data);
+									uni.navigateBack({
+										delta: 1
+									})
+								} else {
+									uni.showToast({
+										title: arr.errmsg,
+										icon: 'error'
+									});
+								}
+							},
+							fail: function (err) {
+								console.log(err);
 							}
-						},
-						fail: function (err) {
-							console.log(err);
-						}
-					})
+						})
+					} else {
+						uni.setStorageSync('user', form.value);
+						uni.navigateBack({
+							delta: 1
+						})
+					}
+
 				}).catch(err => {
 					console.log(err, '校验失败');
 				})