创建新的小程序,进出码,体温上报功能迁移基本完成
This commit is contained in:
129
weixin-miniprogram/pages/index/login.js
Normal file
129
weixin-miniprogram/pages/index/login.js
Normal file
@@ -0,0 +1,129 @@
|
||||
// pages/index/login.js
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
username: '',
|
||||
password: '',
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
},
|
||||
|
||||
|
||||
bindKeyInput: function (e) {
|
||||
// console.log('e', e)
|
||||
let newData = {}
|
||||
newData[e.target.id] = e.detail.value
|
||||
this.setData(newData)
|
||||
},
|
||||
|
||||
login() {
|
||||
console.log("login userInput", this.data.username, this.data.password)
|
||||
if (!this.data.username || !this.data.password) {
|
||||
wx.showToast({
|
||||
title: "请完善登录信息",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
} else {
|
||||
wx.showLoading({
|
||||
title: '加载中'
|
||||
})
|
||||
wx.request({
|
||||
url: `${app.globalData.baseUrl}/user/login`,
|
||||
method: "POST",
|
||||
header: {
|
||||
"Content-Type": "application/x-www-form-urlencoded" //用于post
|
||||
},
|
||||
data: {
|
||||
username: this.data.username,
|
||||
password: this.data.password,
|
||||
},
|
||||
success: function (d) {
|
||||
wx.hideLoading()
|
||||
let result = d.data;
|
||||
if (result.success) {
|
||||
// 登录成功
|
||||
wx.setStorageSync("userInfo", result.data.userInfo);
|
||||
console.log("userInfo", wx.getStorageSync("userInfo"))
|
||||
wx.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: result.msg,
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: function () {
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: "请求失败",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user