vant-fork
Version:
Lightweight Mobile UI Components built on Vue
153 lines (140 loc) • 3.72 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _create = _interopRequireDefault(require("../utils/create"));
var _default = (0, _create.default)({
render: function render() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('div', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.showNoticeBar,
expression: "showNoticeBar"
}],
class: _vm.b({
withicon: _vm.mode
}),
style: _vm.barStyle,
on: {
"click": function click($event) {
_vm.$emit('click');
}
}
}, [_vm.leftIcon ? _c('div', {
class: _vm.b('left-icon')
}, [_c('img', {
attrs: {
"src": _vm.leftIcon
}
})]) : _vm._e(), _c('div', {
ref: "wrap",
class: _vm.b('wrap')
}, [_c('div', {
ref: "content",
class: [_vm.b('content'), _vm.animationClass],
style: _vm.contentStyle,
on: {
"animationend": _vm.onAnimationEnd,
"webkitAnimationEnd": _vm.onAnimationEnd
}
}, [_vm._t("default", [_vm._v(_vm._s(_vm.text))])], 2)]), _vm.iconName ? _c('icon', {
class: _vm.b('right-icon'),
attrs: {
"name": _vm.iconName
},
on: {
"click": _vm.onClickIcon
}
}) : _vm._e()], 1);
},
name: 'notice-bar',
props: {
text: String,
mode: String,
color: String,
leftIcon: String,
background: String,
delay: {
type: [String, Number],
default: 1
},
scrollable: {
type: Boolean,
default: true
},
speed: {
type: Number,
default: 50
}
},
data: function data() {
return {
wrapWidth: 0,
firstRound: true,
duration: 0,
offsetWidth: 0,
showNoticeBar: true,
animationClass: ''
};
},
computed: {
iconName: function iconName() {
return this.mode === 'closeable' ? 'close' : this.mode === 'link' ? 'arrow' : '';
},
barStyle: function barStyle() {
return {
color: this.color,
background: this.background
};
},
contentStyle: function contentStyle() {
return {
paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
animationDelay: (this.firstRound ? this.delay : 0) + 's',
animationDuration: this.duration + 's'
};
}
},
watch: {
text: {
handler: function handler() {
var _this = this;
this.$nextTick(function () {
var _this$$refs = _this.$refs,
wrap = _this$$refs.wrap,
content = _this$$refs.content;
if (!wrap || !content) {
return;
}
var wrapWidth = wrap.getBoundingClientRect().width;
var offsetWidth = content.getBoundingClientRect().width;
if (_this.scrollable && offsetWidth > wrapWidth) {
_this.wrapWidth = wrapWidth;
_this.offsetWidth = offsetWidth;
_this.duration = offsetWidth / _this.speed;
_this.animationClass = _this.b('play');
}
});
},
immediate: true
}
},
methods: {
onClickIcon: function onClickIcon() {
this.showNoticeBar = this.mode !== 'closeable';
},
onAnimationEnd: function onAnimationEnd() {
var _this2 = this;
this.firstRound = false;
this.$nextTick(function () {
_this2.duration = (_this2.offsetWidth + _this2.wrapWidth) / _this2.speed;
_this2.animationClass = _this2.b('play--infinite');
});
}
}
});
exports.default = _default;