登录验证提示
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<view class="wx-login-page">
|
||||
<!-- 顶部导航栏 -->
|
||||
<view class="nav-bar">
|
||||
<!-- <view class="nav-bar">
|
||||
<view class="nav-back" @click="goBack">
|
||||
<uni-icons type="arrowleft" size="24" color="#333"></uni-icons>
|
||||
</view>
|
||||
<view class="nav-title">登录</view>
|
||||
<view class="nav-placeholder"></view>
|
||||
</view>
|
||||
</view> -->
|
||||
|
||||
<!-- 页面内容 -->
|
||||
<view class="page-content">
|
||||
@@ -83,8 +83,7 @@
|
||||
<button
|
||||
class="auth-btn primary"
|
||||
open-type="getPhoneNumber"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
:disabled="!canSubmit"
|
||||
@getphonenumber="onWxGetPhoneNumber"
|
||||
>
|
||||
<uni-icons type="phone" size="20" color="#FFFFFF"></uni-icons>
|
||||
<text>手机号快捷登录</text>
|
||||
@@ -93,7 +92,7 @@
|
||||
|
||||
<!-- H5和App使用普通按钮 -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<button class="auth-btn primary" @click="wxLogin" :disabled="!canSubmit">
|
||||
<button class="auth-btn primary" @click="wxLogin">
|
||||
<uni-icons type="phone" size="20" color="#FFFFFF"></uni-icons>
|
||||
<text>手机号快捷登录</text>
|
||||
</button>
|
||||
@@ -101,7 +100,7 @@
|
||||
|
||||
<!-- 测试登录按钮(仅开发环境) -->
|
||||
<!-- #ifdef APP-PLUS || H5 -->
|
||||
<button class="auth-btn secondary" @click="testLogin" :disabled="!canSubmit">
|
||||
<button class="auth-btn secondary" @click="testLogin">
|
||||
<text>测试账号登录</text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
@@ -198,15 +197,69 @@ const goBack = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
|
||||
// 微信获取手机号
|
||||
const getPhoneNumber = async (e) => {
|
||||
console.log('获取手机号:', e);
|
||||
// 通用的验证函数
|
||||
const validateForm = () => {
|
||||
if (userType.value === null) {
|
||||
uni.showToast({
|
||||
title: '请先选择您的角色(个人或单位)',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!canSubmit.value) {
|
||||
$api.msg('请先完成上述选择并同意隐私协议');
|
||||
if (userType.value === 0 && orgType.value === null) {
|
||||
uni.showToast({
|
||||
title: '请选择机构类型',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!agreedToAgreement.value) {
|
||||
uni.showToast({
|
||||
title: '请先阅读并同意隐私协议',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// 微信小程序授权前的检查
|
||||
const checkBeforeWxAuth = (e) => {
|
||||
console.log('checkBeforeWxAuth called, canSubmit:', canSubmit.value);
|
||||
console.log('userType:', userType.value, 'agreedToAgreement:', agreedToAgreement.value);
|
||||
|
||||
// 验证表单
|
||||
if (!validateForm()) {
|
||||
console.log('Validation failed, preventing wx auth');
|
||||
// 阻止微信授权流程
|
||||
if (e && e.preventDefault) {
|
||||
e.preventDefault();
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
console.log('Validation passed, allowing wx auth');
|
||||
}
|
||||
};
|
||||
|
||||
// 微信获取手机号
|
||||
const onWxGetPhoneNumber = async (e) => {
|
||||
console.log('onWxGetPhoneNumber called, event:', e);
|
||||
console.log('userType:', userType.value, 'agreedToAgreement:', agreedToAgreement.value);
|
||||
|
||||
// 使用通用验证函数
|
||||
if (!validateForm()) {
|
||||
console.log('Validation failed in onWxGetPhoneNumber');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Validation passed, proceeding with wx auth');
|
||||
|
||||
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
@@ -265,23 +318,41 @@ const getPhoneNumber = async (e) => {
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取微信登录code失败:', err);
|
||||
$api.msg('获取登录信息失败,请重试');
|
||||
uni.showToast({
|
||||
title: '获取登录信息失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
|
||||
$api.msg('您取消了授权');
|
||||
uni.showToast({
|
||||
title: '您取消了授权',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
} else {
|
||||
$api.msg('获取手机号失败');
|
||||
uni.showToast({
|
||||
title: '获取手机号失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// H5/App 微信登录(暂保持原有逻辑,后续可调整)
|
||||
const wxLogin = () => {
|
||||
if (!canSubmit.value) {
|
||||
$api.msg('请先完成上述选择并同意隐私协议');
|
||||
console.log('wxLogin called');
|
||||
console.log('userType:', userType.value, 'agreedToAgreement:', agreedToAgreement.value);
|
||||
|
||||
// 使用通用验证函数
|
||||
if (!validateForm()) {
|
||||
console.log('Validation failed in wxLogin');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Validation passed, proceeding with H5/App login');
|
||||
|
||||
// #ifdef H5
|
||||
// H5端跳转到H5登录页面
|
||||
uni.navigateTo({
|
||||
@@ -316,7 +387,11 @@ const wxLogin = () => {
|
||||
uni.setStorageSync('userInfo', userInfo);
|
||||
}
|
||||
|
||||
$api.msg('登录成功');
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
// 登录成功后返回上一页
|
||||
uni.navigateBack();
|
||||
});
|
||||
@@ -325,7 +400,11 @@ const wxLogin = () => {
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('微信登录失败:', err);
|
||||
$api.msg('微信登录失败');
|
||||
uni.showToast({
|
||||
title: '微信登录失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -336,11 +415,17 @@ const wxLogin = () => {
|
||||
|
||||
// 测试账号登录(仅开发环境)
|
||||
const testLogin = () => {
|
||||
if (!canSubmit.value) {
|
||||
$api.msg('请先完成上述选择并同意隐私协议');
|
||||
console.log('testLogin called');
|
||||
console.log('userType:', userType.value, 'agreedToAgreement:', agreedToAgreement.value);
|
||||
|
||||
// 使用通用验证函数
|
||||
if (!validateForm()) {
|
||||
console.log('Validation failed in testLogin');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Validation passed, proceeding with test login');
|
||||
|
||||
uni.showLoading({ title: '登录中...' });
|
||||
|
||||
const params = {
|
||||
@@ -359,15 +444,27 @@ const testLogin = () => {
|
||||
uni.setStorageSync('userInfo', userInfo);
|
||||
}
|
||||
|
||||
$api.msg('测试登录成功');
|
||||
uni.showToast({
|
||||
title: '测试登录成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
// 登录成功后返回上一页
|
||||
uni.navigateBack();
|
||||
}).catch(() => {
|
||||
$api.msg('获取用户信息失败');
|
||||
uni.showToast({
|
||||
title: '获取用户信息失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
});
|
||||
}).catch((err) => {
|
||||
uni.hideLoading();
|
||||
$api.msg(err.msg || '登录失败');
|
||||
uni.showToast({
|
||||
title: err.msg || '登录失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -547,6 +644,8 @@ onLoad(() => {
|
||||
&:disabled
|
||||
opacity: 0.5
|
||||
cursor: not-allowed
|
||||
background: #CCCCCC !important
|
||||
box-shadow: none !important
|
||||
|
||||
text
|
||||
margin-left: 12rpx
|
||||
|
||||
Reference in New Issue
Block a user