input-number.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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 = 117);
  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. /***/ 117:
  164. /***/ (function(module, exports, __webpack_require__) {
  165. module.exports = __webpack_require__(118);
  166. /***/ }),
  167. /***/ 118:
  168. /***/ (function(module, exports, __webpack_require__) {
  169. "use strict";
  170. exports.__esModule = true;
  171. var _inputNumber = __webpack_require__(119);
  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. /***/ 119:
  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__(120);
  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__(121);
  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. /***/ 12:
  209. /***/ (function(module, exports) {
  210. module.exports = require("throttle-debounce/debounce");
  211. /***/ }),
  212. /***/ 120:
  213. /***/ (function(module, exports, __webpack_require__) {
  214. "use strict";
  215. exports.__esModule = true;
  216. var _input = __webpack_require__(6);
  217. var _input2 = _interopRequireDefault(_input);
  218. var _debounce = __webpack_require__(12);
  219. var _debounce2 = _interopRequireDefault(_debounce);
  220. var _focus = __webpack_require__(13);
  221. var _focus2 = _interopRequireDefault(_focus);
  222. var _repeatClick = __webpack_require__(23);
  223. var _repeatClick2 = _interopRequireDefault(_repeatClick);
  224. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  225. //
  226. //
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. //
  256. //
  257. //
  258. //
  259. //
  260. //
  261. //
  262. //
  263. //
  264. //
  265. //
  266. //
  267. //
  268. //
  269. //
  270. //
  271. //
  272. //
  273. //
  274. //
  275. //
  276. //
  277. //
  278. exports.default = {
  279. name: 'ElInputNumber',
  280. mixins: [(0, _focus2.default)('input')],
  281. inject: {
  282. elFormItem: {
  283. default: ''
  284. }
  285. },
  286. directives: {
  287. repeatClick: _repeatClick2.default
  288. },
  289. components: {
  290. ElInput: _input2.default
  291. },
  292. props: {
  293. step: {
  294. type: Number,
  295. default: 1
  296. },
  297. max: {
  298. type: Number,
  299. default: Infinity
  300. },
  301. min: {
  302. type: Number,
  303. default: -Infinity
  304. },
  305. value: {
  306. default: 0
  307. },
  308. disabled: Boolean,
  309. size: String,
  310. controls: {
  311. type: Boolean,
  312. default: true
  313. },
  314. controlsPosition: {
  315. type: String,
  316. default: ''
  317. },
  318. debounce: {
  319. type: Number,
  320. default: 300
  321. },
  322. name: String,
  323. label: String
  324. },
  325. data: function data() {
  326. return {
  327. currentValue: 0
  328. };
  329. },
  330. watch: {
  331. value: {
  332. immediate: true,
  333. handler: function handler(value) {
  334. var newVal = Number(value);
  335. if (isNaN(newVal)) return;
  336. if (newVal >= this.max) newVal = this.max;
  337. if (newVal <= this.min) newVal = this.min;
  338. this.currentValue = newVal;
  339. this.$emit('input', newVal);
  340. }
  341. }
  342. },
  343. computed: {
  344. minDisabled: function minDisabled() {
  345. return this._decrease(this.value, this.step) < this.min;
  346. },
  347. maxDisabled: function maxDisabled() {
  348. return this._increase(this.value, this.step) > this.max;
  349. },
  350. precision: function precision() {
  351. var value = this.value,
  352. step = this.step,
  353. getPrecision = this.getPrecision;
  354. return Math.max(getPrecision(value), getPrecision(step));
  355. },
  356. controlsAtRight: function controlsAtRight() {
  357. return this.controlsPosition === 'right';
  358. },
  359. _elFormItemSize: function _elFormItemSize() {
  360. return (this.elFormItem || {}).elFormItemSize;
  361. },
  362. inputNumberSize: function inputNumberSize() {
  363. return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
  364. }
  365. },
  366. methods: {
  367. toPrecision: function toPrecision(num, precision) {
  368. if (precision === undefined) precision = this.precision;
  369. return parseFloat(parseFloat(Number(num).toFixed(precision)));
  370. },
  371. getPrecision: function getPrecision(value) {
  372. var valueString = value.toString();
  373. var dotPosition = valueString.indexOf('.');
  374. var precision = 0;
  375. if (dotPosition !== -1) {
  376. precision = valueString.length - dotPosition - 1;
  377. }
  378. return precision;
  379. },
  380. _increase: function _increase(val, step) {
  381. if (typeof val !== 'number') return this.currentValue;
  382. var precisionFactor = Math.pow(10, this.precision);
  383. return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
  384. },
  385. _decrease: function _decrease(val, step) {
  386. if (typeof val !== 'number') return this.currentValue;
  387. var precisionFactor = Math.pow(10, this.precision);
  388. return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
  389. },
  390. increase: function increase() {
  391. if (this.disabled || this.maxDisabled) return;
  392. var value = this.value || 0;
  393. var newVal = this._increase(value, this.step);
  394. if (newVal > this.max) return;
  395. this.setCurrentValue(newVal);
  396. },
  397. decrease: function decrease() {
  398. if (this.disabled || this.minDisabled) return;
  399. var value = this.value || 0;
  400. var newVal = this._decrease(value, this.step);
  401. if (newVal < this.min) return;
  402. this.setCurrentValue(newVal);
  403. },
  404. handleBlur: function handleBlur(event) {
  405. this.$emit('blur', event);
  406. this.$refs.input.setCurrentValue(this.currentValue);
  407. },
  408. handleFocus: function handleFocus(event) {
  409. this.$emit('focus', event);
  410. },
  411. setCurrentValue: function setCurrentValue(newVal) {
  412. var oldVal = this.currentValue;
  413. if (newVal >= this.max) newVal = this.max;
  414. if (newVal <= this.min) newVal = this.min;
  415. if (oldVal === newVal) {
  416. this.$refs.input.setCurrentValue(this.currentValue);
  417. return;
  418. }
  419. this.$emit('change', newVal, oldVal);
  420. this.$emit('input', newVal);
  421. this.currentValue = newVal;
  422. },
  423. handleInput: function handleInput(value) {
  424. if (value === '') {
  425. return;
  426. }
  427. if (value.indexOf('.') === value.length - 1) {
  428. return;
  429. }
  430. if (value.indexOf('-') === value.length - 1) {
  431. return;
  432. }
  433. var newVal = Number(value);
  434. if (!isNaN(newVal)) {
  435. this.setCurrentValue(newVal);
  436. } else {
  437. this.$refs.input.setCurrentValue(this.currentValue);
  438. }
  439. }
  440. },
  441. created: function created() {
  442. var _this = this;
  443. this.debounceHandleInput = (0, _debounce2.default)(this.debounce, function (value) {
  444. _this.handleInput(value);
  445. });
  446. },
  447. mounted: function mounted() {
  448. var innerInput = this.$refs.input.$refs.input;
  449. innerInput.setAttribute('role', 'spinbutton');
  450. innerInput.setAttribute('aria-valuemax', this.max);
  451. innerInput.setAttribute('aria-valuemin', this.min);
  452. innerInput.setAttribute('aria-valuenow', this.currentValue);
  453. innerInput.setAttribute('aria-disabled', this.disabled);
  454. },
  455. updated: function updated() {
  456. var innerInput = this.$refs.input.$refs.input;
  457. innerInput.setAttribute('aria-valuenow', this.currentValue);
  458. }
  459. };
  460. /***/ }),
  461. /***/ 121:
  462. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  463. "use strict";
  464. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-input-number",class:[
  465. _vm.inputNumberSize ? 'el-input-number--' + _vm.inputNumberSize : '',
  466. { 'is-disabled': _vm.disabled },
  467. { 'is-without-controls': !_vm.controls },
  468. { 'is-controls-right': _vm.controlsAtRight }
  469. ]},[(_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.disabled,"size":_vm.inputNumberSize,"max":_vm.max,"min":_vm.min,"name":_vm.name,"label":_vm.label},on:{"blur":_vm.handleBlur,"focus":_vm.handleFocus,"input":_vm.debounceHandleInput},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)}
  470. var staticRenderFns = []
  471. var esExports = { render: render, staticRenderFns: staticRenderFns }
  472. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  473. /***/ }),
  474. /***/ 13:
  475. /***/ (function(module, exports) {
  476. module.exports = require("element-ui/lib/mixins/focus");
  477. /***/ }),
  478. /***/ 2:
  479. /***/ (function(module, exports) {
  480. module.exports = require("element-ui/lib/utils/dom");
  481. /***/ }),
  482. /***/ 23:
  483. /***/ (function(module, exports, __webpack_require__) {
  484. "use strict";
  485. exports.__esModule = true;
  486. var _dom = __webpack_require__(2);
  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. /***/ 6:
  512. /***/ (function(module, exports) {
  513. module.exports = require("element-ui/lib/input");
  514. /***/ })
  515. /******/ });