index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. btnActive: '1'
  12. },
  13. // 跳转菜单
  14. tabPath(e) {
  15. let { route } = e.detail.detail;
  16. if (route) wx.redirectTo({ url: `/${route}` })
  17. },
  18. toCommon: function (e) {
  19. const { route } = e.currentTarget.dataset;
  20. if (route) { wx.navigateTo({ url: `/pages/${route}` }) };
  21. },
  22. // 选择手风琴
  23. bChange: function (e) {
  24. const that = this;
  25. that.setData({ btnActive: e.detail })
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. const that = this;
  32. // that.watchLogin();
  33. },
  34. watchLogin: async function () {
  35. const that = this;
  36. wx.getStorage({
  37. key: 'user',
  38. success: async (res) => {
  39. const arr = await app.$get(`/newCourt/api/user/${res.data.openid}`);
  40. if (arr.errcode == '0') {
  41. let user = arr.data;
  42. that.setData({ user: user });
  43. let btnData = myBtn.find((i) => i.type == user.type);
  44. that.setData({ btnList: btnData.btn })
  45. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  46. },
  47. fail: async (res) => {
  48. wx.redirectTo({ url: '/pages/index/index' });
  49. },
  50. });
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. const that = this;
  62. that.watchLogin();
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. }
  89. })