// pages/login/login.js const app = getApp(); const { system, router_zero, router_one, router_two, router_thr, router_four, router_five, router_six, type } = require('../../utils/dict'); const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0' Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '个人中心', leftArrow: false, useBar: false }, // 主体高度 infoHeight: '', avatarUrl: defaultAvatarUrl, userInfo: {}, routerList: [] }, // 获取头像 onChooseAvatar(e) { const { avatarUrl } = e.detail; console.log(avatarUrl); this.setData({ avatarUrl }) }, // 跳转页面 toPath: function (e) { const { data } = e.currentTarget.dataset; // 绑定微信 if (data.is_routine && data.is_routine == '1') { wx.showModal({ content: '您确定使用此微信绑定当前登录账号吗?', title: '绑定微信', success: (res) => { if (res.confirm) { wx.showToast({ title: `绑定微信成功`, icon: 'success', duration: 2000 }) } }, }) // wx.getStorage({ // key: 'user', // success: res => { // if (res.data) { // const { openid } = app.globalData.wxInfo; // wx.request({ // url: app.globalData.publicUrl + `/api/hc/user/update/${res.data.id}`, // method: "post", // data: { openid: openid }, // header: {}, // success: (res) => { // if (res.data.errcode == '0') { // wx.showToast({ title: `绑定微信成功`, icon: 'success', duration: 2000 }) // } else { // wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 }) // } // }, // }) // } // } // }) } else if (data.is_routine && data.is_routine == '2') { wx.clearStorage({ key: 'user', success: res => { wx.showToast({ title: `退出登录成功`, icon: 'success', duration: 2000 }) wx.redirectTo({ url: '/pages/login/index', }) } }) } else { wx.navigateTo({ url: `/pages/${data.router}/index` }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 监听用户是否登录 this.watchLogin(); // 计算高度 this.searchHeight(); }, // 监听用户是否登录 watchLogin: function () { let data = { type: '4' } this.searchRouter(data); // wx.getStorage({ // key: 'user', // success: res => { // if (res.data) { // // 查询菜单 // if (res.data) this.searchRouter(res.data); // res.data.type = type.find((i) => i.value == res.data.type).label; // if (res.data) this.setData({ userInfo: res.data }); // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl }); // } else { // wx.redirectTo({ url: '/pages/login/index', }) // } // } // }) }, // 计算高度 searchHeight: function () { let frameStyle = this.data.frameStyle; let client = app.globalData.client; // 减去状态栏 let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2); // 是否减去底部菜单 if (frameStyle.useBar) infoHeight = infoHeight - 50; if (infoHeight) this.setData({ infoHeight: infoHeight }) }, // 查询菜单 searchRouter(data) { // { value: '0', label: '超级管理员' }, // { value: '1', label: '科室人员' }, // { value: '2', label: '办公室人员' }, // { value: '3', label: '采购部门' }, // { value: '4', label: '入库管理部门' }, // { value: '5', label: '财务部门' }, // { value: '6', label: '供货单位' }, var router = []; if (data.type == '0') { router = [...router_zero, ...system] } else if (data.type == '1') { router = [...router_one, ...system] } else if (data.type == '2') { router = [...router_two, ...system] } else if (data.type == '3') { router = [...router_thr, ...system] } else if (data.type == '4') { router = [...router_four, ...system] } else if (data.type == '5') { router = [...router_five, ...system] } else if (data.type == '6') { router = [...router_six, ...system] } this.setData({ routerList: router }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })