index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const app = getApp()
  2. Component({
  3. data: {
  4. selected: '',
  5. color: "#7A7E83",
  6. selectedColor: "#409eff",
  7. list: [{
  8. "pagePath": "/pages/home/index",
  9. "iconPath": "/image/home1.png",
  10. "selectedIconPath": "/image/home2.png",
  11. "text": "首页"
  12. },
  13. {
  14. "pagePath": "/pages/reserve/index",
  15. "iconPath": "/image/reserve1.png",
  16. "selectedIconPath": "/image/reserve2.png",
  17. "text": "报餐"
  18. },
  19. {
  20. "pagePath": "/pages/news/index",
  21. "iconPath": "/image/news1.png",
  22. "selectedIconPath": "/image/news2.png",
  23. "text": "新闻"
  24. },
  25. {
  26. "pagePath": "/pages/my/index",
  27. "iconPath": "/image/my1.png",
  28. "selectedIconPath": "/image/my2.png",
  29. "text": "我的"
  30. }]
  31. },
  32. attached() {
  33. },
  34. methods: {
  35. switchTab(e) {
  36. const { index, path } = e.currentTarget.dataset;
  37. if (index == 3) {
  38. wx.getStorage({
  39. key: 'userInfo',
  40. success: function (res) {
  41. app.globalData.userInfo = res.data;
  42. wx.switchTab({ url: path })
  43. },
  44. fail: function (res) {
  45. wx.getUserProfile({
  46. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  47. success: (res) => {
  48. wx.setStorage({ key: "userInfo", data: res.userInfo })
  49. app.globalData.userInfo = res.userInfo;
  50. wx.switchTab({ url: path })
  51. }
  52. })
  53. }
  54. })
  55. } else {
  56. wx.switchTab({ url: path })
  57. }
  58. // wx.switchTab({ url })
  59. // wx.reLaunch({ url })
  60. // this.setData({
  61. // selected: data.index
  62. // })
  63. }
  64. }
  65. })