yanzhen-design-vue
Version:
75 lines (74 loc) • 2.65 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const antDesignVue = require("ant-design-vue");
const lodashEs = require("lodash-es");
const utils = require("@yanzhen-libs/utils");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
__name: "InnerTreeSelect",
props: {
"value": { default: [] },
"valueModifiers": {}
},
emits: ["update:value"],
setup(__props) {
const value = vue.useModel(__props, "value");
const currentValue = vue.ref([]);
const attrs = vue.useAttrs();
const keyMaps = vue.computed(() => {
var _a, _b;
return {
...attrs["field-names"] || {},
value: ((_a = attrs["field-names"]) == null ? void 0 : _a.value) || "id",
label: ((_b = attrs["field-names"]) == null ? void 0 : _b.label) || "label"
};
});
const treeCheckStrictly = vue.computed(() => attrs["tree-check-strictly"] || false);
const cacheMap = /* @__PURE__ */ new Map([]);
vue.watch(
value,
(newVal, oldVal) => {
if (lodashEs.isEmpty(newVal) || lodashEs.isEqual(newVal, oldVal) || lodashEs.isEqual(newVal, currentValue.value)) {
return;
}
if (vue.toValue(treeCheckStrictly)) {
newVal == null ? void 0 : newVal.forEach((item) => {
if (cacheMap.get(item)) {
currentValue.value.push(cacheMap.get(item));
} else {
const targetNode = utils.dfsFindNodeById(attrs["tree-data"], item);
if (newVal && targetNode) {
const nodeObj = {
label: targetNode[vue.toValue(keyMaps).label],
value: targetNode[vue.toValue(keyMaps).value],
disabled: void 0,
halfChecked: void 0
};
currentValue.value.push(nodeObj);
cacheMap.set(item, nodeObj);
}
}
});
}
},
{
immediate: true
}
);
vue.watch(currentValue, (newVal, oldVal) => {
if (lodashEs.isEqual(newVal, oldVal)) {
return;
}
if (vue.toValue(treeCheckStrictly)) {
value.value = newVal.map((item) => item["value"]);
}
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.TreeSelect), vue.mergeProps({
value: currentValue.value,
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => currentValue.value = $event)
}, _ctx.$attrs), null, 16, ["value"]);
};
}
});
exports.default = _sfc_main;