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