NoticeBar 通告栏
17:06说明
滚动展示通知、公告等内容,内容由 list 数组提供,支持 success/error/primary/info/warning/none 主题、自定义文字与背景色、左右图标与关闭按钮,play-state 控制播放与暂停。水平方向默认采用无缝衔接滚动,垂直方向用 swiper 逐条切换,二者分别由内部的 ux-row-notice 与 ux-column-notice 承载。
兼容性
| 平台 | 支持情况 |
|---|---|
| App | ✅ 支持 |
| H5 | ✅ 支持 |
| 微信小程序 | ✅ 支持 |
示例
水平 - 基础用法
通过 list 数组配置滚动内容,默认 warning 主题,水平左右滚动。
查看源码
vue
<template>
<ux-notice-bar :list="list" @click="onClick"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
function onClick(): void {
uni.showToast({ title: '点击了通知', icon: 'none' });
}
</script>水平 - 配置主题
通过 type 配置 success/error/primary/info/warning/none 主题。
查看源码
vue
<template>
<ux-notice-bar type="primary" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar type="success" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar type="error" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar type="info" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar type="none" :list="list"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>
<style scoped>
.gap {
height: 12px;
}
</style>水平 - 配置图标
volume-icon 左侧喇叭,more-icon 右侧箭头,close-icon 右侧关闭。
查看源码
vue
<template>
<ux-notice-bar :volume-icon="false" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar :more-icon="true" :list="list" @get-more="onGetMore"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar :close-icon="true" :list="list" @close="onClose"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
function onGetMore(): void {
uni.showToast({ title: '点击了更多', icon: 'none' });
}
function onClose(): void {
uni.showToast({ title: '关闭了通知', icon: 'none' });
}
</script>
<style scoped>
.gap {
height: 12px;
}
</style>水平 - 自定义颜色
通过 color/bg-color 自定义文字和图标的颜色、背景颜色。
查看源码
vue
<template>
<ux-notice-bar color="#2979ff" bg-color="#ecf5ff" :list="list"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>水平 - 控制滚动
autoplay 控制是否自动播放,play-state 控制播放/暂停,speed 控制速度。
查看源码
vue
<template>
<ux-notice-bar :speed="200" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar :play-state="playState" :list="list"></ux-notice-bar>
<view class="gap"></view>
<view class="btn" @click="onToggle">
<text class="btn-text">{{ playing ? '暂停' : '播放' }}</text>
</view>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
const playing = ref<boolean>(true);
const playState = ref<string>('play');
function onToggle(): void {
playing.value = !playing.value;
playState.value = playing.value ? 'play' : 'paused';
}
</script>
<style scoped>
.gap {
height: 12px;
}
.btn {
background-color: #2979ff;
border-radius: 4px;
padding-top: 8px;
padding-right: 16px;
padding-bottom: 8px;
padding-left: 16px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.btn-text {
font-size: 14px;
color: #ffffff;
}
</style>垂直 - 基础用法
通过 list 数组配置滚动内容,默认 warning 主题,垂直上下滚动。
查看源码
vue
<template>
<ux-notice-bar mode="vertical" :list="list" @click="onClick"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
function onClick(): void {
uni.showToast({ title: '点击了通知', icon: 'none' });
}
</script>垂直 - 配置主题
通过 type 配置 success/primary/info/none 主题。
查看源码
vue
<template>
<ux-notice-bar mode="vertical" type="primary" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" type="success" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" type="info" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" type="none" :list="list"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>
<style scoped>
.gap {
height: 12px;
}
</style>垂直 - 配置图标
volume-icon 左侧喇叭,more-icon 右侧箭头,close-icon 右侧关闭。
查看源码
vue
<template>
<ux-notice-bar mode="vertical" :volume-icon="false" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" :more-icon="true" :list="list" @get-more="onGetMore"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" :close-icon="true" :list="list" @close="onClose"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
function onGetMore(): void {
uni.showToast({ title: '点击了更多', icon: 'none' });
}
function onClose(): void {
uni.showToast({ title: '关闭了通知', icon: 'none' });
}
</script>
<style scoped>
.gap {
height: 12px;
}
</style>垂直 - 自定义颜色
通过 color/bg-color 自定义文字和图标的颜色、背景颜色。
查看源码
vue
<template>
<ux-notice-bar mode="vertical" color="#2979ff" bg-color="#ecf5ff" :list="list"></ux-notice-bar>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
</script>垂直 - 控制滚动
play-state 控制播放/暂停,duration 控制滚动周期,disable-touch 禁止手滑。
查看源码
vue
<template>
<ux-notice-bar mode="vertical" :play-state="playState" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" :duration="4000" :list="list"></ux-notice-bar>
<view class="gap"></view>
<ux-notice-bar mode="vertical" :disable-touch="false" :list="list" @end="onEnd"></ux-notice-bar>
<view class="gap"></view>
<view class="btn" @click="onToggle">
<text class="btn-text">{{ playing ? '暂停' : '播放' }}</text>
</view>
</template>
<script setup lang="uts">
const list = ['这是一条重要的公告消息', '今天下午三点召开项目评审会议', '系统将于本周六凌晨进行升级维护', '新版本组件库已发布,欢迎体验'];
const playing = ref<boolean>(true);
const playState = ref<string>('play');
function onToggle(): void {
playing.value = !playing.value;
playState.value = playing.value ? 'play' : 'paused';
}
function onEnd(): void {
uni.showToast({ title: '轮播结束', icon: 'none' });
}
</script>
<style scoped>
.gap {
height: 12px;
}
.btn {
background-color: #2979ff;
border-radius: 4px;
padding-top: 8px;
padding-right: 16px;
padding-bottom: 8px;
padding-left: 16px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.btn-text {
font-size: 14px;
color: #ffffff;
}
</style>API
Props
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
customStyle | 自定义根节点样式 | UTSJSONObject | - | - |
customClass | 自定义根节点样式类 | string | '' | - |
list | 滚动内容,数组形式 | string[] | - | - |
type | 显示主题,success/error/primary/info/warning/none | ThemeType | 'none' | 'warning' | - |
volumeIcon | 是否显示左侧喇叭图标 | boolean | true | - |
volumeSize | 左侧喇叭图标大小,单位px | number | string | 17 | - |
moreIcon | 是否显示右侧向右箭头 | boolean | false | - |
closeIcon | 是否显示右侧关闭图标 | boolean | false | - |
autoplay | 是否自动播放(当前未转发给内部子组件) | boolean | true | - |
color | 文字颜色,各图标也使用该颜色 | string | '' | - |
bgColor | 背景颜色 | string | '' | - |
mode | 滚动方向,horizontal-水平,vertical-垂直 | Direction | 'horizontal' | - |
show | 是否显示 | boolean | true | - |
fontSize | 字体大小,单位px | number | string | 14 | - |
duration | 每条内容的切换周期,单位ms(仅 swiper 模式生效) | number | string | 2000 | - |
speed | 水平无缝滚动的速度,每秒滚动多少px(仅水平无缝模式生效) | number | string | 80 | - |
isCircular | 是否开启水平无缝衔接滚动(仅水平方向生效) | boolean | true | - |
playState | 播放状态,play-播放,paused-暂停 | PlayState | 'play' | - |
disableTouch | 是否禁止手动滑动切换(仅 swiper 模式生效) | boolean | true | - |
borderRadius | 圆角,单位px(大于 0 时生效) | number | string | 0 | - |
padding | 内边距 | number | string | '9px 12px' | - |
noListHidden | list 为空时是否隐藏 | boolean | true | - |
Events
| 事件名 | 说明 | 回调参数 | 版本 |
|---|---|---|---|
click | 点击通告文字触发,index 为内容下标(水平无缝模式恒为 0) | index: number | - |
close | 点击关闭图标触发 | - | - |
getMore | 点击右侧更多箭头触发 | - | - |
end | 滚动到最后一条内容时触发(仅 swiper 模式) | - | - |
Slots
ux-notice-bar 无插槽。
注意事项
- 内部实现由
mode与isCircular决定:mode='horizontal'且isCircular=true时用ux-row-notice做无缝衔接滚动,其余情况(isCircular=false的水平、以及mode='vertical')用ux-column-notice的 swiper 逐条切换。 isCircular只在水平方向生效,垂直方向固定走 swiper。- 水平无缝模式会把
list用中文逗号「,」拼成一条连续文本滚动,click回调的 index 恒为 0;只有 swiper 模式才按条展示并回传真实下标。 - 无缝滚动仅在单条文本宽度超过容器宽度时才会滚动,内容较短时保持静止。
speed仅水平无缝模式生效,duration与disableTouch仅 swiper 模式生效,不要混用。end仅在 swiper 模式滚动到最后一条时触发。autoplay当前未转发给内部子组件,暂停请改用play-state='paused'。type='none'时无背景(透明),文字取 content 色;其余主题使用浅色背景加主题色文字。noListHidden默认true,list为空时整个组件隐藏;show=false同样会隐藏。