组件 / 数据展示 / cu-read-more 展开全文

cu-read-more

展开全文把长正文折叠到固定高度,由按钮控制展开与收起。

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-read-more />

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

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

02 / Platform

平台支持

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

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

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

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

03 / Demo

代码演示

01

默认

uvue
<cu-read-more name="case-default" @open="onOpen" @close="onClose">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
02

可反复切换

uvue
<cu-read-more :toggle="true" :showHeight="120" name="case-toggle" @open="onOpen" @close="onClose">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
03

极小高度

uvue
<cu-read-more :toggle="true" :showHeight="40" name="case-tiny">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
04

零高度

uvue
<cu-read-more :toggle="true" :showHeight="0" name="case-zero">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
05

短内容

uvue
<cu-read-more :toggle="true" :showHeight="400" name="case-short">
  <text>
    只有一句话的短内容。
  </text>
</cu-read-more>
06

超长文本

uvue
<cu-read-more :toggle="true" :showHeight="200" name="case-huge">
  <text>
    {{ hugeText }}
  </text>
</cu-read-more>
07

按钮文案

uvue
<cu-read-more :toggle="true" :showHeight="100" closeText="展开阅读全文(本文约三千字,阅读需要十分钟)" openText="收起全文,不再看了">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
08

颜色 / 字号

uvue
<cu-read-more :toggle="true" :showHeight="100" color="#e54d42" :fontSize="20">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
09

插槽

uvue
<cu-read-more :toggle="true" :showHeight="100" name="case-slot">
  <text>
    {{ longText }}
  </text>
  <template v-slot:toggle>
    <text>
      [插槽] 点我看全文 / 收起
    </text>
  </template>
</cu-read-more>
10

未消费项

uvue
<cu-read-more :toggle="true" :showHeight="100" textIndent="2" customClass="custom-class">
  <text>
    {{ longText }}
  </text>
</cu-read-more>
11

最近事件

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

12

取值与事件

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

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
折叠行为
showHeight收起态内容区高度,px 契约值;运行时 ×2 换算成 rpxNumber400
toggle展开后是否保留切换按钮;false 时一展开就把按钮隐藏Booleanfalse
nameopen / close 事件的载荷,原样回传,用于区分同页多个实例String''
按钮文案与样式
closeText收起态的按钮文案String'展开阅读全文'
openText展开态的按钮文案String'收起'
color按钮文字色;空串走主题主色String''
fontSize按钮文字字号,px 契约值;箭头取字号 + 2 后 ×2 换算成 rpxNumber14
样式
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
shadowStyle底部渐隐遮罩的内联样式;本仓不读取,传了不生效Object(): UTSJSONObject => ({})
textIndent内容首行缩进;本仓不读取,缩进请写在插槽内的文字节点上String''
url不产生跳转String''
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@open点展开时触发,载荷为 name 原值Handler-各端一致
@close点收起时触发,载荷同上Handler-各端一致

slots

slot说明
(默认)放被折叠的正文内容;不填时内容区为空,按钮仍在
toggle自定义切换按钮;不填时用 closeText / openText 加三角箭头兜底
05 / Notes

注意事项

短内容也出按钮 :折叠与否不量内容真实高度,再短的正文也照样显示切换按钮,点开可能毫无变化;是否真的需要折叠,要由使用侧自己判断。