tabs.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Component({
  2. options: {
  3. addGlobalClass: true,
  4. pureDataPattern: /^_/,
  5. multipleSlots: true
  6. },
  7. properties: {
  8. tabs: {type: Array, value: []},
  9. tabClass: {type: String, value: ''},
  10. swiperClass: {type: String, value: ''},
  11. activeClass: {type: String, value: ''},
  12. tabUnderlineColor: {type: String, value: '#07c160'},
  13. tabActiveTextColor: {type: String, value: '#000000'},
  14. tabInactiveTextColor: {type: String, value: '#000000'},
  15. tabBackgroundColor: {type: String, value: '#ffffff'},
  16. activeTab: {type: Number, value: 0},
  17. swipeable: {type: Boolean, value: true},
  18. animation: {type: Boolean, value: true},
  19. duration: {type: Number, value: 500},
  20. theme: {type: String, value: 'light'} // light dark
  21. },
  22. data: {
  23. currentView: 0
  24. },
  25. observers: {
  26. activeTab: function activeTab(_activeTab) {
  27. const len = this.data.tabs.length
  28. if (len === 0) return
  29. let currentView = _activeTab - 1
  30. if (currentView < 0) currentView = 0
  31. if (currentView > len - 1) currentView = len - 1
  32. this.setData({currentView})
  33. }
  34. },
  35. lifetimes: {
  36. created: function created() {}
  37. },
  38. methods: {
  39. handleTabClick: function handleTabClick(e) {
  40. const index = e.currentTarget.dataset.index
  41. this.setData({activeTab: index})
  42. this.triggerEvent('tabclick', {index})
  43. },
  44. handleSwiperChange: function handleSwiperChange(e) {
  45. const index = e.detail.current
  46. this.setData({activeTab: index})
  47. this.triggerEvent('change', {index})
  48. }
  49. }
  50. })