yanzhen-design-vue
Version:
78 lines (77 loc) • 3.07 kB
JavaScript
import { defineComponent, mergeModels, useAttrs, computed, useModel, toRefs, toValue, openBlock, createBlock, unref } from "vue";
import { TreeSelect } from "ant-design-vue";
import { cloneDeep } from "lodash-es";
import "./InnerTreeSelect.vue.mjs";
import InnerCascader from "./InnerCascader.vue.mjs";
import _sfc_main$1 from "./InnerTreeSelect.vue2.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "HydrateCascade",
props: /* @__PURE__ */ mergeModels({
mode: {},
isReadonly: { type: Boolean },
isHidden: { type: Boolean },
placeholder: {},
tooltips: {},
options: { default: () => [] },
filterOptions: { default: () => [] },
leafOnly: { type: Boolean },
showAllLevels: { type: Boolean },
selectMaxLimit: {},
selectMaxLimitMsg: {}
}, {
"modelValue": { default: [] },
"modelModifiers": {}
}),
emits: ["update:modelValue"],
setup(__props) {
const attrs = useAttrs();
const targetKey = computed(() => {
const fieldNames = attrs == null ? void 0 : attrs["field-names"];
return (fieldNames == null ? void 0 : fieldNames.value) || "id";
});
const props = __props;
const currentValue = useModel(__props, "modelValue");
const { filterOptions, options } = toRefs(props);
const treeData = computed(() => {
const cloneTreeData = cloneDeep(toValue(options));
const cleanUp = (nodes) => {
const restNodes = nodes.filter(
(node) => !toValue(filterOptions).includes(node[toValue(targetKey)])
);
return restNodes.map((node) => {
if (node.children) {
node.children = cleanUp(node.children);
}
return node;
});
};
return cleanUp(cloneTreeData);
});
return (_ctx, _cache) => {
return _ctx.mode === "tree" ? (openBlock(), createBlock(_sfc_main$1, {
key: 0,
modelValue: currentValue.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => currentValue.value = $event),
"tree-data": treeData.value,
"max-tag-count": "responsive",
"tree-checkable": "",
"allow-clear": "",
placeholder: "请选择",
"tree-check-strictly": !props.leafOnly ? true : false,
"show-checked-strategy": !props.leafOnly ? unref(TreeSelect).SHOW_ALL : unref(TreeSelect).SHOW_CHILD,
"tree-node-filter-prop": "label"
}, null, 8, ["modelValue", "tree-data", "tree-check-strictly", "show-checked-strategy"])) : (openBlock(), createBlock(InnerCascader, {
key: 1,
modelValue: currentValue.value,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => currentValue.value = $event),
options: treeData.value,
"check-strictly": !props.leafOnly,
"field-names": { label: "name", value: "id", children: "children" },
"display-render": props.showAllLevels ? (labels) => labels.join("/") : null
}, null, 8, ["modelValue", "options", "check-strictly", "display-render"]));
};
}
});
export {
_sfc_main as default
};