索引 xIndexbar
预览
介绍
特别提醒:本组件在1.0.9重构不向下兼容,并且删除了子组件:x-indexbar-item,不再需要子组件。请使用对应的动态插槽来渲染数据。 App/Web/鸿蒙端内部为单个 list-view + sticky-section 原生吸顶:顶部 top 插槽随列表上推,下方按 A/B/C 分组,分类标题滑到当前组时原生吸顶(类似 iOS 通讯录 / 微信联系人);小程序端为单个 scroll-view(using-sticky 吸顶),不用嵌套滚动。 右侧索引条默认离右边 12px(right 属性可调),安卓端列表会为它让出一条(索引条宽 16px + right,默认 28px),索引条不再压在列表上,列表内容的可用宽度因此比其它端窄 28px;安卓的索引条触摸挂在每个字母上,不依赖矩形换算。
平台兼容
| Harmony | H5 | andriod | IOS | 小程序 | UTS | UNIAPP-X SDK | version |
|---|---|---|---|---|---|---|---|
| ☑ | ☑ | ☑️ | ☑️ | ☑️ | ☑️ | 4.76+ | 1.1.18 |
文件路径
ts
@/uni_modules/tmx-ui/components/x-indexbar/x-indexbar.uvue使用
ts
<x-indexbar></x-indexbar>Props 属性
| 名称 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| width | 宽 | string | "auto" |
| height | 高,%,rpx,px单位均可。 | string | "100%" |
| right | 右侧索引条离右边的距离,px,rpx单位均可。 | string | "12" |
| dotActiveColor | 侧边指示激活时的文字颜色空值是取全局主题值 | string | "" |
| dotColor | 侧边指示未激活时的文字颜色 | string | "#c0c0c0" |
| dotBgColor | 侧边指示的背景颜色 | string | "white" |
| list | `` | Record<string, any>[] | () : Record<string, any>[] => [] as Record<string, any>[] |
| cellHeight | 项目的高只能是数字,或者带rpx,px单位 | string | '50' |
| titleHeight | 项目的标题高只能是数字,或者带rpx,px单位 | string | '32' |
| customSliderBar | `` | Array<string> | () : string[] => [] as string[] |
Events 事件
| 名称 | 参数 | 说明 |
|---|
Slots 插槽
| 名称 | 说明 | 数据 |
|---|---|---|
| top | 顶部布局,可以自由布局。滚动时会随列表上推。 | - |
| header | 分组标题,滑到当前分类时吸顶 | title: string title: number index: string index: number |
| default | 动态插槽 | index: Record<string, any> index: number index: number currentIndex: Record<string, any> currentIndex: number currentIndex: number current: Record<string, any> current: number current: number |
Ref 方法
| 名称 | 参数 | 返回值 | 说明 |
|---|
示例文件路径
json
/pages/daohang/indexbar示例源码
uvue
vue
<template>
<!-- #ifdef MP-WEIXIN || MP-ALIPAY -->
<page-meta :page-style="`background-color:${xThemeConfigBgColor}`">
<navigation-bar :background-color="xThemeConfigNavBgColor" :front-color="xThemeConfigNavFontColor"></navigation-bar>
</page-meta>
<!-- #endif -->
<view class="flex-1">
<x-indexbar :customSliderBar="['#','搜','火']" :list="list" height="100%" cellHeight="72">
<template v-slot:top>
<!--
top 插槽:索引条上的自定义项(# 搜 火 热 新)没有对应的列表分组,
点它们都会定位到这个插槽,所以这些项对应的内容要写在这里。
-->
<view >
<x-search round="0" darkColor="transparent" color="transparent" input-bg-color="#ffffff"></x-search>
<view class="pa-16">
<!-- # 对应的内容:点右侧 # 回到顶部搜索框这里 -->
<view class="flex flex-row flex-row-center-between mt-16">
<view class="flex flex-row flex-row-center-start">
<text class="text-size-lg text-weight-b" :style="{color:textColor}">#</text>
<text class="text-size-s ml-8" :style="{color:textColor}">快捷入口</text>
</view>
<text class="text-size-xxs opacity-6" :style="{color:textColor}">点右侧 # 回到这里</text>
</view>
<!-- 搜 / 火 / 热 / 新 对应的内容 -->
<view class="flex flex-row flex-wrap mt-12">
<view v-for="(item, index) in quickEntries" :key="index"
class="flex flex-row flex-row-center-start round-12 px-16 py-8 mr-12 mb-12"
:style="{backgroundColor:chipBgColor}">
<text class="text-size-xs text-weight-b" :style="{color:textColor}">{{item.tag}}</text>
<text class="text-size-xs ml-8 opacity-8" :style="{color:textColor}">{{item.title}}</text>
</view>
</view>
</view>
</view>
</template>
<template v-slot:default="{index,currentIndex,current}">
<view class="flex flex-row flex-row-center-start px-16 " style="border-bottom: 1px solid rgba(100, 100, 100, 0.1);height:72px;">
<image class="flex-shrink" :src="`https://picsum.photos/100/100?random=${index}`" style="width:50px;height:50px;border-radius: 50px;"></image>
<text :style="{color:isDark?'#ffffff':'#000000'}" class="ml-20">{{(current as Record<string, any>)["name"]}}</text>
</view>
</template>
</x-indexbar>
</view>
</template>
<script setup lang="ts">
// 示例参数数据,请vip用户到demo中下载查询数据样例.
import {dataslist} from "./indexdata"
import { xConfig } from "@/uni_modules/tmx-ui";
type QuickEntry = {
tag : string,
title : string
}
const isDark = computed(():boolean => xConfig.dark=='dark')
const textColor = computed(():string => isDark.value?'#ffffff':'#000000')
const chipBgColor = computed(():string => isDark.value?'rgba(255,255,255,0.10)':'rgba(0,0,0,0.05)')
// 索引条上的 搜/火/热/新 自定义项对应的内容样例
const quickEntries = ref<QuickEntry[]>([
{ tag: '搜', title: '雷克萨斯 ES 200' },
{ tag: '火', title: '保时捷 911' }
] as QuickEntry[])
const list = ref<Record<string, any>[]>(JSON.parse(dataslist) as Record<string, any>[])
</script>
<style lang="scss">
</style>