fix(ns-login): 修复H5页面在微信App中点击登录无反应的问题
This commit is contained in:
@@ -379,6 +379,36 @@ export default {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 判断是否在微信小程序的web-view中打开H5
|
||||
* @returns {boolean} 是否在微信小程序的web-view中
|
||||
*/
|
||||
isWeChatMiniProgram() {
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
|
||||
// 微信小程序的web-view User-Agent会包含以下特征之一
|
||||
const miniProgramIndicators = [
|
||||
'miniprogram', // 普通微信小程序
|
||||
'wxwork', // 企业微信小程序
|
||||
'micromessenger/[0-9]+\.[0-9]+\.[0-9]+ nettype/wifi wxwebviewtype/1'
|
||||
];
|
||||
|
||||
return miniProgramIndicators.some(indicator => {
|
||||
if (typeof indicator === 'string' && indicator.includes('/')) {
|
||||
// 正则表达式匹配
|
||||
const regex = new RegExp(indicator, 'i');
|
||||
return regex.test(userAgent);
|
||||
}
|
||||
return userAgent.includes(indicator);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 判断是否在微信浏览器中打开H5(非小程序的web-view)
|
||||
* @returns {boolean} 是否在微信浏览器中打开的H5
|
||||
*/
|
||||
isWeChatBrowser() {
|
||||
return isWeiXin() && !isWeChatMiniProgram();
|
||||
},
|
||||
/**
|
||||
* 显示消息提示框
|
||||
* @param {Object} params 参数
|
||||
|
||||
@@ -209,11 +209,16 @@
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
if (this.$util.isWeiXin()) {
|
||||
if (this.$util.isWeChatMiniProgram()) {
|
||||
// 微信小程序环境,使用微信授权登录
|
||||
let authData = uni.getStorageSync('authInfo');
|
||||
if (authData) this.authLogin(authData);
|
||||
else this.getCode();
|
||||
} else if (this.$util.isWeiXin()) {
|
||||
// 微信浏览器环境,显示登录页面
|
||||
this.toLogin();
|
||||
} else {
|
||||
// 其他浏览器环境,显示登录页面
|
||||
this.toLogin();
|
||||
}
|
||||
// #endif
|
||||
|
||||
Reference in New Issue
Block a user