| | |
| | | let Tabs = class Tabs extends SuperComponent { |
| | | constructor() { |
| | | super(...arguments); |
| | | this.options = { |
| | | pureDataPattern: /^currentLabels$/, |
| | | }; |
| | | this.behaviors = [touch]; |
| | | this.externalClasses = [ |
| | | `${prefix}-class`, |
| | |
| | | prefix, |
| | | classPrefix: name, |
| | | tabs: [], |
| | | currentLabels: [], |
| | | currentIndex: -1, |
| | | trackStyle: '', |
| | | offset: 0, |
| | | scrollLeft: 0, |
| | | tabID: '', |
| | | placement: 'top', |
| | | }; |
| | |
| | | onScroll(e) { |
| | | const { scrollLeft } = e.detail; |
| | | this.setData({ |
| | | offset: scrollLeft, |
| | | scrollLeft, |
| | | }); |
| | | }, |
| | | updateTabs(cb) { |
| | |
| | | setCurrentIndex(index) { |
| | | if (index <= -1 || index >= this.children.length) |
| | | return; |
| | | const Labels = []; |
| | | this.children.forEach((child, idx) => { |
| | | const isActive = index === idx; |
| | | if (isActive !== child.data.active) { |
| | | child.render(isActive, this); |
| | | } |
| | | Labels.push(child.data.label); |
| | | }); |
| | | if (this.data.currentIndex === index) |
| | | const { currentIndex, currentLabels } = this.data; |
| | | if (currentIndex === index && currentLabels.join('') === Labels.join('')) |
| | | return; |
| | | this.setData({ |
| | | currentIndex: index, |
| | | }); |
| | | currentLabels: Labels, |
| | | }, () => { |
| | | this.setTrack(); |
| | | }); |
| | | }, |
| | | getCurrentName() { |
| | | if (this.children) { |
| | |
| | | }, |
| | | calcScrollOffset(containerWidth, targetLeft, targetWidth, offset) { |
| | | return offset + targetLeft - (1 / 2) * containerWidth + targetWidth / 2; |
| | | }, |
| | | getTabHeight() { |
| | | return getRect(this, `.${name}`); |
| | | }, |
| | | getTrackSize() { |
| | | return new Promise((resolve, reject) => { |
| | |
| | | }, |
| | | setTrack() { |
| | | return __awaiter(this, void 0, void 0, function* () { |
| | | if (!this.properties.showBottomLine) |
| | | return; |
| | | const { children } = this; |
| | | if (!children) |
| | | return; |
| | |
| | | totalSize += item.width; |
| | | }); |
| | | if (this.containerWidth) { |
| | | const offset = this.calcScrollOffset(this.containerWidth, rect.left, rect.width, this.data.offset); |
| | | const offset = this.calcScrollOffset(this.containerWidth, rect.left, rect.width, this.data.scrollLeft); |
| | | const maxOffset = totalSize - this.containerWidth; |
| | | this.setData({ |
| | | offset: Math.min(Math.max(offset, 0), maxOffset), |
| | |
| | | const len = tabs.length; |
| | | for (let i = step; currentIndex + step >= 0 && currentIndex + step < len; i += step) { |
| | | const newIndex = currentIndex + i; |
| | | if (newIndex >= 0 && newIndex < len && tabs[newIndex] && !tabs[newIndex].disabled) { |
| | | if (newIndex >= 0 && newIndex < len && tabs[newIndex]) { |
| | | if (!tabs[newIndex].disabled) { |
| | | return newIndex; |
| | | } |
| | | } |
| | | else { |
| | | return currentIndex; |
| | | } |
| | | } |
| | | return -1; |
| | | }, |
| | | }; |