@cw-devops/bk-magic-vue
Version:
基于蓝鲸 Magicbox 和 Vue 的前端组件库
1,585 lines (1,525 loc) • 54 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bk-magic-vue/lib/locale')) :
typeof define === 'function' && define.amd ? define(['exports', 'bk-magic-vue/lib/locale'], factory) :
(global = global || self, factory(global.library = {}, global.locale));
}(this, function (exports, locale) { 'use strict';
locale = locale && locale.hasOwnProperty('default') ? locale['default'] : locale;
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 $parseInt = _global.parseInt;
var $trim = _stringTrim.trim;
var hex = /^[-+]?0[xX]/;
var _parseInt = $parseInt(_stringWs + '08') !== 8 || $parseInt(_stringWs + '0x16') !== 22 ? function parseInt(str, radix) {
var string = $trim(String(str), 3);
return $parseInt(string, (radix >>> 0) || (hex.test(string) ? 16 : 10));
} : $parseInt;
_export(_export.G + _export.F * (parseInt != _parseInt), { parseInt: _parseInt });
var _parseInt$1 = _core.parseInt;
var _parseInt$2 = _parseInt$1;
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
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 _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = it.call(o);
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
}
};
}
var $parseFloat = _global.parseFloat;
var $trim$1 = _stringTrim.trim;
var _parseFloat = 1 / $parseFloat(_stringWs + '-0') !== -Infinity ? function parseFloat(str) {
var string = $trim$1(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;
_export(_export.S, 'Number', { MAX_SAFE_INTEGER: 0x1fffffffffffff });
var maxSafeInteger = 0x1fffffffffffff;
var maxSafeInteger$1 = maxSafeInteger;
_export(_export.S, 'Number', { MIN_SAFE_INTEGER: -0x1fffffffffffff });
var minSafeInteger = -0x1fffffffffffff;
var minSafeInteger$1 = minSafeInteger;
var emitter = {
methods: {
dispatch: function dispatch(componentName, eventName, params) {
var parent = this.$parent || this.$root;
var name = parent.$options.name;
while (parent && (!name || name !== componentName)) {
parent = parent.$parent;
if (parent) {
name = parent.$options.name;
}
}
if (parent) {
parent.$emit.apply(parent, [eventName].concat(params));
}
}
}
};
var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
window.setTimeout(callback, 1000 / 60);
};
var cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame || function (id) {
window.clearTimeout(id);
};
var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
var MOZ_HACK_REGEXP = /^moz([A-Z])/;
var trim$1 = function trim(string) {
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
};
var camelCase = function camelCase(name) {
return name.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
return offset ? letter.toUpperCase() : letter;
}).replace(MOZ_HACK_REGEXP, 'Moz$1');
};
function hasClass(el, cls) {
if (!el || !cls) return false;
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
if (el.classList) {
return el.classList.contains(cls);
} else {
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
}
function addClass(el, cls) {
if (!el) return;
var curClass = el.className;
var classes = (cls || '').split(' ');
for (var i = 0, j = classes.length; i < j; i++) {
var clsName = classes[i];
if (!clsName) continue;
if (el.classList) {
el.classList.add(clsName);
} else if (!hasClass(el, clsName)) {
curClass += ' ' + clsName;
}
}
if (!el.classList) {
el.className = curClass;
}
}
function removeClass(el, cls) {
if (!el || !cls) return;
var classes = cls.split(' ');
var curClass = ' ' + el.className + ' ';
for (var i = 0, j = classes.length; i < j; i++) {
var clsName = classes[i];
if (!clsName) continue;
if (el.classList) {
el.classList.remove(clsName);
} else if (hasClass(el, clsName)) {
curClass = curClass.replace(' ' + clsName + ' ', ' ');
}
}
if (!el.classList) {
el.className = trim$1(curClass);
}
}
var getStyle = Number(document.documentMode) < 9 ? function (element, styleName) {
if (!element || !styleName) return null;
styleName = camelCase(styleName);
if (styleName === 'float') {
styleName = 'styleFloat';
}
try {
switch (styleName) {
case 'opacity':
try {
return element.filters.item('alpha').opacity / 100;
} catch (e) {
return 1.0;
}
default:
return element.style[styleName] || element.currentStyle ? element.currentStyle[styleName] : null;
}
} catch (e) {
return element.style[styleName];
}
} : function (element, styleName) {
if (!element || !styleName) return null;
styleName = camelCase(styleName);
if (styleName === 'float') {
styleName = 'cssFloat';
}
try {
var computed = document.defaultView.getComputedStyle(element, '');
return element.style[styleName] || computed ? computed[styleName] : null;
} catch (e) {
return element.style[styleName];
}
};
var script = {
name: 'bk-input',
mixins: [emitter, locale.mixin],
props: {
type: {
type: String,
default: 'text',
validator: function validator(value) {
return ['text', 'textarea', 'password', 'number', 'email', 'url', 'date'].indexOf(value) > -1;
}
},
value: {
type: [String, Number],
default: ''
},
placeholder: {
type: String,
default: ''
},
disabled: {
type: Boolean,
default: false
},
clearable: {
type: Boolean,
default: false
},
readonly: {
type: Boolean,
default: false
},
ellipsis: {
type: Boolean,
default: false
},
name: {
type: String,
default: ''
},
maxlength: {
type: [Number, String]
},
minlength: {
type: [Number, String]
},
min: {
type: Number,
default: minSafeInteger$1
},
max: {
type: Number,
default: maxSafeInteger$1
},
size: {
type: String,
default: '',
validator: function validator(val) {
return ['', 'large', 'small'].includes(val);
}
},
leftIcon: {
type: String,
default: ''
},
rightIcon: {
type: String,
default: ''
},
rows: {
type: Number
},
inputStyle: {
type: Object
},
fontSize: {
type: String,
default: 'normal'
},
precision: Number,
passwordIcon: {
type: Array,
default: function _default() {
return ['icon-eye-slash', 'icon-eye'];
}
},
showControls: {
type: Boolean,
default: true
},
extCls: {
type: String,
default: ''
},
nativeAttributes: {
type: Object,
default: null
},
showWordLimit: {
type: Boolean,
default: undefined
},
behavior: {
type: String,
default: 'normal',
validate: function validate(v) {
return ['simplicity', 'normal'].indexOf(v) > -1;
}
},
showClearOnlyHover: {
type: Boolean,
default: false
},
allowNumberPaste: {
type: Boolean,
default: false
}
},
data: function data() {
return {
hover: false,
curValue: '',
prepend: false,
append: false,
isActive: false,
defaultPlaceholder: '',
rightIconStyle: {
right: '10px'
},
rightPasswordIconStyle: {
right: '10px'
},
inputType: this.type,
inputSize: this.size,
inputPasswordIcon: this.passwordIcon,
inputRightPadding: '10px',
iconAreaSizeObserver: null,
validKeyCodeList: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
8,
189,
109,
190,
110,
38, 40, 37, 39,
46,
9
],
validCodeList: ['Digit0', 'Digit1', 'Digit2', 'Digit3', 'Digit4', 'Digit5', 'Digit6', 'Digit7', 'Digit8', 'Digit9',
'Numpad0', 'Numpad1', 'Numpad2', 'Numpad3', 'Numpad4', 'Numpad5', 'Numpad6', 'Numpad7', 'Numpad8', 'Numpad9',
'Backspace',
'Minus',
'NumpadSubtract',
'Period',
'NumpadDecimal',
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight',
'Delete',
'Tab'
],
isOnComposition: false
};
},
computed: {
showClearIcon: function showClearIcon() {
return this.clearable && this.curValue && !this.disabled && (this.showClearOnlyHover ? this.hover : true);
},
showPwdVisable: function showPwdVisable() {
return this.type === 'password' && this.curValue && this.inputPasswordIcon.length && !this.readonly && !this.disabled;
},
showInputWordLimit: function showInputWordLimit() {
if (!['text', 'textarea'].includes(this.type)) return false;
return this.type === 'text' ? this.maxlength && this.showWordLimit : this.maxlength && this.showWordLimit !== false;
},
bindAttribute: function bindAttribute() {
return this.getAttributeByType(this.inputType);
},
computedStyle: function computedStyle() {
return _extends(this.inputType === 'textarea' ? {} : {
'padding-right': this.inputRightPadding
}, this.inputStyle);
},
showLeftIcon: function showLeftIcon() {
return this.leftIcon;
},
showRightIcon: function showRightIcon() {
return this.rightIcon || this.clearable && this.curValue || this.type === 'password' || this.maxlength;
},
showTwoRightIcon: function showTwoRightIcon() {
return this.clearable && this.curValue && this.type === 'password';
},
wrapperClass: function wrapperClass() {
var wrapperClass = ['bk-form-control', {
'with-left-icon': this.showLeftIcon,
'with-right-icon': this.showRightIcon,
'with-two-right-icon': this.showTwoRightIcon,
'control-prepend-group': this.prepend,
'control-append-group': this.append,
'control-active': this.isActive,
'control-disable': this.disabled
}];
if (this.inputSize) {
wrapperClass.push("bk-input-wrapper-".concat(this.inputSize));
}
return wrapperClass;
},
fontSizeCls: function fontSizeCls() {
var cls = '';
if (this.fontSize === 'medium') {
cls = 'medium-font';
} else if (this.fontSize === 'large') {
cls = 'large-font';
}
return cls;
},
inputSizeCls: function inputSizeCls() {
if (this.inputSize) {
return "bk-input-".concat(this.inputSize);
}
return '';
}
},
watch: {
value: {
handler: function handler(val, old) {
this.setCurValue(val);
old === undefined && this.updateNumberValue(val);
},
immediate: true
},
placeholder: function placeholder(val) {
this.defaultPlaceholder = val || this.t('bk.input.input');
},
type: function type(val) {
this.inputType = val;
},
size: function size(val) {
this.inputSize = val;
}
},
created: function created() {
this.defaultPlaceholder = this.placeholder || this.t('bk.input.input');
},
mounted: function mounted() {
var _this = this;
this.prepend = this.$slots.prepend !== undefined;
this.append = this.$slots.append !== undefined;
if (this.$slots.append) {
this.$nextTick(function () {
var appendWidth = _parseFloat$2(getStyle(_this.$slots.append[0].elm, 'width'));
_this.rightIconStyle = {
right: _parseFloat$2(_this.rightIconStyle.right) + appendWidth + 'px'
};
});
}
if (this.clearable) {
this.rightPasswordIconStyle = {
right: '30px'
};
}
this.observerIconSize();
},
beforeDestroy: function beforeDestroy() {
this.iconAreaSizeObserver && typeof this.iconAreaSizeObserver.disconnect === 'function' && this.iconAreaSizeObserver.disconnect();
this.iconAreaSizeObserver = null;
},
methods: {
observerIconSize: function observerIconSize() {
var _this2 = this;
var element = this.$refs.rightIconArea;
if (!element) return;
if (typeof ResizeObserver !== 'undefined') {
var defaultPadding = 10;
this.iconAreaSizeObserver = new ResizeObserver(function (entries) {
var _iterator = _createForOfIteratorHelper(entries),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var entry = _step.value;
var cr = entry.contentRect;
_this2.inputRightPadding = "".concat(cr.width + defaultPadding, "px");
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
});
this.iconAreaSizeObserver.observe(element);
}
},
getAttributeByType: function getAttributeByType() {
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var defaultAttr = {
type: type,
name: this.name,
placeholder: this.defaultPlaceholder,
disabled: this.disabled,
readonly: this.readonly,
maxlength: this.maxlength,
minlength: this.minlength,
value: this.curValue
};
type = type.toLocaleLowerCase();
var outputAttr = this.nativeAttributes || {};
switch (type) {
case 'number':
var numberAttr = {
min: this.min,
max: this.max
};
_extends(outputAttr, defaultAttr, numberAttr);
outputAttr.type = 'text';
break;
case 'textarea':
var txtAttr = {
rows: this.rows
};
_extends(outputAttr, defaultAttr, txtAttr);
break;
default:
_extends(outputAttr, defaultAttr);
break;
}
return outputAttr;
},
handleToFixed: function handleToFixed(defaultNumber, length) {
var len = _parseInt$2(length, 10);
var number = Number(defaultNumber);
if (isNaN(number) || number >= Math.pow(10, 21)) {
return number.toString();
}
if (typeof len === 'undefined' || len === 0) {
return Math.round(number).toString();
}
var result = number.toString();
var numberArr = result.split('.');
if (numberArr.length < 2) {
return this.handlePadNum(result, len);
}
var intNum = numberArr[0];
var deciNum = numberArr[1];
var lastNum = deciNum.substr(len, 1);
if (deciNum.length === len) {
return result;
}
if (deciNum.length < len) {
return this.handlePadNum(result, len);
}
result = intNum + '.' + deciNum.substr(0, len);
if (_parseInt$2(lastNum, 10) >= 5) {
var times = Math.pow(10, len);
var changedInt = Number(result.replace('.', ''));
changedInt++;
changedInt /= times;
result = this.handlePadNum(changedInt + '', len);
}
return result;
},
handlePadNum: function handlePadNum(num, len) {
var dotPos = num.indexOf('.');
if (dotPos === -1) {
num += '.';
for (var i = 0; i < len; i++) {
num += '0';
}
return num;
} else {
var need = len - (num.length - dotPos - 1);
for (var j = 0; j < need; j++) {
num += '0';
}
return num;
}
},
handleNumberDelete: function handleNumberDelete(event) {
var curNumberValue = Number(this.curValue);
if (curNumberValue - 1 >= this.min) {
var curLenAfterDot = (String(curNumberValue) || '').split('.')[1] || '';
var newVal = curNumberValue - 1;
if (typeof this.precision !== 'undefined') {
newVal = this.handleToFixed(newVal, Math.min(16, Math.max(curLenAfterDot.length, this.precision)));
}
this.setCurValue(newVal);
this.$emit('input', newVal, event);
this.$emit('change', newVal, event);
this.dispatch('bk-form-item', 'form-change');
}
},
handleNumberAdd: function handleNumberAdd(event) {
var curNumberValue = Number(this.curValue);
if (curNumberValue <= this.max - 1) {
var curLenAfterDot = (String(curNumberValue) || '').split('.')[1] || '';
var newVal = curNumberValue + 1;
if (typeof this.precision !== 'undefined') {
newVal = this.handleToFixed(newVal, Math.min(16, Math.max(curLenAfterDot.length, this.precision)));
}
this.setCurValue(newVal);
this.$emit('input', newVal, event);
this.$emit('change', newVal, event);
this.dispatch('bk-form-item', 'form-change');
}
},
handlerEnter: function handlerEnter(event) {
var value = event.target.value;
this.$emit('enter', value, event);
},
handlerKeyup: function handlerKeyup(event) {
var value = event.target.value;
this.$emit('keyup', value, event);
},
handlerKeypress: function handlerKeypress(event) {
var value = event.target.value;
this.$emit('keypress', value, event);
},
handlerKeydown: function handlerKeydown(event) {
var keyCode = event.keyCode;
var code = event.code;
var target = event.currentTarget;
var value = target.value;
var isPaste = (event.ctrlKey || event.metaKey) && keyCode === 86;
if (this.inputType === 'number') {
if (!(this.allowNumberPaste && isPaste) && ((keyCode === 229 ? this.validCodeList.indexOf(code) < 0 : this.validKeyCodeList.indexOf(keyCode) < 0) || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey)) {
event.stopPropagation();
event.preventDefault();
return false;
}
if (keyCode === 190 || code === 'Period') {
if (String(value).trim()) {
if (value.indexOf('.') >= 0) {
event.stopPropagation();
event.preventDefault();
return false;
}
}
}
if (event.keyCode === 189 || code === 'Minus') {
if (String(value).trim()) {
if (value.indexOf('-') >= 0) {
event.stopPropagation();
event.preventDefault();
return false;
}
if (document.getSelection().type !== 'Range') {
if (target.selectionEnd !== 0) {
event.stopPropagation();
event.preventDefault();
return false;
}
}
}
}
if (keyCode === 38 || code === 'ArrowUp') {
event.preventDefault();
this.handleNumberAdd(event);
} else if (keyCode === 40 || code === 'ArrowDown') {
event.preventDefault();
this.handleNumberDelete(event);
}
if (document.getSelection().type !== 'Range') {
if (value.indexOf('-') === 0 && target.selectionStart === 0) {
var keyCodeList = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
189,
109,
190,
110
];
var codeList = ['Digit0', 'Digit1', 'Digit2', 'Digit3', 'Digit4', 'Digit5', 'Digit6', 'Digit7', 'Digit8', 'Digit9',
'Numpad0', 'Numpad1', 'Numpad2', 'Numpad3', 'Numpad4', 'Numpad5', 'Numpad6', 'Numpad7', 'Numpad8', 'Numpad9',
'Minus',
'NumpadSubtract',
'Period',
'NumpadDecimal'
];
if (keyCode === 229 ? codeList.indexOf(code) > -1 : keyCodeList.indexOf(keyCode) > -1) {
event.stopPropagation();
event.preventDefault();
return false;
}
}
}
}
this.$emit('keydown', value, event);
},
handlerFocus: function handlerFocus(event) {
var value = event.target.value;
this.isActive = true;
this.$emit('focus', value, event);
this.dispatch('bk-form-item', 'form-focus');
},
toPrecision: function toPrecision(num, precision) {
if (precision === undefined) precision = 0;
return this.handleToFixed(num, precision);
},
handlerBlur: function handlerBlur(event) {
var value = event.target.value;
if (/^number$/i.test(this.type) && value !== '') {
if (isNaN(value)) {
value = this.min === minSafeInteger$1 ? 0 : this.min;
}
if (value !== '' && /^-?\d*(.\d*)?$/i.test(value)) {
if (value > this.max || value < this.min) {
value = this.getCurrentNumberValue();
}
}
if (typeof this.precision !== 'undefined') {
value = this.toPrecision(_parseFloat$2(value), this.precision, true);
} else {
value = Number(value);
}
if (value + '' !== event.target.value + '') {
this.setCurValue(value);
event.target.value = value;
this.$emit('change', value, event);
this.$emit('input', value, event);
}
}
this.isActive = false;
this.$emit('blur', value, event);
this.dispatch('bk-form-item', 'form-blur');
},
handlerPaste: function handlerPaste(event) {
var value = event.target.value;
this.$emit('paste', value, event);
this.$emit('change', value, event);
this.dispatch('bk-form-item', 'form-change');
},
getCurrentNumberValue: function getCurrentNumberValue() {
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
val = val === null ? this.curValue : val;
var value = '';
if (val !== '' && /^-?\d*(.\d*)?$/i.test(val)) {
value = Number(val);
value = value > this.max ? this.max : value;
value = value < this.min ? this.min : value;
return value;
}
return '';
},
handlerCompositionstart: function handlerCompositionstart(e) {
if (this.inputType === 'number') {
return;
}
this.isOnComposition = true;
},
handlerCompositionend: function handlerCompositionend(e) {
if (this.inputType === 'number' && this.isOnComposition) {
e.target.value = this.curValue;
this.isOnComposition = false;
this.handlerInput(e);
}
},
handlerInput: function handlerInput(event) {
var _this3 = this;
if (this.inputType === 'number' && this.isOnComposition) {
return;
}
this.$nextTick(function () {
var value = event.target.value;
_this3.setCurValue(value);
_this3.$emit('input', value, event);
_this3.$emit('change', value, event);
_this3.dispatch('bk-form-item', 'form-change');
});
},
handlerClear: function handlerClear(event) {
this.curValue = '';
this.$emit('input', this.curValue, event);
this.$emit('change', this.curValue, event);
this.$emit('clear', this.curValue, event);
this.dispatch('bk-form-item', 'form-change');
},
handlerLeftIcon: function handlerLeftIcon(event) {
this.$emit('left-icon-click', this.curValue, event);
},
handlerRightIcon: function handlerRightIcon(event) {
this.$emit('right-icon-click', this.curValue, event);
},
focus: function focus(event) {
if (this.type === 'textarea') {
this.$refs.textarea.focus();
} else {
this.$refs.input.focus();
}
},
blur: function blur(event) {
if (this.type === 'textarea') {
this.$refs.textarea.blur();
} else {
this.$refs.input.blur();
}
},
setCurValue: function setCurValue(val) {
if (val === this.curValue) {
return false;
}
this.curValue = val;
},
updateNumberValue: function updateNumberValue(val) {
if (val !== '' && /^number$/i.test(this.type) && /^-?\d*(.\d*)?$/i.test(val)) {
val = this.getCurrentNumberValue(val);
this.curValue = typeof this.precision === 'number' ? this.toPrecision(Number(val), this.precision) : Number(val);
}
},
togglePass: function togglePass() {
if (this.inputType === 'password') {
this.inputType = 'text';
} else {
this.inputType = 'password';
}
}
}
};
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('div', {
class: [_vm.wrapperClass, _vm.fontSizeCls, _vm.extCls],
on: {
"mouseenter": function mouseenter($event) {
_vm.hover = true;
},
"mouseleave": function mouseleave($event) {
_vm.hover = false;
}
}
}, [_vm.leftIcon ? _c('div', {
staticClass: "control-icon left-icon",
on: {
"click": _vm.handlerLeftIcon
}
}, [_c('i', {
class: ['bk-icon', _vm.leftIcon]
})]) : _vm._e(), _vm.prepend ? _c('div', {
staticClass: "group-box group-prepend"
}, [_vm._t("prepend")], 2) : _vm._e(), _vm.inputType === 'textarea' ? [_c('div', {
staticClass: "bk-textarea-wrapper"
}, [_c('textarea', _vm._b({
ref: "textarea",
class: ['bk-form-textarea', {
'textarea-maxlength': _vm.maxlength
}],
style: _vm.computedStyle,
on: {
"keyup": function keyup($event) {
if (!('button' in $event) && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")) {
return null;
}
return _vm.handlerEnter($event);
},
"keypress": _vm.handlerKeypress,
"keydown": _vm.handlerKeydown,
"focus": _vm.handlerFocus,
"blur": _vm.handlerBlur,
"input": _vm.handlerInput,
"compositionstart": _vm.handlerCompositionstart,
"compositionend": _vm.handlerCompositionend
}
}, 'textarea', _vm.bindAttribute, false)), _vm.showInputWordLimit ? [_c('p', {
staticClass: "bk-limit-box"
}, [_c('span', {
staticClass: "strong"
}, [_vm._v(_vm._s(_vm.curValue && _vm.curValue.length || 0))]), _vm._v("/"), _c('span', [_vm._v(_vm._s(_vm.maxlength))])])] : _vm._e()], 2)] : [_c('div', {
class: ["bk-input-" + _vm.type]
}, [_c('input', _vm._b({
ref: "input",
class: ['bk-form-input', _vm.inputSizeCls, {
'only-bottom-border': _vm.behavior === 'simplicity'
}, {
'input-text-ellipsis': (_vm.readonly || _vm.disabled) && _vm.ellipsis
}],
style: _vm.computedStyle,
on: {
"keyup": [function ($event) {
if (!('button' in $event) && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")) {
return null;
}
return _vm.handlerEnter($event);
}, _vm.handlerKeyup],
"keypress": _vm.handlerKeypress,
"keydown": _vm.handlerKeydown,
"focus": _vm.handlerFocus,
"blur": _vm.handlerBlur,
"input": _vm.handlerInput,
"paste": _vm.handlerPaste,
"compositionstart": _vm.handlerCompositionstart,
"compositionend": _vm.handlerCompositionend
}
}, 'input', _vm.bindAttribute, false)), /^number$/i.test(_vm.type) && !_vm.disabled && !_vm.readonly ? [_vm.showControls ? _c('span', {
staticClass: "input-number-option"
}, [_c('span', {
staticClass: "number-option-item bk-icon icon-angle-up",
on: {
"click": _vm.handleNumberAdd
}
}), _c('span', {
staticClass: "number-option-item bk-icon icon-angle-down",
on: {
"click": _vm.handleNumberDelete
}
})]) : _vm._e()] : _vm._e()], 2)], _vm.append ? _c('div', {
staticClass: "group-box group-append"
}, [_vm._t("append")], 2) : _vm._e(), !/^number$/i.test(_vm.type) ? _c('div', {
ref: "rightIconArea",
staticClass: "control-icon right-icon",
style: _vm.rightIconStyle,
on: {
"click": _vm.handlerRightIcon
}
}, [_vm.showPwdVisable ? _c('i', {
class: ['bk-icon', _vm.inputType === 'password' ? _vm.inputPasswordIcon[0] : _vm.inputPasswordIcon[1]],
on: {
"click": _vm.togglePass
}
}) : _vm._e(), _vm.showClearIcon ? _c('i', {
staticClass: "bk-icon icon-close-circle-shape clear-icon ml5",
on: {
"click": function click($event) {
$event.stopPropagation();
$event.preventDefault();
return _vm.handlerClear($event);
}
}
}) : _vm.rightIcon ? _c('i', {
class: ['input-right-icon', 'bk-icon', _vm.rightIcon]
}) : _vm._e(), _vm.type === 'text' ? [_c('p', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.showInputWordLimit,
expression: "showInputWordLimit"
}],
staticClass: "bk-limit-box ml5",
staticStyle: {
"position": "static"
}
}, [_c('span', {
staticClass: "strong"
}, [_vm._v(_vm._s(_vm.curValue && _vm.curValue.length || 0))]), _vm._v("/"), _c('span', [_vm._v(_vm._s(_vm.maxlength))])])] : _vm._e()], 2) : _vm._e()], 2);
};
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 transition = {
beforeEnter: function beforeEnter(el) {
addClass(el, 'collapse-transition');
if (!el.dataset) {
el.dataset = {};
}
el.dataset.oldPaddingTop = el.style.paddingTop;
el.dataset.oldPaddingBottom = el.style.paddingBottom;
el.style.height = '0';
el.style.paddingTop = 0;
el.style.paddingBottom = 0;
},
enter: function enter(el) {
el.dataset.oldOverflow = el.style.overflow;
if (el.scrollHeight !== 0) {
el.style.height = el.scrollHeight + 'px';
el.style.paddingTop = el.dataset.oldPaddingTop;
el.style.paddingBottom = el.dataset.oldPaddingBottom;
} else {
el.style.height = '';
el.style.paddingTop = el.dataset.oldPaddingTop;
el.style.paddingBottom = el.dataset.oldPaddingBottom;
}
el.style.overflow = 'hidden';
},
afterEnter: function afterEnter(el) {
removeClass(el, 'collapse-transition');
el.style.height = '';
el.style.overflow = el.dataset.oldOverflow;
},
beforeLeave: function beforeLeave(el) {
if (!el.dataset) el.dataset = {};
el.dataset.oldPaddingTop = el.style.paddingTop;
el.dataset.oldPaddingBottom = el.style.paddingBottom;
el.dataset.oldOverflow = el.style.overflow;
el.style.height = el.scrollHeight + 'px';
el.style.overflow = 'hidden';
},
leave: function leave(el) {
if (el.scrollHeight !== 0) {
addClass(el, 'collapse-transition');
el.style.height = 0;
el.style.paddingTop = 0;
el.style.paddingBottom = 0;
}
},
afterLeave: function afterLeave(el) {
removeClass(el, 'collapse-transition');
el.style.height = '';
el.style.overflow = el.dataset.oldOverflow;
el.style.paddingTop = el.dataset.oldPaddingTop;
el.style.paddingBottom = el.dataset.oldPaddingBottom;
}
};
var CollapseTransition = {
name: 'CollapseTransition',
functional: true,
render: function render(h, _ref) {
var children = _ref.children;
var data = {
on: transition
};
return h('transition', data, children);
}
};
var script$1 = {
name: 'bk-transition',
components: {
CollapseTransition: CollapseTransition
},
props: {
name: {
type: String,
default: ''
},
durationTime: {
type: String,
default: '.3s'
},
durationType: {
type: String,
default: 'linear'
}
},
computed: {
transitionName: function transitionName() {
return this.isCollapse ? '' : this.name;
},
isCollapse: function isCollapse() {
return this.name === 'collapse';
}
},
mounted: function mounted() {
var slot = this.getSlot();
slot.elm.style.transitionDuration = this.durationTime;
slot.elm.style.transitionTimingFunction = this.durationType;
},
methods: {
getSlot: function getSlot() {
return this.$slots.default[0];
}
}
};
/* script */
var __vue_script__$1 = script$1;
/* template */
var __vue_render__$1 = function __vue_render__() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('transition', {
staticClass: "bk-transition",
attrs: {
"name": _vm.transitionName
}
}, [_vm.name === 'collapse' ? _c('CollapseTransition', [_vm._t("default")], 2) : _vm._t("default")], 2);
};
var __vue_staticRenderFns__$1 = [];
/* style */
var __vue_inject_styles__$1 = undefined;
/* scoped */
var __vue_scope_id__$1 = undefined;
/* module identifier */
var __vue_module_identifier__$1 = undefined;
/* functional template */
var __vue_is_functional_template__$1 = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
var __vue_component__$1 = /*#__PURE__*/normalizeComponent_1({
render: __vue_render__$1,
staticRenderFns: __vue_staticRenderFns__$1
}, __vue_inject_styles__$1, __vue_script__$1, __vue_scope_id__$1, __vue_is_functional_template__$1, __vue_module_identifier__$1, false, undefined, undefined, undefined);
var script$2 = {
name: 'bk-card',
components: {
bkInput: __vue_component__,
bkTransition: __vue_component__$1
},
props: {
title: {
type: String,
default: ''
},
showHead: {
type: Boolean,
default: true
},
showFoot: {
type: Boolean,
default: false
},
isEdit: {
type: Boolean,
default: false
},
isCollapse: {
type: Boolean,
default: false
},
collapseIcons: {
type: Array,
default: function _default() {
return ['icon-angle-up-line', 'icon-angle-down-line'];
}
},
position: {
type: String,
default: 'left'
},
border: {
type: Boolean,
default: true
},
collapseStatus: {
type: Boolean,
default: true
},
disableHeaderStyle: {
type: Boolean,
default: false
}
},
data: function data() {
return {
collapseActive: true,
showInput: true,
renderTitle: ''
};
},
computed: {
collapseIcon: function collapseIcon() {
return this.collapseIcons[Number(this.collapseActive)];
},
collapseClass: function collapseClass() {
return this.isCollapse ? "bk-card-head bk-card-head-".concat(this.position) : 'bk-card-head';
}
},
watch: {
title: {
immediate: true,
handler: function handler(value) {
this.renderTitle = value;
}
},
collapseStatus: {
immediate: true,
handler: function handler(value) {
this.collapseActive = value;
}
}
},
methods: {
handleCollapse: function handleCollapse() {
if (!this.isCollapse) {
return;
}
this.collapseActive = !this.collapseActive;
this.$emit('update:collapseStatus', this.collapseActive);
},
clickEdit: function clickEdit() {
var _this = this;
this.showInput = !this.showInput;
this.$nextTick(function () {
_this.$refs.titleInputComp && _this.$refs.titleInputComp.focus();
});
},
saveEdit: function saveEdit() {
this.showInput = true;
this.$emit('edit', this.renderTitle);
}
}
};
/* script */
var __vue_script__$2 = script$2;
/* template */
var __vue_render__$2 = function __vue_render__() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('section', {
class: ['bk-card', {
'bk-card-border-none': !_vm.border
}]
}, [_vm.showHead ? _c('div', {
class: [_vm.collapseClass, {
'collapse': _vm.collapseActive
}, {
'no-line-height': _vm.disableHeaderStyle
}],
on: {
"click": _vm.handleCollapse
}
}, [_vm.isCollapse ? _c('i', {
class: "bk-icon bk-card-head-icon " + _vm.collapseIcon
}) : _vm._e(), _vm._t("header", [_vm.showInput ? [_c('span', {
staticClass: "title",
attrs: {
"title": _vm.renderTitle
}
}, [_vm._v(_vm._s(_vm.renderTitle))]), _c('span', {
staticClass: "card-edit"
}, [_vm.isEdit ? _c('i', {
staticClass: "bk-icon icon-edit-line",
on: {
"click": _vm.clickEdit
}
}) : _vm._e()])] : _c('bk-input', {
ref: "titleInputComp",
attrs: {
"ext-cls": "bk-card-input"
},
on: {
"blur": _vm.saveEdit,
"enter": _vm.saveEdit
},
model: {
value: _vm.renderTitle,
callback: function callback($$v) {
_vm.renderTitle = $$v;
},
expression: "renderTitle"
}
})])], 2) : _vm._e(), _vm.collapseActive ? [_c('bk-transition', {
attrs: {
"name": "collapse",
"duration-time": ".1.4s"
}
}, [_c('div', {
staticClass: "bk-card-body"
}, [_vm._t("default")], 2)]), _vm.showFoot ? _c('div', {
staticClass: "bk-card-foot"
}, [_vm._t("footer")], 2) : _vm._e()] : _vm._e()], 2);
};
var __vue_staticRenderFns__$2 = [];
/* style */
var __vue_inject_styles__$2 = undefined;
/* scoped */
var __vue_scope_id__$2 = undefined;
/* module identifier */
var __vue_module_identifier__$2 = undefined;
/* functional template */
var __vue_is_functional_template__$2 = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
var __vue_component__$2 = /*#__PURE__*/normalizeComponent_1({
render: __vue_render__$2,
staticRenderFns: __vue_staticRenderFns__$2
}, __vue_inject_styles__$2, __vue_script__$2, __vue_scope_id__$2, __vue_is_functional_template__$2, __vue_module_identifier__$2, false, undefined, undefined, undefined);
var _toObject = function (it) {
return Object(_defined(it));
};
var toString = {}.