组件 / 基础 / cu-text 文本

cu-text

文本按统一的字号与颜色展示一段文字,支持脱敏与链接档。

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-text />

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

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

02 / Platform

平台支持

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

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

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

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

03 / Demo

代码演示

01

默认

uvue
<cu-text text="ColorUI-X 文本" />
02

类型色

uvue
<cu-text type="primary" text="type=primary" />
<cu-text type="warning" text="type=warning" />
<cu-text type="success" text="type=success" />
<cu-text type="info" text="type=info" />
<cu-text type="error" text="type=error" />
<cu-text type="main" text="type=main" />
<cu-text type="content" text="type=content" />
<cu-text type="tips" text="type=tips" />
<cu-text type="light" text="type=light" />
03

展示模式

uvue
<cu-text mode="text" text="mode=text" />
<cu-text mode="price" text="10000" />
<cu-text mode="phone" text="12345678901" />
<cu-text mode="name" text="张三" />
<cu-text mode="date" text="2026-10-18" />
<cu-text mode="link" href="/pages/base/cu-image" text="mode=link 委托 cu-link" />
04

脱敏

uvue
<cu-text mode="phone" format="encrypt" text="12345678901" />
<cu-text mode="phone" format="encrypt" text="123" />
<cu-text mode="name" format="encrypt" text="张三" />
<cu-text mode="name" format="encrypt" text="欧阳修文" />
05

排版

uvue
<cu-text :size="22" text="size 22 → 44rpx" />
<cu-text color="#e54d42" text="color 使用者传值(走内联,§6 第 3 条)" />
<cu-text :bold="true" text="bold 加粗" />
<cu-text align="center" text="align=center" />
<cu-text align="right" text="align=right" />
<cu-text lineHeight="60rpx" text="lineHeight=60rpx(本仓要求带单位,见组件内注释)" />
<cu-text decoration="underline" text="decoration=underline" />
<cu-text decoration="line-through" text="decoration=line-through" />
06

边界

uvue
<cu-text text="这是一段用来观察换行与截断行为的超长中文文本,lines 在本仓声明未消费,所以它只会按自然换行铺开而不会出现多行省略号,这正是需要真机复核的观察点" />
<cu-text :lines="'1'" text="lines=1 已传但未消费(上一条同形)" />
<cu-text :block="true" text="block=true 未消费(参考实现落 display: block,编译器拒)" />
<cu-text wordWrap="break-word" text="wordWrap 未消费(word-wrap 属性本仓无实测依据)" />
<cu-text openType="share" text="openType 未消费(小程序 button 专属分支)" />
<cu-text text="" />
<cu-text :show="false" text="show=false,这行不应出现" />
07

前后图标

uvue
<cu-text prefixIcon="cuIcon-pic" text="前置图标" />
<cu-text suffixIcon="cuIcon-right" text="后置图标" />
<cu-text prefixIcon="cuIcon-pic" suffixIcon="cuIcon-roundclose" text="两端图标" />
<cu-text :iconStyle="iconStyleDemo" prefixIcon="cuIcon-pic" text="iconStyle 传了但未消费" />
08

拨打 / 自定义

uvue
<cu-text :call="true" mode="phone" text="10086" />
<cu-text :margin="10" text="margin=10 → 20rpx 四向" />
<cu-text customClass="custom-class" text="customClass 追加在类串末尾" />
<cu-text :customStyle="blockStyle" text="customStyle 传对象" @click="onEcho" />
09

取值与事件

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

04 / Props · Events · Slots

全量 API

props

参数说明类型默认值
内容
text要显示的文字String''
modetext / price / phone / name / link;link 档走链接样式String''
show是否显示Booleantrue
外观
typeprimary / warning / success / info / error / main / content / tips / light 色档String''
size字号,px 契约值;运行时 ×2 换算成 rpxNumber15
color文字颜色;指定 type 档时由色档接管String'#303133'
bold加粗Booleanfalse
decorationnone / underline / line-throughString'none'
lineHeight行高,需自带单位String''
alignleft / center / rightString'left'
margin外边距,px 契约值;0 不带单位Number0
前后缀图标
prefixIcon文字前的图标名,取 cu-icon 白名单String''
suffixIcon文字后的图标名String''
链接与格式
hrefmode=link 时传给链接的目标地址String''
formatphone / name 搭配 encrypt 做脱敏String''
callphone 档点击时是否直接拨号Booleanfalse
交互与样式
customStyle根节点内联样式Object(): UTSJSONObject => ({})
customClass追加到根节点的类名String''
声明保留但不被消费
openType微信开放能力;本仓 App 端不接通String''
block块状显示;本仓 display 只支持 flex / none,传了不生效Booleanfalse
lines多行省略行数;App 端未实测,传了不生效String''
iconStyle图标样式透传;本仓 cu-icon 只收 name / size / color,传了不生效Object(): UTSJSONObject => ({ fontSize: '15px' })
wordWrap断词规则;本仓未消费String'normal'
url不产生跳转String''
linkType不产生跳转,同上String'navigateTo'

events

事件说明类型默认值平台差异说明
@click点击时触发,无载荷;phone 档且 call 为真时先拨号Handler-各端一致

slots

本件没有插槽。

05 / Notes

注意事项

23 · 下划线不渲染 :decoration=underline 在 App 端不显示;需要下划线请用 mode=link。

脱敏规则 :phone 档保留前 3 位与后 4 位,name 档保留首尾字符。