锶源昆仑商城

This commit is contained in:
2023-07-22 19:01:37 +08:00
commit 4ba3377084
223 changed files with 10557 additions and 0 deletions

166
pages/login/index.js Normal file
View File

@@ -0,0 +1,166 @@
/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
phone : "",
code : "",
parentId: "", //邀请码
newUser : '', //是否为新用户
checked : false, //勾选协议
codename: '获取验证码',
getSms : false,
inviteata: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 是否有邀请码
if(options) {
this.setData({
channelId : options.channel || ''
})
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
if(wx.getStorageSync("inviteData")) {
this.setData({
parentId: wx.getStorageSync("inviteData")
})
}
},
/**
* 手机号码
*/
bindInput(e) {
this.setData({
phone: e.detail.value
})
},
/**
* 短信验证码
*/
bindCode(e) {
this.setData({
code: e.detail.value
})
},
/**
* 获取短信验证码
*/
getPhoneCode(e) {
let mobile = this.data.phone,
myreg = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/
var _this = this
if (mobile == "") {
wx.showToast({
title : '手机号不能为空',
icon : 'none',
duration : 1000
})
return false;
}else if (!myreg.test(mobile)) {
wx.showToast({
title : '请输入正确的手机号',
icon : 'none',
duration : 1000
})
return false;
}else{
wx.$api.auth.getSms({
mobileNo: mobile
}).then(res=>{
_this.setData({
newUser : res.data.new,
getSms : true
})
wx.showToast({
title : '发送成功',
icon : 'success',
duration: 2000
})
var num = 60;
var timer = setInterval(function () {
num--;
if (num <= 0) {
clearInterval(timer);
_this.setData({
codename : '重新发送',
getSms : false
})
} else {
_this.setData({
codename : num + "s后重新获取",
getSms : true
})
}
}, 1000)
}).catch(err=>{})
}
},
/**
* 邀请码
*/
parentInput(e) {
this.setData({
parentId: e.detail.value
})
},
/**
* 用户登录
*/
login() {
if(this.data.checked) {
wx.$api.auth.smsAuth({
mobileNo : this.data.phone,
code : this.data.code,
invite : this.data.parentId,
channel : this.data.channelId
}).then(res=>{
// 写入缓存
wx.setStorage({
key : 'token',
data : res.data.token_type + ' ' + res.data.access_token
})
// 回到首页
wx.switchTab({
url: '/pages/index/index'
})
}).catch(err=>{})
} else {
wx.showToast({
title: '请勾选用户隐私和服务协议',
icon: "none"
})
}
},
// 勾选协议
radioChange() {
this.setData({
checked: !this.data.checked
})
}
})