index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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: '#BA9D6E' },
  13. tabActiveTextColor: { type: String, value: '#BA9D6E' },
  14. tabInactiveTextColor: { type: String, value: '#323232' },
  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. swiperHeight:{type:String,value:500}
  21. },
  22. data: {
  23. currentView: 0
  24. },
  25. observers: {
  26. activeTab: function activeTab(_activeTab) {
  27. var len = this.data.tabs.length;
  28. if (len === 0) return;
  29. var currentView = _activeTab - 1;
  30. if (currentView < 0) currentView = 0;
  31. if (currentView > len - 1) currentView = len - 1;
  32. this.setData({ currentView: currentView });
  33. }
  34. },
  35. lifetimes: {
  36. created: function created() {}
  37. },
  38. methods: {
  39. handleTabClick: function handleTabClick(e) {
  40. var index = e.currentTarget.dataset.index;
  41. this.setData({ activeTab: index });
  42. this.triggerEvent('tabclick', { index: index });
  43. },
  44. handleSwiperChange: function handleSwiperChange(e) {
  45. var index = e.detail.current;
  46. this.setData({ activeTab: index });
  47. this.triggerEvent('change', { index: index });
  48. }
  49. }
  50. });