01
默认
<cu-alert title="这是一条默认档提示" />
警告条在内容区里显示一条带色的提示框,用于说明风险或引导操作。
整目录放进工程即用: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-alert /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuAlert from '@/uni_modules/colorui-x/components/cu-alert/cu-alert.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-alert title="这是一条默认档提示" />
<cu-alert title="primary" type="primary" effect="light" /> <cu-alert title="success" type="success" effect="light" /> <cu-alert title="warning" type="warning" effect="light" /> <cu-alert title="error" type="error" effect="light" /> <cu-alert title="info" type="info" effect="light" />
<cu-alert title="primary dark" type="primary" effect="dark" /> <cu-alert title="success dark" type="success" effect="dark" /> <cu-alert title="warning dark" type="warning" effect="dark" /> <cu-alert title="error dark" type="error" effect="dark" /> <cu-alert title="info dark" type="info" effect="dark" />
<cu-alert title="带辅助文字" description="辅助文字颜色比标题浅一档、字号同由 fontSize 决定。" /> <cu-alert title="居中排版" description="center 为真时标题与辅助文字都居中。" :center="true" />
<cu-alert title="success 图标" type="success" :showIcon="true" /> <cu-alert title="info 图标(dark)" type="info" effect="dark" :showIcon="true" />
<cu-alert title="fontSize 12" :fontSize="12" /> <cu-alert title="fontSize 14(默认)" :fontSize="14" /> <cu-alert title="fontSize 18" type="error" effect="dark" :fontSize="18" />
<cu-alert type="info" /> <cu-alert title="这是一条用于观察提示条换行的超长标题,超长标题继续重复以撑满整行并触发换行" description="超长辅助文字:重复第三轮以观察关闭图标是否压住文字、内容区右内距是否如实留出、以及文字会不会被容器裁切。" type="warning" :closable="true" @click="onAlertClick" />
<cu-alert v-if="closableMounted" title="可关闭:点右侧叉号" :closable="true" type="error" /> <cu-alert v-if="closableMounted" title="可关闭 + 图标 + 居中" :closable="true" :showIcon="true" :center="true" type="success" description="关闭按钮是 position: absolute 的浮层,App 端绝对定位未实测 ⇒ 真机验证项。" />
<cu-alert title="customClass 大圆角" customClass="custom-class" @click="onAlertClick" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 内容 | |||
| title | 标题文字,加粗一行;空串不渲染 | String | '' |
| description | 辅助说明文字;空串不渲染 | String | '' |
| 外观 | |||
| type | success / warning / info / error / primary,决定底色与左侧图标 | String | 'warning' |
| effect | light 浅底深字 / dark 实底白字 | String | 'light' |
| showIcon | true ⇒ 左侧显示随 type 变化的图标 | Boolean | false |
| center | true ⇒ 标题与说明居中,默认靠左 | Boolean | false |
| fontSize | 标题与说明的字号,px 契约值;运行时 ×2 换算成 rpx | Number | 14 |
| 交互与样式 | |||
| closable | true ⇒ 右侧显示关闭按钮,点击后整块不再渲染,且不抛事件 | Boolean | false |
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| url | 不产生跳转,请在 click 里自行跳转 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @click | 点击提示框主体时触发,无载荷;点右侧关闭按钮不触发 | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| (默认) | 自定义提示内容;不填时按 title 与 description 渲染两行文字 |
关掉就回不来 :点关闭只把组件内部一个可见开关置假,既不发事件也没有受控入口;一旦关掉,想再显示只能让页面重新挂载它。