01
默认
<cu-notice-bar :text="oneText" @click="onClick" @close="onClose" />
通知栏用于展示系统公告,可横向单行或竖向轮播,并支持点击与关闭。
整目录放进工程即用: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-notice-bar /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuNoticeBar from '@/uni_modules/colorui-x/components/cu-notice-bar/cu-notice-bar.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-notice-bar :text="oneText" @click="onClick" @close="onClose" />
<cu-notice-bar :text="manyText" direction="column" :duration="1500" @click="onClickIndex" /> <cu-notice-bar :text="manyText" direction="row" :step="true" :duration="1200" @click="onClickIndex" />
<cu-notice-bar :text="emptyText" @click="onClick" />
<cu-notice-bar :text="oneText" mode="link" @click="onClick" /> <cu-notice-bar :text="oneText" mode="closable" @click="onClick" @close="onClose" /> <cu-notice-bar :text="oneText" mode="close" @click="onClick" />
<cu-notice-bar :text="oneText" color="#0081ff" bgColor="#cce6ff" @click="onClick" /> <cu-notice-bar :text="oneText" color="#e54d42" bgColor="#fadbd9" @click="onClick" /> <cu-notice-bar :text="oneText" color="" bgColor="" @click="onClick" />
<cu-notice-bar :text="oneText" :fontSize="12" @click="onClick" /> <cu-notice-bar :text="oneText" @click="onClick" /> <cu-notice-bar :text="oneText" :fontSize="18" @click="onClick" /> <cu-notice-bar :text="oneText" :fontSize="0" @click="onClick" />
<cu-notice-bar :text="oneText" icon="cuIcon-warnfill" @click="onClick" /> <cu-notice-bar :text="oneText" icon="" @click="onClick" /> <cu-notice-bar :text="oneText" icon="cuIcon-not-exist" @click="onClick" />
<cu-notice-bar :text="manyText" :speed="30" @click="onClick" /> <cu-notice-bar :text="manyText" direction="column" :duration="800" @click="onClickIndex" /> <cu-notice-bar :text="manyText" direction="column" :duration="3000" :disableTouch="false" @click="onClickIndex" />
<cu-notice-bar :text="oneText" url="/pages/base/cu-grid" linkType="navigateTo" @click="onClick" /> <cu-notice-bar :text="oneText" url="" @click="onClick" />
<cu-notice-bar :text="oneText" :customStyle="barStyle" customClass="custom-class" @click="onClick" /> <cu-notice-bar :text="manyText" direction="column" @click="onClickIndex"> <template v-slot:icon> <text> 告 </text> </template> </cu-notice-bar>
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 内容与方向 | |||
| text | 通知文案数组,多个元素按空格串接;竖向档每条独占一屏 | Array | (): Array<any> => [] |
| direction | row / column,横向整行或竖向轮播 | String | 'row' |
| step | 配合 row 使用,改为逐条上下轮播档 | Boolean | false |
| 外观 | |||
| icon | 左侧图标名,取 cu-icon 白名单;空串不渲染图标位 | String | 'cuIcon-notificationfill' |
| mode | link 显示右侧箭头、closable 显示关闭按钮;空串两者都不显示 | String | '' |
| color | 文字与图标颜色;空串走主题警示色 | String | '' |
| bgColor | 整条底色;空串走主题警示浅底 | String | '' |
| fontSize | 文字字号,px 契约值;运行时 ×2 换算成 rpx | Number | 14 |
| 播放与交互 | |||
| duration | 竖向轮播每条停留时长,毫秒 | Number | 2000 |
| speed | 横向滚动速度;本仓未实现跑马灯,当前不生效 | Number | 80 |
| disableTouch | 竖向档是否禁止手势滑动切换 | Boolean | true |
| url | 点击后要去的页面地址;空串只派发 click 不跳转 | String | '' |
| linkType | 跳转方式,随 url 一起生效,默认 navigateTo | String | 'navigateTo' |
| 样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @click | 点整条通知时触发;竖向档回传当前条下标,横向档无载荷 | Handler | - | 各端一致 |
| @close | 点关闭按钮时触发,无载荷,同时整条隐藏 | Handler | - | 各端一致 |
本件没有插槽。
关闭不可复原 :点过关闭后整条被卸载,组件没有重新显示的入口;之后要再出现,只能由父级换 key 重建或重新挂载。
文案须为数组 :文案按数组接收,横向档会把各项用空格拼成一行;只传一个字符串不满足类型契约,单条也要写成只含一项的数组。