qingcheng-xiaochengxu/pages/logain/logain.js

344 lines
7.7 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-15 13:01:14 +00:00
countdown: 60, // 设置倒计时时长(秒)
timer: null, // 存储计时器
},
startCountdown() {
this.setData({
isCountingDown: true,
countdown: 60
});
this.data.timer = setInterval(() => {
let count = this.data.countdown;
if (count <= 1) {
clearInterval(this.data.timer);
this.setData({
isCountingDown: false,
countdown: 60
});
} else {
this.setData({
countdown: count - 1
});
}
}, 1000);
},
onUnload() {
// 页面卸载时清除定时器
if (this.data.timer) {
clearInterval(this.data.timer);
}
2025-04-28 07:59:21 +00:00
},
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
});
2025-05-15 13:01:14 +00:00
try {
wx.setStorageSync('logmessage', {
Authorization: res.data.data
});
console.log("信息存储成功");
} catch (e) {
console.error("存储失败", e);
}
2025-05-16 01:58:51 +00:00
that.setmessage(() => {
2025-05-11 07:12:01 +00:00
wx.switchTab({
url: '/pages/jiedan/jiedan',
});
2025-05-16 01:58:51 +00:00
});
2025-05-11 07:12:01 +00:00
}else{
wx.showToast({
2025-05-15 13:01:14 +00:00
title: res.data.message||res.data.error,
2025-05-11 07:12:01 +00:00
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,
2025-05-15 13:01:14 +00:00
icon: 'error',
2025-05-11 07:12:01 +00:00
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
2025-05-15 13:01:14 +00:00
this.startCountdown();
2025-05-11 07:12:01 +00:00
},
// 验证码登录提交
submityanzhengma(){
2025-05-16 01:58:51 +00:00
const that = this;
2025-05-11 07:12:01 +00:00
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
});
2025-05-15 13:01:14 +00:00
try {
wx.setStorageSync('logmessage', {
Authorization: res.data.data
});
console.log("信息存储成功");
} catch (e) {
console.error("存储失败", e);
}
2025-05-16 01:58:51 +00:00
that.setmessage(() => {
2025-05-11 07:12:01 +00:00
wx.switchTab({
url: '/pages/jiedan/jiedan',
});
2025-05-16 01:58:51 +00:00
});
2025-05-11 07:12:01 +00:00
}else{
wx.showToast({
2025-05-15 13:01:14 +00:00
title: res.data.message||res.data.error,
2025-05-11 07:12:01 +00:00
icon: 'error',
duration: 2000
});
}
},
fail(err) {
console.error('请求失败', err);
}
});
},
2025-05-16 01:58:51 +00:00
setmessage(callback) {
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) {
2025-05-15 13:01:14 +00:00
try {
wx.setStorageSync("usermessage", {
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
});
console.log("信息存储成功");
2025-05-16 01:58:51 +00:00
if (callback) callback();
2025-05-15 13:01:14 +00:00
} catch (e) {
console.error("信息存储失败", e);
}
2025-05-11 07:12:01 +00:00
} 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
})