wot-design
Version:
Mobile UI components built on vue.js
1,035 lines (941 loc) • 29.8 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 = 69);
/******/ })
/************************************************************************/
/******/ ({
/***/ 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
}
}
/***/ }),
/***/ 17:
/***/ (function(module, exports) {
module.exports = require("wot-design/lib/action-sheet");
/***/ }),
/***/ 19:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony default export */ __webpack_exports__["a"] = (function ($el, to, duration) {
var count = 0;
var from = $el.scrollLeft;
var frames = duration === 0 ? 1 : Math.round(duration / 16);
function animate() {
$el.scrollLeft += (to - from) / frames;
if (++count < frames) {
requestAnimationFrame(animate);
}
}
animate();
});
/***/ }),
/***/ 4:
/***/ (function(module, exports) {
module.exports = require("wot-design/lib/mixins/locale");
/***/ }),
/***/ 5:
/***/ (function(module, exports) {
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;
}
module.exports = _defineProperty;
/***/ }),
/***/ 69:
/***/ (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/col-picker/src/main.vue?vue&type=template&id=5aac96f8&
var render = function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c(
"div",
{ staticClass: "wd-col-picker" },
[
_c(
"div",
{ staticClass: "wd-col-picker__field", on: { click: _vm.showPicker } },
[
_vm._t("default", [
_c(
"div",
{
staticClass: "wd-col-picker__cell",
class: [
{
"is-disabled": _vm.disabled,
"is-readonly": _vm.readonly,
"is-align-right": _vm.alignRight,
"is-error": _vm.error
},
_vm.size ? "is-" + _vm.size : ""
]
},
[
_vm.label || _vm.$slots.label
? _c(
"div",
{
staticClass: "wd-col-picker__label",
class: {
"is-required": _vm.required
},
style: _vm.labelWidth
? "min-width: " +
_vm.labelWidth +
"; max-width: " +
_vm.labelWidth
: ""
},
[
_vm._t("label", [
_vm._v(
"\n " +
_vm._s(_vm.label) +
"\n "
)
])
],
2
)
: _vm._e(),
_vm._v(" "),
_c(
"div",
{
staticClass: "wd-col-picker__value",
class: {
"wd-col-picker__value--placeholder":
!_vm.value ||
(_vm.value instanceof Array && !_vm.value.length),
"is-ellipsis": _vm.ellipsis
}
},
[
_vm._v(
_vm._s(
(!_vm.value ||
(_vm.value instanceof Array && !_vm.value.length)
? _vm.placeholder
: _vm.showValue) || _vm.t("wd.colPicker.placeholder")
)
)
]
),
_vm._v(" "),
!_vm.disabled && !_vm.readonly
? _c("i", {
staticClass: "wd-col-picker__arrow wd-icon-arrow-right"
})
: _vm._e()
]
)
])
],
2
),
_vm._v(" "),
_c(
"wd-action-sheet",
{
attrs: {
duration: 250,
title: _vm.title || _vm.t("wd.colPicker.title"),
"close-on-click-modal": _vm.closeOnClickModal,
"close-on-popstate": _vm.closeOnPopstate,
"safe-area-inset-bottom": _vm.safeAreaInsetBottom
},
on: { close: _vm.handlePickerClose },
model: {
value: _vm.pickerShow,
callback: function($$v) {
_vm.pickerShow = $$v
},
expression: "pickerShow"
}
},
[
_c(
"div",
{ ref: "selectedVisible", staticClass: "wd-col-picker__selected" },
[
_c(
"div",
{
ref: "selectedContainer",
staticClass: "wd-col-picker__selected-container"
},
[
_vm._l(_vm.selectList, function(item, colIndex) {
return _c(
"div",
{
key: colIndex,
ref: "selecteds",
refInFor: true,
staticClass: "wd-col-picker__selected-item",
class: {
"is-selected": colIndex === _vm.currentCol
},
on: {
click: function($event) {
return _vm.handleColClick(colIndex)
}
}
},
[
_vm._v(
"\n " +
_vm._s(
(_vm.pickerColSelected[colIndex] &&
_vm.getSelectedItem(
_vm.pickerColSelected[colIndex],
colIndex
)[_vm.labelKey]) ||
_vm.t("wd.colPicker.select")
) +
"\n "
)
]
)
}),
_vm._v(" "),
_c("i", {
staticClass: "wd-col-picker__selected-line",
style: _vm.lineStyle
})
],
2
)
]
),
_vm._v(" "),
_c(
"div",
{ staticClass: "wd-col-picker__list-container" },
[
_vm._l(_vm.selectList, function(col, colIndex) {
return [
_c(
"div",
{
directives: [
{
name: "show",
rawName: "v-show",
value: colIndex === _vm.currentCol,
expression: "colIndex === currentCol"
}
],
key: colIndex,
staticClass: "wd-col-picker__list"
},
_vm._l(col, function(item, index) {
return _c(
"div",
{
key: index,
staticClass: "wd-col-picker__list-item",
class: {
"is-selected":
_vm.pickerColSelected[colIndex] &&
item[_vm.valueKey] ===
_vm.pickerColSelected[colIndex],
"is-disabled": item.disabled
},
on: {
click: function($event) {
return _vm.chooseItem(colIndex, item, index)
}
}
},
[
_c("div", [
_c(
"div",
{ staticClass: "wd-col-picker__list-item-label" },
[_vm._v(_vm._s(item[_vm.labelKey]))]
),
_vm._v(" "),
item[_vm.tipKey]
? _c(
"div",
{
staticClass: "wd-col-picker__list-item-tip"
},
[_vm._v(_vm._s(item[_vm.tipKey]))]
)
: _vm._e()
]),
_vm._v(" "),
_c("i", {
staticClass: "wd-col-picker__checked wd-icon-check"
})
]
)
}),
0
)
]
}),
_vm._v(" "),
_vm.loading
? _c(
"div",
{ staticClass: "wd-col-picker__loading" },
[_c("wd-loading", { attrs: { color: _vm.loadingColor } })],
1
)
: _vm._e()
],
2
)
]
)
],
1
)
}
var staticRenderFns = []
render._withStripped = true
// CONCATENATED MODULE: ./packages/col-picker/src/main.vue?vue&type=template&id=5aac96f8&
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/defineProperty.js
var defineProperty = __webpack_require__(5);
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty);
// EXTERNAL MODULE: external "wot-design/lib/mixins/locale"
var locale_ = __webpack_require__(4);
var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
// EXTERNAL MODULE: external "wot-design/lib/action-sheet"
var action_sheet_ = __webpack_require__(17);
var action_sheet_default = /*#__PURE__*/__webpack_require__.n(action_sheet_);
// EXTERNAL MODULE: external "wot-design/lib/loading"
var loading_ = __webpack_require__(8);
var loading_default = /*#__PURE__*/__webpack_require__.n(loading_);
// EXTERNAL MODULE: ./src/utils/animateScrollLeft.js
var animateScrollLeft = __webpack_require__(19);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/col-picker/src/main.vue?vue&type=script&lang=js&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
/* harmony default export */ var mainvue_type_script_lang_js_ = ({
name: 'WdColPicker',
mixins: [locale_default.a],
components: {
WdActionSheet: action_sheet_default.a,
WdLoading: loading_default.a
},
data: function data() {
return {
pickerShow: false,
currentCol: 0,
selectList: [],
pickerColSelected: [],
loading: false,
showValue: '',
isChange: false,
lastSelectList: [],
lastPickerColSelected: [],
lineStyle: {},
isCompleting: false // 是否在自动补全,锁操作
};
},
props: {
value: {
type: Array,
default: function _default() {
return [];
}
},
columns: {
type: Array,
required: true
},
label: String,
labelWidth: String,
disabled: Boolean,
readonly: Boolean,
placeholder: String,
title: String,
columnChange: {
type: Function,
required: true
},
displayFormat: Function,
beforeConfirm: Function,
alignRight: Boolean,
error: Boolean,
required: Boolean,
size: String,
valueKey: {
type: String,
default: 'value'
},
labelKey: {
type: String,
default: 'label'
},
tipKey: {
type: String,
default: 'tip'
},
loadingColor: String,
closeOnClickModal: {
type: Boolean,
default: true
},
autoComplete: Boolean,
closeOnPopstate: {
type: Boolean,
default: true
},
safeAreaInsetBottom: {
type: Boolean,
default: true
},
ellipsis: Boolean
},
watch: {
value: {
handler: function handler(val) {
var _this = this;
this.checkValueData();
this.pickerColSelected = val;
this.setShowValue();
if (this.autoComplete) {
this.$nextTick(function () {
// 如果 columns 数组长度为空,或者长度小于 value 的长度,自动触发 columnChange 来补齐数据
if (_this.selectList.length < _this.value.length || _this.selectList.length === 0) {
if (!_this.isCompleting) {
// 如果 columns 长度为空,则传入的 colIndex 为 -1
var colIndex = _this.selectList.length === 0 ? -1 : _this.selectList.length - 1;
_this.diffColumns(colIndex);
}
_this.isCompleting = true;
}
});
}
},
immediate: true
},
columns: {
handler: function handler(val, oldVal) {
var _this2 = this;
if (val.length && !(val[0] instanceof Array)) {
console.error('[wot design] error(wd-col-picker): the columns props of wd-col-picker should be a two-dimensional array');
return;
}
if (val.length === 0 && !oldVal) return;
this.selectList = val.slice(0);
if (this.selectList.length > 0) {
this.currentCol = this.selectList.length - 1;
this.setShowValue();
}
this.$nextTick(function () {
_this2.setLineStyle(false);
_this2.lineScrollIntoView(false);
});
},
immediate: true
},
currentCol: function currentCol() {
this.setLineStyle();
this.lineScrollIntoView();
}
},
methods: {
// 对外暴露接口,打开弹框
open: function open() {
this.showPicker();
},
// 对外暴露接口,关闭弹框
close: function close() {
this.pickerShow = false;
this.handlePickerClose();
},
// 检测 selectList 中是否匹配 value,不匹配则重置 selectList
checkValueData: function checkValueData() {
var _this3 = this;
var valueMatchData = this.value.every(function (val, index) {
if (_this3.selectList[index]) {
var isMatch = _this3.selectList[index].some(function (item) {
if (item[_this3.valueKey] === val) {
return true;
}
});
return isMatch;
}
return false;
});
if (!valueMatchData) {
this.selectList = this.columns.slice(0);
this.isCompleting = false;
}
},
handlePickerClose: function handlePickerClose() {
// 未确定选项时,数据还原复位
if (this.isChange) {
this.selectList = this.lastSelectList.slice(0);
this.pickerColSelected = this.lastPickerColSelected.slice(0);
this.currentCol = this.lastSelectList.length - 1;
this.isChange = false;
}
this.$emit('cancel');
},
showPicker: function showPicker() {
if (this.disabled || this.readonly) return;
this.lastSelectList = this.selectList.slice(0);
this.lastPickerColSelected = this.pickerColSelected.slice(0);
this.pickerShow = true;
this.setLineStyle(false);
this.lineScrollIntoView(false);
},
getSelectedItem: function getSelectedItem(value, colIndex) {
var _this4 = this,
_ref;
if (this.selectList[colIndex]) {
var selecteds = this.selectList[colIndex].filter(function (item) {
return item[_this4.valueKey] === value;
});
if (selecteds.length > 0) {
return selecteds[0];
}
}
return _ref = {}, defineProperty_default()(_ref, this.valueKey, value), defineProperty_default()(_ref, this.labelKey, ''), _ref;
},
chooseItem: function chooseItem(colIndex, item, index) {
if (item.disabled) return;
this.isChange = true;
this.pickerColSelected = this.pickerColSelected.slice(0, colIndex);
this.$set(this.pickerColSelected, colIndex, item[this.valueKey]);
this.setLineStyle();
this.lineScrollIntoView();
this.selectList = this.selectList.slice(0, colIndex + 1);
this.handleColChange(colIndex, item, index);
},
// 触发 columnChange,如果有 callback 回调,则为递归补齐 columns 数据,需要避免触发 confirm 事件
handleColChange: function handleColChange(colIndex, item, index, callback) {
var _this5 = this;
this.loading = true;
this.columnChange({
selectedItem: item,
index: colIndex,
rowIndex: index,
resolve: function resolve(nextColumn) {
if (!(nextColumn instanceof Array)) {
console.error('[wot design] error(wd-col-picker): the data of each column of wd-col-picker should be an array');
return;
}
_this5.$set(_this5.selectList, colIndex + 1, nextColumn);
_this5.loading = false;
_this5.currentCol = colIndex + 1;
if (typeof callback === 'function') {
_this5.isCompleting = false;
callback();
}
},
finish: function finish(isOk) {
if (typeof callback === 'function') {
_this5.isCompleting = false;
_this5.loading = false;
return;
}
if (typeof isOk === 'boolean' && !isOk) {
_this5.loading = false;
return;
}
if (_this5.beforeConfirm) {
_this5.beforeConfirm(_this5.pickerColSelected, _this5.pickerColSelected.map(function (item, colIndex) {
return _this5.getSelectedItem(item, colIndex);
}), function (isPass) {
if (isPass) {
_this5.onConfirm();
} else {
_this5.loading = false;
}
});
} else {
_this5.onConfirm();
}
}
});
},
onConfirm: function onConfirm() {
var _this6 = this;
this.isChange = false;
this.loading = false;
this.pickerShow = false;
this.$emit('input', this.pickerColSelected);
this.setShowValue();
this.setLineStyle();
this.lineScrollIntoView();
this.$emit('confirm', this.pickerColSelected, this.pickerColSelected.map(function (item, colIndex) {
return _this6.getSelectedItem(item, colIndex);
}));
},
handleColClick: function handleColClick(colIndex) {
this.isChange = true;
this.currentCol = colIndex;
},
setLineStyle: function setLineStyle() {
var _this7 = this;
var isAnimate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (!this.$refs.selecteds || this.$refs.selecteds.length === 0) return;
this.$nextTick(function () {
var left = 0;
var width = 16;
if (_this7.$refs.selecteds[_this7.currentCol]) {
var _this7$$refs$selected = _this7.$refs.selecteds[_this7.currentCol],
clientWidth = _this7$$refs$selected.clientWidth,
offsetLeft = _this7$$refs$selected.offsetLeft;
left = offsetLeft + (clientWidth - width) / 2;
}
_this7.lineStyle = {
transform: "translateX(".concat(left, "px)"),
transition: isAnimate ? 'width 300ms, transform 300ms' : ''
};
});
},
lineScrollIntoView: function lineScrollIntoView() {
var _this8 = this;
var isAnimate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (!this.$refs.selecteds || this.$refs.selecteds.length === 0) return;
this.$nextTick(function () {
var activeNav = _this8.$refs.selecteds[_this8.currentCol];
if (!activeNav) return;
var visibleWidth = _this8.$refs.selectedVisible.offsetWidth;
var activeLeft = activeNav.offsetWidth / 2 + activeNav.offsetLeft;
var nextNavContainerLeft = activeLeft - visibleWidth / 2;
Object(animateScrollLeft["a" /* default */])(_this8.$refs.selectedContainer, nextNavContainerLeft, isAnimate ? 300 : 0);
});
},
setShowValue: function setShowValue() {
var _this9 = this;
var selectedItems = this.value.map(function (item, colIndex) {
return _this9.getSelectedItem(item, colIndex);
});
if (this.displayFormat) {
this.showValue = this.displayFormat(selectedItems);
} else {
this.showValue = selectedItems.map(function (item) {
return item[_this9.labelKey];
}).join('');
}
},
// 递归列数据补齐
diffColumns: function diffColumns(colIndex) {
var _this10 = this;
// colIndex 为 -1 时,item 为空对象,>=0 时则具有 value 属性
var item = colIndex === -1 ? {} : defineProperty_default()({}, this.valueKey, this.value[colIndex]);
this.handleColChange(colIndex, item, -1, function () {
// 如果 columns 长度还小于 value 长度,colIndex + 1,继续递归补齐
if (_this10.selectList.length < _this10.value.length) {
_this10.diffColumns(colIndex + 1);
} else {
_this10.setShowValue();
}
});
}
}
});
// CONCATENATED MODULE: ./packages/col-picker/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/col-picker/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/col-picker/src/main.vue"
/* harmony default export */ var main = (component.exports);
// CONCATENATED MODULE: ./packages/col-picker/index.js
main.install = function (Vue) {
Vue.component(main.name, main);
};
/* harmony default export */ var col_picker = __webpack_exports__["default"] = (main);
/***/ }),
/***/ 8:
/***/ (function(module, exports) {
module.exports = require("wot-design/lib/loading");
/***/ })
/******/ });