@cmstops/pro-compo
Version:
[物料平台文档中心](https://arco.design/docs/material/guide)
153 lines (152 loc) • 5.34 kB
JavaScript
;
var vue = require("vue");
var webVue = require("@arco-design/web-vue");
var icon = require("@arco-design/web-vue/es/icon");
var api = require("../../../script/api.js");
const _hoisted_1 = { class: "column-selection-container" };
const _hoisted_2 = { class: "search-column" };
const _sfc_main = vue.defineComponent({
...{ name: "columnTree" },
__name: "index",
props: {
column_id: {},
tree: {},
height: {},
userInfo: {}
},
emits: ["update:column_id"],
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const treeOptions = {
title: "alias",
isLeaf: "leaf"
};
const selectAlias = vue.ref("\u5168\u90E8\u5185\u5BB9");
const lastSearchKey = vue.ref(window.localStorage.getItem("lastSearchKey") || "");
const searchKey = vue.ref("");
const aTreeRef = vue.ref();
const treeData = vue.computed(() => {
if (!searchKey.value)
return props.tree;
return searchData(searchKey.value);
});
const searchData = (keyword) => {
const loop = (data) => {
const result = [];
data.forEach((item) => {
var _a;
if ((_a = item.alias) == null ? void 0 : _a.includes(keyword)) {
result.push({ ...item });
} else if (item.children) {
const filterData = loop(item.children);
if (filterData.length) {
result.push({
...item,
children: filterData
});
}
}
});
return result;
};
return loop(props.tree);
};
const clickLastItem = () => {
aTreeRef.value.selectNode(lastSearchKey.value, true);
};
vue.watch(
() => props.column_id,
(val) => {
setSelectAlias(val);
}
);
const setSelectAlias = async (id) => {
if (id === "all") {
selectAlias.value = "\u5168\u90E8\u5185\u5BB9";
return;
}
const { code, message } = await api.getCategoryPath(props.userInfo.BASE_API, {
repo: props.userInfo.repository_id,
category: id
});
if (code === 0) {
const pathArr = [];
for (const i of message) {
pathArr.push(i.category_alias);
}
selectAlias.value = pathArr.join("/");
}
};
const AddColumnSelected = (selectedKeys, data) => {
lastSearchKey.value = selectedKeys[0];
window.localStorage.setItem("lastSearchKey", lastSearchKey.value);
emit("update:column_id", data.node.id);
};
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
vue.createVNode(vue.unref(webVue.Popover), {
"content-style": { minWidth: "120px" },
"content-class": "column-selection-popover-content",
position: "bottom",
trigger: "click"
}, {
content: vue.withCtx(() => [
vue.createElementVNode("div", _hoisted_2, [
vue.createVNode(vue.unref(webVue.InputSearch), {
modelValue: searchKey.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchKey.value = $event),
placeholder: "\u8BF7\u8F93\u5165\u680F\u76EE\u540D\u79F0"
}, null, 8, ["modelValue"])
]),
lastSearchKey.value ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: "last-search-key",
onClick: clickLastItem
}, "\u4E0A\u4E00\u6B21\u9009\u62E9 ")) : vue.createCommentVNode("v-if", true),
vue.createElementVNode("div", {
style: vue.normalizeStyle({ minHeight: props.height + "px" }),
class: "column-selection-main"
}, [
vue.createElementVNode("div", {
style: vue.normalizeStyle({ height: props.height + "px" }),
class: "column-v"
}, [
vue.createVNode(vue.unref(webVue.Scrollbar), {
"outer-class": "column-outer-scrollbar",
style: { "height": "100%", "overflow": "auto" }
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(webVue.Tree), {
ref_key: "aTreeRef",
ref: aTreeRef,
data: treeData.value,
"default-expand-all": false,
"field-names": treeOptions,
"block-node": "",
"check-strictly": "",
onSelect: AddColumnSelected
}, null, 8, ["data"])
]),
_: 1
})
], 4)
], 4)
]),
default: vue.withCtx(() => [
vue.createVNode(vue.unref(webVue.Button), { class: "button" }, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(icon.IconDragDotVertical)),
vue.createTextVNode(" " + vue.toDisplayString(selectAlias.value) + " ", 1),
vue.createVNode(vue.unref(icon.IconCaretRight))
]),
_: 1
})
]),
_: 1
})
]);
};
}
});
module.exports = _sfc_main;