更新记录
1.0.0(2025-12-07)
下载此版本
appx-notice-bar 是基于 uniappx 开发的通用通告栏组件,用于展示系统通知、活动提醒等轻量提示信息。组件保留核心交互能力(关闭按钮、基础样式自定义),移除了滚动动画相关逻辑(仅保留兼容参数),具备样式高度可定制、交互简洁的特点,适配多端展示。
平台兼容性
uni-app x(4.87)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| √ |
√ |
√ |
√ |
√ |
√ |
appx-notice-bar 通告栏组件
组件介绍
appx-notice-bar 是基于 uniappx 开发的通用通告栏组件,用于展示系统通知、活动提醒等轻量提示信息。组件保留核心交互能力(关闭按钮、基础样式自定义),移除了滚动动画相关逻辑(仅保留兼容参数),具备样式高度可定制、交互简洁的特点,适配多端展示。
组件属性(Props)
| 属性名 |
类型 |
默认值 |
说明 |
| text |
string |
'' |
通告栏展示的文本内容 |
| showIcon |
boolean / string |
true |
是否显示左侧图标(字符串类型支持"true"/"false") |
| icon |
string |
'📢' |
左侧图标内容(支持 emoji、文本、图标字体字符) |
| iconSize |
string / number |
'16px' |
左侧图标尺寸(数字类型自动拼接px) |
| iconColor |
string |
'#FF6600' |
左侧图标颜色(支持十六进制、rgb等格式) |
| iconMargin |
string / number |
'8px' |
左侧图标右侧外边距(数字类型自动拼接px) |
| scroll |
boolean / string |
true |
【兼容保留】是否开启滚动(无实际功能) |
| scrollDuration |
number / string |
10 |
【兼容保留】滚动时长(无实际功能) |
| delay |
number / string |
1 |
【兼容保留】滚动延迟(无实际功能) |
| loop |
boolean / string |
true |
【兼容保留】是否循环滚动(无实际功能) |
| showClose |
boolean / string |
true |
是否显示右侧关闭按钮(字符串类型支持"true"/"false") |
| closeIcon |
string |
'✕' |
关闭按钮内容(支持 emoji、文本、图标字体字符) |
| closeSize |
string / number |
'16px' |
关闭按钮尺寸(数字类型自动拼接px) |
| closeColor |
string |
'#666666' |
关闭按钮默认颜色(支持十六进制、rgb等格式) |
| closeMargin |
string / number |
'8px' |
关闭按钮左侧外边距(数字类型自动拼接px) |
| bgColor |
string |
'#FFF7E6' |
通告栏背景色(支持十六进制、rgb等格式) |
| textColor |
string |
'#FF6600' |
文本颜色(支持十六进制、rgb等格式) |
| textSize |
string / number |
'14px' |
文本字号(数字类型自动拼接px) |
| lineHeight |
string / number |
'20px' |
文本行高(数字类型自动拼接px) |
| padding |
string / number |
'8px 12px' |
通告栏内边距(数字类型自动拼接px) |
| containerStyle |
object / string |
{} |
容器自定义样式(字符串类型需符合JSON格式,支持替换单引号) |
| iconStyle |
object / string |
{} |
图标自定义样式(字符串类型需符合JSON格式,支持替换单引号) |
| contentStyle |
object / string |
{} |
文本自定义样式(字符串类型需符合JSON格式,支持替换单引号) |
| closeStyle |
object / string |
{} |
关闭按钮自定义样式(字符串类型需符合JSON格式,支持替换单引号) |
组件事件
| 事件名 |
说明 |
回调参数 |
| close |
点击关闭按钮时触发 |
无 |
基础使用示例
<template>
<appx-notice-bar
text="这是一条普通的通告栏提示信息"
@close="handleNoticeClose"
/>
</template>
<script lang="uts" setup>
const handleNoticeClose = () => {
console.log('通告栏已关闭');
};
</script>
自定义样式示例
<template>
<appx-notice-bar
text="自定义样式的通告栏"
bgColor="#E8F4F8"
textColor="#1890FF"
icon="🔔"
iconColor="#1890FF"
closeColor="#1890FF"
:containerStyle="{ borderRadius: '8px' }"
:contentStyle="{ fontWeight: 'bold' }"
/>
</template>
禁用关闭按钮示例
<template>
<appx-notice-bar
text="无关闭按钮的通告栏"
showClose="false"
/>
</template>
禁用左侧图标示例
<template>
<appx-notice-bar
text="无左侧图标的通告栏"
showIcon="false"
/>
</template>
样式字符串传入示例
<template>
<appx-notice-bar
text="样式字符串自定义示例"
containerStyle="{'border': '1px solid #FF6600', 'margin': '10px 0'}"
/>
</template>
注意事项
- 组件兼容布尔值/数字类型的属性传入字符串形式(如
showIcon="false"),内部会自动解析;
- 自定义样式传入字符串时,需保证格式接近JSON(组件会自动替换单引号为双引号、补全属性名引号),解析失败会默认使用空样式;
- 尺寸类属性传入数字时,会自动拼接
px单位,如需使用其他单位(如rpx、rem),请传入字符串形式;
- 滚动相关属性仅做兼容保留,无实际功能,如需滚动效果需自行扩展;
- 关闭按钮点击后会隐藏整个通告栏,如需重新显示可通过父组件控制组件的
v-show/v-if。