epmet 工作端 小程序
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.

148 lines
3.4 KiB

// pages/register/register.js
// 到入一个
import {userLoginlog} from "../../utils/api"
Page({
/**
* 页面的初始数据
*/
data: {
formData:{
mobile:'',
password:'',
appId:'wxaf87b420b87e2d79'
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
handelBlurMobile(e){
this.setData({
// 获取绑定过的值,付给fromData.mobile
'formData.mobile': e.detail.value
})
console.log(this.data.formData)
},
handelBlurPassword(e){
this.setData({
// 获取绑定过的值,付给fromData.password
'formData.password': e.detail.value
})
console.log(this.data.formData)
},
handelClickSubmit(){
if(!this.data.formData.mobile){
// 微信的轻量级api
wx.showToast({
title: '请填写手机号',
// 不显示图标
icon:'none',
duration:3000
})
return
}
if(!this.data.formData.password){
wx.showToast({
title: '请输入密码',
icon:'none',
// 提示时间为3s
duration:3000
})
return
}
//var和const的区别,一个可变,一个不可变,
// const 声明一个不可变的对象parm,并创建了对象
const parm = {
// wxCode对象的初始化
wxCode :'',
// ...将this.data.formData所有属性,赋值到表单中
...this.data.formData
}
// 轻量级api,在加载时进行显示
wx.showLoading({
title: '登录中',
})
//微信的api,获取登录凭证
// 在这一步骤中,用户获取凭证
wx.login({
success: (res) => {
parm.wxCode = res.code
console.log(parm.wxCode);
// 调用登录的接口
userLoginlog(parm).then((res)=>{
console.log(res);
// 不明白这里判断的是什么
if(res.code == 0){
// 用于跳转的api,跳转到某某某
wx.switchTab({
url: '/pages/index/index',
})
//加入本地内存的api
wx.setStorageSync('token', res.data.token)
}
}).catch(err=>{
wx.showToast({
title: res.msg,
icon:'none',
duration:3000
})
console.log(err);
})
wx.hideLoading()
},
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})