// pages/index/index.ts import { httpUtil } from "../../utils/restful"; import { loginType } from '../../utils/loginType'; import { ConstsData } from "../../utils/const" import { storage } from "../../utils/storageUtil" Page({ /** * 页面的初始数据 */ data: { init: false, userType: '', userRole: '', teacherEnable: false, installerEnable: false, repairmanEnable: false, itEnable: false }, /** * 生命周期函数--监听页面加载 */ onLoad() { }, onShow() { httpUtil.wxGet(httpUtil.interfaces.getOrganizeAll, null).then((res: any) => { ConstsData.AppData.organizeInfo = res.data storage.getStorage(storage.storageKey.userId).then((res: any) => { httpUtil.httpData.userId = res.data httpUtil.wxGet(httpUtil.interfaces.getUserById, null).then(((myinfo: any) => { console.log("获取个人信息成功:", myinfo) ConstsData.AppData.myInfoData = myinfo.data.data this.setData({ init: true, userType: myinfo.data.data.type, userRole: myinfo.data.data.role }) console.log("this.data.userType:", this.data.userType) let typeArr: string[] = [] if (this.data.userRole) { typeArr = this.data.userRole.split(",") } switch (Number(this.data.userType)) { case 0: //超级管理员,判断userRole case 1: //区域管理员,判断userRole case 2: //普通管理员,判断userRole if (typeArr) { this.choseType(typeArr) } break; case 3: //教师,除了教师亮,其他都不亮 this.setData({ teacherEnable: true, installerEnable: false, repairmanEnable: false, itEnable: false }) break; } })).catch((myinfo) => { console.log("获取个人信息失败:", myinfo) this.setData({ init: true }) }) }).catch((res) => { console.log("获取保存的UID失败了=", res) this.setData({ init: true, teacherEnable: true, installerEnable: true, repairmanEnable: true, itEnable: true }) }) }).catch((res) => { console.log(res) this.setData({ init: true }) }) }, choseType: function (arr: any[]) { arr.forEach((item: any) => { switch (Number(item)) { case 1: //安装员 this.setData({ installerEnable: true }) break; case 2: //IT管理员 this.setData({ itEnable: true }) break; case 3: //维修员 this.setData({ repairmanEnable: true }) break; } }); }, clickItem: function (event: any) { if (!this.data.init) { wx.showToast({ title: '初始化信息中', icon: 'none' }) return; } console.log(event.target.id) let type = null; let toUrl = ''; switch (Number(event.target.id)) { case 0: if (!this.data.teacherEnable) { return; } console.log("click teacher") type = loginType.Teacher toUrl = "../teacher/index/index" break; case 1: if (!this.data.installerEnable) { return; } console.log("click installer") type = loginType.Installer toUrl = "../installer/index/index" break; case 2: if (!this.data.repairmanEnable) { return; } console.log("click repairman") type = loginType.Repairman toUrl = "../repairman/index/index" break; case 3: if (!this.data.itEnable) { return; } console.log("click it") type = loginType.IT toUrl = "../itadministrator/index/index" break; } if (ConstsData.AppData.myInfoData.id == 0) { //代表没有获取到用户,去登录界面 toUrl = '../login/login?loginType=' + type; } //有用户,直接去首页,不登录 this.toNextPage(toUrl) }, toNextPage: function (url: string) { wx.navigateTo({ url: url, }) }, })