UNPKG

bk-magic-vue

Version:

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

534 lines (499 loc) 17.2 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('bk-magic-vue/lib/locale')) : typeof define === 'function' && define.amd ? define(['exports', 'vue', 'bk-magic-vue/lib/locale'], factory) : (global = global || self, factory(global.library = {}, global.Vue, global.locale)); }(this, function (exports, Vue, locale) { 'use strict'; Vue = Vue && Vue.hasOwnProperty('default') ? Vue['default'] : Vue; locale = locale && locale.hasOwnProperty('default') ? locale['default'] : locale; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } 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$1 = 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$1(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; _export(_export.S, 'Date', { now: function () { return new Date().getTime(); } }); var now = _core.Date.now; var now$1 = now; var ICONS = { primary: 'icon-info-circle-shape', error: 'icon-close-circle-shape', warning: 'icon-exclamation-circle-shape', success: 'icon-check-circle-shape' }; var script = { name: 'bk-notify', mixins: [locale.mixin], data: function data() { return { theme: 'primary', icon: '', title: '', message: '', position: 'top-right', delay: 5000, dismissable: true, limitLine: 2, showViewMore: false, verticalOffset: 0, horizonOffset: 0, visible: false, limit: 0, countID: null, onClose: function onClose() {}, extCls: '', useHTMLString: false }; }, computed: { themeClass: function themeClass() { return "bk-notify-".concat(this.theme); }, vDirection: function vDirection() { return /top-/.test(this.position) ? 'top' : 'bottom'; }, hDirection: function hDirection() { return this.position.indexOf('right') > -1 ? 'right' : 'left'; }, placementStyle: function placementStyle() { var _ref; return _ref = {}, _defineProperty(_ref, this.hDirection, "".concat(this.horizonOffset, "px")), _defineProperty(_ref, this.vDirection, "".concat(this.verticalOffset, "px")), _ref; }, contentStyle: function contentStyle() { var contentStyle = {}; if (this.limitLine > 0) { contentStyle['max-height'] = "".concat(20 * this.limitLine, "px"); } return contentStyle; }, tipsIcon: function tipsIcon() { return this.icon || ICONS[this.theme]; } }, mounted: function mounted() { this.startCountDown(); }, methods: { destroyEl: function destroyEl() { this.$destroy(); this.$el.parentNode && this.$el.parentNode.removeChild(this.$el); }, onClickViewMore: function onClickViewMore() { typeof this.onViewMoreHandler === 'function' && this.onViewMoreHandler(); }, startCountDown: function startCountDown() { var _this = this; if (this.delay > 0) { this.countID = setTimeout(function () { _this.visible && _this.close(); }, this.delay); } }, stopCountDown: function stopCountDown() { clearTimeout(this.countID); }, close: function close() { this.visible = false; typeof this.onClose === 'function' && this.onClose(); } } }; 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 _c('transition', { attrs: { "name": "placement-slide" }, on: { "after-leave": _vm.destroyEl } }, [_c('div', { directives: [{ name: "show", rawName: "v-show", value: _vm.visible, expression: "visible" }], class: ['bk-notify', _vm.themeClass, _vm.hDirection, _vm.extCls], style: _vm.placementStyle, on: { "mouseenter": _vm.stopCountDown, "mouseleave": _vm.startCountDown } }, [_c('div', { staticClass: "bk-notify-icon" }, [_c('i', { class: ['bk-icon', _vm.tipsIcon] })]), _c('div', { staticClass: "bk-notify-content" }, [_vm.title ? _c('h3', { staticClass: "bk-notify-content-title" }, [_vm._v(_vm._s(_vm.title))]) : _vm._e(), _vm._t("default", function () { return [_c('div', { class: ['bk-notify-content-text', { limitLine: _vm.limitLine > 0 }], style: _vm.contentStyle }, [!_vm.useHTMLString ? [_vm._v(_vm._s(_vm.message))] : _c('span', { domProps: { "innerHTML": _vm._s(_vm.message) } }), _vm.showViewMore ? _c('button', { staticClass: "showMoreBtn", on: { "click": _vm.onClickViewMore } }, [_vm._v("\n " + _vm._s(_vm.t('bk.notify.showMore')) + "\n ")]) : _vm._e()], 2)]; })], 2), _vm.dismissable ? _c('div', { staticClass: "bk-notify-close" }, [_c('i', { staticClass: "bk-icon icon-close", on: { "click": function click($event) { $event.stopPropagation(); return _vm.close.apply(null, arguments); } } })]) : _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 NotifyComponent = Vue.extend(__vue_component__); var notifyList = []; var seed = 0; var BkNotify = function BkNotify(config) { if (config.limit === 0) { BkNotify.batchClose(); return; } if (config.limit > 0) { BkNotify.batchClose(config.limit); } var instanceId = "notifyInstance_".concat(now$1(), "_").concat(seed++); var offsetY = config.offsetY || 30; var offsetX = config.offsetX || 10; var spacing = config.spacing || 10; var verticalOffset = offsetY; if (typeof config === 'string' || typeof config === 'number') { config = { message: config }; } var configClose = config.onClose; config.onClose = function () { BkNotify.close(instanceId, configClose); }; var instance = new NotifyComponent({ data: config }); if (config.message !== null && _typeof(config.message) === 'object' && config.message.hasOwnProperty('componentOptions')) { instance.$slots.default = [config.message]; instance.message = null; } instance.id = instanceId; instance.spacing = spacing; instance.verticalOffset = 0; instance.$mount(); instance.dom = instance.$el; document.body.appendChild(instance.$el); notifyList.forEach(function (item) { if (item.position === config.position) { verticalOffset += item.$el.offsetHeight + spacing; } }); instance.verticalOffset = verticalOffset; instance.horizonOffset = offsetX; instance.visible = true; notifyList.push(instance); return instance; }; BkNotify.close = function (id, configClose) { var instanceIndex = -1; notifyList.some(function (item, index) { if (item.id === id) { instanceIndex = index; return true; } }); if (instanceIndex > -1) { var instance = notifyList[instanceIndex]; if (typeof configClose === 'function') { configClose(instance); } notifyList.forEach(function (item, i) { if (item.position === instance.position && i > instanceIndex) { item.verticalOffset -= instance.dom.offsetHeight + instance.spacing; } }); notifyList.splice(instanceIndex, 1); } }; BkNotify.batchClose = function () { var limit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var len = notifyList.length; if (limit <= len) { var InstancesShouldClose = notifyList.slice(0, len - limit + 1); InstancesShouldClose.forEach(function (item) { item.close(); }); } }; Vue.prototype.$bkNotify = BkNotify; exports.default = BkNotify; Object.defineProperty(exports, '__esModule', { value: true }); }));