@mdsfe/mds-ui
Version:
A set of enterprise-class Vue UI components.
1,840 lines (1,720 loc) • 54.7 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("./icon"), require("./transition"), require("./checkbox"));
else if(typeof define === 'function' && define.amd)
define(["./icon", "./transition", "./checkbox"], factory);
else {
var a = typeof exports === 'object' ? factory(require("./icon"), require("./transition"), require("./checkbox")) : factory(root["./icon"], root["./transition"], root["./checkbox"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(window, function(__WEBPACK_EXTERNAL_MODULE__7__, __WEBPACK_EXTERNAL_MODULE__12__, __WEBPACK_EXTERNAL_MODULE__28__) {
return /******/ (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 = "/dist/";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 102);
/******/ })
/************************************************************************/
/******/ ({
/***/ 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,
(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
}
}
/***/ }),
/***/ 10:
/***/ (function(module, exports) {
module.exports = require("babel-runtime/helpers/typeof");
/***/ }),
/***/ 102:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXTERNAL MODULE: ./components/style/index.less
var style = __webpack_require__(142);
// EXTERNAL MODULE: ./components/tree/style/index.less
var tree_style = __webpack_require__(241);
// CONCATENATED MODULE: ./components/tree/style/index.js
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./components/tree/tree.vue?vue&type=template&id=e2198d78&
var render = function () {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c(
"div",
{ staticClass: "mds-tree", attrs: { flag: "tree" } },
[
_vm._l(_vm.root.childNodes, function (item) {
return _c("mds-tree-item", {
directives: [
{
name: "show",
rawName: "v-show",
value: !_vm.isEmpty,
expression: "!isEmpty",
},
],
key: _vm.getNodeKey(item),
attrs: {
node: item,
checkboxDisplay: _vm.checkboxDisplay,
checkTotalLine: _vm.checkTotalLine,
},
})
}),
_c(
"div",
{
directives: [
{
name: "show",
rawName: "v-show",
value: _vm.isEmpty,
expression: "isEmpty",
},
],
staticClass: "mds-tree-empty-wrapper",
},
[
_c("div", { staticClass: "mds-tree-empty-text" }, [
_vm._v(_vm._s(_vm.emptyText)),
]),
]
),
],
2
)
}
var staticRenderFns = []
render._withStripped = true
// CONCATENATED MODULE: ./components/tree/tree.vue?vue&type=template&id=e2198d78&
// EXTERNAL MODULE: external "babel-runtime/core-js/get-iterator"
var get_iterator_ = __webpack_require__(25);
var get_iterator_default = /*#__PURE__*/__webpack_require__.n(get_iterator_);
// EXTERNAL MODULE: external "babel-runtime/core-js/map"
var map_ = __webpack_require__(31);
var map_default = /*#__PURE__*/__webpack_require__.n(map_);
// EXTERNAL MODULE: external "babel-runtime/helpers/typeof"
var typeof_ = __webpack_require__(10);
var typeof_default = /*#__PURE__*/__webpack_require__.n(typeof_);
// EXTERNAL MODULE: external "babel-runtime/helpers/classCallCheck"
var classCallCheck_ = __webpack_require__(34);
var classCallCheck_default = /*#__PURE__*/__webpack_require__.n(classCallCheck_);
// EXTERNAL MODULE: external "babel-runtime/helpers/createClass"
var createClass_ = __webpack_require__(35);
var createClass_default = /*#__PURE__*/__webpack_require__.n(createClass_);
// CONCATENATED MODULE: ./components/_util/tree/node.js
var defaultId = 0;
var node_Node = function () {
function Node(options) {
classCallCheck_default()(this, Node);
this.id = defaultId++;
this.checked = false;
this.indeterminate = false;
this.data = null;
this.expanded = false;
this.parent = null;
this.isLeaf = false;
// 是否显示,用于搜索
this.visible = true;
// 搜索关键字,用于标记高亮
this.searchWords = null;
for (var name in options) {
if (options.hasOwnProperty(name)) {
this[name] = options[name];
}
}
this.level = 0;
// 是否被选中
this.selected = false;
// 是否已经加载完毕,用于懒加载
this.loaded = false;
// 是否是加载中状态,用于懒加载
this.loading = false;
this.childNodes = [];
this.parent ? this.level = this.parent.level + 1 : this.level = 0;
this.update();
}
createClass_default()(Node, [{
key: 'update',
value: function update() {
var _this = this;
if (!this.data) {
this.handleIsLeaf();
return;
}
var data = this.data;
var prop = this.tree.prop;
// 生成_nodeId
// this.markData(data)
// 非根节点添加到nodesMap中
this.fillNodesMap();
// 处理defaultExpandAll
if (!this.load && this.tree.defaultExpandAll) {
this.expanded = true;
}
// 处理defaultExpandedKeys
if (!this.load && this.tree.defaultExpandedKeys) {
this.tree.defaultExpandedKeys.forEach(function (item) {
if (_this.key === item) {
_this.expanded = true;
if (_this.tree.autoExpandParent) {
_this.getPath(true).forEach(function (node) {
node.expanded = true;
});
}
}
});
}
// 生成childNodes
var children = void 0;
// 根节点的情况把整个data作为children
if (Array.isArray(data) && this.level === 0) {
children = data;
this.id = 'root';
} else if (data.hasOwnProperty(prop.children)) {
children = data[prop.children];
} else {
if (!this.tree.load) this.isLeaf = true;
}
if (Array.isArray(children) && children.length > 0) {
children.forEach(function (data) {
_this.appendChild(data);
});
} else {
if (!this.tree.load) this.isLeaf = true;
}
this.handleIsLeaf();
}
}, {
key: 'handleIsLeaf',
value: function handleIsLeaf() {
// 懒加载且未加载的情况
if (this.tree.load && !this.loaded) {
this.isLeaf = this.getTrueData('isLeaf');
}
// 非懒加载或懒加载但已加载的情况
if (!this.tree.load || this.tree.load && this.loaded) {
var childNodes = this.childNodes;
this.isLeaf = !childNodes || childNodes.length === 0;
}
}
}, {
key: 'fillNodesMap',
value: function fillNodesMap() {
var key = this.key;
if (!key && this.level !== 0) {
throw new Error('必须指定节点的key');
}
if (key) {
// 处理初始选中的节点
this.handleSelectedKey(key);
if (this.tree.nodesMap.get(key)) {
throw new Error('节点的key不能重复');
}
this.tree.nodesMap.set(key, this);
}
}
}, {
key: 'handleSelectedKey',
value: function handleSelectedKey(key) {
this.selected = false;
if (this.tree.selectedKey === key) {
this.selected = true;
}
}
}, {
key: 'appendChild',
value: function appendChild(data, index) {
var child = new Node({
parent: this,
data: data,
tree: this.tree
});
if (index) {
this.childNodes.splice(index, 0, child);
} else {
this.childNodes.push(child);
}
}
}, {
key: 'getTrueData',
value: function getTrueData(prop) {
var props = this.tree.prop[prop];
var data = this.data;
if (!data) return;
if (data.hasOwnProperty(props)) {
return data[props];
} else if (data.hasOwnProperty(prop)) {
return data[prop];
} else {
return null;
}
}
}, {
key: 'markData',
value: function markData(data) {
Object.defineProperty(data, '_node', {
value: this,
enumerable: false,
configurable: false,
writable: false
});
if (!Array.isArray(data)) {
Object.defineProperty(data, '_nodeId', {
value: this.id,
enumerable: false,
configurable: false,
writable: false
});
} else if (this.level === 0) {
Object.defineProperty(data, '_nodeId', {
value: 'root',
enumerable: false,
configurable: false,
writable: false
});
}
}
}, {
key: 'changeExpanded',
value: function changeExpanded(value) {
if (this.tree.load && !this.loaded) {
this.loadNode();
}
if (!this.tree.load || this.loaded) {
this.expanded = value;
}
// 手风琴模式展开的时候所有兄弟节点收起
if (this.tree.accordion && value && !this.tree.searchNodeMethod) {
this.siblingsNodes.forEach(function (node) {
node.expanded = false;
});
}
}
}, {
key: 'loadNode',
value: function loadNode() {
var _this2 = this;
var node = this;
if (node.loaded || node.loading || node.childNodes.length > 0) {
return;
}
node.loading = true;
node.tree.load(node.data, function (data) {
if (!Array.isArray(data)) throw new Error('传入子元素必须是数组');
data.forEach(function (data) {
node.appendChild(data);
});
node.loading = false;
node.loaded = true;
node.check = false;
node.expanded = true;
_this2.handleIsLeaf();
});
}
}, {
key: 'getPath',
value: function getPath(nodeFlag) {
var arr = [];
var n = 0;
var node = this;
// if (Array.isArray(this.tree.root)) {
// n = 1
// }
while (node.level > n) {
arr.push(nodeFlag ? node : node.data);
node = node.parent;
}
return arr;
}
}, {
key: 'handleCheckChange',
value: function handleCheckChange() {
var checked = this.checked;
this.childNodes.forEach(function (node) {
node.check = checked;
});
if (this.parent) {
this.parent.handleChildCheckChange();
}
}
}, {
key: 'handleChildCheckChange',
value: function handleChildCheckChange() {
if (Array.isArray(this.data) || this.level === 0) {
return;
}
if (this.childNodes.length === this.checkedChildNodes.length && this.childNodes.length !== 0) {
this.checked = true;
this.indeterminate = false;
} else if (this.checkedChildNodes.length > 0) {
this.checked = false;
this.indeterminate = true;
} else {
this.checked = false;
this.indeterminate = false;
for (var i = 0; i < this.childNodes.length; i++) {
if (this.childNodes[i].indeterminate) {
this.indeterminate = true;
break;
}
}
}
this.parent.handleChildCheckChange();
}
}, {
key: 'after',
value: function after(node) {
var oldIndex = node.index;
node.parent.childNodes.splice(oldIndex, 1);
node.parent.handleChildCheckChange();
if (node.parent.childNodes.length === 0) {
node.parent.isLeaf = true;
}
node.parent = this.parent;
node.level = this.level;
this.parent.childNodes.splice(this.index + 1, 0, node);
this.handleChildCheckChange();
}
}, {
key: 'first',
value: function first(node) {
var oldIndex = node.index;
node.parent.childNodes.splice(oldIndex, 1);
node.parent.handleChildCheckChange();
if (node.parent.childNodes.length === 0) {
node.parent.isLeaf = true;
}
this.isLeaf = false;
node.parent = this;
node.level = this.level + 1;
this.childNodes.splice(0, 0, node);
this.handleChildCheckChange();
}
}, {
key: 'append',
value: function append(node) {
var oldIndex = node.index;
node.parent.childNodes.splice(oldIndex, 1);
node.parent.handleChildCheckChange();
if (node.parent.childNodes.length === 0) {
node.parent.isLeaf = true;
}
this.isLeaf = false;
node.parent = this;
node.level = this.level + 1;
this.childNodes.push(node);
this.handleChildCheckChange();
}
}, {
key: 'moveNode',
value: function moveNode(node, index) {
var oldIndex = node.index;
node.parent.childNodes.splice(oldIndex, 1);
node.parent.handleChildCheckChange();
if (node.parent.childNodes.length === 0) {
node.parent.isLeaf = true;
}
this.isLeaf = false;
node.parent = this;
node.level = this.level + 1;
if (index !== null) {
this.childNodes.splice(index, 0, node);
} else {
this.childNodes.push(node);
}
this.handleChildCheckChange();
}
}, {
key: 'remove',
value: function remove() {
var node = this;
var index = node.index;
node.parent.childNodes.splice(index, 1);
node.parent.handleChildCheckChange();
node.tree.nodesMap.delete(node.id);
node = null;
}
}, {
key: 'label',
get: function get() {
return this.getTrueData('label');
}
}, {
key: 'key',
get: function get() {
return this.getTrueData('key');
}
}, {
key: 'disabled',
get: function get() {
return this.getTrueData('disabled');
}
}, {
key: 'check',
get: function get() {
return this.checked;
},
set: function set(val) {
if (val !== this.checked) {
this.checked = val;
this.handleCheckChange();
}
}
}, {
key: 'siblingsNodes',
get: function get() {
var arr = [];
var currentNode = this;
this.parent.childNodes.forEach(function (node) {
if (node.id !== currentNode.id) {
arr.push(node);
}
});
return arr;
}
}, {
key: 'checkedChildNodes',
get: function get() {
var arr = [];
this.childNodes.forEach(function (node) {
if (node.checked) arr.push(node);
});
return arr;
}
}, {
key: 'indeterminateChildNodes',
get: function get() {
var arr = [];
this.childNodes.forEach(function (node) {
if (node.checked || node.indeterminate) arr.push(node);
});
return arr;
}
}, {
key: 'isExpanded',
get: function get() {
return this.expanded;
},
set: function set(value) {
this.changeExpanded(value);
}
}, {
key: 'index',
get: function get() {
return this.parent.childNodes.indexOf(this);
}
}]);
return Node;
}();
// CONCATENATED MODULE: ./components/_util/tree/tree.js
var tree_Tree = function () {
function Tree(options) {
var _this = this;
classCallCheck_default()(this, Tree);
for (var name in options) {
if (options.hasOwnProperty(name)) {
this[name] = options[name];
}
}
if (!this.prop || typeof_default()(this.prop) !== 'object') {
this.prop = {
label: 'label',
key: 'key',
isLeaf: 'isLeaf',
disabled: 'disabled',
children: 'children'
};
}
this.nodesMap = new map_default.a();
this.root = new node_Node({
data: this.data,
tree: this
});
// 根据load函数渲染根节点
if (this.load) {
this.load(this.root, function (arr) {
if (!Array.isArray(arr)) {
throw new Error('传入子元素必须是数组');
}
arr.forEach(function (item) {
_this.root.appendChild(item);
});
});
}
}
createClass_default()(Tree, [{
key: 'setData',
value: function setData(newVal) {
var dataChange = newVal !== this.root.data;
if (dataChange) {
this.nodesMap = new map_default.a();
this.root = new node_Node({
data: newVal,
tree: this
});
}
}
}, {
key: 'handleSelectedChange',
value: function handleSelectedChange(key) {
var selectedNode = this.nodesMap.get(key);
if (!selectedNode.selected) {
this.nodesMap.forEach(function (node, nodeKey) {
node.selected = false;
if (nodeKey === key) {
node.selected = true;
}
});
this.$tree.$emit('node-selected-change', selectedNode.data, selectedNode, selectedNode.getPath(), selectedNode.getPath(true));
}
}
}, {
key: 'handleDefaultCheckedKeys',
value: function handleDefaultCheckedKeys() {
var _this2 = this;
// 处理defaultCheckedKeys
if (this.defaultCheckedKeys) {
this.defaultCheckedKeys.forEach(function (item) {
_this2.nodesMap.get(item).check = true;
});
}
}
}, {
key: 'search',
value: function search(value) {
var _this3 = this;
var recursionChildren = function recursionChildren(node) {
var childNodes = node.root ? node.root.childNodes : node.childNodes;
childNodes.forEach(function (item) {
item.searchWords = null;
item.visible = _this3.searchNodeMethod.call(item, value, item.data, item);
if (item.visible) {
item.searchWords = value;
}
recursionChildren(item);
});
// 子节点有匹配项的情况父节点需要显示
if (!node.visible && childNodes.length) {
var hiddenAllChildren = void 0;
hiddenAllChildren = !childNodes.some(function (child) {
return child.visible;
});
if (!node.root) {
node.visible = !hiddenAllChildren;
} else {
node.root.visible = false;
}
}
// 节点显示的情况下展开所有子节点
if (node.visible && !node.isLeaf && !_this3.load && value) {
node.changeExpanded(true);
}
};
recursionChildren(this);
}
}, {
key: 'getCheckedNodes',
value: function getCheckedNodes(leafOnly) {
var result = [];
if (leafOnly) {
this.nodesMap.forEach(function (item) {
if (item.checked && !item.data.children) {
result.push(item.data);
}
});
} else {
this.nodesMap.forEach(function (item) {
if (item.checked) {
result.push(item.data);
}
});
}
return result;
}
}, {
key: 'getCheckedKeys',
value: function getCheckedKeys(leafOnly) {
var result = [];
if (leafOnly) {
this.nodesMap.forEach(function (item) {
if (item.checked && !item.data.children) {
result.push(item.key);
}
});
} else {
this.nodesMap.forEach(function (item) {
if (item.checked) {
result.push(item.key);
}
});
}
return result;
}
}, {
key: 'setCheckedKeys',
value: function setCheckedKeys(checkArr) {
var _this4 = this;
if (!Array.isArray(checkArr)) {
throw new Error('需要输入一个key数组');
}
var exec = function exec() {
_this4.nodesMap.forEach(function (item) {
item.check = false;
});
checkArr.forEach(function (item) {
_this4.nodesMap.get(item).check = true;
});
};
window.requestAnimationFrame(exec);
}
}, {
key: 'setChecked',
value: function setChecked(key, checkState) {
var _this5 = this;
// 分{key, check}数组和单独传入key两种形式
var is = function is(val, type) {
var res = Object.prototype.toString.call(val);
return res.includes(type);
};
var checkNode = function checkNode(_key, _checkState) {
var node = _this5.nodesMap.get(_key);
if (!node) {
throw new Error('请输入正确的key');
}
node.check = _checkState;
};
if (is(key, 'String') && is(checkState, 'Boolean')) {
checkNode(key, checkState);
return;
}
if (is(key, 'Array') && !checkState) {
var exec = function exec() {
key.forEach(function (_ref) {
var key = _ref.key,
check = _ref.check;
checkNode(key, check);
});
};
window.requestAnimationFrame(exec);
}
}
}, {
key: 'getHalfCheckedNodes',
value: function getHalfCheckedNodes() {
var result = [];
this.nodesMap.forEach(function (item) {
if (item.indeterminate) {
result.push(item.data);
}
});
return result;
}
}, {
key: 'getHalfCheckedKeys',
value: function getHalfCheckedKeys() {
var result = [];
this.nodesMap.forEach(function (item) {
if (item.indeterminate) {
result.push(item.data.key);
}
});
return result;
}
}, {
key: 'getCurrentKey',
value: function getCurrentKey() {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = get_iterator_default()(this.nodesMap.values()), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var item = _step.value;
if (item.selected) {
return item.data.key;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return null;
}
}, {
key: 'getCurrentNode',
value: function getCurrentNode() {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = get_iterator_default()(this.nodesMap.values()), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var item = _step2.value;
if (item.selected) {
return item.data;
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return null;
}
}, {
key: 'setCurrentKey',
value: function setCurrentKey(key) {
if (key) {
this.handleSelectedChange(key);
} else {
this.nodesMap.forEach(function (node) {
node.selected = false;
});
}
}
}, {
key: 'getNode',
value: function getNode(key) {
var node = this.nodesMap.get(key);
if (node) {
return node;
}
return null;
}
}, {
key: 'getCheckNode',
value: function getCheckNode(nodeFlag) {
var arr = [];
this.nodesMap.forEach(function (item) {
if (item.checked) {
nodeFlag ? arr.push(item) : arr.push(item.data);
}
});
return arr;
}
}, {
key: 'getCheckNodeKey',
value: function getCheckNodeKey() {
var arr = [];
this.getCheckNode(true).forEach(function (node) {
arr.push(node.key);
});
return arr;
}
}, {
key: 'getIndeterminateNode',
value: function getIndeterminateNode(nodeFlag) {
var arr = [];
this.nodesMap.forEach(function (item) {
if (item.indeterminate) {
nodeFlag ? arr.push(item) : arr.push(item.data);
}
});
return arr;
}
}, {
key: 'getIndeterminateNodeKey',
value: function getIndeterminateNodeKey() {
var arr = [];
this.getIndeterminateNode(true).forEach(function (node) {
arr.push(node.key);
});
return arr;
}
}, {
key: 'setCheckNode',
value: function setCheckNode(keys) {
var bor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var nodesMap = this.nodesMap;
if (Array.isArray(keys)) {
keys.forEach(function (item) {
var node = nodesMap.get(item);
if (node) node.check = bor;
});
} else {
var node = nodesMap.get(keys);
if (node) nodesMap.get(keys).check = bor;
}
}
}, {
key: 'getCheckNodeTree',
value: function getCheckNodeTree() {
var _this6 = this;
var root = this.root;
if (Array.isArray(root.data)) {
var newTree = [];
root.indeterminateChildNodes.forEach(function (item) {
newTree.push(copyNode(item, _this6));
});
return newTree;
} else {
return copyNode(root, this);
}
}
}, {
key: 'appendNodes',
value: function appendNodes(key, nodes) {
var parent = this.nodesMap.get(key);
if (!parent) {
return;
}
if (Array.isArray(nodes)) {
if ((typeof nodes === 'undefined' ? 'undefined' : typeof_default()(nodes)) === 'object') {
nodes.forEach(function (item) {
parent.appendChild(item);
});
}
} else if ((typeof nodes === 'undefined' ? 'undefined' : typeof_default()(nodes)) === 'object') {
parent.appendChild(nodes);
}
}
}, {
key: 'deleteNodeByKey',
value: function deleteNodeByKey(keys) {
var _this7 = this;
if (Array.isArray(keys)) {
keys.forEach(function (item) {
var node = _this7.nodesMap.get(item);
if (node) node.remove();
});
} else {
var node = this.nodesMap.get(keys);
node.remove();
}
}
}, {
key: 'clearCheckNode',
value: function clearCheckNode() {
this.nodesMap.forEach(function (item) {
item.checked = false;
item.indeterminate = false;
});
}
}]);
return Tree;
}();
var copyData = function copyData(data, tree) {
var newData = {};
for (var key in data) {
if (data.hasOwnProperty(key) && key !== tree.prop.children) {
newData[key] = data[key];
}
}
return newData;
};
var copyNode = function copyNode(node, tree) {
var newData = copyData(node.data, tree);
if (node.isLeaf) {
return newData;
}
newData[tree.prop.children] = [];
node.indeterminateChildNodes.forEach(function (item) {
newData[tree.prop.children].push(copyNode(item, tree));
});
return newData;
};
// const deepCopy = function(o) {
// if (o instanceof Array) {
// let n = []
// for (let i = 0; i < o.length; ++i) {
// n[i] = deepCopy(o[i])
// }
// return n
// } else if (o instanceof Object) {
// let n = {}
// for (let i in o) {
// n[i] = deepCopy(o[i])
// }
// return n
// } else {
// return o
// }
// }
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./components/tree/tree-item.vue?vue&type=template&id=7faeb42c&
var tree_itemvue_type_template_id_7faeb42c_render = function () {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c(
"div",
{
directives: [
{
name: "show",
rawName: "v-show",
value: _vm.node.visible,
expression: "node.visible",
},
],
staticClass: "mds-tree-item",
on: { click: _vm.handleCheckTotalLine },
},
[
_c(
"div",
{
class: {
"mds-tree-content": true,
"mds-tree-active": this.checkTotalLine ? false : _vm.node.selected,
},
style: { "padding-left": (_vm.node.level - 1) * 15 + "px" },
on: {
mouseenter: _vm.contentEnter,
mouseleave: _vm.contentLeave,
click: function ($event) {
$event.stopPropagation()
return _vm.handleClick()
},
contextmenu: function ($event) {
return _vm.handleContextMenu($event)
},
},
},
[
_c(
"span",
{
staticClass: "mds-tree-expand",
on: {
mousedown: function ($event) {
$event.stopPropagation()
},
click: function ($event) {
$event.stopPropagation()
return _vm.expanded()
},
},
},
[
!_vm.node.isLeaf
? _c(
"span",
{ staticClass: "mds-tree-expand-content" },
[
_c("mds-icon", {
class: { "mds-tree-trans": !_vm.node.expanded },
attrs: { type: "fill-solid-down" },
}),
],
1
)
: _vm._e(),
]
),
_c("mds-icon", {
directives: [
{
name: "show",
rawName: "v-show",
value: _vm.node.loading,
expression: "node.loading",
},
],
staticClass: "mds-tree-loading",
attrs: { type: "line-sync", spin: "" },
}),
_vm.checkboxDisplay
? [
_c(
"label",
{ staticClass: "mds-tree-checkbox" },
[
_c("mds-checkbox", {
attrs: {
indeterminate: _vm.node.indeterminate,
disabled: _vm.node.disabled,
},
on: { change: _vm.handleCheck },
nativeOn: {
click: function ($event) {
$event.stopPropagation()
},
},
model: {
value: _vm.node.check,
callback: function ($$v) {
_vm.$set(_vm.node, "check", $$v)
},
expression: "node.check",
},
}),
],
1
),
_c(
"div",
{ staticClass: "mds-tree-label-wrapper" },
[
_c(
"label-content",
_vm._b({}, "label-content", _vm.$props, false)
),
],
1
),
]
: [
_c(
"div",
{
staticClass: "mds-tree-label-wrapper",
on: { click: _vm.handleCheck },
},
[
_c(
"label-content",
_vm._b({}, "label-content", _vm.$props, false)
),
],
1
),
],
],
2
),
_c("div", {
class: {
"mds-tree-block": true,
"mds-tree-block-hover": _vm.topHover,
},
staticStyle: { height: "4px" },
on: { mouseenter: _vm.enterTop, mouseleave: _vm.leaveTop },
}),
!_vm.node.isLeaf
? [
_c("mds-transition", { attrs: { type: "collapse" } }, [
_vm.node.expanded
? _c(
"div",
{ staticClass: "mds-tree-group" },
_vm._l(_vm.node.childNodes, function (item, index) {
return _c("mds-tree-item", {
key: index,
attrs: {
checkboxDisplay: _vm.checkboxDisplay,
node: item,
checkTotalLine: _vm.checkTotalLine,
},
})
}),
1
)
: _vm._e(),
]),
]
: _vm._e(),
],
2
)
}
var tree_itemvue_type_template_id_7faeb42c_staticRenderFns = []
tree_itemvue_type_template_id_7faeb42c_render._withStripped = true
// CONCATENATED MODULE: ./components/tree/tree-item.vue?vue&type=template&id=7faeb42c&
// EXTERNAL MODULE: external "./icon"
var external_icon_ = __webpack_require__(7);
var external_icon_default = /*#__PURE__*/__webpack_require__.n(external_icon_);
// EXTERNAL MODULE: external "./checkbox"
var external_checkbox_ = __webpack_require__(28);
var external_checkbox_default = /*#__PURE__*/__webpack_require__.n(external_checkbox_);
// EXTERNAL MODULE: external "./transition"
var external_transition_ = __webpack_require__(12);
var external_transition_default = /*#__PURE__*/__webpack_require__.n(external_transition_);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./components/tree/tree-item.vue?vue&type=script&lang=js&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
/* harmony default export */ var tree_itemvue_type_script_lang_js_ = ({
name: 'MdsTreeItem',
componentName: 'MdsTreeItem',
components: {
MdsIcon: external_icon_default.a,
MdsCheckbox: external_checkbox_default.a,
MdsTransition: external_transition_default.a,
labelContent: {
props: ['node', 'checkTotalLine'],
methods: {
highlightLabel: function highlightLabel() {
var h = this.$createElement;
var _node = this.node,
searchWords = _node.searchWords,
label = _node.label;
var index = label.indexOf(searchWords);
if (index > -1) {
var reg = new RegExp('(' + searchWords + ')', 'g');
var tempArr = label.split(reg);
return tempArr.map(function (el) {
if (el === searchWords) {
return h(
'span',
{ 'class': 'mds-tree-label-highlight' },
[el]
);
} else {
return el;
}
});
} else {
return this.node.label;
}
}
},
render: function render() {
var h = arguments[0];
var slot = this.node.tree.$tree.$scopedSlots.default;
var node = this.node;
if (slot) {
return slot(node);
}
return h(
'label',
{
'class': {
'mds-tree-label': true,
'mds-tree-active-label': this.checkTotalLine ? false : node.selected
}
},
[node.searchWords ? this.highlightLabel() : node.label]
);
}
}
},
props: {
node: {
type: Object,
required: true
},
checkboxDisplay: Boolean,
checkTotalLine: Boolean
},
data: function data() {
return {
development: false,
topHover: false,
blockHover: false
};
},
computed: {
$tree: function $tree() {
return this.node.tree.$tree;
}
},
methods: {
// 处理有checkbox时需要选中整行的情况
handleCheckTotalLine: function handleCheckTotalLine() {
if (this.checkTotalLine) {
this.node.check = !this.node.check;
this.handleCheck(this.node.check);
}
},
expanded: function expanded() {
this.node.changeExpanded(!this.node.expanded);
var expandOrCollapse = void 0;
if (this.node.expanded) {
expandOrCollapse = 'expand';
} else {
expandOrCollapse = 'collapse';
}
this.$tree.$emit('node-expand-change', expandOrCollapse, this.node.data, this.node, this.node.getPath(), this.node.getPath(true));
},
handleCheck: function handleCheck(value) {
this.node.check = value;
this.$tree.$emit('node-check', this.node.data, {
checkedNodes: this.node.tree.getCheckNode(),
checkedKeys: this.node.tree.getCheckNodeKey(),
indeterminateNodes: this.node.tree.getIndeterminateNode(),
indeterminateKeys: this.node.tree.getIndeterminateNodeKey()
});
},
handleClick: function handleClick() {
this.node.tree.handleSelectedChange(this.node.key);
this.$tree.$emit('node-click', this.node.data, this.node, this.node.getPath(), this.node.getPath(true));
this.handleCheckTotalLine();
},
handleContextMenu: function handleContextMenu(e) {
this.$tree.$emit('node-contextmenu', e, this.node.data, this.node, this.node.getPath(), this.node.getPath(true));
},
contentEnter: function contentEnter() {
if (!this.node.tree.dragStatus) {
return false;
}
this.node.tree.currentTargetNode = this.node;
this.node.tree.targetAction = 'append';
},
contentLeave: function contentLeave() {
if (!this.node.tree.dragStatus) {
return false;
}
},
enterTop: function enterTop() {
if (!this.node.tree.dragStatus) {
return false;
}
this.topHover = true;
this.node.tree.currentTargetNode = this.node;
this.node.tree.targetAction = 'first';
},
leaveTop: function leaveTop() {
this.topHover = false;
},
enterBlock: function enterBlock() {
if (!this.node.tree.dragStatus) {
return false;
}
this.blockHover = true;
this.node.tree.currentTargetNode = this.node;
this.node.tree.targetAction = 'after';
},
leaveBlock: function leaveBlock() {
this.blockHover = false;
},
listenDrag: function listenDrag() {
var _this = this;
var el = this.$el;
el.onmousedown = function (event) {
var node = _this.node;
var vnode = void 0;
var rect = el.getBoundingClientRect();
event.stopPropagation();
vnode = el.cloneNode(true);
vnode.style.position = 'fixed';
vnode.style.opacity = '0.6';
vnode.style.left = rect.left;
vnode.style.top = rect.top;
// (clientX, clientY)点击位置距离当前可视区域的坐标(x,y)
// offsetLeft, offsetTop 距离上层或父级的左边距和上边距
// 获取鼠标在弹窗中的位置
var mouseX = event.clientX - rect.left;
var mouseY = event.clientY - rect.top;
// 绑定移动和停止函数
document.onmousemove = function (event) {
var left = void 0,
top = void 0;
// 获取新的鼠标位置(event.clientX, event.clientY)
// 弹窗应该在的位置(left, top)
left = event.clientX - mouseX;
top = event.clientY - mouseY;
if (Math.abs(left - rect.left) > 10 || Math.abs(top - rect.top) > 10) {
document.body.appendChild(vnode);
node.tree.currentCathcNode = node;
node.tree.dragStatus = true;
}
// offsetWidth、offsetHeight 当前元素的宽度
// innerWidth、innerHeight 浏览器可视区的宽度和高度
// 获取弹窗在页面中距X轴的最小、最大 位置
// let minX = -vnode.offsetWidth / 2 + 150
// let maxX = window.innerWidth + vnode.offsetWidth / 2 - 150
// if (left <= minX) {
// left = minX
// } else if (left >= maxX) {
// left = maxX
// }
// 获取弹窗在页面中距Y轴的最小、最大 位置
// let minY = 20
// let maxY = window.innerHeight + vnode.offsetHeight / 2 - 50
// if (top <= minY) {
// top = minY
// } else if (top >= maxY) {
// top = maxY
// }
// 赋值移动
vnode.style.left = left + 'px';
vnode.style.top = top + 'px';
};
document.onmouseup = function () {
var target = node.tree.currentTargetNode;
document.onmousemove = document.onmouseup = null;
if (node.tree.dragStatus) {
document.body.removeChild(vnode);
}
node.tree.dragStatus = false;
if (target && target !== node) {
console.log(node.tree.targetAction);
if (node.tree.targetAction === 'first') {
target.first(node);
} else if (node.tree.targetAction === 'after') {
target.after(node);
} else if (node.tree.targetAction === 'append') {
target.append(node);
}
}
node.tree.currentCathcNode = null;
node.tree.currentTargetNode = null;
};
};
}
},
mounted: function mounted() {
if (this.node.tree.aollowDrag) {
this.listenDrag();
}
},
watch: {
'node.check': function nodeCheck() {
this.$tree.$emit('node-check-change', this.node.data, this.node.checked);
}
}
});
// CONCATENATED MODULE: ./components/tree/tree-item.vue?vue&type=script&lang=js&
/* harmony default export */ var tree_tree_itemvue_type_script_lang_js_ = (tree_itemvue_type_script_lang_js_);
// EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
var componentNormalizer = __webpack_require__(0);
// CONCATENATED MODULE: ./components/tree/tree-item.vue
/* normalize component */
var component = Object(componentNormalizer["a" /* default */])(
tree_tree_itemvue_type_script_lang_js_,
tree_itemvue_type_template_id_7faeb42c_render,
tree_itemvue_type_template_id_7faeb42c_staticRenderFns,
false,
null,
null,
null
)
/* hot reload */
if (false) { var api; }
component.options.__file = "components/tree/tree-item.vue"
/* harmony default export */ var tree_item = (component.exports);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./components/tree/tree.vue?vue&type=script&lang=js&
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
/* harmony default export */ var treevue_type_script_lang_js_ = ({
name: 'MdsTree',
componentName: 'MdsTree',
components: {
MdsTreeItem: tree_item
},
props: {
data: Array,
prop: {
default: function _default() {
return {
label: 'label',
key: 'key',
isLeaf: 'isLeaf',
disabled: 'disabled',
children: 'children'
};
}
},
// 选中的节点
selectedKey: String,
// 设置默认值与展开收起相关属性
defaultExpandAll: Boolean,
defaultCheckedKeys: Array,
autoExpandParent: {
type: Boolean,
default: true
},
defaultExpandedKeys: Array,
checkboxDisplay: Boolean,
searchNodeMethod: Function,
loadData: Function,
drag: Boolean,
accordion: Boolean,
emptyText: {
type: String,
default: '暂无数据'
},
checkTotalLine: Boolean // 有checkbox时是否点击整行元素都响应
},
computed: {
isEmpty: function isEmpty() {
var childNodes = this.root.childNodes;
var childInvisible = childNodes.every(function (node) {
return !node.visible;
});
return !childNodes || childNodes.length === 0 || childInvisible;
}
},
data: function data() {
return {
tree: null,
root: null,
currentNode: null
// dragState: {
// showDropIndicator: false,
// draggingNode: null,
// dropNode: null,
// allowDrop: true
// }
};
},
methods: {
getNodeKey: funct