index.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. let typeArr: string[] = []
  38. if (this.data.userRole) {
  39. typeArr = this.data.userRole.split(",")
  40. }
  41. switch (Number(this.data.userType)) {
  42. case 0:
  43. //超级管理员,判断userRole
  44. case 1:
  45. //区域管理员,判断userRole
  46. case 2:
  47. //普通管理员,判断userRole
  48. if (typeArr) {
  49. this.choseType(typeArr)
  50. }
  51. break;
  52. case 3:
  53. //教师,除了教师亮,其他都不亮
  54. this.setData({
  55. teacherEnable: true,
  56. installerEnable: false,
  57. repairmanEnable: false,
  58. itEnable: false
  59. })
  60. break;
  61. }
  62. })).catch((myinfo) => {
  63. console.log("获取个人信息失败:", myinfo)
  64. this.setData({
  65. init: true
  66. })
  67. })
  68. }).catch((res) => {
  69. console.log("获取保存的UID失败了=", res)
  70. this.setData({
  71. init: true,
  72. teacherEnable: true,
  73. installerEnable: true,
  74. repairmanEnable: true,
  75. itEnable: true
  76. })
  77. })
  78. }).catch((res) => {
  79. console.log(res)
  80. this.setData({
  81. init: true
  82. })
  83. })
  84. },
  85. choseType: function (arr: any[]) {
  86. arr.forEach((item: any) => {
  87. switch (Number(item)) {
  88. case 1:
  89. //安装员
  90. this.setData({
  91. installerEnable: true
  92. })
  93. break;
  94. case 2:
  95. //IT管理员
  96. this.setData({
  97. itEnable: true
  98. })
  99. break;
  100. case 3:
  101. //维修员
  102. this.setData({
  103. repairmanEnable: true
  104. })
  105. break;
  106. }
  107. });
  108. },
  109. clickItem: function (event: any) {
  110. if (!this.data.init) {
  111. wx.showToast({
  112. title: '初始化信息中',
  113. icon: 'none'
  114. })
  115. return;
  116. }
  117. console.log(event.target.id)
  118. let type = null;
  119. let toUrl = '';
  120. switch (Number(event.target.id)) {
  121. case 0:
  122. if (!this.data.teacherEnable) {
  123. return;
  124. }
  125. console.log("click teacher")
  126. type = loginType.Teacher
  127. toUrl = "../teacher/index/index"
  128. break;
  129. case 1:
  130. if (!this.data.installerEnable) {
  131. return;
  132. }
  133. console.log("click installer")
  134. type = loginType.Installer
  135. toUrl = "../installer/index/index"
  136. break;
  137. case 2:
  138. if (!this.data.repairmanEnable) {
  139. return;
  140. }
  141. console.log("click repairman")
  142. type = loginType.Repairman
  143. toUrl = "../repairman/index/index"
  144. break;
  145. case 3:
  146. if (!this.data.itEnable) {
  147. return;
  148. }
  149. console.log("click it")
  150. type = loginType.IT
  151. toUrl = "../itadministrator/index/index"
  152. break;
  153. }
  154. if (ConstsData.AppData.myInfoData.id == 0) {
  155. //代表没有获取到用户,去登录界面
  156. toUrl = '../login/login?loginType=' + type;
  157. }
  158. //有用户,直接去首页,不登录
  159. this.toNextPage(toUrl)
  160. },
  161. toNextPage: function (url: string) {
  162. wx.navigateTo({
  163. url: url,
  164. })
  165. },
  166. })