index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const app = getApp()
  2. Component({
  3. data: {
  4. selected: 0,
  5. color: "#7A7E83",
  6. selectedColor: "#45A6B5",
  7. list: [{
  8. pagePath: "/pages/index/index",
  9. iconPath: "/imaes/home_nor@2x.png",
  10. selectedIconPath: "/imaes/home_sel@2x.png",
  11. text: "首页"
  12. }, {
  13. pagePath: "/pages/report/report",
  14. iconPath: "/imaes/baogao_nor@2x.png",
  15. selectedIconPath: "/imaes/baogao_sel@2x.png",
  16. text: "报告"
  17. },{
  18. pagePath: "/pages/my/my",
  19. iconPath: "/imaes/me_nor@2x.png",
  20. selectedIconPath: "/imaes/me_sel@2x.png",
  21. text: "我的"
  22. }]
  23. },
  24. attached() {
  25. },
  26. ready () {
  27. this.setData({
  28. selected: app.globalData.selectedInex
  29. })
  30. },
  31. methods: {
  32. switchTab(e) {
  33. const data = e.currentTarget.dataset
  34. const url = data.path
  35. if (data.index == 1 || data.index == 2) {
  36. if (!app.globalData.userInfo.login) {
  37. wx.showToast({
  38. title: '请先授权登录',
  39. icon: 'error'
  40. })
  41. return false
  42. } else {
  43. app.globalData.selectedInex = data.index
  44. wx.switchTab({url})
  45. }
  46. } else {
  47. app.globalData.selectedInex = data.index
  48. wx.switchTab({url})
  49. }
  50. }
  51. }
  52. })