slider.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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 = 306);
  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. /***/ 1:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/mixins/emitter");
  166. /***/ }),
  167. /***/ 22:
  168. /***/ (function(module, exports) {
  169. module.exports = require("element-ui/lib/tooltip");
  170. /***/ }),
  171. /***/ 306:
  172. /***/ (function(module, exports, __webpack_require__) {
  173. module.exports = __webpack_require__(307);
  174. /***/ }),
  175. /***/ 307:
  176. /***/ (function(module, exports, __webpack_require__) {
  177. "use strict";
  178. exports.__esModule = true;
  179. var _main = __webpack_require__(308);
  180. var _main2 = _interopRequireDefault(_main);
  181. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  182. /* istanbul ignore next */
  183. _main2.default.install = function (Vue) {
  184. Vue.component(_main2.default.name, _main2.default);
  185. };
  186. exports.default = _main2.default;
  187. /***/ }),
  188. /***/ 308:
  189. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  190. "use strict";
  191. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  192. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__ = __webpack_require__(309);
  193. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__);
  194. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_ec0df926_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__ = __webpack_require__(314);
  195. var normalizeComponent = __webpack_require__(0)
  196. /* script */
  197. /* template */
  198. /* template functional */
  199. var __vue_template_functional__ = false
  200. /* styles */
  201. var __vue_styles__ = null
  202. /* scopeId */
  203. var __vue_scopeId__ = null
  204. /* moduleIdentifier (server only) */
  205. var __vue_module_identifier__ = null
  206. var Component = normalizeComponent(
  207. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default.a,
  208. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_ec0df926_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__["a" /* default */],
  209. __vue_template_functional__,
  210. __vue_styles__,
  211. __vue_scopeId__,
  212. __vue_module_identifier__
  213. )
  214. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  215. /***/ }),
  216. /***/ 309:
  217. /***/ (function(module, exports, __webpack_require__) {
  218. "use strict";
  219. exports.__esModule = true;
  220. var _inputNumber = __webpack_require__(310);
  221. var _inputNumber2 = _interopRequireDefault(_inputNumber);
  222. var _button = __webpack_require__(311);
  223. var _button2 = _interopRequireDefault(_button);
  224. var _emitter = __webpack_require__(1);
  225. var _emitter2 = _interopRequireDefault(_emitter);
  226. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  227. exports.default = {
  228. name: 'ElSlider',
  229. mixins: [_emitter2.default],
  230. props: {
  231. min: {
  232. type: Number,
  233. default: 0
  234. },
  235. max: {
  236. type: Number,
  237. default: 100
  238. },
  239. step: {
  240. type: Number,
  241. default: 1
  242. },
  243. value: {
  244. type: [Number, Array],
  245. default: 0
  246. },
  247. showInput: {
  248. type: Boolean,
  249. default: false
  250. },
  251. showInputControls: {
  252. type: Boolean,
  253. default: true
  254. },
  255. showStops: {
  256. type: Boolean,
  257. default: false
  258. },
  259. showTooltip: {
  260. type: Boolean,
  261. default: true
  262. },
  263. formatTooltip: Function,
  264. disabled: {
  265. type: Boolean,
  266. default: false
  267. },
  268. range: {
  269. type: Boolean,
  270. default: false
  271. },
  272. vertical: {
  273. type: Boolean,
  274. default: false
  275. },
  276. height: {
  277. type: String
  278. },
  279. debounce: {
  280. type: Number,
  281. default: 300
  282. },
  283. label: {
  284. type: String
  285. }
  286. },
  287. components: {
  288. ElInputNumber: _inputNumber2.default,
  289. SliderButton: _button2.default
  290. },
  291. data: function data() {
  292. return {
  293. firstValue: null,
  294. secondValue: null,
  295. oldValue: null,
  296. dragging: false,
  297. sliderSize: 1
  298. };
  299. },
  300. watch: {
  301. value: function value(val, oldVal) {
  302. if (this.dragging || Array.isArray(val) && Array.isArray(oldVal) && val.every(function (item, index) {
  303. return item === oldVal[index];
  304. })) {
  305. return;
  306. }
  307. this.setValues();
  308. },
  309. dragging: function dragging(val) {
  310. if (!val) {
  311. this.setValues();
  312. }
  313. },
  314. firstValue: function firstValue(val) {
  315. if (this.range) {
  316. this.$emit('input', [this.minValue, this.maxValue]);
  317. } else {
  318. this.$emit('input', val);
  319. }
  320. },
  321. secondValue: function secondValue() {
  322. if (this.range) {
  323. this.$emit('input', [this.minValue, this.maxValue]);
  324. }
  325. },
  326. min: function min() {
  327. this.setValues();
  328. },
  329. max: function max() {
  330. this.setValues();
  331. }
  332. },
  333. methods: {
  334. valueChanged: function valueChanged() {
  335. var _this = this;
  336. if (this.range) {
  337. return ![this.minValue, this.maxValue].every(function (item, index) {
  338. return item === _this.oldValue[index];
  339. });
  340. } else {
  341. return this.value !== this.oldValue;
  342. }
  343. },
  344. setValues: function setValues() {
  345. var val = this.value;
  346. if (this.range && Array.isArray(val)) {
  347. if (val[1] < this.min) {
  348. this.$emit('input', [this.min, this.min]);
  349. } else if (val[0] > this.max) {
  350. this.$emit('input', [this.max, this.max]);
  351. } else if (val[0] < this.min) {
  352. this.$emit('input', [this.min, val[1]]);
  353. } else if (val[1] > this.max) {
  354. this.$emit('input', [val[0], this.max]);
  355. } else {
  356. this.firstValue = val[0];
  357. this.secondValue = val[1];
  358. if (this.valueChanged()) {
  359. this.dispatch('ElFormItem', 'el.form.change', [this.minValue, this.maxValue]);
  360. this.oldValue = val.slice();
  361. }
  362. }
  363. } else if (!this.range && typeof val === 'number' && !isNaN(val)) {
  364. if (val < this.min) {
  365. this.$emit('input', this.min);
  366. } else if (val > this.max) {
  367. this.$emit('input', this.max);
  368. } else {
  369. this.firstValue = val;
  370. if (this.valueChanged()) {
  371. this.dispatch('ElFormItem', 'el.form.change', val);
  372. this.oldValue = val;
  373. }
  374. }
  375. }
  376. },
  377. setPosition: function setPosition(percent) {
  378. var targetValue = this.min + percent * (this.max - this.min) / 100;
  379. if (!this.range) {
  380. this.$refs.button1.setPosition(percent);
  381. return;
  382. }
  383. var button = void 0;
  384. if (Math.abs(this.minValue - targetValue) < Math.abs(this.maxValue - targetValue)) {
  385. button = this.firstValue < this.secondValue ? 'button1' : 'button2';
  386. } else {
  387. button = this.firstValue > this.secondValue ? 'button1' : 'button2';
  388. }
  389. this.$refs[button].setPosition(percent);
  390. },
  391. onSliderClick: function onSliderClick(event) {
  392. if (this.disabled || this.dragging) return;
  393. this.resetSize();
  394. if (this.vertical) {
  395. var sliderOffsetBottom = this.$refs.slider.getBoundingClientRect().bottom;
  396. this.setPosition((sliderOffsetBottom - event.clientY) / this.sliderSize * 100);
  397. } else {
  398. var sliderOffsetLeft = this.$refs.slider.getBoundingClientRect().left;
  399. this.setPosition((event.clientX - sliderOffsetLeft) / this.sliderSize * 100);
  400. }
  401. this.emitChange();
  402. },
  403. resetSize: function resetSize() {
  404. if (this.$refs.slider) {
  405. this.sliderSize = this.$refs.slider['client' + (this.vertical ? 'Height' : 'Width')];
  406. }
  407. },
  408. emitChange: function emitChange() {
  409. var _this2 = this;
  410. this.$nextTick(function () {
  411. _this2.$emit('change', _this2.range ? [_this2.minValue, _this2.maxValue] : _this2.value);
  412. });
  413. }
  414. },
  415. computed: {
  416. stops: function stops() {
  417. var _this3 = this;
  418. if (this.step === 0) {
  419. "production" !== 'production' && console.warn('[Element Warn][Slider]step should not be 0.');
  420. return [];
  421. }
  422. var stopCount = (this.max - this.min) / this.step;
  423. var stepWidth = 100 * this.step / (this.max - this.min);
  424. var result = [];
  425. for (var i = 1; i < stopCount; i++) {
  426. result.push(i * stepWidth);
  427. }
  428. if (this.range) {
  429. return result.filter(function (step) {
  430. return step < 100 * (_this3.minValue - _this3.min) / (_this3.max - _this3.min) || step > 100 * (_this3.maxValue - _this3.min) / (_this3.max - _this3.min);
  431. });
  432. } else {
  433. return result.filter(function (step) {
  434. return step > 100 * (_this3.firstValue - _this3.min) / (_this3.max - _this3.min);
  435. });
  436. }
  437. },
  438. minValue: function minValue() {
  439. return Math.min(this.firstValue, this.secondValue);
  440. },
  441. maxValue: function maxValue() {
  442. return Math.max(this.firstValue, this.secondValue);
  443. },
  444. barSize: function barSize() {
  445. return this.range ? 100 * (this.maxValue - this.minValue) / (this.max - this.min) + '%' : 100 * (this.firstValue - this.min) / (this.max - this.min) + '%';
  446. },
  447. barStart: function barStart() {
  448. return this.range ? 100 * (this.minValue - this.min) / (this.max - this.min) + '%' : '0%';
  449. },
  450. precision: function precision() {
  451. var precisions = [this.min, this.max, this.step].map(function (item) {
  452. var decimal = ('' + item).split('.')[1];
  453. return decimal ? decimal.length : 0;
  454. });
  455. return Math.max.apply(null, precisions);
  456. },
  457. runwayStyle: function runwayStyle() {
  458. return this.vertical ? { height: this.height } : {};
  459. },
  460. barStyle: function barStyle() {
  461. return this.vertical ? {
  462. height: this.barSize,
  463. bottom: this.barStart
  464. } : {
  465. width: this.barSize,
  466. left: this.barStart
  467. };
  468. }
  469. },
  470. mounted: function mounted() {
  471. var valuetext = void 0;
  472. if (this.range) {
  473. if (Array.isArray(this.value)) {
  474. this.firstValue = Math.max(this.min, this.value[0]);
  475. this.secondValue = Math.min(this.max, this.value[1]);
  476. } else {
  477. this.firstValue = this.min;
  478. this.secondValue = this.max;
  479. }
  480. this.oldValue = [this.firstValue, this.secondValue];
  481. valuetext = this.firstValue + '-' + this.secondValue;
  482. } else {
  483. if (typeof this.value !== 'number' || isNaN(this.value)) {
  484. this.firstValue = this.min;
  485. } else {
  486. this.firstValue = Math.min(this.max, Math.max(this.min, this.value));
  487. }
  488. this.oldValue = this.firstValue;
  489. valuetext = this.firstValue;
  490. }
  491. this.$el.setAttribute('aria-valuetext', valuetext);
  492. // label screen reader
  493. this.$el.setAttribute('aria-label', this.label ? this.label : 'slider between ' + this.min + ' and ' + this.max);
  494. this.resetSize();
  495. window.addEventListener('resize', this.resetSize);
  496. },
  497. beforeDestroy: function beforeDestroy() {
  498. window.removeEventListener('resize', this.resetSize);
  499. }
  500. }; //
  501. //
  502. //
  503. //
  504. //
  505. //
  506. //
  507. //
  508. //
  509. //
  510. //
  511. //
  512. //
  513. //
  514. //
  515. //
  516. //
  517. //
  518. //
  519. //
  520. //
  521. //
  522. //
  523. //
  524. //
  525. //
  526. //
  527. //
  528. //
  529. //
  530. //
  531. //
  532. //
  533. //
  534. //
  535. //
  536. //
  537. //
  538. //
  539. //
  540. //
  541. //
  542. //
  543. //
  544. //
  545. //
  546. //
  547. //
  548. //
  549. //
  550. //
  551. //
  552. //
  553. /***/ }),
  554. /***/ 310:
  555. /***/ (function(module, exports) {
  556. module.exports = require("element-ui/lib/input-number");
  557. /***/ }),
  558. /***/ 311:
  559. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  560. "use strict";
  561. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  562. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_button_vue__ = __webpack_require__(312);
  563. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_button_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_button_vue__);
  564. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_28634966_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_button_vue__ = __webpack_require__(313);
  565. var normalizeComponent = __webpack_require__(0)
  566. /* script */
  567. /* template */
  568. /* template functional */
  569. var __vue_template_functional__ = false
  570. /* styles */
  571. var __vue_styles__ = null
  572. /* scopeId */
  573. var __vue_scopeId__ = null
  574. /* moduleIdentifier (server only) */
  575. var __vue_module_identifier__ = null
  576. var Component = normalizeComponent(
  577. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_button_vue___default.a,
  578. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_28634966_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_button_vue__["a" /* default */],
  579. __vue_template_functional__,
  580. __vue_styles__,
  581. __vue_scopeId__,
  582. __vue_module_identifier__
  583. )
  584. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  585. /***/ }),
  586. /***/ 312:
  587. /***/ (function(module, exports, __webpack_require__) {
  588. "use strict";
  589. exports.__esModule = true;
  590. var _tooltip = __webpack_require__(22);
  591. var _tooltip2 = _interopRequireDefault(_tooltip);
  592. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  593. exports.default = {
  594. name: 'ElSliderButton',
  595. components: {
  596. ElTooltip: _tooltip2.default
  597. },
  598. props: {
  599. value: {
  600. type: Number,
  601. default: 0
  602. },
  603. vertical: {
  604. type: Boolean,
  605. default: false
  606. }
  607. },
  608. data: function data() {
  609. return {
  610. hovering: false,
  611. dragging: false,
  612. isClick: false,
  613. startX: 0,
  614. currentX: 0,
  615. startY: 0,
  616. currentY: 0,
  617. startPosition: 0,
  618. newPosition: null,
  619. oldValue: this.value
  620. };
  621. },
  622. computed: {
  623. disabled: function disabled() {
  624. return this.$parent.disabled;
  625. },
  626. max: function max() {
  627. return this.$parent.max;
  628. },
  629. min: function min() {
  630. return this.$parent.min;
  631. },
  632. step: function step() {
  633. return this.$parent.step;
  634. },
  635. showTooltip: function showTooltip() {
  636. return this.$parent.showTooltip;
  637. },
  638. precision: function precision() {
  639. return this.$parent.precision;
  640. },
  641. currentPosition: function currentPosition() {
  642. return (this.value - this.min) / (this.max - this.min) * 100 + '%';
  643. },
  644. enableFormat: function enableFormat() {
  645. return this.$parent.formatTooltip instanceof Function;
  646. },
  647. formatValue: function formatValue() {
  648. return this.enableFormat && this.$parent.formatTooltip(this.value) || this.value;
  649. },
  650. wrapperStyle: function wrapperStyle() {
  651. return this.vertical ? { bottom: this.currentPosition } : { left: this.currentPosition };
  652. }
  653. },
  654. watch: {
  655. dragging: function dragging(val) {
  656. this.$parent.dragging = val;
  657. }
  658. },
  659. methods: {
  660. displayTooltip: function displayTooltip() {
  661. this.$refs.tooltip && (this.$refs.tooltip.showPopper = true);
  662. },
  663. hideTooltip: function hideTooltip() {
  664. this.$refs.tooltip && (this.$refs.tooltip.showPopper = false);
  665. },
  666. handleMouseEnter: function handleMouseEnter() {
  667. this.hovering = true;
  668. this.displayTooltip();
  669. },
  670. handleMouseLeave: function handleMouseLeave() {
  671. this.hovering = false;
  672. this.hideTooltip();
  673. },
  674. onButtonDown: function onButtonDown(event) {
  675. if (this.disabled) return;
  676. event.preventDefault();
  677. this.onDragStart(event);
  678. window.addEventListener('mousemove', this.onDragging);
  679. window.addEventListener('mouseup', this.onDragEnd);
  680. window.addEventListener('contextmenu', this.onDragEnd);
  681. },
  682. onLeftKeyDown: function onLeftKeyDown() {
  683. if (this.disabled) return;
  684. this.newPosition = parseFloat(this.currentPosition) - this.step / (this.max - this.min) * 100;
  685. this.setPosition(this.newPosition);
  686. },
  687. onRightKeyDown: function onRightKeyDown() {
  688. if (this.disabled) return;
  689. this.newPosition = parseFloat(this.currentPosition) + this.step / (this.max - this.min) * 100;
  690. this.setPosition(this.newPosition);
  691. },
  692. onDragStart: function onDragStart(event) {
  693. this.dragging = true;
  694. this.isClick = true;
  695. if (this.vertical) {
  696. this.startY = event.clientY;
  697. } else {
  698. this.startX = event.clientX;
  699. }
  700. this.startPosition = parseFloat(this.currentPosition);
  701. this.newPosition = this.startPosition;
  702. },
  703. onDragging: function onDragging(event) {
  704. if (this.dragging) {
  705. this.isClick = false;
  706. this.displayTooltip();
  707. this.$parent.resetSize();
  708. var diff = 0;
  709. if (this.vertical) {
  710. this.currentY = event.clientY;
  711. diff = (this.startY - this.currentY) / this.$parent.sliderSize * 100;
  712. } else {
  713. this.currentX = event.clientX;
  714. diff = (this.currentX - this.startX) / this.$parent.sliderSize * 100;
  715. }
  716. this.newPosition = this.startPosition + diff;
  717. this.setPosition(this.newPosition);
  718. }
  719. },
  720. onDragEnd: function onDragEnd() {
  721. var _this = this;
  722. if (this.dragging) {
  723. /*
  724. * 防止在 mouseup 后立即触发 click,导致滑块有几率产生一小段位移
  725. * 不使用 preventDefault 是因为 mouseup 和 click 没有注册在同一个 DOM 上
  726. */
  727. setTimeout(function () {
  728. _this.dragging = false;
  729. _this.hideTooltip();
  730. if (!_this.isClick) {
  731. _this.setPosition(_this.newPosition);
  732. _this.$parent.emitChange();
  733. }
  734. }, 0);
  735. window.removeEventListener('mousemove', this.onDragging);
  736. window.removeEventListener('mouseup', this.onDragEnd);
  737. window.removeEventListener('contextmenu', this.onDragEnd);
  738. }
  739. },
  740. setPosition: function setPosition(newPosition) {
  741. var _this2 = this;
  742. if (newPosition === null) return;
  743. if (newPosition < 0) {
  744. newPosition = 0;
  745. } else if (newPosition > 100) {
  746. newPosition = 100;
  747. }
  748. var lengthPerStep = 100 / ((this.max - this.min) / this.step);
  749. var steps = Math.round(newPosition / lengthPerStep);
  750. var value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
  751. value = parseFloat(value.toFixed(this.precision));
  752. this.$emit('input', value);
  753. this.$nextTick(function () {
  754. _this2.$refs.tooltip && _this2.$refs.tooltip.updatePopper();
  755. });
  756. if (!this.dragging && this.value !== this.oldValue) {
  757. this.oldValue = this.value;
  758. }
  759. }
  760. }
  761. }; //
  762. //
  763. //
  764. //
  765. //
  766. //
  767. //
  768. //
  769. //
  770. //
  771. //
  772. //
  773. //
  774. //
  775. //
  776. //
  777. //
  778. //
  779. //
  780. //
  781. //
  782. //
  783. //
  784. //
  785. /***/ }),
  786. /***/ 313:
  787. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  788. "use strict";
  789. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{ref:"button",staticClass:"el-slider__button-wrapper",class:{ 'hover': _vm.hovering, 'dragging': _vm.dragging },style:(_vm.wrapperStyle),attrs:{"tabindex":"0"},on:{"mouseenter":_vm.handleMouseEnter,"mouseleave":_vm.handleMouseLeave,"mousedown":_vm.onButtonDown,"focus":_vm.handleMouseEnter,"blur":_vm.handleMouseLeave,"keydown":[function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"left",37,$event.key)){ return null; }if('button' in $event && $event.button !== 0){ return null; }_vm.onLeftKeyDown($event)},function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"right",39,$event.key)){ return null; }if('button' in $event && $event.button !== 2){ return null; }_vm.onRightKeyDown($event)},function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"down",40,$event.key)){ return null; }$event.preventDefault();_vm.onLeftKeyDown($event)},function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"up",38,$event.key)){ return null; }$event.preventDefault();_vm.onRightKeyDown($event)}]}},[_c('el-tooltip',{ref:"tooltip",attrs:{"placement":"top","disabled":!_vm.showTooltip}},[_c('span',{attrs:{"slot":"content"},slot:"content"},[_vm._v(_vm._s(_vm.formatValue))]),_c('div',{staticClass:"el-slider__button",class:{ 'hover': _vm.hovering, 'dragging': _vm.dragging }})])],1)}
  790. var staticRenderFns = []
  791. var esExports = { render: render, staticRenderFns: staticRenderFns }
  792. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  793. /***/ }),
  794. /***/ 314:
  795. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  796. "use strict";
  797. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-slider",class:{ 'is-vertical': _vm.vertical, 'el-slider--with-input': _vm.showInput },attrs:{"role":"slider","aria-valuemin":_vm.min,"aria-valuemax":_vm.max,"aria-orientation":_vm.vertical ? 'vertical': 'horizontal',"aria-disabled":_vm.disabled}},[(_vm.showInput && !_vm.range)?_c('el-input-number',{ref:"input",staticClass:"el-slider__input",attrs:{"step":_vm.step,"disabled":_vm.disabled,"controls":_vm.showInputControls,"min":_vm.min,"max":_vm.max,"debounce":_vm.debounce,"size":"small"},on:{"change":function($event){_vm.$nextTick(_vm.emitChange)}},model:{value:(_vm.firstValue),callback:function ($$v) {_vm.firstValue=$$v},expression:"firstValue"}}):_vm._e(),_c('div',{ref:"slider",staticClass:"el-slider__runway",class:{ 'show-input': _vm.showInput, 'disabled': _vm.disabled },style:(_vm.runwayStyle),on:{"click":_vm.onSliderClick}},[_c('div',{staticClass:"el-slider__bar",style:(_vm.barStyle)}),_c('slider-button',{ref:"button1",attrs:{"vertical":_vm.vertical},model:{value:(_vm.firstValue),callback:function ($$v) {_vm.firstValue=$$v},expression:"firstValue"}}),(_vm.range)?_c('slider-button',{ref:"button2",attrs:{"vertical":_vm.vertical},model:{value:(_vm.secondValue),callback:function ($$v) {_vm.secondValue=$$v},expression:"secondValue"}}):_vm._e(),_vm._l((_vm.stops),function(item){return (_vm.showStops)?_c('div',{staticClass:"el-slider__stop",style:(_vm.vertical ? { 'bottom': item + '%' } : { 'left': item + '%' })}):_vm._e()})],2)],1)}
  798. var staticRenderFns = []
  799. var esExports = { render: render, staticRenderFns: staticRenderFns }
  800. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  801. /***/ })
  802. /******/ });