slider.js 29 KB

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