123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- // 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
- })
- 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,
- })
- },
- })
|