组件 / 布局 / cu-collapse-item 折叠项

cu-collapse-item

折叠项是折叠面板中的一块,由标题行与展开后的内容区组成。

01 / Install

引入组件

整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。

install
# 1  整目录放进工程(easycom 自动解析)
your-project/
└── uni_modules/
    └── colorui-x/

# 2  App.uvue 全局引入主题层(一次)
@import 'uni_modules/colorui-x/theme/base.css';
@import 'uni_modules/colorui-x/theme/layout.css';
@import 'uni_modules/colorui-x/theme/color.scss';  // 颜色工具类(.bg-* / .text-*)

# 3  页面里直接用,不写 import(只编译用到的组件)
<cu-collapse-item />

# 4  单个组件也可以显式引入(可选,不用 easycom 时)
import CuCollapseItem from '@/uni_modules/colorui-x/components/cu-collapse-item/cu-collapse-item.uvue'

组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。

02 / Platform

平台支持

AndroidiOSHarmonyOSWeb(H5)微信小程序支付宝小程序
√ — — √ — —

Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。

Web 列只表示已编出可运行的预览产物,非真机渲染。

其余三端没有任何实测证据,不作支持承诺。

03 / Demo

代码演示

01

文本

uvue
<cu-collapse :border="false">
  <cu-collapse-item title="只有 title" :expanded="t1" @change="toggle('t1')" />
  <cu-collapse-item title="title + label" label="label 在 title 下方" :expanded="t2" @change="toggle('t2')">
    <text>
      内容区。
    </text>
  </cu-collapse-item>
  <cu-collapse-item title="title + value" value="副值" :expanded="t3" @change="toggle('t3')" />
  <cu-collapse-item icon="cuIcon-homefill" title="左图标 cuIcon-homefill" :expanded="t4" @change="toggle('t4')" />
  <cu-collapse-item icon="cuIcon-phone" title="左图标 + label + value" label="三条同现" value="138****8888" :expanded="t5" @change="toggle('t5')" />
  <cu-collapse-item title="标题超长(负向对照:参考实现无 max-width 与省略号)" label="整段标题用来观察换行与右侧箭头区被挤压的表现,这里继续加长内容以逼近一行放不下" value="副值也很长" :expanded="t6" @change="toggle('t6')" />
  <cu-collapse-item :expanded="t7" @change="toggle('t7')">
    <text>
      全空的边界:title / label / value / icon 都不传,只剩箭头与两条线。
    </text>
  </cu-collapse-item>
</cu-collapse>
02

箭头

uvue
<cu-collapse :border="false">
  <cu-collapse-item title="isLink=true(默认),展开时箭头朝上" :expanded="l1" @change="toggle('l1')" />
  <cu-collapse-item title="isLink=false ⇒ 右侧箭头整块不渲染" :isLink="false" :expanded="l2" @change="toggle('l2')" />
</cu-collapse>
03

禁用 / 动效

uvue
<cu-collapse :border="false">
  <cu-collapse-item title="disabled=true ⇒ 不 emit、三段文字变灰" :disabled="true" :expanded="d1" @change="toggle('d1')" />
  <cu-collapse-item title="duration=0(无过渡窗口,可连点)" :duration="0" :expanded="d2" @change="toggle('d2')" />
  <cu-collapse-item title="duration=1000(一秒内二次点击被吞)" :duration="1000" :expanded="d3" @change="toggle('d3')" />
</cu-collapse>
04

描边

uvue
<cu-collapse :border="false">
  <cu-collapse-item title="border=true(默认)收起态:只有末尾线" :expanded="r1" @change="toggle('r1')" />
  <cu-collapse-item title="border=true 展开态:标题下线 + 末尾线" :expanded="true" />
  <cu-collapse-item title="border=false:两条线都没有" :border="false" :expanded="r3" @change="toggle('r3')" />
</cu-collapse>
05

插槽

uvue
<cu-collapse :border="false">
  <cu-collapse-item :expanded="s1" @change="toggle('s1')">
    <template #icon>
      <text>
        槽 icon
      </text>
    </template>
    <template #title>
      <text>
        槽 title(覆盖 title prop)
      </text>
    </template>
    <template #value>
      <text>
        槽 value
      </text>
    </template>
    <template #right-icon>
      <text>
        槽 right-icon
      </text>
    </template>
    <text>
      默认 slot 的面板内容。
    </text>
  </cu-collapse-item>
  <cu-collapse-item title="只覆盖 title 槽,其余走 prop" icon="cuIcon-phone" value="副值">
    <template #title>
      <text>
        只有标题被换成槽内容
      </text>
    </template>
    <text>
      label 没有槽位(参考实现也只透传 title / icon / value / right-icon 四个,:17-28)。
    </text>
  </cu-collapse-item>
</cu-collapse>
06

事件载荷

这一节的交互由演示页脚本驱动,效果见右侧实时预览。

07

未消费项

uvue
<cu-collapse :border="false">
  <cu-collapse-item title="align=center 与 left 无差别" align="center" :expanded="u1" @change="toggle('u1')" />
  <cu-collapse-item title="clickable=false 与 true 无差别" :clickable="false" :expanded="u2" @change="toggle('u2')" />
  <cu-collapse-item title="url / linkType 不跳转" url="/pages/debug/icon" linkType="navigateTo" :expanded="u3" @change="toggle('u3')" />
  <cu-collapse-item title="expanded 由父件下发,本件不改它" :expanded="true" :duration="200" />
</cu-collapse>
08

自定义样式

uvue
<cu-collapse :border="false">
  <cu-collapse-item title="customStyle 落根节点" :customStyle="itemStyle" :expanded="c1" @change="toggle('c1')" />
  <cu-collapse-item title="customClass 落根节点动态类唯一位" customClass="custom-class" :expanded="c2" @change="toggle('c2')" />
</cu-collapse>
09

取值与事件

这一节的交互由演示页脚本驱动,效果见右侧实时预览。

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
文本与标识
title标题文字,显示在头部主行String''
label描述文字,显示在标题下方String''
value右侧内容,显示在头部右端String''
icon左侧图标名,取 cu-icon 白名单;传空串则不留图标位String''
name面板标识;接入折叠容器后作为展开集合的比对键,也是 change 载荷里的 nameString''
展开与外观
expanded是否展开;独立使用时由本属性决定,接入折叠容器后改由容器的展开集合决定Booleanfalse
disabled禁用点击,头部文字一并转灰且不发事件Booleanfalse
isLink是否显示右侧方向指示,收起为 ›、展开为 ▾Booleantrue
duration展开收起的过渡时长,毫秒;同时作为连点节流窗口,传 0 表示可连点Number300
border是否画分隔线;收起时只有末尾一条,展开时头部下方再加一条Booleantrue
对齐与样式
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
align标题对齐方向;本仓头部固定左对齐,传 center 不改变排版String'left'
clickable是否响应点击;本仓未读取,传 false 仍可点开Booleantrue
url不产生跳转,传参不生效String''
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@change点击头部切换时触发,载荷 { name, status },status 取 open / close;disabled 为真时不触发Handler-各端一致

slots

slot说明
icon自定义左侧图标位;不填时按 icon 渲染图标
title自定义标题区内容;不填时显示 title 文字
value自定义右侧内容位;不填时显示 value 文字
right-icon自定义右侧指示位;不填时显示随展开态切换的方向字符
(默认)面板展开后显示的面板内容;不填时展开区为空
05 / Notes

注意事项

不传名退独立 :接入折叠容器后展开态由容器集合决定,但 name 为空时子项退回独立模式,expanded 与 change 都要页面自己管,容易与容器状态脱节。