index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. Component({
  2. data: {
  3. selected: 0,
  4. "color": "#AAAFC4",
  5. "selectedColor": "#0BC3AA",
  6. list: [{
  7. "pagePath": "/pages/index/index",
  8. "text": "控制主页",
  9. "iconPath": "/static/tabs/home@2x.png",
  10. "selectedIconPath": "/static/tabs/home-active@2x.png"
  11. },
  12. {
  13. "pagePath": "/pages/shop/shop",
  14. "text": "商城",
  15. "iconPath": "/static/tabs/report@2x.png",
  16. "selectedIconPath": "/static/tabs/report-active@2x.png"
  17. },
  18. {
  19. "pagePath": "/pages/data/data",
  20. "text": "睡眠报告",
  21. "iconPath": "/static/tabs/report@2x.png",
  22. "selectedIconPath": "/static/tabs/report-active@2x.png"
  23. },
  24. {
  25. "pagePath": "/pages/testSAS/testSAS",
  26. "text": "调查问卷",
  27. "iconPath": "/static/tabs/investigation@2x.png",
  28. "selectedIconPath": "/static/tabs/investigation-active@2x.png"
  29. },
  30. {
  31. "pagePath": "/pages/empower/empower",
  32. "text": "我的",
  33. "iconPath": "/static/tabs/report@2x.png",
  34. "selectedIconPath": "/static/tabs/report-active@2x.png"
  35. }]
  36. },
  37. attached() {
  38. const app = getApp();
  39. this.setData({
  40. selected: app.globalData.selectedTabIndex || 0
  41. })
  42. console.log("da=>", app.globalData.selectedTabIndex);
  43. },
  44. methods: {
  45. switchTab(e) {
  46. const data = e.currentTarget.dataset
  47. const url = data.path
  48. if (url === "/pages/shop/shop") {
  49. wx.showToast({
  50. icon: "none",
  51. title: '暂未开通',
  52. })
  53. return
  54. }
  55. console.log("data.index", data.index);
  56. wx.switchTab({ url })
  57. const app = getApp();
  58. app.globalData.selectedTabIndex = data.index;
  59. }
  60. }
  61. })