index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 {
  19. wx.navigateTo({ url: `/pagesSchool/${route}` });
  20. }
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) { },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady: function () { },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow: function () {
  34. const that = this;
  35. // 监听用户是否登录
  36. that.watchLogin();
  37. },
  38. // 监听用户是否登录
  39. watchLogin: async function () {
  40. const that = this;
  41. wx.getStorage({
  42. key: 'user',
  43. success: async res => {
  44. const arr = await app.$get(`/user/${res.data._id}`);
  45. if (arr.errcode == '0') {
  46. that.setData({ user: arr.data })
  47. let btnData = school_menu.find((i) => i.type == '2');
  48. that.setData({ list: [...btnData.menu, ...school_sysmenu] })
  49. }
  50. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  51. },
  52. fail: async res => {
  53. wx.redirectTo({ url: '/pages/index/index' })
  54. }
  55. })
  56. },
  57. /**
  58. * 页面上拉触底事件的处理函数
  59. */
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload: function () {
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh: function () {
  74. },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage: function () {
  79. }
  80. })