You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.2 KiB

5 months ago
const app = getApp<IAppOption>();
let timer: number | null = 0;
5 months ago
Page({
5 months ago
data: {
5 months ago
show: false,
5 months ago
menuButtonInfo: {},
5 months ago
mobile: '',
code: '',
5 months ago
protool: false,
5 months ago
codeText: '发送验证码',
5 months ago
},
5 months ago
onLoad() {},
5 months ago
getCode() {
if (timer) return;
const mobile = this.data.mobile;
if (!mobile) {
wx.showToast({
5 months ago
title: '手机号不能为空',
icon: 'none',
5 months ago
});
return;
}
// 验证手机号
if (!/^1[3-9,]\d{9}$/.test(mobile)) {
wx.showToast({
5 months ago
title: '手机号格式不正确',
icon: 'none',
5 months ago
});
return;
}
wx.ajax({
5 months ago
method: 'POST',
5 months ago
url: '?r=shizhong/login/send-verify-code',
5 months ago
data: {
mobile,
},
}).then(() => {
wx.showToast({
5 months ago
icon: 'none',
title: '验证码已发送~',
5 months ago
});
let time = 60;
timer = setInterval(() => {
time--;
this.setData({
codeText: `${time}s后重新发送`,
});
if (time <= 0) {
clearInterval(timer as number);
timer = null;
this.setData({
5 months ago
codeText: '发送验证码',
5 months ago
});
}
}, 1000);
});
},
handleSubmit() {
const { mobile, code, protool } = this.data;
if (!protool) {
5 months ago
wx.showToast({
icon: 'none',
title: '请先同意用户隐私协议',
});
5 months ago
return;
}
if (!mobile) {
wx.showToast({
5 months ago
title: '请输入手机号',
icon: 'none',
5 months ago
});
return;
}
if (!code) {
wx.showToast({
5 months ago
title: '请输入验证码',
icon: 'none',
5 months ago
});
return;
}
wx.ajax({
5 months ago
method: 'POST',
5 months ago
url: '?r=shizhong/login/reg-login',
5 months ago
data: {
mobile,
code,
},
}).then(() => {
this.submitCallback();
5 months ago
});
},
handleWxSubmit(e: any) {
const { protool } = this.data;
if (!protool) {
5 months ago
wx.showToast({
icon: 'none',
title: '请先同意用户隐私协议',
});
5 months ago
return;
}
const { iv, encryptedData } = e.detail;
5 months ago
if (iv && encryptedData) {
wx.ajax({
5 months ago
method: 'POST',
5 months ago
url: '?r=shizhong/login/wx-reg-login',
5 months ago
data: {
iv: encodeURIComponent(iv),
encryptedData: encodeURIComponent(encryptedData),
},
}).then(() => {
this.submitCallback();
5 months ago
});
}
},
submitCallback() {
5 months ago
app.globalData.isLogin = 1;
app.getUserInfo(null, (res) => {
app.globalData.isAnswer = res.isAnswer;
if (res.isAnswer === '0') {
this.setData({
show: true,
});
} else {
wx.reLaunch({ url: '/pages/home/index' });
}
5 months ago
});
},
handleProtool() {
5 months ago
this.setData({
protool: !this.data.protool,
});
5 months ago
},
5 months ago
handleNavProtool() {
wx.navigateTo({ url: `/pages/protocol/index` });
5 months ago
},
handleTopic() {
wx.reLaunch({
url: '/pages/topic/index',
});
},
5 months ago
handleCancelTopic() {
app.globalData.isAnswer = '1';
wx.reLaunch({
url: '/pages/home/index',
});
},
handleVisitor() {
app.globalData.isLogin = 999;
wx.reLaunch({
url: '/pages/home/index',
5 months ago
});
},
5 months ago
});
5 months ago
export {};