// 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 }, /** * 生命周期函数--监听页面加载 */ onLoad() { 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 }) })).catch((myinfo) => { console.log("获取个人信息失败:", myinfo) this.setData({ init: true }) }) }).catch((res) => { console.log("获取保存的UID失败了=", res) this.setData({ init: true }) }) }).catch((res) => { console.log(res) this.setData({ init: true }) }) }, 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: console.log("click teacher") type = loginType.Teacher toUrl = "../teacher/index/index" break; case 1: console.log("click installer") type = loginType.Installer toUrl = "../installer/index/index" break; case 2: console.log("click repairman") type = loginType.Repairman toUrl = "../repairman/index/index" break; case 3: 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, }) }, })