import { ExtractPropTypes } from 'vue'; export interface IState { // 当前激活的列表锚点的序号 activeAnchorIndex: number // 显示侧边索引栏 showSidebar: boolean // 标记是否开始触摸移动 touchMove: boolean // 当前触摸移动到对应索引的序号 touchMoveIndex: number // 滚动到对应锚点的序号 scrollToAnchorIndex: number // 侧边栏的信息 sidebar: { height: number top: number } // 内容区域高度 height: number // 内容区域top top: number } // 生成 A-Z的字母列表 let indexList = function() { let indexList = [] let charCodeOfA = 'A'.charCodeAt(0) for (var i = 0; i < 26; i++) { indexList.push(String.fromCharCode(charCodeOfA + i)) } return indexList } export const indexListProps = { // 索引列表 indexList: { type: Array, default() { return indexList() } }, // 是否自动吸顶 sticky: { type: Boolean, default: true }, // 自动吸顶时距离顶部的距离,单位px stickyTop: { type: [Number, String], default: 0 }, // 自定义顶栏的高度,单位px customBarHeight: { type: Number, default: 0 }, // 当前滚动的高度 // 由于自定义组件无法获取滚动高度,所以依赖传入 scrollTop: { type: Number, default: 0 }, // 选中索引时的颜色 activeColor: { type: String, default: '#01BEFF' }, // 吸顶时的z-index zIndex: { type: Number, default: 0 } } const useIndexList = (props: ExtractPropTypes, state: IState) => { }