input-number.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(166);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 9:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/input");
  85. /***/ },
  86. /***/ 117:
  87. /***/ function(module, exports) {
  88. module.exports = require("element-ui/lib/utils/dom");
  89. /***/ },
  90. /***/ 166:
  91. /***/ function(module, exports, __webpack_require__) {
  92. 'use strict';
  93. exports.__esModule = true;
  94. var _inputNumber = __webpack_require__(167);
  95. var _inputNumber2 = _interopRequireDefault(_inputNumber);
  96. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  97. /* istanbul ignore next */
  98. _inputNumber2.default.install = function (Vue) {
  99. Vue.component(_inputNumber2.default.name, _inputNumber2.default);
  100. };
  101. exports.default = _inputNumber2.default;
  102. /***/ },
  103. /***/ 167:
  104. /***/ function(module, exports, __webpack_require__) {
  105. var Component = __webpack_require__(3)(
  106. /* script */
  107. __webpack_require__(168),
  108. /* template */
  109. __webpack_require__(169),
  110. /* scopeId */
  111. null,
  112. /* cssModules */
  113. null
  114. )
  115. module.exports = Component.exports
  116. /***/ },
  117. /***/ 168:
  118. /***/ function(module, exports, __webpack_require__) {
  119. 'use strict';
  120. exports.__esModule = true;
  121. var _input = __webpack_require__(9);
  122. var _input2 = _interopRequireDefault(_input);
  123. var _dom = __webpack_require__(117);
  124. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  125. //
  126. //
  127. //
  128. //
  129. //
  130. //
  131. //
  132. //
  133. //
  134. //
  135. //
  136. //
  137. //
  138. //
  139. //
  140. //
  141. //
  142. //
  143. //
  144. //
  145. //
  146. //
  147. //
  148. //
  149. //
  150. //
  151. //
  152. //
  153. //
  154. //
  155. //
  156. //
  157. //
  158. //
  159. //
  160. //
  161. //
  162. //
  163. //
  164. //
  165. //
  166. //
  167. //
  168. //
  169. //
  170. exports.default = {
  171. name: 'ElInputNumber',
  172. directives: {
  173. repeatClick: {
  174. bind: function bind(el, binding, vnode) {
  175. var interval = null;
  176. var startTime = void 0;
  177. var handler = function handler() {
  178. return vnode.context[binding.expression].apply();
  179. };
  180. var clear = function clear() {
  181. if (new Date() - startTime < 100) {
  182. handler();
  183. }
  184. clearInterval(interval);
  185. interval = null;
  186. };
  187. (0, _dom.on)(el, 'mousedown', function () {
  188. startTime = new Date();
  189. (0, _dom.once)(document, 'mouseup', clear);
  190. clearInterval(interval);
  191. interval = setInterval(handler, 100);
  192. });
  193. }
  194. }
  195. },
  196. components: {
  197. ElInput: _input2.default
  198. },
  199. props: {
  200. step: {
  201. type: Number,
  202. default: 1
  203. },
  204. max: {
  205. type: Number,
  206. default: Infinity
  207. },
  208. min: {
  209. type: Number,
  210. default: -Infinity
  211. },
  212. value: {
  213. default: 0
  214. },
  215. disabled: Boolean,
  216. size: String,
  217. controls: {
  218. type: Boolean,
  219. default: true
  220. }
  221. },
  222. data: function data() {
  223. return {
  224. currentValue: 0
  225. };
  226. },
  227. watch: {
  228. value: {
  229. immediate: true,
  230. handler: function handler(value) {
  231. var newVal = Number(value);
  232. if (isNaN(newVal)) return;
  233. if (newVal >= this.max) newVal = this.max;
  234. if (newVal <= this.min) newVal = this.min;
  235. this.currentValue = newVal;
  236. this.$emit('input', newVal);
  237. }
  238. }
  239. },
  240. computed: {
  241. minDisabled: function minDisabled() {
  242. return this._decrease(this.value, this.step) < this.min;
  243. },
  244. maxDisabled: function maxDisabled() {
  245. return this._increase(this.value, this.step) > this.max;
  246. },
  247. precision: function precision() {
  248. var value = this.value,
  249. step = this.step,
  250. getPrecision = this.getPrecision;
  251. return Math.max(getPrecision(value), getPrecision(step));
  252. }
  253. },
  254. methods: {
  255. toPrecision: function toPrecision(num, precision) {
  256. if (precision === undefined) precision = this.precision;
  257. return parseFloat(parseFloat(Number(num).toFixed(precision)));
  258. },
  259. getPrecision: function getPrecision(value) {
  260. var valueString = value.toString();
  261. var dotPosition = valueString.indexOf('.');
  262. var precision = 0;
  263. if (dotPosition !== -1) {
  264. precision = valueString.length - dotPosition - 1;
  265. }
  266. return precision;
  267. },
  268. _increase: function _increase(val, step) {
  269. if (typeof val !== 'number') return this.currentValue;
  270. var precisionFactor = Math.pow(10, this.precision);
  271. return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
  272. },
  273. _decrease: function _decrease(val, step) {
  274. if (typeof val !== 'number') return this.currentValue;
  275. var precisionFactor = Math.pow(10, this.precision);
  276. return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
  277. },
  278. increase: function increase() {
  279. if (this.disabled || this.maxDisabled) return;
  280. var value = this.value || 0;
  281. var newVal = this._increase(value, this.step);
  282. if (newVal > this.max) return;
  283. this.setCurrentValue(newVal);
  284. },
  285. decrease: function decrease() {
  286. if (this.disabled || this.minDisabled) return;
  287. var value = this.value || 0;
  288. var newVal = this._decrease(value, this.step);
  289. if (newVal < this.min) return;
  290. this.setCurrentValue(newVal);
  291. },
  292. handleBlur: function handleBlur() {
  293. this.$refs.input.setCurrentValue(this.currentValue);
  294. },
  295. setCurrentValue: function setCurrentValue(newVal) {
  296. var oldVal = this.currentValue;
  297. if (newVal >= this.max) newVal = this.max;
  298. if (newVal <= this.min) newVal = this.min;
  299. if (oldVal === newVal) return;
  300. this.$emit('change', newVal, oldVal);
  301. this.$emit('input', newVal);
  302. this.currentValue = newVal;
  303. },
  304. handleInput: function handleInput(value) {
  305. var newVal = Number(value);
  306. if (!isNaN(newVal)) {
  307. this.setCurrentValue(newVal);
  308. }
  309. }
  310. }
  311. };
  312. /***/ },
  313. /***/ 169:
  314. /***/ function(module, exports) {
  315. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  316. return _c('div', {
  317. staticClass: "el-input-number",
  318. class: [
  319. _vm.size ? 'el-input-number--' + _vm.size : '', {
  320. 'is-disabled': _vm.disabled
  321. }, {
  322. 'is-without-controls': !_vm.controls
  323. }
  324. ]
  325. }, [(_vm.controls) ? _c('span', {
  326. directives: [{
  327. name: "repeat-click",
  328. rawName: "v-repeat-click",
  329. value: (_vm.decrease),
  330. expression: "decrease"
  331. }],
  332. staticClass: "el-input-number__decrease",
  333. class: {
  334. 'is-disabled': _vm.minDisabled
  335. }
  336. }, [_c('i', {
  337. staticClass: "el-icon-minus"
  338. })]) : _vm._e(), (_vm.controls) ? _c('span', {
  339. directives: [{
  340. name: "repeat-click",
  341. rawName: "v-repeat-click",
  342. value: (_vm.increase),
  343. expression: "increase"
  344. }],
  345. staticClass: "el-input-number__increase",
  346. class: {
  347. 'is-disabled': _vm.maxDisabled
  348. }
  349. }, [_c('i', {
  350. staticClass: "el-icon-plus"
  351. })]) : _vm._e(), _c('el-input', {
  352. ref: "input",
  353. attrs: {
  354. "value": _vm.currentValue,
  355. "disabled": _vm.disabled,
  356. "size": _vm.size,
  357. "max": _vm.max,
  358. "min": _vm.min
  359. },
  360. on: {
  361. "blur": _vm.handleBlur,
  362. "input": _vm.handleInput
  363. },
  364. nativeOn: {
  365. "keydown": [function($event) {
  366. if (_vm._k($event.keyCode, "up", 38)) { return; }
  367. $event.preventDefault();
  368. _vm.increase($event)
  369. }, function($event) {
  370. if (_vm._k($event.keyCode, "down", 40)) { return; }
  371. $event.preventDefault();
  372. _vm.decrease($event)
  373. }]
  374. }
  375. }, [(_vm.$slots.prepend) ? _c('template', {
  376. slot: "prepend"
  377. }, [_vm._t("prepend")], 2) : _vm._e(), (_vm.$slots.append) ? _c('template', {
  378. slot: "append"
  379. }, [_vm._t("append")], 2) : _vm._e()], 2)], 1)
  380. },staticRenderFns: []}
  381. /***/ }
  382. /******/ });