index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const selectedInex = wx.getStorageSync('selectedInex')
  28. this.setData({
  29. selected: selectedInex
  30. })
  31. },
  32. methods: {
  33. switchTab(e) {
  34. const data = e.currentTarget.dataset
  35. const url = data.path
  36. if (data.index == 1 || data.index == 2) {
  37. const isLogin = wx.getStorageSync('login')
  38. if (isLogin != true) {
  39. wx.showToast({
  40. title: '请先授权登录',
  41. icon: 'error'
  42. })
  43. return false
  44. } else {
  45. app.globalData.selectedInex = data.index
  46. wx.setStorageSync('selectedInex', data.index)
  47. wx.switchTab({url})
  48. }
  49. } else {
  50. app.globalData.selectedInex = data.index
  51. wx.setStorageSync('selectedInex', data.index)
  52. wx.switchTab({url})
  53. }
  54. }
  55. }
  56. })