| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- exports.__esModule = true;
- exports["default"] = void 0;
- var _utils = require("../utils");
- var _icon = _interopRequireDefault(require("../icon"));
- var _use = (0, _utils.use)('notice-bar'),
- sfc = _use[0],
- bem = _use[1];
- var _default = sfc({
- props: {
- text: String,
- mode: String,
- color: String,
- leftIcon: String,
- wrapable: Boolean,
- 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: ''
- };
- },
- 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 = bem('play');
- }
- });
- },
- immediate: true
- }
- },
- methods: {
- onClickIcon: function onClickIcon() {
- if (this.mode === 'closeable') {
- this.showNoticeBar = false;
- this.$emit('close');
- }
- },
- onAnimationEnd: function onAnimationEnd() {
- var _this2 = this;
- this.firstRound = false;
- this.$nextTick(function () {
- _this2.duration = (_this2.offsetWidth + _this2.wrapWidth) / _this2.speed;
- _this2.animationClass = bem('play--infinite');
- });
- }
- },
- render: function render(h) {
- var _this3 = this;
- var mode = this.mode;
- var iconName = mode === 'closeable' ? 'cross' : mode === 'link' ? 'arrow' : '';
- var barStyle = {
- color: this.color,
- background: this.background
- };
- var contentStyle = {
- paddingLeft: this.firstRound ? 0 : this.wrapWidth + 'px',
- animationDelay: (this.firstRound ? this.delay : 0) + 's',
- animationDuration: this.duration + 's'
- };
- return h("div", {
- "directives": [{
- name: "show",
- value: this.showNoticeBar
- }],
- "class": bem({
- withicon: mode,
- wrapable: this.wrapable
- }),
- "style": barStyle,
- "on": {
- "click": function click() {
- _this3.$emit('click');
- }
- }
- }, [this.leftIcon && h(_icon["default"], {
- "class": bem('left-icon'),
- "attrs": {
- "name": this.leftIcon
- }
- }), h("div", {
- "ref": "wrap",
- "class": bem('wrap')
- }, [h("div", {
- "ref": "content",
- "class": [bem('content'), this.animationClass, {
- 'van-ellipsis': !this.scrollable && !this.wrapable
- }],
- "style": contentStyle,
- "on": {
- "animationend": this.onAnimationEnd,
- "webkitAnimationEnd": this.onAnimationEnd
- }
- }, [this.slots() || this.text])]), iconName && h(_icon["default"], {
- "class": bem('right-icon'),
- "attrs": {
- "name": iconName
- },
- "on": {
- "click": this.onClickIcon
- }
- })]);
- }
- });
- exports["default"] = _default;
|