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.
171 lines
3.4 KiB
171 lines
3.4 KiB
3 weeks ago
|
const app = getApp<IAppOption>();
|
||
|
let timer: number | null = 0;
|
||
|
|
||
|
Page({
|
||
|
data: {
|
||
|
menuButtonInfo: {},
|
||
|
mobile: '',
|
||
|
code: '',
|
||
|
protool: false,
|
||
|
codeText: '发送验证码',
|
||
|
|
||
|
back: false,
|
||
|
|
||
|
type: '',
|
||
|
show: false,
|
||
|
},
|
||
|
onLoad(options) {
|
||
|
this.setData({
|
||
|
back: options.back === '1',
|
||
|
});
|
||
|
},
|
||
|
onShow() {
|
||
|
wx.hideShareMenu();
|
||
|
},
|
||
|
getCode() {
|
||
|
if (timer) return;
|
||
|
const mobile = this.data.mobile;
|
||
|
if (!mobile) {
|
||
|
wx.showToast({
|
||
|
title: '手机号不能为空',
|
||
|
icon: 'none',
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
// 验证手机号
|
||
|
if (!/^1[3-9,]\d{9}$/.test(mobile)) {
|
||
|
wx.showToast({
|
||
|
title: '手机号格式不正确',
|
||
|
icon: 'none',
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
wx.ajax({
|
||
|
method: 'POST',
|
||
|
url: '?r=shizhong/login/send-verify-code',
|
||
|
data: {
|
||
|
mobile,
|
||
|
},
|
||
|
}).then(() => {
|
||
|
wx.showToast({
|
||
|
icon: 'none',
|
||
|
title: '验证码已发送~',
|
||
|
});
|
||
|
let time = 60;
|
||
|
timer = setInterval(() => {
|
||
|
time--;
|
||
|
this.setData({
|
||
|
codeText: `${time}s后重新发送`,
|
||
|
});
|
||
|
if (time <= 0) {
|
||
|
clearInterval(timer as number);
|
||
|
timer = null;
|
||
|
this.setData({
|
||
|
codeText: '发送验证码',
|
||
|
});
|
||
|
}
|
||
|
}, 1000);
|
||
|
});
|
||
|
},
|
||
|
handleSubmit() {
|
||
|
const { show, mobile, code, protool } = this.data;
|
||
|
if (!protool && !show) {
|
||
|
this.setData({
|
||
|
type: 'login',
|
||
|
show: true,
|
||
|
});
|
||
|
return;
|
||
|
} else if (show) {
|
||
|
this.setData({
|
||
|
show: false,
|
||
|
protool: true,
|
||
|
});
|
||
|
}
|
||
|
if (!mobile) {
|
||
|
wx.showToast({
|
||
|
title: '请输入手机号',
|
||
|
icon: 'none',
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
if (!code) {
|
||
|
wx.showToast({
|
||
|
title: '请输入验证码',
|
||
|
icon: 'none',
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
wx.ajax({
|
||
|
method: 'POST',
|
||
|
url: '?r=shizhong/login/reg-login',
|
||
|
data: {
|
||
|
mobile,
|
||
|
code,
|
||
|
},
|
||
|
}).then(() => {
|
||
|
this.submitCallback();
|
||
|
});
|
||
|
},
|
||
|
handleWxSubmit(e: any) {
|
||
|
const { show, protool } = this.data;
|
||
|
if (!protool && !show) {
|
||
|
this.setData({
|
||
|
type: 'phone',
|
||
|
show: true,
|
||
|
});
|
||
|
return;
|
||
|
} else if (show) {
|
||
|
this.setData({
|
||
|
show: false,
|
||
|
protool: true,
|
||
|
});
|
||
|
}
|
||
|
const { iv, encryptedData } = e.detail;
|
||
|
if (iv && encryptedData) {
|
||
|
wx.ajax({
|
||
|
method: 'POST',
|
||
|
url: '?r=shizhong/login/wx-reg-login',
|
||
|
data: {
|
||
|
iv: encodeURIComponent(iv),
|
||
|
encryptedData: encodeURIComponent(encryptedData),
|
||
|
},
|
||
|
}).then(() => {
|
||
|
this.submitCallback();
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
submitCallback() {
|
||
|
app.globalData.isLogin = 1;
|
||
|
const backPath = app.globalData.backPath;
|
||
|
wx.reLaunch({ url: backPath || '/pages/home/index' });
|
||
|
app.globalData.backPath = '';
|
||
|
},
|
||
|
handleProtool() {
|
||
|
this.setData({
|
||
|
protool: !this.data.protool,
|
||
|
});
|
||
|
},
|
||
|
handleNavProtool() {
|
||
|
wx.navigateTo({ url: `/pages/protocol/index` });
|
||
|
},
|
||
|
handleVisitor() {
|
||
|
if (app.globalData.isLogin !== 1) {
|
||
|
app.globalData.isLogin = 999;
|
||
|
app.globalData.backPath = '';
|
||
|
}
|
||
|
wx.reLaunch({
|
||
|
url: '/pages/home/index',
|
||
|
});
|
||
|
},
|
||
|
handleCancel() {
|
||
|
this.setData({
|
||
|
show: false,
|
||
|
});
|
||
|
},
|
||
|
handleBack() {
|
||
|
wx.navigateBack();
|
||
|
},
|
||
|
});
|
||
|
|
||
|
export {};
|