import { login } from "../../service/user"; import { alertError, alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index"; import request from "../../utils/request"; import Dialog from '@vant/weapp/dialog/dialog'; const { OK } = request; // pages/login/index.js Page({ /** * 页面的初始数据 */ data: { input: "", disabled: false, show: false, }, /** * 生命周期函数--监听页面加载 */ onLoad() { const user = wx.getStorageSync('user') if (!user || !user.id) { return; } // if (user.status === 0 || user.status === 2) { // wx.redirectTo({ // url: '/pages/waitApprove/index', // }) // return // } wx.switchTab({ url: '/pages/home/index', }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, onClose() { // wx.exitMiniProgram() }, onConfirm() { // this.handleLogin() }, async handleLogin(phoneCode) { loadingFunc(async () => { const wxLoginCode = await wxLogin() const result = await login({ code: wxLoginCode, phoneCode }) const { code, message, data } = result; if (code !== OK) { alertError(message) return } if (!data?.id) { this.noPermission() return; } alertSuccess("登录成功") const { token, ...user } = data wx.setStorageSync('user', user) wx.setStorageSync('token', data?.token) wx.switchTab({ url: '/pages/home/index', }) }) }, getPhoneNumber(e) { const { errno, code: phoneCode } = e.detail; switch(errno) { case 103: alertInfo("已拒绝"); return; case 1400001: alertInfo("服务达到上限") return; default: this.handleLogin(phoneCode) return; } }, onChangeAgree(e) { this.setData({ agree: e.detail }) }, beforeClose(e) { return false; }, noPermission() { Dialog.confirm({ title: '提示', message: '当前手机号不是用电管理联系账号', confirmButtonText: '手动绑定', cancelButtonText: '取消', }) .then(() => { // on confirm wx.navigateTo({ url: '/pages/handleLogin/index', }) }) .catch(() => { // on cancel }); }, jumpToUserAgreement() { wx.navigateTo({ url: '/pages/agreements/index', }) }, jumpToLoginAgreement() { }, jumpToSecret() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })