Ver Fonte

修改微信监听

11wqe1 há 3 semanas atrás
pai
commit
b4cb5997ef
2 ficheiros alterados com 32 adições e 28 exclusões
  1. 30 25
      src/components/userInfoA.vue
  2. 2 3
      src/mixins/mixin.js

+ 30 - 25
src/components/userInfoA.vue

@@ -285,6 +285,7 @@ export default {
 		openDig() {
 			this.dialogVisibleInfo = true;
 			this.updateInfo();
+			this.monitorWechat()
 			// this.getTypeInfo();
 		},
 		updatePasswordL() {
@@ -322,6 +323,31 @@ export default {
 		changeEye() {
 			this.isLook = !this.isLook;
 		},
+		monitorWechat(){
+			let _this = this;
+			this.messageHandler = function (e) {
+				// 监听 message 事件
+				console.log("userinfoA", e);
+				if (e.data && e.data.method === "getOpenId") {
+					console.log("eA", e);
+					console.log("e.data.codeA", e.data.code);
+					console.log("_this.loginTypeA", _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);
+					}
+				}
+			};
+
+			window.addEventListener("message", this.messageHandler);
+		},
 		//切换弹框
 		midInfo(type) {
 			if (type == 0) {
@@ -374,6 +400,7 @@ export default {
 		close() {
 			this.typeId = "";
 			this.dialogVisibleInfo = false;
+			window.removeEventListener("message", this.messageHandler);
 			// this.$emit("update:dialogVisibleInfo", false);
 		},
 		generateResultInfo() {
@@ -698,33 +725,11 @@ export default {
 		},
 	},
 	mounted() {
-		let _this = this;
-		this.messageHandler = function (e) {
-			// 监听 message 事件
-			console.log("userinfoA", e);
-			if (e.data && e.data.method === "getOpenId") {
-				console.log("eA", e);
-				console.log("e.data.codeA", e.data.code);
-				console.log("_this.loginTypeA", _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);
-				}
-			}
-		};
 
-		window.addEventListener("message", this.messageHandler);
-	},
-	beforeDestroy() {
-		window.removeEventListener("message", this.messageHandler);
 	},
+	// beforeDestroy() {
+	// 	window.removeEventListener("message", this.messageHandler);
+	// },
 };
 </script>
 

+ 2 - 3
src/mixins/mixin.js

@@ -7,10 +7,9 @@ export const myMixin = {
       return Object.keys(this.userinfo).length != 0 ? this.userinfo : this.userJson
     },
     prefixL(){
-        let liyuan = window.topU.U.UF.UI.form.allForm.U_MD_HomeC_Pop.header.baseURI.includes("liyuan")
-        let liyuan2 = window.topU.U.UF.UI.form.allForm.U_MD_HomeC_Pop.header.baseURI.includes("lyxx")
+        let liyuan = window.topU.location.href.includes("lyxx")
         let newArr = ''
-        if (liyuan || liyuan2) {
+        if (liyuan) {
           newArr = "liyuan_"
         }else{
           newArr = "admin_"