qingcheng-xiaochengxu/pages/logain/logain.js

316 lines
7.0 KiB
JavaScript
Raw Normal View History

2025-05-11 07:12:01 +00:00
import {url} from '../../request'
2025-04-28 07:59:21 +00:00
Page({
data: {
show: true,
morenshow: false,
currentTab: 'code',
},
2025-05-11 07:12:01 +00:00
// 初始加载
2025-04-28 07:59:21 +00:00
onShow(){
this.setData({
show: false,
morenshow: true,
currentTab: 'password'
})
},
2025-05-11 07:12:01 +00:00
// 账号密码登录
2025-04-28 07:59:21 +00:00
showchange() {
this.setData({
show: true,
morenshow: false,
currentTab: 'code'
})
},
2025-05-11 07:12:01 +00:00
// 注册界面
2025-04-28 07:59:21 +00:00
gozucepage(){
wx.navigateTo({
url: '/pages/zucepage/zucepage',
})
},
2025-05-11 07:12:01 +00:00
yanzhengphone(e){
this.setData({
yanzhengphone: e.detail.value
})
console.log(e.detail.value);
},
yanzhengcode(e){
this.setData({
yanzhengcode: e.detail.value
})
console.log(e.detail.value);
},
// 账号登录账号
bindKeyInput(e){
this.setData({
inputValue: e.detail.value
})
console.log(e.detail.value);
},
// 账号登录密码
bindKeyInputpassword(e){
this.setData({
inputValuepassword: e.detail.value
})
console.log(e.detail.value);
},
// 验证码登录
2025-04-28 07:59:21 +00:00
showchangeback() {
this.setData({
show: false,
morenshow: true,
currentTab: 'password'
})
},
2025-05-11 07:12:01 +00:00
// 忘记密码
2025-04-28 07:59:21 +00:00
wangji() {
wx.navigateTo({
url: '/pages/wangjimima/wangjimima',
})
2025-05-11 07:12:01 +00:00
},
// 账号密码登录提交
submit(){
const that = this
const phone = this.data.inputValue;
const password = this.data.inputValuepassword;
2025-05-15 01:40:36 +00:00
console.log(password,'isdjidasjiodaso');
2025-05-11 07:12:01 +00:00
// 手机号验证6~11位数字
if (!/^\d{6,11}$/.test(phone)) {
wx.showToast({
title: '请输入6到11位的账号',
icon: 'none'
});
return;
}
// 密码验证6~10位字符
2025-05-15 01:40:36 +00:00
if (!/^[a-zA-Z0-9]{6,10}$/.test(password)) {
2025-05-11 07:12:01 +00:00
wx.showToast({
2025-05-15 01:40:36 +00:00
title: '请输入6到10位密码',
2025-05-11 07:12:01 +00:00
icon: 'none'
});
return;
}
// 勾选校验
if (this.data.isAgree!=true) {
wx.showToast({
title: '请先勾选协议',
icon: 'none'
});
return;
2025-04-28 07:59:21 +00:00
}
2025-05-11 07:12:01 +00:00
console.log("sakldhasjdhja");
wx.request({
url: url + '/userInfo/mini/pwd/login',
method: 'POST',
data: {
phoneNumber: this.data.inputValue,
userPassword: this.data.inputValuepassword
},
header: {
2025-05-15 01:40:36 +00:00
'content-type': 'application/json',
2025-05-11 07:12:01 +00:00
},
success(res) {
console.log('登录成功', res);
if(res.data.code==1){
2025-05-15 01:40:36 +00:00
console.log(res.data.data,'zhehsidata');
2025-05-11 07:12:01 +00:00
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000
});
wx.setStorage({
key: "logmessage",
data: {
Authorization:res.data.data
},
success() {
console.log("信息存储成功");
}
})
setTimeout(() => {
that.setmessage();
wx.switchTab({
url: '/pages/jiedan/jiedan',
});
}, 2000);
}else{
wx.showToast({
title: res.data.message,
icon: 'error',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
},
// 勾选
onAgreeChange(e) {
this.setData({
isAgree: true
});
console.log("gaibianler",this.data.isAgree);
},
// 获取验证码
getcode(){
const phone = this.data.yanzhengphone;
if (!/^\d{11}$/.test(phone)) {
wx.showToast({
title: '请输入11位的手机号',
icon: 'none'
});
return;
}
wx.request({
url: url + '/userInfo/code',
method: 'POST',
data: {
templateString: this.data.yanzhengphone
},
header: {
2025-05-15 01:40:36 +00:00
'content-type': 'application/json',
2025-05-11 07:12:01 +00:00
},
success(res) {
console.log('发送成功', res);
if(res.data.code==1){
wx.showToast({
title: '发送成功',
icon: 'success',
duration: 2000
});
}else{
wx.showToast({
title: res.data.message,
icon: 'success',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
},
// 验证码登录提交
submityanzhengma(){
const _this = this;
const code = this.data.yanzhengcode
if (!/^\d{6}$/.test(code)) {
wx.showToast({
title: '请输入6位的有效验证码',
icon: 'none'
});
return;
}
if (this.data.isAgree!=true) {
wx.showToast({
title: '请先勾选协议',
icon: 'none'
});
return;
}
console.log("sakldhasjdhja");
wx.request({
url: url + '/userInfo/mini/vcd/login',
method: 'POST',
data: {
phoneNumber: this.data.yanzhengphone,
verificationCode: this.data.yanzhengcode
},
header: {
2025-05-15 01:40:36 +00:00
'content-type': 'application/json',
2025-05-11 07:12:01 +00:00
},
success(res) {
console.log('登录成功', res);
if(res.data.code==1){
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000
});
wx.setStorage({
key: "logmessage",
data: {
Authorization:res.data.data
},
success() {
console.log("信息存储成功");
}
})
setTimeout(() => {
_this.setmessage();
wx.switchTab({
url: '/pages/jiedan/jiedan',
});
}, 2000);
}else{
wx.showToast({
title: res.data.message,
icon: 'error',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
},
setmessage() {
2025-05-15 01:40:36 +00:00
console.log("diaoyongle ");
2025-05-11 07:12:01 +00:00
const that = this;
wx.getStorage({
key: "logmessage",
success(res) {
console.log(res.data, 'sajlkdlasjdkl');
const userinfo = res.data;
2025-05-15 01:40:36 +00:00
console.log(userinfo,'这是获取的');
2025-05-11 07:12:01 +00:00
wx.request({
url: url + '/userInfo/get/jwt',
method: 'GET',
data: {},
header: {
'content-type': 'application/json',
'Authorization': userinfo.Authorization
},
success(res) {
console.log('查询成功', res);
if (res.data.code==1) {
wx.setStorage({
key: "usermessage",
data: {
nickName:res.data.data.nickName,
phoneNumber:res.data.data.phoneNumber,
userRole:res.data.data.userRole,
invitationCode:res.data.data.invitationCode,
userAvatar:res.data.data.userAvatar
},
success() {
console.log("信息存储成功");
}
})
} else {
wx.showToast({
title: res.data.message,
icon: 'error',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
},
fail(err) {
console.error("获取 logmessage 失败", err);
}
});
}
2025-04-28 07:59:21 +00:00
})