Bladeren bron

修改微信登录

11wqe1 5 dagen geleden
bovenliggende
commit
d256921ccc
2 gewijzigde bestanden met toevoegingen van 45 en 1 verwijderingen
  1. 2 1
      src/common/apiConfig.js
  2. 43 0
      src/components/userInfoA.vue

+ 2 - 1
src/common/apiConfig.js

@@ -60,7 +60,8 @@ export const API_CONFIG = {
   ajax_selectliyuanUserInfo: {
     functionName: "selectliyuanUserInfo",
   },
-  //获取教研室列表
+
+  //微信登录
   ajax_UpdateOpenId: {
     functionName: "UpdateOpenId",
   },

+ 43 - 0
src/components/userInfoA.vue

@@ -611,10 +611,53 @@ export default {
 				}, 0);
 			}, 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();
+				})
+				.catch((err) => {
+					this.$message.error("绑定失败请重新扫码");
+					console.error(err);
+				});
+		},
 		Ochange() {
 			this.$forceUpdate();
 		},
 	},
+	mounted() {
+		let _this = this;
+		window.addEventListener("message", function (e) {
+			// 监听 message 事件
+			console.log(e);
+			if (e.data && e.data.method == "getOpenId") {
+				console.log(e);
+				console.log(e.data.code);
+				console.log(_this.loginType);
+
+				if (e.data.code == 200) {
+					_this.setOpenId(e.data.data.openid);
+				} else {
+					_this.$message.error("扫码登录失败请重新扫码");
+					_this.wechatDialogVisible = false;
+					setTimeout(() => {
+						_this.wechatDialogVisible = true;
+						_this.wechatLogin();
+					}, 1000);
+				}
+			}
+		});
+	},
 };
 </script>