01
默认
<cu-read-more name="case-default" @open="onOpen" @close="onClose"> <text> {{ longText }} </text> </cu-read-more>
展开全文把长正文折叠到固定高度,由按钮控制展开与收起。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 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-read-more /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuReadMore from '@/uni_modules/colorui-x/components/cu-read-more/cu-read-more.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-read-more name="case-default" @open="onOpen" @close="onClose"> <text> {{ longText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="120" name="case-toggle" @open="onOpen" @close="onClose"> <text> {{ longText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="40" name="case-tiny"> <text> {{ longText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="0" name="case-zero"> <text> {{ longText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="400" name="case-short"> <text> 只有一句话的短内容。 </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="200" name="case-huge"> <text> {{ hugeText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="100" closeText="展开阅读全文(本文约三千字,阅读需要十分钟)" openText="收起全文,不再看了"> <text> {{ longText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="100" color="#e54d42" :fontSize="20"> <text> {{ longText }} </text> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="100" name="case-slot"> <text> {{ longText }} </text> <template v-slot:toggle> <text> [插槽] 点我看全文 / 收起 </text> </template> </cu-read-more>
<cu-read-more :toggle="true" :showHeight="100" textIndent="2" customClass="custom-class"> <text> {{ longText }} </text> </cu-read-more>
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 折叠行为 | |||
| showHeight | 收起态内容区高度,px 契约值;运行时 ×2 换算成 rpx | Number | 400 |
| toggle | 展开后是否保留切换按钮;false 时一展开就把按钮隐藏 | Boolean | false |
| name | open / close 事件的载荷,原样回传,用于区分同页多个实例 | String | '' |
| 按钮文案与样式 | |||
| closeText | 收起态的按钮文案 | String | '展开阅读全文' |
| openText | 展开态的按钮文案 | String | '收起' |
| color | 按钮文字色;空串走主题主色 | String | '' |
| fontSize | 按钮文字字号,px 契约值;箭头取字号 + 2 后 ×2 换算成 rpx | Number | 14 |
| 样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| shadowStyle | 底部渐隐遮罩的内联样式;本仓不读取,传了不生效 | Object | (): UTSJSONObject => ({}) |
| textIndent | 内容首行缩进;本仓不读取,缩进请写在插槽内的文字节点上 | String | '' |
| url | 不产生跳转 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @open | 点展开时触发,载荷为 name 原值 | Handler | - | 各端一致 |
| @close | 点收起时触发,载荷同上 | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| (默认) | 放被折叠的正文内容;不填时内容区为空,按钮仍在 |
| toggle | 自定义切换按钮;不填时用 closeText / openText 加三角箭头兜底 |
短内容也出按钮 :折叠与否不量内容真实高度,再短的正文也照样显示切换按钮,点开可能毫无变化;是否真的需要折叠,要由使用侧自己判断。