input-number.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 106);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 106:
  164. /***/ (function(module, exports, __webpack_require__) {
  165. "use strict";
  166. exports.__esModule = true;
  167. var _inputNumber = __webpack_require__(107);
  168. var _inputNumber2 = _interopRequireDefault(_inputNumber);
  169. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  170. /* istanbul ignore next */
  171. _inputNumber2.default.install = function (Vue) {
  172. Vue.component(_inputNumber2.default.name, _inputNumber2.default);
  173. };
  174. exports.default = _inputNumber2.default;
  175. /***/ }),
  176. /***/ 107:
  177. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  178. "use strict";
  179. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  180. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_input_number_vue__ = __webpack_require__(108);
  181. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_input_number_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_input_number_vue__);
  182. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_223987a9_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_input_number_vue__ = __webpack_require__(109);
  183. var normalizeComponent = __webpack_require__(0)
  184. /* script */
  185. /* template */
  186. /* template functional */
  187. var __vue_template_functional__ = false
  188. /* styles */
  189. var __vue_styles__ = null
  190. /* scopeId */
  191. var __vue_scopeId__ = null
  192. /* moduleIdentifier (server only) */
  193. var __vue_module_identifier__ = null
  194. var Component = normalizeComponent(
  195. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_input_number_vue___default.a,
  196. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_223987a9_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_input_number_vue__["a" /* default */],
  197. __vue_template_functional__,
  198. __vue_styles__,
  199. __vue_scopeId__,
  200. __vue_module_identifier__
  201. )
  202. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  203. /***/ }),
  204. /***/ 108:
  205. /***/ (function(module, exports, __webpack_require__) {
  206. "use strict";
  207. exports.__esModule = true;
  208. var _input = __webpack_require__(6);
  209. var _input2 = _interopRequireDefault(_input);
  210. var _focus = __webpack_require__(19);
  211. var _focus2 = _interopRequireDefault(_focus);
  212. var _repeatClick = __webpack_require__(24);
  213. var _repeatClick2 = _interopRequireDefault(_repeatClick);
  214. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  215. exports.default = {
  216. name: 'ElInputNumber',
  217. mixins: [(0, _focus2.default)('input')],
  218. inject: {
  219. elForm: {
  220. default: ''
  221. },
  222. elFormItem: {
  223. default: ''
  224. }
  225. },
  226. directives: {
  227. repeatClick: _repeatClick2.default
  228. },
  229. components: {
  230. ElInput: _input2.default
  231. },
  232. props: {
  233. step: {
  234. type: Number,
  235. default: 1
  236. },
  237. max: {
  238. type: Number,
  239. default: Infinity
  240. },
  241. min: {
  242. type: Number,
  243. default: -Infinity
  244. },
  245. value: {},
  246. disabled: Boolean,
  247. size: String,
  248. controls: {
  249. type: Boolean,
  250. default: true
  251. },
  252. controlsPosition: {
  253. type: String,
  254. default: ''
  255. },
  256. name: String,
  257. label: String,
  258. placeholder: String,
  259. precision: {
  260. type: Number,
  261. validator: function validator(val) {
  262. return val >= 0 && val === parseInt(val, 10);
  263. }
  264. }
  265. },
  266. data: function data() {
  267. return {
  268. currentValue: 0
  269. };
  270. },
  271. watch: {
  272. value: {
  273. immediate: true,
  274. handler: function handler(value) {
  275. var newVal = value === undefined ? value : Number(value);
  276. if (newVal !== undefined) {
  277. if (isNaN(newVal)) {
  278. return;
  279. }
  280. if (this.precision !== undefined) {
  281. newVal = this.toPrecision(newVal, this.precision);
  282. }
  283. }
  284. if (newVal >= this.max) newVal = this.max;
  285. if (newVal <= this.min) newVal = this.min;
  286. this.currentValue = newVal;
  287. this.$emit('input', newVal);
  288. }
  289. }
  290. },
  291. computed: {
  292. minDisabled: function minDisabled() {
  293. return this._decrease(this.value, this.step) < this.min;
  294. },
  295. maxDisabled: function maxDisabled() {
  296. return this._increase(this.value, this.step) > this.max;
  297. },
  298. numPrecision: function numPrecision() {
  299. var value = this.value,
  300. step = this.step,
  301. getPrecision = this.getPrecision,
  302. precision = this.precision;
  303. var stepPrecision = getPrecision(step);
  304. if (precision !== undefined) {
  305. if (stepPrecision > precision) {
  306. console.warn('[Element Warn][InputNumber]precision should not be less than the decimal places of step');
  307. }
  308. return precision;
  309. } else {
  310. return Math.max(getPrecision(value), stepPrecision);
  311. }
  312. },
  313. controlsAtRight: function controlsAtRight() {
  314. return this.controls && this.controlsPosition === 'right';
  315. },
  316. _elFormItemSize: function _elFormItemSize() {
  317. return (this.elFormItem || {}).elFormItemSize;
  318. },
  319. inputNumberSize: function inputNumberSize() {
  320. return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
  321. },
  322. inputNumberDisabled: function inputNumberDisabled() {
  323. return this.disabled || (this.elForm || {}).disabled;
  324. },
  325. currentInputValue: function currentInputValue() {
  326. var currentValue = this.currentValue;
  327. if (typeof currentValue === 'number' && this.precision !== undefined) {
  328. return currentValue.toFixed(this.precision);
  329. } else {
  330. return currentValue;
  331. }
  332. }
  333. },
  334. methods: {
  335. toPrecision: function toPrecision(num, precision) {
  336. if (precision === undefined) precision = this.numPrecision;
  337. return parseFloat(parseFloat(Number(num).toFixed(precision)));
  338. },
  339. getPrecision: function getPrecision(value) {
  340. if (value === undefined) return 0;
  341. var valueString = value.toString();
  342. var dotPosition = valueString.indexOf('.');
  343. var precision = 0;
  344. if (dotPosition !== -1) {
  345. precision = valueString.length - dotPosition - 1;
  346. }
  347. return precision;
  348. },
  349. _increase: function _increase(val, step) {
  350. if (typeof val !== 'number' && val !== undefined) return this.currentValue;
  351. var precisionFactor = Math.pow(10, this.numPrecision);
  352. // Solve the accuracy problem of JS decimal calculation by converting the value to integer.
  353. return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
  354. },
  355. _decrease: function _decrease(val, step) {
  356. if (typeof val !== 'number' && val !== undefined) return this.currentValue;
  357. var precisionFactor = Math.pow(10, this.numPrecision);
  358. return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
  359. },
  360. increase: function increase() {
  361. if (this.inputNumberDisabled || this.maxDisabled) return;
  362. var value = this.value || 0;
  363. var newVal = this._increase(value, this.step);
  364. this.setCurrentValue(newVal);
  365. },
  366. decrease: function decrease() {
  367. if (this.inputNumberDisabled || this.minDisabled) return;
  368. var value = this.value || 0;
  369. var newVal = this._decrease(value, this.step);
  370. this.setCurrentValue(newVal);
  371. },
  372. handleBlur: function handleBlur(event) {
  373. this.$emit('blur', event);
  374. this.$refs.input.setCurrentValue(this.currentInputValue);
  375. },
  376. handleFocus: function handleFocus(event) {
  377. this.$emit('focus', event);
  378. },
  379. setCurrentValue: function setCurrentValue(newVal) {
  380. var oldVal = this.currentValue;
  381. if (typeof newVal === 'number' && this.precision !== undefined) {
  382. newVal = this.toPrecision(newVal, this.precision);
  383. }
  384. if (newVal >= this.max) newVal = this.max;
  385. if (newVal <= this.min) newVal = this.min;
  386. if (oldVal === newVal) {
  387. this.$refs.input.setCurrentValue(this.currentInputValue);
  388. return;
  389. }
  390. this.$emit('input', newVal);
  391. this.$emit('change', newVal, oldVal);
  392. this.currentValue = newVal;
  393. },
  394. handleInputChange: function handleInputChange(value) {
  395. var newVal = value === '' ? undefined : Number(value);
  396. if (!isNaN(newVal) || value === '') {
  397. this.setCurrentValue(newVal);
  398. }
  399. },
  400. select: function select() {
  401. this.$refs.input.select();
  402. }
  403. },
  404. mounted: function mounted() {
  405. var innerInput = this.$refs.input.$refs.input;
  406. innerInput.setAttribute('role', 'spinbutton');
  407. innerInput.setAttribute('aria-valuemax', this.max);
  408. innerInput.setAttribute('aria-valuemin', this.min);
  409. innerInput.setAttribute('aria-valuenow', this.currentValue);
  410. innerInput.setAttribute('aria-disabled', this.inputNumberDisabled);
  411. },
  412. updated: function updated() {
  413. if (!this.$refs || !this.$refs.input) return;
  414. var innerInput = this.$refs.input.$refs.input;
  415. innerInput.setAttribute('aria-valuenow', this.currentValue);
  416. }
  417. }; //
  418. //
  419. //
  420. //
  421. //
  422. //
  423. //
  424. //
  425. //
  426. //
  427. //
  428. //
  429. //
  430. //
  431. //
  432. //
  433. //
  434. //
  435. //
  436. //
  437. //
  438. //
  439. //
  440. //
  441. //
  442. //
  443. //
  444. //
  445. //
  446. //
  447. //
  448. //
  449. //
  450. //
  451. //
  452. //
  453. //
  454. //
  455. //
  456. //
  457. //
  458. //
  459. //
  460. //
  461. //
  462. //
  463. /***/ }),
  464. /***/ 109:
  465. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  466. "use strict";
  467. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{class:[
  468. 'el-input-number',
  469. _vm.inputNumberSize ? 'el-input-number--' + _vm.inputNumberSize : '',
  470. { 'is-disabled': _vm.inputNumberDisabled },
  471. { 'is-without-controls': !_vm.controls },
  472. { 'is-controls-right': _vm.controlsAtRight }
  473. ],on:{"dragstart":function($event){$event.preventDefault();}}},[(_vm.controls)?_c('span',{directives:[{name:"repeat-click",rawName:"v-repeat-click",value:(_vm.decrease),expression:"decrease"}],staticClass:"el-input-number__decrease",class:{'is-disabled': _vm.minDisabled},attrs:{"role":"button"},on:{"keydown":function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"enter",13,$event.key)){ return null; }_vm.decrease($event)}}},[_c('i',{class:("el-icon-" + (_vm.controlsAtRight ? 'arrow-down' : 'minus'))})]):_vm._e(),(_vm.controls)?_c('span',{directives:[{name:"repeat-click",rawName:"v-repeat-click",value:(_vm.increase),expression:"increase"}],staticClass:"el-input-number__increase",class:{'is-disabled': _vm.maxDisabled},attrs:{"role":"button"},on:{"keydown":function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"enter",13,$event.key)){ return null; }_vm.increase($event)}}},[_c('i',{class:("el-icon-" + (_vm.controlsAtRight ? 'arrow-up' : 'plus'))})]):_vm._e(),_c('el-input',{ref:"input",attrs:{"value":_vm.currentInputValue,"placeholder":_vm.placeholder,"disabled":_vm.inputNumberDisabled,"size":_vm.inputNumberSize,"max":_vm.max,"min":_vm.min,"name":_vm.name,"label":_vm.label},on:{"blur":_vm.handleBlur,"focus":_vm.handleFocus,"change":_vm.handleInputChange},nativeOn:{"keydown":[function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"up",38,$event.key)){ return null; }$event.preventDefault();_vm.increase($event)},function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"down",40,$event.key)){ return null; }$event.preventDefault();_vm.decrease($event)}]}})],1)}
  474. var staticRenderFns = []
  475. var esExports = { render: render, staticRenderFns: staticRenderFns }
  476. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  477. /***/ }),
  478. /***/ 19:
  479. /***/ (function(module, exports) {
  480. module.exports = require("element-ui/lib/mixins/focus");
  481. /***/ }),
  482. /***/ 24:
  483. /***/ (function(module, exports, __webpack_require__) {
  484. "use strict";
  485. exports.__esModule = true;
  486. var _dom = __webpack_require__(3);
  487. exports.default = {
  488. bind: function bind(el, binding, vnode) {
  489. var interval = null;
  490. var startTime = void 0;
  491. var handler = function handler() {
  492. return vnode.context[binding.expression].apply();
  493. };
  494. var clear = function clear() {
  495. if (new Date() - startTime < 100) {
  496. handler();
  497. }
  498. clearInterval(interval);
  499. interval = null;
  500. };
  501. (0, _dom.on)(el, 'mousedown', function (e) {
  502. if (e.button !== 0) return;
  503. startTime = new Date();
  504. (0, _dom.once)(document, 'mouseup', clear);
  505. clearInterval(interval);
  506. interval = setInterval(handler, 100);
  507. });
  508. }
  509. };
  510. /***/ }),
  511. /***/ 3:
  512. /***/ (function(module, exports) {
  513. module.exports = require("element-ui/lib/utils/dom");
  514. /***/ }),
  515. /***/ 6:
  516. /***/ (function(module, exports) {
  517. module.exports = require("element-ui/lib/input");
  518. /***/ })
  519. /******/ });