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.
 
 
 
 

132 lines
2.4 KiB

// pages/login/login.js
import { loginUrl } from "../../utils/getApiUrl";
import { Request } from "../../common";
Page({
/**
* 页面的初始数据
*/
data: {
scene: null,
},
// 登录
getLogin: function (e) {
if (e.detail.value.username.length == 0 || e.detail.value.password == 0) {
wx.showToast({
title: '请输入账号密码',
icon: 'none',
})
return
}
wx.showLoading()
Request.post(loginUrl(), {
"username": e.detail.value.username,
"password": e.detail.value.password
}).then((res) => {
if (!res.authorized) {
wx.showToast({ title: "登录失败", icon: "none" });
return;
}
wx.setStorageSync('token', res.token);
wx.setStorageSync("userInfo", res);
getApp().globalData.userInfo = res
wx.hideLoading()
if (this.data.scene) {
wx.redirectTo({
url: `/package/startInspection/startInspection?scene=${this.data.scene}`,
})
return;
}
wx.switchTab({
url: '/pages/index/index',
})
})
},
bindForget() {
wx.showModal({
title: '温馨提示',
content: '请联系管理员:18888888888',
confirmText: '拨打电话',
confirmColor: '#488EFF',
cancelColor: '#488EFF',
success(res) {
if (res.confirm) {
wx.makePhoneCall({
phoneNumber: "18888888888",
success: function () {
console.log("拨打电话成功!")
},
fail: function () {
console.log("拨打电话失败!")
}
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let that = this;
const { scene } = options;
if (scene) {
that.setData({
scene
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})