index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const app = getApp();
  2. import { school_menu, school_sysmenu } from "../../utils/dict";
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '系统首页', leftArrow: true, useBar: false },
  6. user: {},
  7. list: []
  8. },
  9. // 返回
  10. back: function () { wx.navigateBack({ delta: 1 }) },
  11. // 功能跳转
  12. toCommon: function (e) {
  13. const { route, type } = e.currentTarget.dataset;
  14. if (type && type == 'logout') {
  15. // 退出登录
  16. try { wx.clearStorage(); wx.redirectTo({ url: '/pages/index/index' }) }
  17. catch (e) { }
  18. } else if (type && type == 'custom') {
  19. wx.navigateTo({ url: `/${route}` });
  20. } else {
  21. wx.navigateTo({ url: `/pagesSchool/${route}` });
  22. }
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) { },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () { },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. const that = this;
  37. // 监听用户是否登录
  38. that.watchLogin();
  39. },
  40. // 监听用户是否登录
  41. watchLogin: async function () {
  42. const that = this;
  43. wx.getStorage({
  44. key: 'user',
  45. success: async res => {
  46. const arr = await app.$get(`/user/${res.data._id}`);
  47. if (arr.errcode == '0') {
  48. that.setData({ user: arr.data })
  49. let btnData = school_menu.find((i) => i.type == arr.data.type);
  50. that.setData({ list: [...btnData.menu, ...school_sysmenu] })
  51. }
  52. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  53. },
  54. fail: async res => {
  55. wx.redirectTo({ url: '/pages/index/index' })
  56. }
  57. })
  58. },
  59. /**
  60. * 页面上拉触底事件的处理函数
  61. */
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage: function () {
  81. }
  82. })