UNPKG

bk-magic-vue

Version:

基于蓝鲸 Magicbox 和 Vue 的前端组件库

772 lines (716 loc) 24.8 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory(global.library = {})); }(this, function (exports) { 'use strict'; function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var _global = createCommonjsModule(function (module) { var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); if (typeof __g == 'number') __g = global; }); var _core = createCommonjsModule(function (module) { var core = module.exports = { version: '2.6.12' }; if (typeof __e == 'number') __e = core; }); var _core_1 = _core.version; var _aFunction = function (it) { if (typeof it != 'function') throw TypeError(it + ' is not a function!'); return it; }; var _ctx = function (fn, that, length) { _aFunction(fn); if (that === undefined) return fn; switch (length) { case 1: return function (a) { return fn.call(that, a); }; case 2: return function (a, b) { return fn.call(that, a, b); }; case 3: return function (a, b, c) { return fn.call(that, a, b, c); }; } return function () { return fn.apply(that, arguments); }; }; var _isObject = function (it) { return typeof it === 'object' ? it !== null : typeof it === 'function'; }; var _anObject = function (it) { if (!_isObject(it)) throw TypeError(it + ' is not an object!'); return it; }; var _fails = function (exec) { try { return !!exec(); } catch (e) { return true; } }; var _descriptors = !_fails(function () { return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; }); var document$1 = _global.document; var is = _isObject(document$1) && _isObject(document$1.createElement); var _domCreate = function (it) { return is ? document$1.createElement(it) : {}; }; var _ie8DomDefine = !_descriptors && !_fails(function () { return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7; }); var _toPrimitive = function (it, S) { if (!_isObject(it)) return it; var fn, val; if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val; if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val; throw TypeError("Can't convert object to primitive value"); }; var dP = Object.defineProperty; var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) { _anObject(O); P = _toPrimitive(P, true); _anObject(Attributes); if (_ie8DomDefine) try { return dP(O, P, Attributes); } catch (e) { } if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); if ('value' in Attributes) O[P] = Attributes.value; return O; }; var _objectDp = { f: f }; var _propertyDesc = function (bitmap, value) { return { enumerable: !(bitmap & 1), configurable: !(bitmap & 2), writable: !(bitmap & 4), value: value }; }; var _hide = _descriptors ? function (object, key, value) { return _objectDp.f(object, key, _propertyDesc(1, value)); } : function (object, key, value) { object[key] = value; return object; }; var hasOwnProperty = {}.hasOwnProperty; var _has = function (it, key) { return hasOwnProperty.call(it, key); }; var PROTOTYPE = 'prototype'; var $export = function (type, name, source) { var IS_FORCED = type & $export.F; var IS_GLOBAL = type & $export.G; var IS_STATIC = type & $export.S; var IS_PROTO = type & $export.P; var IS_BIND = type & $export.B; var IS_WRAP = type & $export.W; var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {}); var expProto = exports[PROTOTYPE]; var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] : (_global[name] || {})[PROTOTYPE]; var key, own, out; if (IS_GLOBAL) source = name; for (key in source) { own = !IS_FORCED && target && target[key] !== undefined; if (own && _has(exports, key)) continue; out = own ? target[key] : source[key]; exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] : IS_BIND && own ? _ctx(out, _global) : IS_WRAP && target[key] == out ? (function (C) { var F = function (a, b, c) { if (this instanceof C) { switch (arguments.length) { case 0: return new C(); case 1: return new C(a); case 2: return new C(a, b); } return new C(a, b, c); } return C.apply(this, arguments); }; F[PROTOTYPE] = C[PROTOTYPE]; return F; })(out) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out; if (IS_PROTO) { (exports.virtual || (exports.virtual = {}))[key] = out; if (type & $export.R && expProto && !expProto[key]) _hide(expProto, key, out); } } }; $export.F = 1; $export.G = 2; $export.S = 4; $export.P = 8; $export.B = 16; $export.W = 32; $export.U = 64; $export.R = 128; var _export = $export; var _defined = function (it) { if (it == undefined) throw TypeError("Can't call method on " + it); return it; }; var _stringWs = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'; var space = '[' + _stringWs + ']'; var non = '\u200b\u0085'; var ltrim = RegExp('^' + space + space + '*'); var rtrim = RegExp(space + space + '*$'); var exporter = function (KEY, exec, ALIAS) { var exp = {}; var FORCE = _fails(function () { return !!_stringWs[KEY]() || non[KEY]() != non; }); var fn = exp[KEY] = FORCE ? exec(trim) : _stringWs[KEY]; if (ALIAS) exp[ALIAS] = fn; _export(_export.P + _export.F * FORCE, 'String', exp); }; var trim = exporter.trim = function (string, TYPE) { string = String(_defined(string)); if (TYPE & 1) string = string.replace(ltrim, ''); if (TYPE & 2) string = string.replace(rtrim, ''); return string; }; var _stringTrim = exporter; var $parseFloat = _global.parseFloat; var $trim = _stringTrim.trim; var _parseFloat = 1 / $parseFloat(_stringWs + '-0') !== -Infinity ? function parseFloat(str) { var string = $trim(String(str), 3); var result = $parseFloat(string); return result === 0 && string.charAt(0) == '-' ? -0 : result; } : $parseFloat; _export(_export.G + _export.F * (parseFloat != _parseFloat), { parseFloat: _parseFloat }); var _parseFloat$1 = _core.parseFloat; var _parseFloat$2 = _parseFloat$1; var getElementSize = function getElementSize(node) { if (node === undefined) { return { height: 0, width: 0 }; } var computedStyle = getComputedStyle(node); var width = node.clientWidth - _parseFloat$2(computedStyle.paddingTop) - _parseFloat$2(computedStyle.paddingBottom); var height = node.clientHeight - _parseFloat$2(computedStyle.paddingLeft) - _parseFloat$2(computedStyle.paddingRight); return { height: height, width: width }; }; var script = { name: 'bk-swiper', props: { pics: { type: Array, default: function _default() { return []; } }, list: { type: Array, default: function _default() { return []; } }, isLoop: { type: Boolean, default: true }, loopTime: { type: Number, default: 8000 }, extCls: { type: String, default: '' }, height: { type: [Number, String], default: 0 }, width: { type: [Number, String], default: 0 } }, data: function data() { return { currentIndex: 1, isStartMove: false, isTransition: false, startMovePoint: 0, mouseDistance: 0, loopId: '', isClick: false, realWidth: 0, realHeight: 0, resizeObserver: {} }; }, computed: { sourceList: function sourceList() { return this.list.length > 0 ? this.list : this.pics; }, dataList: function dataList() { var first = this.sourceList[0]; var last = this.sourceList.slice(-1); return [].concat(_toConsumableArray(last), _toConsumableArray(this.sourceList), [first]); }, swiperMainWith: function swiperMainWith() { return this.realWidth * this.dataList.length; }, imageTransfer: function imageTransfer() { var indexMove = this.realWidth * this.currentIndex; var imageMove = indexMove - this.mouseDistance; return -imageMove; }, swiperStyle: function swiperStyle() { var swiperStyle = {}; if (this.realWidth > 0) { swiperStyle.width = "".concat(this.realWidth, "px"); } if (this.realHeight > 0) { swiperStyle.height = "".concat(this.realHeight, "px"); } return swiperStyle; } }, watch: { currentIndex: { handler: function handler(val) { if (val <= 0 || val > this.dataList.length - 2) return; this.$emit('index-change', val); }, immediate: true }, height: function height() { this.calcSize(); }, width: function width() { this.calcSize(); } }, mounted: function mounted() { var _this = this; setTimeout(function () { _this.initStatus(); }); }, beforeDestroy: function beforeDestroy() { this.destoryStatus(); }, methods: { calcSize: function calcSize() { var swiperSize = getElementSize(this.$refs.swiper); var swiperParentSize = getElementSize(this.$refs.swiper && this.$refs.swiper.parentElement); this.realWidth = +this.width > 0 ? this.width : swiperSize.width > 0 ? swiperSize.width : swiperParentSize.width; this.realHeight = +this.height > 0 ? this.height : swiperSize.height > 25 ? swiperSize.height : swiperParentSize.height; }, initStatus: function initStatus() { this.calcSize(); this.startLoop(); this.watchParentSizeChange(); document.addEventListener('visibilitychange', this.visChange); }, destoryStatus: function destoryStatus() { this.endLoop(); this.endWatchParentSizeChange(); document.removeEventListener('visibilitychange', this.visChange); }, watchParentSizeChange: function watchParentSizeChange() { var _this2 = this; var parentEle = this.$refs.swiper && this.$refs.swiper.parentElement; if (!parentEle || !window.ResizeObserver) { return; } this.resizeObserver = new ResizeObserver(function () { _this2.calcSize(); }); this.resizeObserver.observe(parentEle); }, endWatchParentSizeChange: function endWatchParentSizeChange() { if (this.resizeObserver && this.resizeObserver.disconnect) { this.resizeObserver.disconnect(); } }, goToLink: function goToLink(link) { if (this.isClick && link) window.open(link, '_blank'); }, visChange: function visChange(event) { var hidden = event.target.hidden || false; if (hidden) this.endLoop();else this.startLoop(); }, changeIndex: function changeIndex(index) { this.isTransition = true; this.startLoop(); this.changeCurrentIndex(index); }, moveStart: function moveStart(event) { this.endLoop(); event.preventDefault(); this.isTransition = false; this.isStartMove = true; this.startMovePoint = event.clientX; }, moving: function moving(event) { if (!this.isStartMove) return; var mouseMove = event.clientX - this.startMovePoint; this.mouseDistance = mouseMove; }, moveEnd: function moveEnd(event) { if (!this.isStartMove) return; var threshold = this.realWidth / 3; var absMouseDis = Math.abs(this.mouseDistance); this.isClick = this.isStartMove && absMouseDis < 5; if (absMouseDis > threshold) { var index = this.currentIndex - absMouseDis / this.mouseDistance; this.changeCurrentIndex(index); } this.startLoop(); this.isTransition = true; this.isStartMove = false; this.mouseDistance = 0; }, changeCurrentIndex: function changeCurrentIndex(val) { var picLength = this.dataList.length; if (val <= -1) { val = picLength - 2; } else if (this.currentIndex >= picLength) { val = 1; } this.currentIndex = val; }, transitionend: function transitionend() { var picLength = this.dataList.length - 1; if (this.currentIndex <= 0) { this.isTransition = false; this.currentIndex = picLength - 1; } else if (this.currentIndex >= picLength) { this.isTransition = false; this.currentIndex = 1; } }, startLoop: function startLoop() { var _this3 = this; if (!this.isLoop) return; this.endLoop(); this.loopId = window.setTimeout(function () { _this3.isTransition = true; _this3.changeCurrentIndex(_this3.currentIndex + 1); _this3.startLoop(); }, this.loopTime); }, endLoop: function endLoop() { window.clearTimeout(this.loopId); } } }; function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier , shadowMode, createInjector, createInjectorSSR, createInjectorShadow) { if (typeof shadowMode !== 'boolean') { createInjectorSSR = createInjector; createInjector = shadowMode; shadowMode = false; } var options = typeof script === 'function' ? script.options : script; if (template && template.render) { options.render = template.render; options.staticRenderFns = template.staticRenderFns; options._compiled = true; if (isFunctionalTemplate) { options.functional = true; } } if (scopeId) { options._scopeId = scopeId; } var hook; if (moduleIdentifier) { hook = function hook(context) { context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext; if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { context = __VUE_SSR_CONTEXT__; } if (style) { style.call(this, createInjectorSSR(context)); } if (context && context._registeredComponents) { context._registeredComponents.add(moduleIdentifier); } }; options._ssrRegister = hook; } else if (style) { hook = shadowMode ? function () { style.call(this, createInjectorShadow(this.$root.$options.shadowRoot)); } : function (context) { style.call(this, createInjector(context)); }; } if (hook) { if (options.functional) { var originalRender = options.render; options.render = function renderWithStyleInjection(h, context) { hook.call(context); return originalRender(h, context); }; } else { var existing = options.beforeCreate; options.beforeCreate = existing ? [].concat(existing, hook) : [hook]; } } return script; } var normalizeComponent_1 = normalizeComponent; /* script */ var __vue_script__ = script; /* template */ var __vue_render__ = function __vue_render__() { var _vm = this; var _h = _vm.$createElement; var _c = _vm._self._c || _h; return _vm.sourceList.length ? _c('section', { ref: "swiper", class: ['bk-swiper-home', _vm.extCls], style: _vm.swiperStyle }, [_c('hgroup', { class: [{ 'bk-transition': _vm.isTransition }, 'bk-swiper-main'], style: { width: _vm.swiperMainWith + "px", transform: "translateX(" + _vm.imageTransfer + "px)" }, on: { "mousedown": _vm.moveStart, "mousemove": _vm.moving, "mouseup": _vm.moveEnd, "mouseout": _vm.moveEnd, "transitionend": _vm.transitionend } }, _vm._l(_vm.dataList, function (pic, index) { return _c('h3', { key: index, staticClass: "bk-swiper-card", style: { 'width': _vm.realWidth + "px" } }, [_vm._t("default", function () { return [_c('span', { class: [{ 'bk-swiper-link': pic.link }, pic.class, 'bk-swiper-img'], style: { 'background-image': "url(" + pic.url + ")", 'background-color': pic.color }, on: { "click": function click($event) { return _vm.goToLink(pic.link); } } })]; }, { "data": pic })], 2); }), 0), _c('ul', { staticClass: "bk-swiper-index" }, _vm._l(_vm.sourceList, function (pic, index) { return _c('li', { key: index, class: { 'bk-current-index': _vm.currentIndex === index + 1 }, on: { "mouseover": function mouseover($event) { return _vm.changeIndex(index + 1); } } }); }), 0), _c('span', { staticClass: "bk-swiper-nav bk-nav-prev", on: { "click": function click($event) { return _vm.changeIndex(_vm.currentIndex - 1); } } }, [_c('i', { staticClass: "bk-swiper-nav-icon" })]), _c('span', { staticClass: "bk-swiper-nav bk-nav-next", on: { "click": function click($event) { return _vm.changeIndex(_vm.currentIndex + 1); } } }, [_c('i', { staticClass: "bk-swiper-nav-icon" })])]) : _vm._e(); }; var __vue_staticRenderFns__ = []; /* style */ var __vue_inject_styles__ = undefined; /* scoped */ var __vue_scope_id__ = undefined; /* module identifier */ var __vue_module_identifier__ = undefined; /* functional template */ var __vue_is_functional_template__ = false; /* style inject */ /* style inject SSR */ /* style inject shadow dom */ var __vue_component__ = /*#__PURE__*/normalizeComponent_1({ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined); var _toObject = function (it) { return Object(_defined(it)); }; var toString = {}.toString; var _cof = function (it) { return toString.call(it).slice(8, -1); }; var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) { return _cof(it) == 'String' ? it.split('') : Object(it); }; var _toIobject = function (it) { return _iobject(_defined(it)); }; var ceil = Math.ceil; var floor = Math.floor; var _toInteger = function (it) { return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); }; var min = Math.min; var _toLength = function (it) { return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; }; var max = Math.max; var min$1 = Math.min; var _toAbsoluteIndex = function (index, length) { index = _toInteger(index); return index < 0 ? max(index + length, 0) : min$1(index, length); }; var _arrayIncludes = function (IS_INCLUDES) { return function ($this, el, fromIndex) { var O = _toIobject($this); var length = _toLength(O.length); var index = _toAbsoluteIndex(fromIndex, length); var value; if (IS_INCLUDES && el != el) while (length > index) { value = O[index++]; if (value != value) return true; } else for (;length > index; index++) if (IS_INCLUDES || index in O) { if (O[index] === el) return IS_INCLUDES || index || 0; } return !IS_INCLUDES && -1; }; }; var _shared = createCommonjsModule(function (module) { var SHARED = '__core-js_shared__'; var store = _global[SHARED] || (_global[SHARED] = {}); (module.exports = function (key, value) { return store[key] || (store[key] = value !== undefined ? value : {}); })('versions', []).push({ version: _core.version, mode: 'pure' , copyright: '© 2020 Denis Pushkarev (zloirock.ru)' }); }); var id = 0; var px = Math.random(); var _uid = function (key) { return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); }; var shared = _shared('keys'); var _sharedKey = function (key) { return shared[key] || (shared[key] = _uid(key)); }; var arrayIndexOf = _arrayIncludes(false); var IE_PROTO = _sharedKey('IE_PROTO'); var _objectKeysInternal = function (object, names) { var O = _toIobject(object); var i = 0; var result = []; var key; for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key); while (names.length > i) if (_has(O, key = names[i++])) { ~arrayIndexOf(result, key) || result.push(key); } return result; }; var _enumBugKeys = ( 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' ).split(','); var _objectKeys = Object.keys || function keys(O) { return _objectKeysInternal(O, _enumBugKeys); }; var _objectSap = function (KEY, exec) { var fn = (_core.Object || {})[KEY] || Object[KEY]; var exp = {}; exp[KEY] = exec(fn); _export(_export.S + _export.F * _fails(function () { fn(1); }), 'Object', exp); }; _objectSap('keys', function () { return function keys(it) { return _objectKeys(_toObject(it)); }; }); var keys = _core.Object.keys; var keys$1 = keys; function setInstaller (component, afterInstall) { component.install = function (Vue) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var props = component.props || {}; keys$1(options).forEach(function (key) { if (props.hasOwnProperty(key)) { if (typeof props[key] === 'function' || props[key] instanceof Array) { props[key] = { type: props[key], default: options[key] }; } else { props[key].default = options[key]; } } }); component.name = options.namespace ? component.name.replace('bk', options.namespace) : component.name; Vue.component(component.name, component); typeof afterInstall === 'function' && afterInstall(Vue, options); }; } setInstaller(__vue_component__); exports.default = __vue_component__; Object.defineProperty(exports, '__esModule', { value: true }); }));