import { use } from '../utils'; import { TouchMixin } from '../mixins/touch'; import { ParentMixin } from '../mixins/relation'; const [sfc, bem] = use('index-bar'); export default sfc({ mixins: [TouchMixin, ParentMixin('vanIndexBar')], props: { indexList: { type: Array, default() { const indexList = []; const charCodeOfA = 'A'.charCodeAt(0); for (let i = 0; i < 26; i++) { indexList.push(String.fromCharCode(charCodeOfA + i)); } return indexList; } } }, methods: { onClick(event) { this.scrollToElement(event.target); }, onTouchStart(event) { this.touchStart(event); }, onTouchMove(event) { this.touchMove(event); if (this.direction === 'vertical') { /* istanbul ignore else */ if (event.cancelable) { event.preventDefault(); } const { clientX, clientY } = event.touches[0]; const target = document.elementFromPoint(clientX, clientY); this.scrollToElement(target); } }, scrollToElement(element, setActive) { if (!element) { return; } const { index } = element.dataset; if (!index) { return; } const match = this.children.filter(item => String(item.index) === index); if (match[0]) { match[0].scrollIntoView(); } }, onTouchEnd() { this.active = null; } }, render(h) { return (