ten-design-vue
Version:
ten-vue
631 lines (573 loc) • 20.4 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = require("../tooltip");
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./src/components/slider/slider.vue?vue&type=template&id=65397afa&
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{ref:"sliderDom",class:_vm._class,on:{"click":function($event){$event.stopPropagation();return _vm.onClick.apply(null, arguments)}}},[_c('div',{class:_vm._bgClass}),_c('div',{class:_vm._containerClass},[(_vm.range)?_c('div',{class:_vm._leftBarClass,style:({'width': _vm.barLeftWidth + '%'}),on:{"mousedown":function($event){$event.stopPropagation();return _vm.onMouseDown(1, $event)}}},[_c('ten-tool-tip',{attrs:{"message":_vm.leftToolTipMsg.toString(),"show":_vm.showToolTip === true ? _vm.showToolTip : _vm.leftTooltipShow,"trigger-type":"manual","dark":""}},[_c('div',{class:_vm._leftIndicator,on:{"mouseenter":function($event){return _vm.onMouseEnter(1)},"mouseleave":_vm.onMouseLeave}})])],1):_vm._e(),_c('div',{class:_vm._rightBarClass,style:({'width': _vm.barRightWidth + '%'}),on:{"mousedown":function($event){$event.stopPropagation();return _vm.onMouseDown(2, $event)}}},[_c('ten-tool-tip',{attrs:{"message":_vm.rightToolTipMsg.toString(),"show":_vm.showToolTip === true ? _vm.showToolTip : _vm.rightTooltipShow,"trigger-type":"manual","dark":""}},[_c('div',{class:_vm._rightIndicator,on:{"mouseenter":function($event){return _vm.onMouseEnter(2)},"mouseleave":_vm.onMouseLeave}})])],1),_c('div',{class:_vm._markClass},[(_vm.marks)?_vm._l((_vm.marks),function(item,i){return _c('span',{key:i,staticClass:"ten-slider__mark_i",class:{
'ten-slider__mark_i--focus':
(_vm.marksDistance * i) >= _vm.barLeftWidth && (_vm.marksDistance * i) <= (100 - _vm.barRightWidth)
},style:({ left: (_vm.marksDistance * i) + '%' })},[_vm._v(_vm._s(item))])}):_vm._e()],2)])])}
var staticRenderFns = []
// CONCATENATED MODULE: ./src/components/slider/slider.vue?vue&type=template&id=65397afa&
// EXTERNAL MODULE: external "../tooltip"
var external_tooltip_ = __webpack_require__(0);
var external_tooltip_default = /*#__PURE__*/__webpack_require__.n(external_tooltip_);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--1!./node_modules/vue-loader/lib??vue-loader-options!./src/components/slider/slider.vue?vue&type=script&lang=js&
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var slidervue_type_script_lang_js_name = 'ten-slider';
/* harmony default export */ var slidervue_type_script_lang_js_ = ({
name: slidervue_type_script_lang_js_name,
components: {
TenToolTip: external_tooltip_default.a
},
props: {
/**
* 滑块是否禁用
*/
disabled: {
type: Boolean,
default: false
},
/**
* 步长 , 必须大于 0
*/
step: {
type: Number,
default: 1
},
/**
* 双滑块模式
*/
range: {
type: Boolean,
default: false
},
/**
* 刻度标记
*/
marks: Array,
/**
* 初始值, 当 range 为 false 时,defaultValue 默认为 0 ;当 range 为 true 时,defaultValue 默认为 [0, 100]
*/
defaultValue: {
type: [Number, Array],
default: function _default() {
var returnVal = this.range ? [0, 100] : 0;
return returnVal;
}
},
/**
* 设置当前取值。当 range 为 false 时,使用 number,否则用 [number, number]
*/
isValue: [Number, Array],
/**
* 是否始终显示 ToolTip , 当值为 true 时 , ToolTip 始终显示, 当值为 false 时 , ToolTip 始终隐藏
*/
showToolTip: Boolean,
/**
* 自定义 ToolTip 内容 , renderTip , 当 renderTip 为 null 时则隐藏 ToolTip
*/
renderTip: Function,
/**
* 当 Slider 发生改变时,触发 onChange 事件,并返回 Slider 当前值,当 range 为 true 是,返回值为 [number, number]
*/
onChange: Function
},
data: function data() {
return {
sliderDomWidth: 0,
// 最外层宽度
sliderDomLeft: 0,
// 最外层左距离
calculated: 0,
// 鼠标点击与元素的距离
barLeftWidth: 0,
barRightWidth: 100,
canMoveLeft: false,
canMoveRight: false,
effectiveLeave: true,
leftTooltipShow: false,
rightTooltipShow: false,
marksDistance: 0,
clickChange: true,
leftToolTipMsg: 0,
rightToolTipMsg: 0
};
},
computed: {
_class: function _class() {
return ["".concat(slidervue_type_script_lang_js_name), _defineProperty({}, "".concat(slidervue_type_script_lang_js_name, "--disabled"), this.disabled)];
},
_bgClass: function _bgClass() {
return ["".concat(slidervue_type_script_lang_js_name, "__background")];
},
_containerClass: function _containerClass() {
return ["".concat(slidervue_type_script_lang_js_name, "__container")];
},
_markClass: function _markClass() {
return ["".concat(slidervue_type_script_lang_js_name, "__mark")];
},
_leftBarClass: function _leftBarClass() {
return ["".concat(slidervue_type_script_lang_js_name, "__bar"), "".concat(slidervue_type_script_lang_js_name, "__leftbar")];
},
_rightBarClass: function _rightBarClass() {
return ["".concat(slidervue_type_script_lang_js_name, "__bar"), "".concat(slidervue_type_script_lang_js_name, "__rightbar")];
},
_leftIndicator: function _leftIndicator() {
return ["".concat(slidervue_type_script_lang_js_name, "__indicator"), "".concat(slidervue_type_script_lang_js_name, "__leftindicator"), _defineProperty({}, "".concat(slidervue_type_script_lang_js_name, "__indicator--toplevel"), this.showToolTip || this.leftTooltipShow)];
},
_rightIndicator: function _rightIndicator() {
return ["".concat(slidervue_type_script_lang_js_name, "__indicator"), "".concat(slidervue_type_script_lang_js_name, "__rightindicator"), _defineProperty({}, "".concat(slidervue_type_script_lang_js_name, "__indicator--toplevel"), this.showToolTip || this.rightTooltipShow)];
}
},
watch: {
isValue: function isValue() {
this.setBarWidth(this.isValue);
},
barLeftWidth: function barLeftWidth() {
this.barWidthChange();
},
barRightWidth: function barRightWidth() {
this.barWidthChange();
}
},
mounted: function mounted() {
var _this = this;
if (this.marks) {
this.marksDistance = 100 / (this.marks.length - 1);
}
setTimeout(function () {
_this.sliderDomLeft = _this.$refs.sliderDom.getBoundingClientRect().left;
_this.sliderDomWidth = _this.$refs.sliderDom.offsetWidth;
}, 200);
this.isValue && this.isValue.length > 0 ? this.setBarWidth(this.isValue) : this.setBarWidth(this.defaultValue);
window.addEventListener('resize', this.onResize, false);
},
beforeDestroy: function beforeDestroy() {
window.removeEventListener('mousemove', this.onMouseMove);
window.removeEventListener('mouseup', this.onMouseUp);
window.removeEventListener('resize', this.onResize);
},
methods: {
onClick: function onClick(e) {
if (!this.disabled) {
this.calculated = (e.clientX - this.sliderDomLeft) / this.sliderDomWidth * 100;
var moveDistance;
if (this.calculated < 0) {
moveDistance = 0;
} else if (this.calculated > 100) {
moveDistance = 100;
} else {
moveDistance = this.getStep(this.calculated);
}
;
var leftDistance = this.calculated - this.barLeftWidth;
var rightDistance = 100 - this.barRightWidth - this.calculated;
if (this.range) {
if (leftDistance <= 0 || rightDistance > leftDistance) {
this.barLeftWidth = moveDistance;
} else {
this.barRightWidth = 100 - moveDistance;
}
} else {
this.barRightWidth = 100 - moveDistance;
}
this.clickChange && this.onHandleChange();
}
},
onMouseDown: function onMouseDown(value) {
if (!this.disabled) {
this.effectiveLeave = false;
if (value === 1) {
this.canMoveLeft = true;
this.leftTooltipShow = true;
} else {
this.canMoveRight = true;
this.rightTooltipShow = true;
}
;
if (Math.round(100 - this.barRightWidth) - Math.round(this.barLeftWidth) === 0) {
this.canMoveLeft = true;
this.canMoveRight = true;
}
;
this.clickChange = false;
window.addEventListener('mousemove', this.onMouseMove, false);
window.addEventListener('mouseup', this.onMouseUp, false);
}
;
},
onMouseMove: function onMouseMove(e) {
this.calculated = (e.clientX - this.sliderDomLeft) / this.sliderDomWidth * 100;
var moveDistance;
if (this.calculated < 0) {
moveDistance = 0;
} else if (this.calculated > 100) {
moveDistance = 100;
} else {
moveDistance = this.getStep(this.calculated);
}
; // 判断移动哪个点
if (this.canMoveLeft) {
if (moveDistance >= 100 - this.barRightWidth) {
this.canMoveLeft = false;
this.canMoveRight = true;
this.leftTooltipShow = true;
this.rightTooltipShow = false;
this.barLeftWidth = 100 - this.barRightWidth;
} else {
this.barLeftWidth = moveDistance;
}
}
if (this.canMoveRight) {
if (moveDistance <= this.barLeftWidth) {
this.canMoveLeft = true;
this.canMoveRight = false;
this.leftTooltipShow = false;
this.rightTooltipShow = true;
this.barRightWidth = 100 - this.barLeftWidth;
} else {
this.barRightWidth = 100 - moveDistance;
}
}
},
onMouseUp: function onMouseUp() {
this.canMoveLeft = false;
this.canMoveRight = false;
this.leftTooltipShow = false;
this.rightTooltipShow = false;
this.effectiveLeave = true;
window.removeEventListener('mousemove', this.onMouseMove);
window.removeEventListener('mouseup', this.onMouseUp);
!this.clickChange && this.onHandleChange();
},
onHandleChange: function onHandleChange() {
var _this2 = this;
this.$nextTick(function () {
var returnVal = _this2.range ? [Math.round(_this2.barLeftWidth), Math.round(100 - _this2.barRightWidth)] : Math.round(100 - _this2.barRightWidth);
_this2.$emit('onChange', returnVal);
!_this2.clickChange && setTimeout(function () {
_this2.clickChange = true;
}, 100);
});
},
onMouseEnter: function onMouseEnter(val) {
val === 1 ? this.leftTooltipShow = true : this.rightTooltipShow = true;
},
onMouseLeave: function onMouseLeave() {
if (this.effectiveLeave) {
this.leftTooltipShow = false;
this.rightTooltipShow = false;
}
},
onResize: function onResize() {
this.sliderDomWidth = this.$refs.sliderDom.offsetWidth;
this.sliderDomLeft = this.$refs.sliderDom.getBoundingClientRect().left;
},
setBarWidth: function setBarWidth(_val) {
var val = _val;
var stepNum = this.step <= 0 ? 1 : this.step;
var newDefaultValue;
var multiple1;
var multiple2;
if (this.range) {
if (Array.isArray(val)) {
val.length = 2;
multiple1 = Math.round(Math.min.apply(null, val) / stepNum);
multiple2 = Math.round(Math.max.apply(null, val) / stepNum);
newDefaultValue = [stepNum * multiple1, stepNum * multiple2];
} else {
newDefaultValue = [0, 100];
}
this.barLeftWidth = newDefaultValue[0]; // eslint-disable-line
this.barRightWidth = 100 - newDefaultValue[1];
} else {
if (Array.isArray(val)) {
multiple1 = Math.round(val[0] / stepNum);
} else {
multiple1 = Math.round(val / stepNum);
}
newDefaultValue = stepNum * multiple1;
this.barRightWidth = 100 - newDefaultValue;
}
},
getStep: function getStep(num) {
var stepNum = this.step <= 0 ? 1 : this.step;
if (this.step === 1) return num;
var multiple = Math.round(num / stepNum);
return multiple * stepNum;
},
barWidthChange: function barWidthChange() {
if (this.renderTip) {
this.leftToolTipMsg = this.renderTip(Math.round(this.barLeftWidth));
this.rightToolTipMsg = this.renderTip(Math.round(100 - this.barRightWidth));
} else {
this.leftToolTipMsg = Math.round(this.barLeftWidth);
this.rightToolTipMsg = Math.round(100 - this.barRightWidth);
}
}
}
});
// CONCATENATED MODULE: ./src/components/slider/slider.vue?vue&type=script&lang=js&
/* harmony default export */ var slider_slidervue_type_script_lang_js_ = (slidervue_type_script_lang_js_);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent (
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier, /* server only */
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () {
injectStyles.call(
this,
(options.functional ? this.parent : this).$root.$options.shadowRoot
)
}
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functional component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
// CONCATENATED MODULE: ./src/components/slider/slider.vue
/* normalize component */
var component = normalizeComponent(
slider_slidervue_type_script_lang_js_,
render,
staticRenderFns,
false,
null,
null,
null
)
/* harmony default export */ var slider = __webpack_exports__["default"] = (component.exports);
/***/ })
/******/ ]);