UNPKG

wot-design

Version:

Mobile UI components built on vue.js

720 lines (655 loc) 21.2 kB
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 = 96); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; }); /* 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, 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 functioal 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 } } /***/ }), /***/ 14: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(vue__WEBPACK_IMPORTED_MODULE_0__); var MIN_DISTANCE = 5; function getDirection(offsetX, offsetY) { if (offsetX > MIN_DISTANCE || offsetY > MIN_DISTANCE) { return offsetX > offsetY ? 'horizontal' : 'vertical'; } return ''; } /* harmony default export */ __webpack_exports__["a"] = (vue__WEBPACK_IMPORTED_MODULE_0___default.a.extend({ data: function data() { return { direction: '', accurateDirection: '' // 详细方向 }; }, methods: { touchStart: function touchStart(event) { this.resetTouchStatus(); this.startX = event.touches[0].clientX; this.startY = event.touches[0].clientY; }, touchMove: function touchMove(event) { var touch = event.touches[0]; this.deltaX = touch.clientX - this.startX; this.deltaY = touch.clientY - this.startY; this.offsetX = Math.abs(this.deltaX); this.offsetY = Math.abs(this.deltaY); this.direction = this.direction || getDirection(this.offsetX, this.offsetY); if (this.direction === 'horizontal') { this.accurateDirection = this.deltaX > 0 ? 'right' : 'left'; } else if (this.direction === 'vertical') { this.accurateDirection = this.deltaY > 0 ? 'down' : 'up'; } }, resetTouchStatus: function resetTouchStatus() { this.direction = ''; this.accurateDirection = ''; this.deltaX = 0; this.deltaY = 0; this.offsetX = 0; this.offsetY = 0; } } })); /***/ }), /***/ 2: /***/ (function(module, exports) { module.exports = require("vue"); /***/ }), /***/ 96: /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __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!./packages/slider/src/main.vue?vue&type=template&id=32708644& var render = function() { var _vm = this var _h = _vm.$createElement var _c = _vm._self._c || _h return _c( "div", { ref: "track", class: { "wd-slider": true, "wd-slider__has-label": !_vm.hideLabel, "wd-slider--disabled": _vm.disabled } }, [ !_vm.hideMinMax ? _c("div", { staticClass: "wd-slider__label-min" }, [ _vm._v("\n " + _vm._s(_vm.min) + "\n ") ]) : _vm._e(), _vm._v(" "), _c( "div", { class: { "wd-slider__bar-wrapper": true }, style: { background: _vm.inactiveColor ? _vm.inactiveColor : "" } }, [ _c("div", { staticClass: "wd-slider__bar", style: { background: _vm.activeColor ? _vm.activeColor : "", width: _vm.barWidth + "%", left: _vm.barLeft + "%" } }), _vm._v(" "), _c( "div", { staticClass: "wd-slider__button-wrapper", style: { left: _vm.leftBarPercent + "%", visibility: !_vm.disabled ? "show" : "hidden" }, on: { touchstart: function($event) { return _vm.onTouchStart(true) }, touchmove: function($event) { return _vm.onTouchMove(true) }, touchend: _vm.onTouchEnd } }, [ !_vm.hideLabel ? _c("div", { staticClass: "wd-slider__label" }, [ _vm._v(_vm._s(_vm.leftNewValue)) ]) : _vm._e(), _vm._v(" "), _c("div", { staticClass: "wd-slider__button" }) ] ), _vm._v(" "), _vm.showRight ? _c( "div", { staticClass: "wd-slider__button-wrapper", style: { left: _vm.rightBarPercent + "%", visibility: !_vm.disabled ? "show" : "hidden" }, on: { touchstart: function($event) { return _vm.onTouchStart(false) }, touchmove: function($event) { return _vm.onTouchMove(false) }, touchend: _vm.onTouchEnd } }, [ !_vm.hideLabel ? _c("div", { staticClass: "wd-slider__label" }, [ _vm._v(_vm._s(_vm.rightNewValue)) ]) : _vm._e(), _vm._v(" "), _c("div", { staticClass: "wd-slider__button" }) ] ) : _vm._e() ] ), _vm._v(" "), !_vm.hideMinMax ? _c("div", { staticClass: "wd-slider__label-max" }, [ _vm._v(_vm._s(_vm.max)) ]) : _vm._e() ] ) } var staticRenderFns = [] render._withStripped = true // CONCATENATED MODULE: ./packages/slider/src/main.vue?vue&type=template&id=32708644& // EXTERNAL MODULE: ./src/mixins/touch.js var touch = __webpack_require__(14); // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/slider/src/main.vue?vue&type=script&lang=js& // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // /* harmony default export */ var mainvue_type_script_lang_js_ = ({ name: 'WdSlider', mixins: [touch["a" /* default */]], props: { hideMinMax: Boolean, hideLabel: Boolean, disabled: { type: Boolean, default: false }, max: { type: Number, default: 100 }, min: { type: Number, default: 0 }, value: { type: [Number, Array], default: 0 }, step: { type: Number, default: 1 }, inactiveColor: { type: String, default: '#e5e5e5' }, activeColor: { type: String, default: '' } }, data: function data() { return { showRight: false, barWidth: '', barLeft: '', barHeight: '6px', leftNewValue: 0, rightNewValue: 0, // 右边滑轮距离右端点的百分比距离 rightBarPercent: 0, // 左边滑轮距离左顶点的百分比距离 leftBarPercent: 0 }; }, watch: { value: function value(newValue, oldValue) { this.updateValue(newValue, oldValue); } }, created: function created() { this.updateValue(); }, mounted: function mounted() { var _this = this; // 获取轨道长度 this.trackWidth = this.$refs.track && this.$refs.track.clientWidth; window.onresize = function () { _this.trackWidth = _this.$refs.track && _this.$refs.track.clientWidth; }; }, methods: { onTouchStart: function onTouchStart(left) { if (this.disabled) return; this.touchStart(window.event); if (left) { // 是左边滑轮 this.startValue = this.checkType(this.currentValue) !== 'Array' ? this.format(this.currentValue) : this.leftBarPercent < this.rightBarPercent ? this.format(this.currentValue[0]) : this.format(this.currentValue[1]); } else { // 记录开始数据值 this.startValue = this.leftBarPercent < this.rightBarPercent ? this.format(this.currentValue[1]) : this.format(this.currentValue[0]); } this.$emit('dragstart', this.currentValue); }, /** * 确定移动的是哪一个滑轮 * @param {Boolean} left true:左 false:右 */ onTouchMove: function onTouchMove(left) { if (this.disabled) return; var max = this.max, min = this.min; this.touchMove(window.event); // 禁止页面滚动 if (this.direction) { window.event.preventDefault(); } var diff = this.deltaX / this.trackWidth * (max - min); this.newValue = this.startValue + diff; if (left) { this.leftBarSlider(this.newValue); } else { this.rightBarSlider(this.newValue); } this.$emit('dragmove', this.currentValue); this.$emit('input', this.currentValue); }, onTouchEnd: function onTouchEnd() { if (this.disabled) return; this.$emit('dragend', this.currentValue); this.$emit('change', this.currentValue); }, /** * 控制右侧滑轮滑动, value校验 * @param {Number} value 当前滑轮绑定值 */ rightBarSlider: function rightBarSlider(value) { var min = this.min, max = this.max; var rightBarPercent = (value - min) / (max - min) * 100; this.rightNewValue = this.format(value); this.rightBarPercent = this.format(rightBarPercent); this.styleControl(); }, /** * 控制左滑轮滑动,更新渲染数据,对 value 进行校验取整 * @param {Number} value 当前滑轮绑定值 */ leftBarSlider: function leftBarSlider(value) { var min = this.min, max = this.max, showRight = this.showRight; value = this.format(value); // 把 value 转换成百分比 var percent = (value - min) / (max - min) * 100; this.leftNewValue = value; this.leftBarPercent = percent; if (!showRight) { this.currentValue = value; this.barWidth = percent; } else { this.styleControl(); } }, // 样式控制 styleControl: function styleControl() { var leftNewValue = this.leftNewValue, rightNewValue = this.rightNewValue; var leftBarPercent = this.leftBarPercent, rightBarPercent = this.rightBarPercent; // 左右滑轮距离左边最短为当前激活条所处位置 var barLeft = leftBarPercent < rightBarPercent ? [leftBarPercent, rightBarPercent] : [rightBarPercent, leftBarPercent]; this.barWidth = barLeft[1] - barLeft[0]; this.barLeft = barLeft[0]; // 更新当前绑定值 this.currentValue = leftNewValue < rightNewValue ? [leftNewValue, rightNewValue] : [rightNewValue, leftNewValue]; }, updateValue: function updateValue(newValue, oldValue) { var condition = newValue && oldValue && (this.checkType(newValue) === 'Array' ? !this.equal(newValue, oldValue) : newValue === oldValue); if (condition) return; if (newValue && oldValue) { // 类型校验,支持所有值(除null、undefined。undefined建议统一写成void (0)防止全局undefined被覆盖) if (newValue === null || newValue === undefined) { throw Error('value can\'t be null or undefined'); } else if (this.checkType(newValue) === 'Array' && newValue.length !== 2) { throw Error('value must be dyadic array'); } else if (this.checkType(newValue) !== 'Number' && this.checkType(newValue) !== 'Array') { throw Error('value must be dyadic array Or Number'); } } // 动态传值后修改 if (this.checkType(this.value) === 'Array') { this.showRight = true; this.currentValue = this.value; if (this.leftBarPercent < this.rightBarPercent) { this.leftBarSlider(this.value[0]); this.rightBarSlider(this.value[1]); } else { this.leftBarSlider(this.value[1]); this.rightBarSlider(this.value[0]); } } else { this.leftBarSlider(this.value); } }, // 将pos转化为value pos2Value: function pos2Value(pos) { var max = this.max, min = this.min, step = this.step; var percent = pos / this.trackWidth; var value = percent * (max - min) + min; var res = min + Math.floor((value - min) / step) * step; return res; }, checkType: function checkType(value) { return Object.prototype.toString.call(value).slice(8, -1); }, equal: function equal(arr1, arr2) { var i = 0; arr1.forEach(function (item, index) { item === arr2[index] && i++; }); return i === 2; }, format: function format(value) { var max = this.max, min = this.min, step = this.step; return Math.round(Math.max(min, Math.min(value, max)) / step) * step; } } }); // CONCATENATED MODULE: ./packages/slider/src/main.vue?vue&type=script&lang=js& /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_); // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js var componentNormalizer = __webpack_require__(0); // CONCATENATED MODULE: ./packages/slider/src/main.vue /* normalize component */ var component = Object(componentNormalizer["a" /* default */])( src_mainvue_type_script_lang_js_, render, staticRenderFns, false, null, null, null ) /* hot reload */ if (false) { var api; } component.options.__file = "packages/slider/src/main.vue" /* harmony default export */ var main = (component.exports); // CONCATENATED MODULE: ./packages/slider/index.js /** * slider组件 * 使用: * <wd-slider * 属性: * type // 类型,可选值"single","double",默认值为"single" * :value // 初始值,类型是Array,默认值是[0, 0] * :min-value // 最小值,类型是Number,默认值为0 * :max-value // 最大值,类型是Number,默认值为100 * :step // 步长,类型是Number,默认值为1 * :disabled // 是否禁用,类型是Boolean,默认值为false * :show-label // 是否展示当前值,类型是Boolean,默认值为true * :show-min-max // 是否展示最大值最小值,类型是Boolean,默认值为true * 事件: * @slidingstart // 滑动开始事件 * @sliding // 滑动中事件 * @slidingend // 滑动结束事件 * @change // 值改变事件 * @input // 操作滑块事件 * ></wd-slider> */ main.install = function (Vue) { Vue.component(main.name, main); }; /* harmony default export */ var slider = __webpack_exports__["default"] = (main); /***/ }) /******/ });