neverland 3f7985ed2e
[bugfix] NoticeBar text disappeared when page back (#280)
* [bugfix] CouponList always show empty info

* [bugfix] add click feedback of buttons in components

* [Doc] add custom theme document

* [new feature] Notice bar support more props

* [bugfix] PullRefresh test cases

* [bugfix] unused NoticeBar style

* [bugfix] Swipe width calc error

* [Doc] english document of all action components

* [Doc] change document site path to /zanui/vant

* [Doc] fix

* [bugfix] uploader style error

* [bugfix] tabs document demo

* [new feature] Cell support vue-router target route

* [bugfix] add cell test cases

* update yarn.lock

* [bugfix] Tabbar cann't display info when use icon slot

* [Doc] update document title

* [bugfix] Dialog should reset button text when showed

* [new feature] CouponList add showCloseButton prop

* [new feature] Swipe add 'initialSwipe' prop

* [bugfix] NoticeBar text disappeared when page back
2017-11-03 07:13:18 -05:00

116 lines
2.6 KiB
Vue

<template>
<div
v-show="showNoticeBar"
:class="['van-notice-bar', { 'van-notice-bar--withicon': mode }]"
:style="barStyle"
@click="$emit('click')"
>
<div class="van-notice-bar__left-icon" v-if="leftIcon">
<img :src="leftIcon" />
</div>
<div class="van-notice-bar__content-wrap" ref="contentWrap">
<div
ref="content"
:class="['van-notice-bar__content', animationClass]"
:style="contentStyle"
@animationend="onAnimationEnd"
>
<slot>{{ text }}</slot>
</div>
</div>
<van-icon class="van-notice-bar__right-icon" :name="iconName" v-if="iconName" @click="onClickIcon" />
</div>
</template>
<script>
import Icon from '../icon';
const NOTICE_BAR_MODE = ['', 'closeable', 'link'];
export default {
name: 'van-notice-bar',
components: {
[Icon.name]: Icon
},
props: {
text: String,
leftIcon: String,
color: String,
background: String,
mode: {
type: String,
default: '',
validator: val => NOTICE_BAR_MODE.indexOf(val) !== -1
},
delay: {
type: [String, Number],
default: 1
},
scrollable: {
type: Boolean,
default: true
},
speed: {
type: Number,
default: 50
}
},
data() {
return {
wrapWidth: 0,
firstRound: true,
duration: 0,
offsetWidth: 0,
showNoticeBar: true,
animationClass: ''
};
},
computed: {
iconName() {
return this.mode === 'closeable' ? 'close' : this.mode === 'link' ? 'arrow' : '';
},
barStyle() {
return {
color: this.color,
background: this.background
};
},
contentStyle() {
return {
paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
animationDelay: (this.firstRound ? this.delay : 0) + 's',
animationDuration: this.duration + 's'
};
}
},
mounted() {
const offsetWidth = this.$refs.content.getBoundingClientRect().width;
const wrapWidth = this.$refs.contentWrap.getBoundingClientRect().width;
if (this.scrollable && offsetWidth > wrapWidth) {
this.wrapWidth = wrapWidth;
this.offsetWidth = offsetWidth;
this.duration = offsetWidth / this.speed;
this.animationClass = 'van-notice-bar__play';
}
},
methods: {
onClickIcon() {
this.showNoticeBar = this.mode !== 'closeable';
},
onAnimationEnd() {
this.firstRound = false;
this.$nextTick(() => {
this.duration = (this.offsetWidth + this.wrapWidth) / this.speed;
this.animationClass = 'van-notice-bar__play--infinite';
});
}
}
};
</script>