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.

163 lines
3.6 KiB

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