NoticeBar 通告栏
展示静态、多行、横向跑马灯或纵向轮换公告。
引入
uni-app 配置 easycom 后使用 <hui-notice-bar>。公开类型和函数从 @nscode/handy-uni 导入;普通 Vue 3 安装 @nscode/handy-uni/web 预览插件。
示例
示例可独立运行;交互结果直接显示在页面。
vue
<template>
<view>
<hui-space direction="vertical" fill>
<hui-notice-bar
custom-class="hui-space__item"
text="公告:请及时保存 / Notice: save your work."
closable
@close="lastEvent = 'close'"
@click="(context) => (lastEvent = 'click:' + JSON.stringify(context))"
/>
<hui-notice-bar
custom-class="hui-space__item"
:text="['第一条 / First', '第二条 / Second']"
direction="vertical"
:interval="2500"
@next="(index) => (lastEvent = 'next:' + index)"
@replay="lastEvent = 'replay'"
/>
<hui-notice-bar
custom-class="hui-space__item"
text="长公告 / Long notice. Long notice. Long notice."
wrapable
:scrollable="false"
type="info"
/>
<text class="hui-space__item">{{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
</script>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
text | string | string[] | — | 数组时依次播放 |
type | NoticeBarType | 'warning' | 配色 |
color | string | — | 文字色,优先于 type |
bgColor | string | — | 背景色,优先于 type |
leftIcon | string | 'volume-up' | 传 '' 不显示 |
scrollable | boolean | undefined | 不传时文字超出才滚动;true 总是滚;false 不滚、单行省略号 |
wrapable | boolean | false | 多行显示,不滚动(优先于 scrollable) |
direction | NoticeBarDirection | 'horizontal' | vertical 只对数组有效:每条一行,到时间向上翻 |
speed | number | 50 | 横向滚动速度,px/s |
delay | number | 1000 | 开始滚动前停留,ms(组件用秒,本库时长统一用毫秒) |
interval | number | 3000 | 纵向翻页间隔,ms |
closable | boolean | false | 右侧关闭按钮 |
link | boolean | false | 右侧箭头,整条可点 |
to | string | — | 点击跳转,走适配器 router.push;隐含 link |
根节点类名和样式使用 customClass、customStyle。尺寸数字按 px,时长除明确说明外按 ms。
Events
| 事件 | 参数 |
|---|---|
click | (context: { text: string; index: number }) |
close | () |
next | (index: number) |
replay | () |
受控状态由父级回写更新事件后改变。多词事件使用短横线。禁用操作、取消及过期异步结果不提交成功变更。
Slots
| 插槽 | 作用域 |
|---|---|
left-icon | — |
default | — |
right-icon | — |
方法
| 方法 | 签名 | 说明 |
|---|---|---|
reset | (): Promise<void> | 按当前属性重置 |
pause | (): void | 暂停并保存剩余状态 |
resume | (): void | 继续暂停的动画 |
类型
NoticeBarType、NoticeBarDirection、NoticeBarProps、NoticeBarEmits、NoticeBarExpose.
平台说明
H5 和普通 Web 尊重减少动态效果偏好,退化为静态多行文本。微信和 App 按 scrollable、wrapable 和 direction 控制运行;横向速度单位 px/s,其他时长均为 ms。失活和卸载清理计时器,reset 后重新测量。
设备冒烟清单.