123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <template>
- <view
- class="u-notice"
- @tap="clickHandler"
- >
- <slot name="icon">
- <view
- class="u-notice__left-icon"
- v-if="icon"
- >
- <u-icon
- :name="icon"
- :color="color"
- size="19"
- ></u-icon>
- </view>
- </slot>
- <swiper
- :disable-touch="disableTouch"
- :vertical="step ? false : true"
- circular
- :interval="duration"
- :autoplay="true"
- class="u-notice__swiper"
- @change="noticeChange"
- >
- <swiper-item
- v-for="(item, index) in text"
- :key="index"
- class="u-notice__swiper__item"
- >
- <text
- class="u-notice__swiper__item__text u-line-1"
- :style="[textStyle]"
- >{{ item }}</text>
- </swiper-item>
- </swiper>
- <view
- class="u-notice__right-icon"
- v-if="['link', 'closable'].includes(mode)"
- >
- <u-icon
- v-if="mode === 'link'"
- name="arrow-right"
- :size="17"
- :color="color"
- ></u-icon>
- <u-icon
- v-if="mode === 'closable'"
- name="close"
- :size="16"
- :color="color"
- @click="close"
- ></u-icon>
- </view>
- </view>
- </template>
- <script>
- import props from './props.js';
-
- export default {
- mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
- watch: {
- text: {
- immediate: true,
- handler(newValue, oldValue) {
- if(!uni.$u.test.array(newValue)) {
- uni.$u.error('noticebar组件direction为column时,要求text参数为数组形式')
- }
- }
- }
- },
- computed: {
-
- textStyle() {
- let style = {}
- style.color = this.color
- style.fontSize = uni.$u.addUnit(this.fontSize)
- return style
- },
-
- vertical() {
- if (this.mode == 'horizontal') return false
- else return true
- },
- },
- data() {
- return {
- index:0
- }
- },
- methods: {
- noticeChange(e){
- this.index = e.detail.current
- },
-
- clickHandler() {
- this.$emit('click', this.index)
- },
-
- close() {
- this.$emit('close')
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/components.scss";
- .u-notice {
- @include flex;
- align-items: center;
- justify-content: space-between;
- &__left-icon {
- align-items: center;
- margin-right: 5px;
- }
- &__right-icon {
- margin-left: 5px;
- align-items: center;
- }
- &__swiper {
- height: 16px;
- @include flex;
- align-items: center;
- flex: 1;
- &__item {
- @include flex;
- align-items: center;
- overflow: hidden;
- &__text {
- font-size: 14px;
- color: $u-warning;
- }
- }
- }
- }
- </style>
|