@cw-devops/bk-magic-vue
Version:
基于蓝鲸 Magicbox 和 Vue 的前端组件库
1,448 lines (1,388 loc) • 168 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 _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
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 _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 _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? Object(arguments[i]) : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys.push.apply(ownKeys, Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
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 _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;
}
}
};
}
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;
var toString$1 = {}.toString;
var _cof = function (it) {
return toString$1.call(it).slice(8, -1);
};
var _isArray = Array.isArray || function isArray(arg) {
return _cof(arg) == 'Array';
};
_export(_export.S, 'Array', { isArray: _isArray });
var isArray = _core.Array.isArray;
var isArray$1 = isArray;
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 $parseInt = _global.parseInt;
var $trim$1 = _stringTrim.trim;
var hex = /^[-+]?0[xX]/;
var _parseInt = $parseInt(_stringWs + '08') !== 8 || $parseInt(_stringWs + '0x16') !== 22 ? function parseInt(str, radix) {
var string = $trim$1(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;
var requestAnimationFrame$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
window.setTimeout(callback, 1000 / 60);
};
var cancelAnimationFrame$1 = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame || function (id) {
window.clearTimeout(id);
};
function getTag(value) {
if (value === null) {
return '[object Null]';
}
return toString.call(value);
}
function isString(value) {
var type = _typeof(value);
return type === 'string' || type === 'object' && value !== null && getTag(value) === '[object String]';
}
function isArray$2(value) {
return isArray$1(value);
}
function isEmpty(value) {
return value === undefined || value === null || isString(value) && value === '' || isArray$2(value) && value.length === 0;
}
function checkOverflow(el) {
if (!el) return false;
var createDom = function createDom(el, css) {
var dom = document.createElement('div');
var width = _parseFloat$2(css['width']) ? Math.ceil(_parseFloat$2(css['width'])) + 'px' : css['width'];
dom.style.cssText = "\n width: ".concat(width, ";\n line-height: ").concat(css['line-height'], ";\n font-size: ").concat(css['font-size'], ";\n word-break: ").concat(css['word-break'], ";\n padding: ").concat(css['padding'], ";\n ");
dom.textContent = el.textContent;
return dom;
};
var isOverflow = false;
try {
var css = window.getComputedStyle(el, null);
var lineClamp = css.webkitLineClamp;
if (lineClamp !== 'none') {
var targetHeight = _parseFloat$2(css.height);
var dom = createDom(el, css);
document.body.appendChild(dom);
var domHeight = window.getComputedStyle(dom, null)['height'];
document.body.removeChild(dom);
isOverflow = targetHeight < _parseFloat$2(domHeight);
} else {
isOverflow = el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight;
}
} catch (e) {
console.warn('There is an error when check element overflow state: ', e);
}
return isOverflow;
}
function addWheelListener(elem, callback, useCapture) {
var prefix = '';
var _addEventListener;
if (window.addEventListener) {
_addEventListener = 'addEventListener';
} else {
_addEventListener = 'attachEvent';
prefix = 'on';
}
var support = 'onwheel' in document.createElement('div') ? 'wheel' : document.onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll';
function _addWheelListener(elem, eventName, callback, useCapture) {
elem[_addEventListener](prefix + eventName, support === 'wheel' ? callback : function (originalEvent) {
!originalEvent && (originalEvent = window.event);
var event = {
originalEvent: originalEvent,
target: originalEvent.target || originalEvent.srcElement,
type: 'wheel',
deltaMode: originalEvent.type === 'MozMousePixelScroll' ? 0 : 1,
deltaX: 0,
deltaZ: 0,
preventDefault: function preventDefault() {
originalEvent.preventDefault ? originalEvent.preventDefault() : originalEvent.returnValue = false;
}
};
if (support === 'mousewheel') {
event.deltaY = -1 / 40 * originalEvent.wheelDelta;
originalEvent.wheelDeltaX && (event.deltaX = -1 / 40 * originalEvent.wheelDeltaX);
} else {
event.deltaY = originalEvent.detail;
}
return callback(event);
}, useCapture || false);
}
if (support === 'DOMMouseScroll') {
_addWheelListener(elem, 'MozMousePixelScroll', callback, useCapture);
} else {
_addWheelListener(elem, support, callback, useCapture);
}
}
_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$2 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
window.setTimeout(callback, 1000 / 60);
};
var cancelAnimationFrame$2 = 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 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');
};
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 _toObject = function (it) {
return Object(_defined(it));
};
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 = cre