Browse Source

修改已绑定微信不可再绑定

11wqe1 3 weeks ago
parent
commit
91a914efb3
1 changed files with 37 additions and 18 deletions
  1. 37 18
      src/components/userInfoA.vue

+ 37 - 18
src/components/userInfoA.vue

@@ -184,7 +184,7 @@
 							<div
 								style="width: 100%; display: flex; justify-content: flex-end"
 							>
-								<el-button type="primary" @click="updatePassword"
+								<el-button type="primary" @click="updatePasswordL"
 									>保存</el-button
 								>
 							</div>
@@ -216,6 +216,8 @@ import avator from "../assets/info/teacher.jpg";
 import { API_CONFIG } from "@/common/apiConfig";
 import { updatePassword, getUser } from "@/api/user";
 import store from "../store";
+import qs from "qs";
+import axios from "axios";
 
 import "@/common/wxLogin.js";
 
@@ -283,7 +285,7 @@ export default {
 			this.updateInfo();
 			// this.getTypeInfo();
 		},
-		updatePassword() {
+		updatePasswordL() {
 			const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,16}$/;
 			if (!reg.test(this.password)) {
 				this.$message.error("密码长度为8-16位,且包含大小写字母");
@@ -640,24 +642,41 @@ export default {
 			}, 0);
 		},
 		setOpenId(openid) {
-			let params = [
-				{
-					functionName: API_CONFIG.ajax_UpdateOpenId.functionName, // 调用存储过程的名称
-					uid: this.userid,
-					openid: openid,
-				},
-			];
-			this.$ajax
-				.post(API_CONFIG.baseUrl, params)
-				.then(() => {
-					this.$message.success("绑定成功");
-					this.wechatDialogVisible = false;
-					this.getData();
+			axios.defaults.withCredentials = false;
+			let params = {
+				openid: openid,
+			};
+			
+			this.openid = openid;
+			axios.defaults.withCredentials = true;
+			axios
+				.post(`https://beta.api.cocorobo.cn/api/user`, qs.stringify(params))
+				.then(async (res) => {
+					let _data = res.data[0][0];
+					this.$message.error('该微信已绑定'+_data.username+'账号')
 				})
 				.catch((err) => {
-					this.$message.error("绑定失败请重新扫码");
-					console.error(err);
-				});
+					console.log('err',err);
+					
+					let params = [
+						{
+							functionName: API_CONFIG.ajax_UpdateOpenId.functionName, // 调用存储过程的名称
+							uid: this.userid,
+							openid: openid,
+						},
+					];
+					this.$ajax
+						.post(API_CONFIG.baseUrl, params)
+						.then(() => {
+							this.$message.success("绑定成功");
+							this.wechatDialogVisible = false;
+							this.getData();
+						})
+						.catch((err) => {
+							this.$message.error("绑定失败请重新扫码");
+							console.error(err);
+						});
+					});
 		},
 		Ochange() {
 			this.$forceUpdate();