index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const app = getApp()
  2. import { myBtn } from "../../utils/dict";
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
  6. user: {},
  7. btnList: [],
  8. },
  9. // 跳转菜单
  10. tabPath(e) {
  11. let { route } = e.detail.detail;
  12. if (route) wx.redirectTo({ url: `/${route}` })
  13. },
  14. toCommon: function (e) {
  15. const { route } = e.currentTarget.dataset;
  16. if (route) { wx.navigateTo({ url: `/pages/${route}` }) };
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) { },
  22. // 监听用户是否登录
  23. watchLogin: async function () {
  24. const that = this;
  25. wx.getStorage({
  26. key: 'user',
  27. success: async (res) => {
  28. const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
  29. if (arr.errcode == '0') {
  30. let user = arr.data;
  31. that.setData({ user: user });
  32. let btnData = myBtn.find((i) => i.type == user.type);
  33. that.setData({ btnList: btnData.menu })
  34. } else { wx.showToast({ title: `${res.errmsg}`, icon: 'fail', duration: 2000 }); }
  35. },
  36. fail: async (res) => {
  37. wx.redirectTo({ url: '/pages/index/index' });
  38. },
  39. });
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. const that = this;
  51. // 监听用户是否登录
  52. that.watchLogin();
  53. },
  54. /**
  55. * 生命周期函数--监听页面隐藏
  56. */
  57. onHide: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面卸载
  61. */
  62. onUnload: function () {
  63. },
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh: function () {
  68. },
  69. /**
  70. * 页面上拉触底事件的处理函数
  71. */
  72. onReachBottom: function () {
  73. },
  74. /**
  75. * 用户点击右上角分享
  76. */
  77. onShareAppMessage: function () {
  78. }
  79. })