fs-notice-bar.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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-notice1" :color="color"></fs-icon>
  4. <swiper
  5. class="fs-notice-bar-swiper"
  6. autoplay
  7. circular
  8. :vertical="vertical"
  9. :interval="interval"
  10. :duration="1000">
  11. <swiper-item v-for="(item, index) in list" :key="index">
  12. <view class="fs-notice-bar-item line1" @click="handleRoute(item)">{{item[titleKey]}}</view>
  13. </swiper-item>
  14. </swiper>
  15. <fs-icon
  16. v-if="showClose"
  17. class="fs-notice-bar-close"
  18. :color="color"
  19. type="icon-error"
  20. @click="handleClose">
  21. </fs-icon>
  22. </view>
  23. </template>
  24. <script setup>
  25. import { ref } from 'vue'
  26. const props = defineProps({
  27. list: {
  28. type: Array,
  29. default() {
  30. return []
  31. }
  32. },
  33. titleKey: {
  34. type: String,
  35. default: 'title'
  36. },
  37. urlKey: {
  38. type: String,
  39. default: 'url'
  40. },
  41. bgColor: {
  42. type: String,
  43. default: '#fffbe8'
  44. },
  45. color: {
  46. type: String,
  47. default: '#de8c17'
  48. },
  49. vertical: Boolean,
  50. interval: {
  51. type: Number,
  52. default: 5000
  53. },
  54. showClose: {
  55. type: Boolean,
  56. default: true
  57. },
  58. showIcon: {
  59. type: Boolean,
  60. default: true
  61. },
  62. linkType: {
  63. type: String,
  64. default: 'navigateTo'
  65. }
  66. })
  67. const emits = defineEmits(['click'])
  68. let visible = ref(true)
  69. let animationData = ref(null)
  70. const animation = uni.createAnimation({
  71. duration: 200,
  72. })
  73. const handleClose = () => {
  74. animation.scale(0.7, 0.7).opacity(0).step()
  75. animationData.value = animation.export()
  76. setTimeout(() => {
  77. visible.value = false
  78. }, 200)
  79. }
  80. const handleRoute = item => {
  81. if (item[urlKey]) {
  82. uni[props.linkType]({
  83. url: item[urlKey]
  84. })
  85. }
  86. emits('click')
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .fs-notice-bar{
  91. margin: 0 var(--gutter);
  92. position: relative;
  93. display: flex;
  94. align-items: center;
  95. &-notice{
  96. margin-left: var(--gutter);
  97. }
  98. &-swiper{
  99. height: 80rpx;
  100. flex: 1;
  101. }
  102. &-item{
  103. height: 80rpx;
  104. line-height: 80rpx;
  105. padding: 0 var(--gutter);
  106. }
  107. &-close{
  108. margin-right: var(--gutter);
  109. }
  110. }
  111. </style>