sohelp-ele
Version:
SohelpEle Library
203 lines (202 loc) • 5.62 kB
JavaScript
(function() {
"use strict";
try {
if (typeof document != "undefined") {
var elementStyle = document.createElement("style");
elementStyle.appendChild(document.createTextNode("[data-v-337768d0] .el-tree-node.is-current > .el-tree-node__content {\n background: #f2f4f8;\n color: #3c77fe;\n font-weight: bold;\n}"));
document.head.appendChild(elementStyle);
}
} catch (e) {
console.error("vite-plugin-css-injected-by-js", e);
}
})();
"use strict";
var core = require("../utils/core");
var render = function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c("el-tree", _vm._g(_vm._b({ ref: "tree", attrs: { "data": _vm.treeData, "props": { label: "title" } }, on: { "node-click": _vm.nodeClick }, model: { value: _vm.value, callback: function($$v) {
_vm.value = $$v;
}, expression: "value" } }, "el-tree", _vm.$attrs, false), _vm.$listeners));
};
var staticRenderFns = [];
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
if (render2) {
options.render = render2;
options.staticRenderFns = staticRenderFns2;
options._compiled = true;
}
if (functionalTemplate) {
options.functional = true;
}
if (scopeId) {
options._scopeId = "data-v-" + scopeId;
}
var hook;
if (moduleIdentifier) {
hook = function(context) {
context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
context = __VUE_SSR_CONTEXT__;
}
if (injectStyles) {
injectStyles.call(this, context);
}
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
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) {
options._injectStyles = hook;
var originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
} else {
var existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return {
exports: scriptExports,
options
};
}
const __vue2_script = {
name: "SohelpTree",
props: {
split: {
type: String,
default: "/"
},
namespace: "",
url: {
type: String,
default: "/engine/service/crud/page"
},
mappingFields: {
type: Object,
default: {
key: "id",
value: "id",
title: "text",
parent_id: "parent_id"
}
},
value: {
type: String | Number
},
data: Array
},
data() {
return {
treeData: [],
pkValues: [],
currentKey: "",
valuePath: [],
labelPath: []
};
},
methods: {
treeFindChildren(tree, value, func, _arr = []) {
if (!tree)
return [];
for (const node of tree) {
_arr.push(node[value]);
if (func(node))
return _arr;
if (node.children) {
const findChildren = this.treeFindChildren(
node.children,
value,
func,
_arr
);
if (findChildren.length)
return findChildren;
}
_arr.pop();
}
return [];
},
nodeClick(data, node) {
this.labelPath = this.treeFindChildren(
this.treeData,
this.mappingFields.title,
(item) => item.id === data.id
);
this.valuePath = this.treeFindChildren(
this.treeData,
this.mappingFields.key,
(item) => item.id === data.id
);
this.$emit("input", data.id);
},
getValuePath() {
return this.split + this.valuePath.join(this.split);
},
getLabelPath() {
return this.split + this.labelPath.join(this.split);
},
load() {
SohelpHttp.get(this.url, { namespace: this.namespace }).then((res) => {
var _a, _b;
let rec = (_b = (_a = res.data) == null ? void 0 : _a.results) != null ? _b : res.data;
rec == null ? void 0 : rec.forEach((d) => {
d.key = d[this.mappingFields.key];
d.value = d[this.mappingFields.value];
d.title = d[this.mappingFields.title];
this.pkValues.push(d.key);
});
let data = [];
data = core.toTreeData({
data: rec,
idField: this.mappingFields.key,
parentIdField: this.mappingFields.parent_id
});
this.treeData = data;
});
}
},
mounted() {
if (this.data) {
this.treeData = this.data;
} else {
this.load();
}
}
};
const __cssModules = {};
var __component__ = /* @__PURE__ */ normalizeComponent(
__vue2_script,
render,
staticRenderFns,
false,
__vue2_injectStyles,
"337768d0",
null,
null
);
function __vue2_injectStyles(context) {
for (let o in __cssModules) {
this[o] = __cssModules[o];
}
}
var index = /* @__PURE__ */ function() {
return __component__.exports;
}();
module.exports = index;