index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { myBtn } from "../../utils/dict";
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
  9. user: {},
  10. btnList: [],
  11. },
  12. // 跳转菜单
  13. tabPath(e) {
  14. let { route } = e.detail.detail;
  15. if (route) wx.redirectTo({ url: `/${route}` })
  16. },
  17. toCommon: function (e) {
  18. const { route, type } = e.currentTarget.dataset;
  19. // 自定义路径
  20. if (type == '0') { wx.navigateTo({ url: `${route}` }) }
  21. // 默认路径
  22. else if (type == '1') { wx.navigateTo({ url: `/pages/${route}/index` }) };
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. const that = this;
  29. that.watchLogin();
  30. },
  31. watchLogin: async function () {
  32. const that = this;
  33. wx.getStorage({
  34. key: 'user',
  35. success: async (res) => {
  36. const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
  37. if (arr.errcode == '0') {
  38. let user = arr.data;
  39. that.setData({ user: user });
  40. let btn = myBtn.filter((i) => i.type.includes(user.type));
  41. that.setData({ btnList: btn })
  42. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  43. },
  44. fail: async (res) => {
  45. wx.redirectTo({ url: '/pages/index/index' });
  46. },
  47. });
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {
  58. this.watchLogin();
  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. onReachBottom: function () {
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {
  84. }
  85. })