index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const app = getApp();
  2. import { match_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: `/pagesMatch/${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: 'raceuser',
  45. success: async res => {
  46. const arr = await app.$get(`/user/${res.data._id}`, {}, 'race');
  47. if (arr.errcode == '0') {
  48. const aee = await app.$get(`/user/${arr.data.user_id}`);
  49. if (aee.errcode == '0') { arr.data.user_id = aee.data; }
  50. that.setData({ user: arr.data })
  51. let btnData = match_menu.find((i) => i.type == arr.data.type);
  52. that.setData({ list: [...btnData.menu, ...school_sysmenu] })
  53. }
  54. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  55. },
  56. fail: async res => {
  57. wx.redirectTo({ url: '/pages/index/index' })
  58. }
  59. })
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage: function () {
  83. }
  84. })