index.js 2.4 KB

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