index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. let tabBar = {
  2. "custom": true,
  3. "backgroundColor": "#fff",
  4. "borderStyle": "black",
  5. "selectedColor": "#ED5D18",
  6. "color": "#666C7D",
  7. "list": [
  8. {
  9. "pagePath": "/pages/index/index",
  10. "iconPath": "/static/images/hbtab_home@2x.png",
  11. "selectedIconPath": "/static/images/btab_home@2x.png",
  12. "text": "店铺"
  13. },
  14. {
  15. "pagePath": "/pages/catalog/catalog",
  16. "iconPath": "/static/images/hbtab_classify@2x.png",
  17. "selectedIconPath": "/static/images/btab_classify@2x.png",
  18. "text": "分类"
  19. },
  20. // {
  21. // "pagePath": "/pages/discover/discover",
  22. // "iconPath": "/static/images/btab_view@2x.png",
  23. // "selectedIconPath": "/static/images/btab_view_active@2x.png",
  24. // "keyiconPath": "/static/images/key_btab_view@2x.png",
  25. // "text": "发现",
  26. // "keynote": true
  27. // },
  28. {
  29. "pagePath": "/pages/cart/cart",
  30. "iconPath": "/static/images/hbtab_cart@2x.png",
  31. "selectedIconPath": "/static/images/btab_cart@2x.png",
  32. "text": "购物车"
  33. },
  34. {
  35. "pagePath": "/pages/ucenter/index/index",
  36. "iconPath": "/static/images/hbtab_my@2x.png",
  37. "selectedIconPath": "/static/images/btab_my@2x.png",
  38. "text": "我的"
  39. }
  40. ]
  41. }
  42. let selectIndex = 0
  43. let fns = []
  44. let setCountFns = []
  45. global.setTabBarBadge = function(args) {
  46. setCountFns.forEach(fn => fn(args))
  47. }
  48. Component({
  49. data: {
  50. tips: {},
  51. selectIndex,
  52. color: tabBar.color,
  53. selectedColor: tabBar.selectedColor,
  54. backgroundColor: tabBar.backgroundColor,
  55. borderStyle: tabBar.borderStyle,
  56. list: tabBar.list
  57. },
  58. attached() {
  59. setCountFns.push((args) => {
  60. this.setData({
  61. tips: {
  62. index: args.index,
  63. count: args.text
  64. }
  65. })
  66. })
  67. fns.push(() => this.setData({ selectIndex }))
  68. fns.forEach(fn => fn())
  69. },
  70. methods: {
  71. switchTab(e) {
  72. const data = e.currentTarget.dataset
  73. const url = data.path
  74. wx.switchTab({url})
  75. this.setData({
  76. selectIndex: data.index
  77. })
  78. selectIndex = data.index
  79. fns.forEach(fn => fn())
  80. }
  81. }
  82. })