index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // custom-tab-bar/index.js
  2. Component({
  3. data: {
  4. rightId:wx.getStorageSync('rightId') || 0,
  5. list: [],
  6. list1: [
  7. {
  8. "pagePath": "../home/home",
  9. "text": "首页",
  10. "iconPath": "/img/index_unaction.png",
  11. "selectedIconPath": "/img/index_action.png"
  12. },
  13. {
  14. "pagePath": "../me/me",
  15. "text": "我的",
  16. "iconPath": "/img/me_unaction.png",
  17. "selectedIconPath": "/img/me_action.png"
  18. }
  19. ],
  20. list2: [
  21. {
  22. "pagePath": "../home/home",
  23. "text": "首页",
  24. "iconPath": "/img/index_unaction.png",
  25. "selectedIconPath": "/img/index_action.png"
  26. },
  27. {
  28. "pagePath": "../index/index",
  29. "text": "频道",
  30. "iconPath": "/img/index_unaction.png",
  31. "selectedIconPath": "/img/index_action.png"
  32. },
  33. {
  34. "pagePath": "../me/me",
  35. "text": "我的",
  36. "iconPath": "/img/me_unaction.png",
  37. "selectedIconPath": "/img/me_action.png"
  38. }
  39. ]
  40. },
  41. attached() {
  42. this.changeList()
  43. getApp().eventBus.on('rightChange', data => {
  44. if (data !== this.data.rightId) {
  45. this.setData({
  46. rightId: data
  47. })
  48. this.changeList()
  49. }
  50. })
  51. },
  52. detached() {
  53. app.eventBus.off('rightChange')
  54. },
  55. methods: {
  56. changeList() {
  57. this.setData({
  58. rightId: wx.getStorageSync('rightId') || 0
  59. })
  60. if (this.data.rightId === 1) {
  61. this.setData({
  62. list: this.data.list2
  63. })
  64. } else {
  65. this.setData({
  66. list: this.data.list1
  67. })
  68. }
  69. },
  70. switchTab(e) {
  71. const data = e.currentTarget.dataset
  72. const url = data.path
  73. console.log("点击切换"+ url);
  74. wx.switchTab({
  75. url: url,
  76. fail:function(e){
  77. console.log("点击切换失败"+ e.errMsg);
  78. }
  79. })
  80. }
  81. }
  82. })