Skip to content

XtfNoticeBar

组件说明

xtf-notice-bar 是用于发布运营通知、系统提醒和活动公告的通告栏组件,支持单行省略、滚动、图标、查看更多及关闭。与 xtf-marquee 相比,它额外提供了公告栏布局和操作事件。


基础用法

1. 基础公告

用于展示简短的静态通知。

vue
<template><xtf-notice-bar text="新版本已发布,欢迎体验。" /></template>
<script>
export default {}
</script>

2. 单行图标公告

空间有限时以省略方式展示,并强化提示图标。

vue
<template>
  <xtf-notice-bar single show-icon text="订单量较昨日增长 18%,请及时处理新增订单。" />
</template>
<script>
export default {}
</script>

3. 滚动与查看更多

用于较长公告,并处理查看更多事件。

vue
<template>
  <xtf-notice-bar
    show-icon
    scrollable
    show-get-more
    more-text="详情"
    text="本周五 22:00 至周六 02:00 将进行系统维护,期间部分服务可能短暂不可用。"
    @getmore="showDetail"
  />
</template>
<script>
export default {
  methods: {
    showDetail() {
      uni.showToast({ title: '打开公告详情', icon: 'none' })
    }
  }
}
</script>

4. 可关闭公告

关闭后组件会自行隐藏,并发送关闭通知。

vue
<template>
  <xtf-notice-bar
    single
    show-close
    color="#2979ff"
    background-color="#eaf2ff"
    text="已为你保存草稿。"
    @close="onClose"
  />
</template>
<script>
export default {
  methods: {
    onClose() {
      console.log('notice closed')
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
textString''公告文本所有公告
backgroundColorString'#FFF9EA'背景色需要品牌色时
colorString'#FF9A43'文字及图标颜色需要调整强调色时
speedString | Number48滚动速度scrollable 为真时
singleBoolean | Stringfalse单行溢出省略紧凑布局
scrollableBoolean | Stringfalse启用跑马灯长文本公告
showIconBoolean | Stringfalse显示左侧图标需要视觉提示时
showGetMoreBoolean | Stringfalse显示右侧查看更多入口有详情页时
moreTextString''查看更多文案,空时显示箭头自定义入口文案
showCloseBoolean | Stringfalse显示关闭按钮可忽略提醒
iconString''左侧图标名,空时为 volume_upshowIcon 为真时
customClassString''根节点自定义类名局部样式定制
customStyleString | Object''根节点自定义样式局部样式定制

事件

事件名称触发时机回调参数参数说明
click点击公告主体时()
getmore点击查看更多区域时()
close点击关闭按钮并隐藏后()

事件使用示例

vue
<template>
  <xtf-notice-bar
    show-get-more
    show-close
    text="服务通知"
    @click="log('click')"
    @getmore="log('getmore')"
    @close="log('close')"
  />
</template>
<script>
export default {
  methods: {
    log(type) {
      console.log('notice event:', type)
    }
  }
}
</script>

主题说明

  • 背景由 var(--xtf-notice-bar-bg) 控制,组件会将 backgroundColor 写入该变量。
  • 文本和图标由 var(--xtf-notice-bar-color) 控制,组件会将 color 写入该变量。
  • 通过 customStylextf-config-provider 覆盖变量即可统一调整主题。

MIT Licensed