input-number.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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 = 118);
  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. /***/ 118:
  164. /***/ (function(module, exports, __webpack_require__) {
  165. module.exports = __webpack_require__(119);
  166. /***/ }),
  167. /***/ 119:
  168. /***/ (function(module, exports, __webpack_require__) {
  169. "use strict";
  170. exports.__esModule = true;
  171. var _inputNumber = __webpack_require__(120);
  172. var _inputNumber2 = _interopRequireDefault(_inputNumber);
  173. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  174. /* istanbul ignore next */
  175. _inputNumber2.default.install = function (Vue) {
  176. Vue.component(_inputNumber2.default.name, _inputNumber2.default);
  177. };
  178. exports.default = _inputNumber2.default;
  179. /***/ }),
  180. /***/ 120:
  181. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  182. "use strict";
  183. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  184. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_input_number_vue__ = __webpack_require__(121);
  185. /* 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__);
  186. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_2d07efb5_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_input_number_vue__ = __webpack_require__(122);
  187. var normalizeComponent = __webpack_require__(0)
  188. /* script */
  189. /* template */
  190. /* template functional */
  191. var __vue_template_functional__ = false
  192. /* styles */
  193. var __vue_styles__ = null
  194. /* scopeId */
  195. var __vue_scopeId__ = null
  196. /* moduleIdentifier (server only) */
  197. var __vue_module_identifier__ = null
  198. var Component = normalizeComponent(
  199. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_input_number_vue___default.a,
  200. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_2d07efb5_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_input_number_vue__["a" /* default */],
  201. __vue_template_functional__,
  202. __vue_styles__,
  203. __vue_scopeId__,
  204. __vue_module_identifier__
  205. )
  206. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  207. /***/ }),
  208. /***/ 121:
  209. /***/ (function(module, exports, __webpack_require__) {
  210. "use strict";
  211. exports.__esModule = true;
  212. var _input = __webpack_require__(6);
  213. var _input2 = _interopRequireDefault(_input);
  214. var _focus = __webpack_require__(19);
  215. var _focus2 = _interopRequireDefault(_focus);
  216. var _repeatClick = __webpack_require__(24);
  217. var _repeatClick2 = _interopRequireDefault(_repeatClick);
  218. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  219. exports.default = {
  220. name: 'ElInputNumber',
  221. mixins: [(0, _focus2.default)('input')],
  222. inject: {
  223. elForm: {
  224. default: ''
  225. },
  226. elFormItem: {
  227. default: ''
  228. }
  229. },
  230. directives: {
  231. repeatClick: _repeatClick2.default
  232. },
  233. components: {
  234. ElInput: _input2.default
  235. },
  236. props: {
  237. step: {
  238. type: Number,
  239. default: 1
  240. },
  241. max: {
  242. type: Number,
  243. default: Infinity
  244. },
  245. min: {
  246. type: Number,
  247. default: -Infinity
  248. },
  249. value: {},
  250. disabled: Boolean,
  251. size: String,
  252. controls: {
  253. type: Boolean,
  254. default: true
  255. },
  256. controlsPosition: {
  257. type: String,
  258. default: ''
  259. },
  260. name: String,
  261. label: String
  262. },
  263. data: function data() {
  264. return {
  265. currentValue: 0
  266. };
  267. },
  268. watch: {
  269. value: {
  270. immediate: true,
  271. handler: function handler(value) {
  272. var newVal = value === undefined ? value : Number(value);
  273. if (newVal !== undefined && isNaN(newVal)) return;
  274. if (newVal >= this.max) newVal = this.max;
  275. if (newVal <= this.min) newVal = this.min;
  276. this.currentValue = newVal;
  277. this.$emit('input', newVal);
  278. }
  279. }
  280. },
  281. computed: {
  282. minDisabled: function minDisabled() {
  283. return this._decrease(this.value, this.step) < this.min;
  284. },
  285. maxDisabled: function maxDisabled() {
  286. return this._increase(this.value, this.step) > this.max;
  287. },
  288. precision: function precision() {
  289. var value = this.value,
  290. step = this.step,
  291. getPrecision = this.getPrecision;
  292. return Math.max(getPrecision(value), getPrecision(step));
  293. },
  294. controlsAtRight: function controlsAtRight() {
  295. return this.controlsPosition === 'right';
  296. },
  297. _elFormItemSize: function _elFormItemSize() {
  298. return (this.elFormItem || {}).elFormItemSize;
  299. },
  300. inputNumberSize: function inputNumberSize() {
  301. return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
  302. },
  303. inputNumberDisabled: function inputNumberDisabled() {
  304. return this.disabled || (this.elForm || {}).disabled;
  305. }
  306. },
  307. methods: {
  308. toPrecision: function toPrecision(num, precision) {
  309. if (precision === undefined) precision = this.precision;
  310. return parseFloat(parseFloat(Number(num).toFixed(precision)));
  311. },
  312. getPrecision: function getPrecision(value) {
  313. if (value === undefined) return 0;
  314. var valueString = value.toString();
  315. var dotPosition = valueString.indexOf('.');
  316. var precision = 0;
  317. if (dotPosition !== -1) {
  318. precision = valueString.length - dotPosition - 1;
  319. }
  320. return precision;
  321. },
  322. _increase: function _increase(val, step) {
  323. if (typeof val !== 'number' && val !== undefined) return this.currentValue;
  324. var precisionFactor = Math.pow(10, this.precision);
  325. // Solve the accuracy problem of JS decimal calculation by converting the value to integer.
  326. return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
  327. },
  328. _decrease: function _decrease(val, step) {
  329. if (typeof val !== 'number' && val !== undefined) return this.currentValue;
  330. var precisionFactor = Math.pow(10, this.precision);
  331. return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
  332. },
  333. increase: function increase() {
  334. if (this.inputNumberDisabled || this.maxDisabled) return;
  335. var value = this.value || 0;
  336. var newVal = this._increase(value, this.step);
  337. this.setCurrentValue(newVal);
  338. },
  339. decrease: function decrease() {
  340. if (this.inputNumberDisabled || this.minDisabled) return;
  341. var value = this.value || 0;
  342. var newVal = this._decrease(value, this.step);
  343. this.setCurrentValue(newVal);
  344. },
  345. handleBlur: function handleBlur(event) {
  346. this.$emit('blur', event);
  347. this.$refs.input.setCurrentValue(this.currentValue);
  348. },
  349. handleFocus: function handleFocus(event) {
  350. this.$emit('focus', event);
  351. },
  352. setCurrentValue: function setCurrentValue(newVal) {
  353. var oldVal = this.currentValue;
  354. if (newVal >= this.max) newVal = this.max;
  355. if (newVal <= this.min) newVal = this.min;
  356. if (oldVal === newVal) {
  357. this.$refs.input.setCurrentValue(this.currentValue);
  358. return;
  359. }
  360. this.$emit('input', newVal);
  361. this.$emit('change', newVal, oldVal);
  362. this.currentValue = newVal;
  363. },
  364. handleInputChange: function handleInputChange(value) {
  365. var newVal = value === '' ? undefined : Number(value);
  366. if (!isNaN(newVal) || value === '') {
  367. this.setCurrentValue(newVal);
  368. }
  369. }
  370. },
  371. mounted: function mounted() {
  372. var innerInput = this.$refs.input.$refs.input;
  373. innerInput.setAttribute('role', 'spinbutton');
  374. innerInput.setAttribute('aria-valuemax', this.max);
  375. innerInput.setAttribute('aria-valuemin', this.min);
  376. innerInput.setAttribute('aria-valuenow', this.currentValue);
  377. innerInput.setAttribute('aria-disabled', this.inputNumberDisabled);
  378. },
  379. updated: function updated() {
  380. if (!this.$refs || !this.$refs.input) return;
  381. var innerInput = this.$refs.input.$refs.input;
  382. innerInput.setAttribute('aria-valuenow', this.currentValue);
  383. }
  384. }; //
  385. //
  386. //
  387. //
  388. //
  389. //
  390. //
  391. //
  392. //
  393. //
  394. //
  395. //
  396. //
  397. //
  398. //
  399. //
  400. //
  401. //
  402. //
  403. //
  404. //
  405. //
  406. //
  407. //
  408. //
  409. //
  410. //
  411. //
  412. //
  413. //
  414. //
  415. //
  416. //
  417. //
  418. //
  419. //
  420. //
  421. //
  422. //
  423. //
  424. //
  425. //
  426. //
  427. //
  428. //
  429. //
  430. //
  431. //
  432. //
  433. //
  434. //
  435. /***/ }),
  436. /***/ 122:
  437. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  438. "use strict";
  439. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{class:[
  440. 'el-input-number',
  441. _vm.inputNumberSize ? 'el-input-number--' + _vm.inputNumberSize : '',
  442. { 'is-disabled': _vm.inputNumberDisabled },
  443. { 'is-without-controls': !_vm.controls },
  444. { 'is-controls-right': _vm.controlsAtRight }
  445. ],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.currentValue,"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)}]}},[(_vm.$slots.prepend)?_c('template',{attrs:{"slot":"prepend"},slot:"prepend"},[_vm._t("prepend")],2):_vm._e(),(_vm.$slots.append)?_c('template',{attrs:{"slot":"append"},slot:"append"},[_vm._t("append")],2):_vm._e()],2)],1)}
  446. var staticRenderFns = []
  447. var esExports = { render: render, staticRenderFns: staticRenderFns }
  448. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  449. /***/ }),
  450. /***/ 19:
  451. /***/ (function(module, exports) {
  452. module.exports = require("element-ui/lib/mixins/focus");
  453. /***/ }),
  454. /***/ 2:
  455. /***/ (function(module, exports) {
  456. module.exports = require("element-ui/lib/utils/dom");
  457. /***/ }),
  458. /***/ 24:
  459. /***/ (function(module, exports, __webpack_require__) {
  460. "use strict";
  461. exports.__esModule = true;
  462. var _dom = __webpack_require__(2);
  463. exports.default = {
  464. bind: function bind(el, binding, vnode) {
  465. var interval = null;
  466. var startTime = void 0;
  467. var handler = function handler() {
  468. return vnode.context[binding.expression].apply();
  469. };
  470. var clear = function clear() {
  471. if (new Date() - startTime < 100) {
  472. handler();
  473. }
  474. clearInterval(interval);
  475. interval = null;
  476. };
  477. (0, _dom.on)(el, 'mousedown', function (e) {
  478. if (e.button !== 0) return;
  479. startTime = new Date();
  480. (0, _dom.once)(document, 'mouseup', clear);
  481. clearInterval(interval);
  482. interval = setInterval(handler, 100);
  483. });
  484. }
  485. };
  486. /***/ }),
  487. /***/ 6:
  488. /***/ (function(module, exports) {
  489. module.exports = require("element-ui/lib/input");
  490. /***/ })
  491. /******/ });