fs-notice-bar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="fs-notice-bar" :animation="animationData" :style="{ backgroundColor: bgColor, color }" v-if="visible">
  3. <fs-icon v-if="showIcon" class="fs-notice-bar-notice" type="icon-sound" :color="color"></fs-icon>
  4. <swiper class="fs-notice-bar-swiper" autoplay circular :vertical="vertical" :interval="interval" :duration="1000">
  5. <swiper-item v-for="(item, index) in list" :key="index">
  6. <view class="fs-notice-bar-item line1" @click="handleRoute(item)">{{ item[titleKey] }}</view>
  7. </swiper-item>
  8. </swiper>
  9. <fs-icon
  10. v-if="showClose"
  11. class="fs-notice-bar-close"
  12. :color="color"
  13. type="icon-close-circle"
  14. @click="handleClose"
  15. ></fs-icon>
  16. </view>
  17. </template>
  18. <script>
  19. /**
  20. * 通告栏组件
  21. * @description 通告栏组件
  22. * @property {Array} list 通告栏列表
  23. * @property {String} titleKey 展示标题的key
  24. * @property {String} urlKey 跳转路径的key
  25. * @property {String} bgColor 背景色
  26. * @property {String} color 文字颜色
  27. * @property {Number} vertical 是否垂直滚动
  28. * @property {String} interval 滚动间隔
  29. * @property {Boolean} showClose 是否显示关闭按钮
  30. * @property {Boolean} showIcon 是否显示通知icon
  31. * @property {String} linkType 跳转类型
  32. */
  33. export default {
  34. name: 'fs-notice-bar'
  35. }
  36. </script>
  37. <script setup>
  38. import { ref } from 'vue'
  39. const props = defineProps({
  40. list: {
  41. type: Array,
  42. default() {
  43. return []
  44. }
  45. },
  46. titleKey: {
  47. type: String,
  48. default: 'title'
  49. },
  50. urlKey: {
  51. type: String,
  52. default: 'url'
  53. },
  54. bgColor: {
  55. type: String,
  56. default: '#fffbe8'
  57. },
  58. color: {
  59. type: String,
  60. default: '#de8c17'
  61. },
  62. vertical: Boolean,
  63. interval: {
  64. type: Number,
  65. default: 5000
  66. },
  67. showClose: {
  68. type: Boolean,
  69. default: true
  70. },
  71. showIcon: {
  72. type: Boolean,
  73. default: true
  74. },
  75. linkType: {
  76. type: String,
  77. default: 'navigateTo'
  78. }
  79. })
  80. const emits = defineEmits(['click'])
  81. let visible = ref(true)
  82. let animationData = ref(null)
  83. const animation = uni.createAnimation({
  84. duration: 200
  85. })
  86. const handleClose = () => {
  87. animation
  88. .scale(0.7, 0.7)
  89. .opacity(0)
  90. .step()
  91. animationData.value = animation.export()
  92. setTimeout(() => {
  93. visible.value = false
  94. }, 200)
  95. }
  96. const handleRoute = item => {
  97. if (item[urlKey]) {
  98. uni[props.linkType]({
  99. url: item[urlKey]
  100. })
  101. }
  102. emits('click')
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .fs-notice-bar {
  107. margin: 0 var(--gutter);
  108. position: relative;
  109. display: flex;
  110. align-items: center;
  111. &-notice {
  112. margin-left: var(--gutter);
  113. }
  114. &-swiper {
  115. height: 80rpx;
  116. flex: 1;
  117. }
  118. &-item {
  119. height: 80rpx;
  120. line-height: 80rpx;
  121. padding: 0 var(--gutter);
  122. }
  123. &-close {
  124. margin-right: var(--gutter);
  125. }
  126. }
  127. </style>