73 lines
1.3 KiB
JavaScript
73 lines
1.3 KiB
JavaScript
import request from '~/api/request';
|
|
import { resetTokenInvalid } from '~/api/request';
|
|
import { aesCryptoJS } from '~/utils/util';
|
|
|
|
Page({
|
|
data: {
|
|
|
|
mobile: '',//13888888888
|
|
password: '',//doctor2025
|
|
showPassword: false,
|
|
},
|
|
|
|
|
|
|
|
onLoad(options) {
|
|
|
|
},
|
|
bindKeyInput(e) {
|
|
const { mode } = e.currentTarget.dataset;
|
|
this.setData({
|
|
[mode]: e.detail.value
|
|
})
|
|
},
|
|
async login() {
|
|
// 验证手机号
|
|
if (!this.data.mobile) {
|
|
wx.showToast({
|
|
title: '请输入手机号',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
// 验证手机号格式
|
|
if (!/^1[3-9]\d{9}$/.test(this.data.mobile)) {
|
|
wx.showToast({
|
|
title: '请输入正确的手机号',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
// 验证验证码
|
|
if (!this.data.password) {
|
|
wx.showToast({
|
|
title: '请输入密码',
|
|
icon: 'none'
|
|
});
|
|
return;
|
|
}
|
|
|
|
resetTokenInvalid()
|
|
const res = await request('doctor/login', 'post', {
|
|
password: aesCryptoJS(this.data.password),
|
|
mobile: this.data.mobile
|
|
});
|
|
await wx.setStorageSync('access_token', res.token);
|
|
wx.navigateBack({
|
|
delta: 1
|
|
});
|
|
|
|
},
|
|
toBack() {
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
});
|
|
},
|
|
|
|
togglePassword() {
|
|
this.setData({
|
|
showPassword: !this.data.showPassword
|
|
});
|
|
},
|
|
});
|