index.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // pages/index/index.ts
  2. import { httpUtil } from "../../utils/restful";
  3. import { loginType } from '../../utils/loginType';
  4. import { ConstsData } from "../../utils/const"
  5. import { storage } from "../../utils/storageUtil"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. init: false,
  12. userType: '',
  13. userRole: '',
  14. teacherEnable: false,
  15. installerEnable: false,
  16. repairmanEnable: false,
  17. itEnable: false
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad() {
  23. },
  24. onShow() {
  25. httpUtil.wxGet(httpUtil.interfaces.getOrganizeAll, null).then((res: any) => {
  26. ConstsData.AppData.organizeInfo = res.data
  27. storage.getStorage(storage.storageKey.userId).then((res: any) => {
  28. httpUtil.httpData.userId = res.data
  29. httpUtil.wxGet(httpUtil.interfaces.getUserById, null).then(((myinfo: any) => {
  30. console.log("获取个人信息成功:", myinfo)
  31. ConstsData.AppData.myInfoData = myinfo.data.data
  32. this.setData({
  33. init: true,
  34. userType: myinfo.data.data.type,
  35. userRole: myinfo.data.data.role
  36. })
  37. console.log("this.data.userType:", this.data.userType)
  38. let typeArr: string[] = []
  39. if (this.data.userRole) {
  40. typeArr = this.data.userRole.split(",")
  41. }
  42. switch (Number(this.data.userType)) {
  43. case 0:
  44. //超级管理员,判断userRole
  45. case 1:
  46. //区域管理员,判断userRole
  47. case 2:
  48. //普通管理员,判断userRole
  49. if (typeArr) {
  50. this.choseType(typeArr)
  51. }
  52. break;
  53. case 3:
  54. //教师,除了教师亮,其他都不亮
  55. this.setData({
  56. teacherEnable: true,
  57. installerEnable: false,
  58. repairmanEnable: false,
  59. itEnable: false
  60. })
  61. break;
  62. }
  63. })).catch((myinfo) => {
  64. console.log("获取个人信息失败:", myinfo)
  65. this.setData({
  66. init: true
  67. })
  68. })
  69. }).catch((res) => {
  70. console.log("获取保存的UID失败了=", res)
  71. this.setData({
  72. init: true,
  73. teacherEnable: true,
  74. installerEnable: true,
  75. repairmanEnable: true,
  76. itEnable: true
  77. })
  78. })
  79. }).catch((res) => {
  80. console.log(res)
  81. this.setData({
  82. init: true
  83. })
  84. })
  85. },
  86. choseType: function (arr: any[]) {
  87. arr.forEach((item: any) => {
  88. switch (Number(item)) {
  89. case 1:
  90. //安装员
  91. this.setData({
  92. installerEnable: true
  93. })
  94. break;
  95. case 2:
  96. //IT管理员
  97. this.setData({
  98. itEnable: true
  99. })
  100. break;
  101. case 3:
  102. //维修员
  103. this.setData({
  104. repairmanEnable: true
  105. })
  106. break;
  107. }
  108. });
  109. },
  110. clickItem: function (event: any) {
  111. if (!this.data.init) {
  112. wx.showToast({
  113. title: '初始化信息中',
  114. icon: 'none'
  115. })
  116. return;
  117. }
  118. console.log(event.target.id)
  119. let type = null;
  120. let toUrl = '';
  121. switch (Number(event.target.id)) {
  122. case 0:
  123. if (!this.data.teacherEnable) {
  124. return;
  125. }
  126. console.log("click teacher")
  127. type = loginType.Teacher
  128. toUrl = "../teacher/index/index"
  129. break;
  130. case 1:
  131. if (!this.data.installerEnable) {
  132. return;
  133. }
  134. console.log("click installer")
  135. type = loginType.Installer
  136. toUrl = "../installer/index/index"
  137. break;
  138. case 2:
  139. if (!this.data.repairmanEnable) {
  140. return;
  141. }
  142. console.log("click repairman")
  143. type = loginType.Repairman
  144. toUrl = "../repairman/index/index"
  145. break;
  146. case 3:
  147. if (!this.data.itEnable) {
  148. return;
  149. }
  150. console.log("click it")
  151. type = loginType.IT
  152. toUrl = "../itadministrator/index/index"
  153. break;
  154. }
  155. if (ConstsData.AppData.myInfoData.id == 0) {
  156. //代表没有获取到用户,去登录界面
  157. toUrl = '../login/login?loginType=' + type;
  158. }
  159. //有用户,直接去首页,不登录
  160. this.toNextPage(toUrl)
  161. },
  162. toNextPage: function (url: string) {
  163. wx.navigateTo({
  164. url: url,
  165. })
  166. },
  167. })