|
|
|
|
@ -19,7 +19,7 @@
|
|
|
|
|
手机号
|
|
|
|
|
</div>
|
|
|
|
|
<uv-input v-model="userInfo.phone" color="#000" border="bottom"
|
|
|
|
|
:placeholderStyle="{ color: '#666778' }" placeholder="请输入用户名"></uv-input>
|
|
|
|
|
:placeholderStyle="{ color: '#666778' }" placeholder="请输入手机号"></uv-input>
|
|
|
|
|
</uv-form-item>
|
|
|
|
|
<uv-form-item prop="password">
|
|
|
|
|
<div class="formLabel">
|
|
|
|
|
@ -29,7 +29,7 @@
|
|
|
|
|
<uv-input v-model="userInfo.password" color="#000" border="bottom"
|
|
|
|
|
:placeholderStyle="{ color: '#666778' }" placeholder="请输入验证码">
|
|
|
|
|
<template v-slot:suffix>
|
|
|
|
|
<uv-code ref="codeRef" @change="codeChange" seconds="20" changeText="X秒重新获取"></uv-code>
|
|
|
|
|
<uv-code ref="codeRef" @change="codeChange" seconds="60" changeText="X秒重新获取"></uv-code>
|
|
|
|
|
<text style="color: #4d82fd" @click="getCode">{{ tips }}</text>
|
|
|
|
|
</template>
|
|
|
|
|
</uv-input>
|
|
|
|
|
@ -84,10 +84,11 @@
|
|
|
|
|
</uv-button>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</uv-popup>
|
|
|
|
|
<a style="display: none;" ref="ToLoginRef" href="weixin://dl/business/?appid=wxc504638e03981812&path=pages/login/login?from=h5ToWechat">
|
|
|
|
|
打开小程序并登录
|
|
|
|
|
</a>
|
|
|
|
|
</uv-popup>
|
|
|
|
|
<!-- <a style="display: none;" ref="ToLoginRef"
|
|
|
|
|
href="weixin://dl/business/?appid=wxc504638e03981812&path=pages/login/login?from=h5ToWechat">
|
|
|
|
|
打开小程序并登录
|
|
|
|
|
</a> -->
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
@ -146,8 +147,8 @@
|
|
|
|
|
message: "请输入验证码",
|
|
|
|
|
trigger: ["blur", "change"],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const ToLoginRef = ref(null)
|
|
|
|
|
|
|
|
|
|
const tips = ref("获取验证码");
|
|
|
|
|
@ -156,9 +157,17 @@
|
|
|
|
|
};
|
|
|
|
|
const codeRef = ref(null);
|
|
|
|
|
const getCode = () => {
|
|
|
|
|
if (!userInfo.phone) {
|
|
|
|
|
if (!userInfo.value.phone) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "请填写手机号",
|
|
|
|
|
title: "请输入手机号",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!/^1[3-9]\d{9}$/.test(userInfo.value.phone)) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "请输入正确的手机号",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
@ -168,16 +177,22 @@
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: "正在获取验证码",
|
|
|
|
|
});
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
// 这里此提示会被this.start()方法中的提示覆盖
|
|
|
|
|
RPC.post('/login/phone/send_code', {
|
|
|
|
|
phone: userInfo.value.phone,
|
|
|
|
|
}).then(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "验证码已发送",
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
// 通知验证码组件内部开始倒计时
|
|
|
|
|
codeRef.value.start();
|
|
|
|
|
}, 2000);
|
|
|
|
|
title: '验证码已发送',
|
|
|
|
|
icon: 'success'
|
|
|
|
|
})
|
|
|
|
|
codeRef.value.start()
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '发送失败,请重试',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "倒计时结束后再发送",
|
|
|
|
|
@ -211,11 +226,12 @@
|
|
|
|
|
});
|
|
|
|
|
let redirect = HOME_PATH;
|
|
|
|
|
onLoad((options) => {
|
|
|
|
|
if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
|
|
|
|
|
if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
|
|
|
|
|
if(decodeURIComponent(options.redirect) && decodeURIComponent(options.redirect) != 'undefined')
|
|
|
|
|
redirect = decodeURIComponent(options.redirect);
|
|
|
|
|
}
|
|
|
|
|
if(options.from && options.from === 'h5ToWechat') {
|
|
|
|
|
XcxLogin()
|
|
|
|
|
}
|
|
|
|
|
if (options.from && options.from === 'h5ToWechat') {
|
|
|
|
|
XcxLogin()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -228,9 +244,9 @@
|
|
|
|
|
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
// H5环境,检查是否在微信内
|
|
|
|
|
const ua = navigator.userAgent.toLowerCase();
|
|
|
|
|
const isWechat = ua.indexOf("micromessenger") !== -1;
|
|
|
|
|
showWechatLogin.value = isWechat;
|
|
|
|
|
// const ua = navigator.userAgent.toLowerCase();
|
|
|
|
|
// const isWechat = ua.indexOf("micromessenger") !== -1;
|
|
|
|
|
// showWechatLogin.value = isWechat;
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
@ -250,19 +266,23 @@
|
|
|
|
|
js_code: loginRes.code
|
|
|
|
|
}).then(res => {
|
|
|
|
|
console.log('phonelogin', res)
|
|
|
|
|
authStore.setAccessToken(res.token)
|
|
|
|
|
userStore.setUserInfo(res.user)
|
|
|
|
|
if(!res.user.phone) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "登录成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
uni.$uv.route({
|
|
|
|
|
type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
|
|
|
|
|
url: redirect,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
popup.value.open()
|
|
|
|
|
if (res.user.phone) {
|
|
|
|
|
authStore.setAccessToken(res.token)
|
|
|
|
|
userStore.setUserInfo(res.user)
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "登录成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
uni.$uv.route({
|
|
|
|
|
type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" :
|
|
|
|
|
"redirectTo",
|
|
|
|
|
url: redirect || HOME_PATH,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
accessToken.value = res.token
|
|
|
|
|
accessUserInfo.value = res.user
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
popup.value.open()
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
@ -291,7 +311,7 @@
|
|
|
|
|
// H5微信登录
|
|
|
|
|
if (typeof WeixinJSBridge !== "undefined") {
|
|
|
|
|
// 在微信内,使用微信JS-SDK进行授权登录
|
|
|
|
|
// wechatH5Login();
|
|
|
|
|
// wechatH5Login();
|
|
|
|
|
ToLoginRef.value.click()
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
@ -324,35 +344,28 @@
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: "正在获取验证码",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 调用发送验证码API
|
|
|
|
|
// RPC.post('/api/sms/send', {
|
|
|
|
|
// phone: bindPhoneInfo.value.phone,
|
|
|
|
|
// type: 'bind'
|
|
|
|
|
// }).then(() => {
|
|
|
|
|
// uni.hideLoading()
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
// title: '验证码已发送',
|
|
|
|
|
// icon: 'success'
|
|
|
|
|
// })
|
|
|
|
|
// bindCodeRef.value.start()
|
|
|
|
|
// }).catch(() => {
|
|
|
|
|
// uni.hideLoading()
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
// title: '发送失败,请重试',
|
|
|
|
|
// icon: 'none'
|
|
|
|
|
// })
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// 模拟发送验证码
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
RPC.post('/user/bind_phone/send_code', {
|
|
|
|
|
phone: bindPhoneInfo.value.phone,
|
|
|
|
|
token: accessToken.value
|
|
|
|
|
}, {
|
|
|
|
|
custom: {
|
|
|
|
|
customToken: accessToken.value
|
|
|
|
|
}
|
|
|
|
|
}).then(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "验证码已发送",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
bindCodeRef.value.start();
|
|
|
|
|
}, 1500);
|
|
|
|
|
title: '验证码已发送',
|
|
|
|
|
icon: 'success'
|
|
|
|
|
})
|
|
|
|
|
bindCodeRef.value.start()
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '发送失败,请重试',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "倒计时结束后再发送",
|
|
|
|
|
@ -399,6 +412,9 @@
|
|
|
|
|
// #endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const accessToken = ref('')
|
|
|
|
|
const accessUserInfo = ref({})
|
|
|
|
|
|
|
|
|
|
// 处理微信H5授权回调
|
|
|
|
|
const handleWechatH5Callback = async (code) => {
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
@ -410,30 +426,32 @@
|
|
|
|
|
// 调用后端接口,通过code获取用户信息
|
|
|
|
|
// const result = await RPC.post('/api/wechat/h5-login', {
|
|
|
|
|
// code: code
|
|
|
|
|
// });
|
|
|
|
|
RPC.post('/login/wechat_mini', {
|
|
|
|
|
js_code: loginRes.code
|
|
|
|
|
}).then(res => {
|
|
|
|
|
console.log('phonelogin', res)
|
|
|
|
|
authStore.setAccessToken(res.token)
|
|
|
|
|
userStore.setUserInfo(res.user)
|
|
|
|
|
if(!res.user.phone) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "登录成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
uni.$uv.route({
|
|
|
|
|
type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
|
|
|
|
|
url: redirect,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
popup.value.open()
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "登录失败",
|
|
|
|
|
icon: "error",
|
|
|
|
|
});
|
|
|
|
|
// });
|
|
|
|
|
RPC.post('/login/wechat_mini', {
|
|
|
|
|
js_code: loginRes.code
|
|
|
|
|
}).then(res => {
|
|
|
|
|
console.log('phonelogin', res)
|
|
|
|
|
if (res.user.phone) {
|
|
|
|
|
authStore.setAccessToken(res.token)
|
|
|
|
|
userStore.setUserInfo(res.user)
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "登录成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
uni.$uv.route({
|
|
|
|
|
type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" : "redirectTo",
|
|
|
|
|
url: redirect || HOME_PATH,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
accessToken.value = res.token
|
|
|
|
|
accessUserInfo.value = res.user
|
|
|
|
|
popup.value.open()
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "登录失败",
|
|
|
|
|
icon: "error",
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 模拟获取用户信息
|
|
|
|
|
@ -507,35 +525,32 @@
|
|
|
|
|
bindingPhone.value = true;
|
|
|
|
|
|
|
|
|
|
// 调用绑定手机号API
|
|
|
|
|
// const result = await RPC.post('/api/wechat/bind-phone', {
|
|
|
|
|
// phone: bindPhoneInfo.value.phone,
|
|
|
|
|
// code: bindPhoneInfo.value.code,
|
|
|
|
|
// wechatCode: wechatLoginCode // 微信登录返回的code
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// 模拟绑定过程
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
RPC.post('/user/bind_phone', {
|
|
|
|
|
phone: bindPhoneInfo.value.phone,
|
|
|
|
|
code: bindPhoneInfo.value.code,
|
|
|
|
|
token: accessToken.value
|
|
|
|
|
},{
|
|
|
|
|
custom: {
|
|
|
|
|
customToken: accessToken.value
|
|
|
|
|
}
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
console.log('bind_phone', res)
|
|
|
|
|
bindingPhone.value = false;
|
|
|
|
|
|
|
|
|
|
authStore.setAccessToken(accessToken.value)
|
|
|
|
|
userStore.setUserInfo(accessUserInfo.value)
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "绑定成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 设置登录状态
|
|
|
|
|
authStore.setAccessToken("wechat_access_token");
|
|
|
|
|
// userStore.setUserInfo(result.userInfo)
|
|
|
|
|
|
|
|
|
|
closeBindPhoneModal();
|
|
|
|
|
|
|
|
|
|
// 跳转到首页
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
closeBindPhoneModal()
|
|
|
|
|
uni.$uv.route({
|
|
|
|
|
type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
|
|
|
|
|
url: redirect,
|
|
|
|
|
type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" :
|
|
|
|
|
"redirectTo",
|
|
|
|
|
url: redirect || HOME_PATH,
|
|
|
|
|
});
|
|
|
|
|
}, 1000);
|
|
|
|
|
}, 2000);
|
|
|
|
|
}, 500);
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("绑定手机号失败:", error);
|
|
|
|
|
bindingPhone.value = false;
|
|
|
|
|
@ -571,9 +586,9 @@
|
|
|
|
|
// url: redirect,
|
|
|
|
|
// });
|
|
|
|
|
// })
|
|
|
|
|
RPC.post('/login', {
|
|
|
|
|
username: userInfo.value.phone,
|
|
|
|
|
password: userInfo.value.password,
|
|
|
|
|
RPC.post('/login/phone', {
|
|
|
|
|
phone: userInfo.value.phone,
|
|
|
|
|
code: userInfo.value.password,
|
|
|
|
|
}, {
|
|
|
|
|
custom: {
|
|
|
|
|
loading: true,
|
|
|
|
|
@ -588,8 +603,8 @@
|
|
|
|
|
.then((res) => {
|
|
|
|
|
userStore.setUserInfo(res)
|
|
|
|
|
uni.$uv.route({
|
|
|
|
|
type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
|
|
|
|
|
url: redirect,
|
|
|
|
|
type: isTabBarPath(redirect || HOME_PATH) ? "switchTab" : "redirectTo",
|
|
|
|
|
url: redirect || HOME_PATH,
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
@ -607,8 +622,8 @@
|
|
|
|
|
// // #ifdef MP-WEIXIN
|
|
|
|
|
// // 检查是否是微信授权回调
|
|
|
|
|
// const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
|
// const code = urlParams.get("code");
|
|
|
|
|
// const from = urlParams.get("from");
|
|
|
|
|
// const code = urlParams.get("code");
|
|
|
|
|
// const from = urlParams.get("from");
|
|
|
|
|
// console.log('from',from)
|
|
|
|
|
// if (from && from === 'h5') {
|
|
|
|
|
// handleWechatH5Callback(code);
|
|
|
|
|
|