index.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad() {
  17. httpUtil.wxGet(httpUtil.interfaces.getOrganizeAll, null).then((res: any) => {
  18. ConstsData.AppData.organizeInfo = res.data
  19. storage.getStorage(storage.storageKey.userId).then((res: any) => {
  20. httpUtil.httpData.userId = res.data
  21. httpUtil.wxGet(httpUtil.interfaces.getUserById, null).then(((myinfo: any) => {
  22. console.log("获取个人信息成功:", myinfo)
  23. ConstsData.AppData.myInfoData = myinfo.data.data
  24. this.setData({
  25. init: true
  26. })
  27. })).catch((myinfo) => {
  28. console.log("获取个人信息失败:", myinfo)
  29. this.setData({
  30. init: true
  31. })
  32. })
  33. }).catch((res) => {
  34. console.log("获取保存的UID失败了=", res)
  35. this.setData({
  36. init: true
  37. })
  38. })
  39. }).catch((res) => {
  40. console.log(res)
  41. this.setData({
  42. init: true
  43. })
  44. })
  45. },
  46. clickItem: function (event: any) {
  47. if (!this.data.init) {
  48. wx.showToast({
  49. title: '初始化信息中',
  50. icon: 'none'
  51. })
  52. return;
  53. }
  54. console.log(event.target.id)
  55. let type = null;
  56. let toUrl = '';
  57. switch (Number(event.target.id)) {
  58. case 0:
  59. console.log("click teacher")
  60. type = loginType.Teacher
  61. toUrl = "../teacher/index/index"
  62. break;
  63. case 1:
  64. console.log("click installer")
  65. type = loginType.Installer
  66. toUrl = "../installer/index/index"
  67. break;
  68. case 2:
  69. console.log("click repairman")
  70. type = loginType.Repairman
  71. toUrl = "../repairman/index/index"
  72. break;
  73. case 3:
  74. console.log("click it")
  75. type = loginType.IT
  76. toUrl = "../itadministrator/index/index"
  77. break;
  78. }
  79. if (ConstsData.AppData.myInfoData.id == 0) {
  80. //代表没有获取到用户,去登录界面
  81. toUrl = '../login/login?loginType=' + type;
  82. }
  83. //有用户,直接去首页,不登录
  84. this.toNextPage(toUrl)
  85. },
  86. toNextPage: function (url: string) {
  87. wx.navigateTo({
  88. url: url,
  89. })
  90. },
  91. })