yanzhen-design-vue
Version:
69 lines (68 loc) • 2.97 kB
JavaScript
import { defineComponent, openBlock, createElementBlock, Fragment, renderList, unref, normalizeClass, createVNode, withModifiers, createElementVNode, toDisplayString, createBlock, createCommentVNode } from "vue";
import { Checkbox } from "ant-design-vue";
import { RightOutlined } from "@ant-design/icons-vue";
import { useInjectInnerCascader } from "./context.mjs";
import { isLeaf } from "./utils.mjs";
const _hoisted_1 = { class: "inner-cascader-menu" };
const _hoisted_2 = ["onClick"];
const _hoisted_3 = ["title"];
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "Column",
props: {
options: {},
prevValuePath: {},
activeValue: {},
checkedSet: { default: () => /* @__PURE__ */ new Set() },
halfCheckedSet: { default: () => /* @__PURE__ */ new Set() }
},
emits: ["active", "select"],
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const { fieldNames } = useInjectInnerCascader();
const triggerOpenPath = (e, fullPath, isLeaf2) => {
e.preventDefault();
emit("active", fullPath);
if (isLeaf2) {
triggerSelect(fullPath);
}
};
const triggerSelect = (fullPath) => {
emit("select", fullPath);
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock("ul", _hoisted_1, [
(openBlock(true), createElementBlock(Fragment, null, renderList(props.options, (option, index) => {
var _a;
return openBlock(), createElementBlock("li", {
key: option[unref(fieldNames).value] || index,
class: normalizeClass(["inner-cascader-menu-item", { active: props.activeValue === option[unref(fieldNames).value] }]),
onClick: (e) => triggerOpenPath(
e,
[...props.prevValuePath, option[unref(fieldNames).value]],
unref(isLeaf)(option, unref(fieldNames))
)
}, [
createVNode(unref(Checkbox), {
class: "inner-cascader-checkbox",
checked: props.checkedSet.has(option[unref(fieldNames).value]),
indeterminate: props.halfCheckedSet.has(option[unref(fieldNames).value]),
onClick: withModifiers(($event) => triggerSelect([...props.prevValuePath, option[unref(fieldNames).value]]), ["stop"])
}, null, 8, ["checked", "indeterminate", "onClick"]),
createElementVNode("div", {
class: "inner-cascader-item-content",
title: option[unref(fieldNames).label]
}, toDisplayString(option[unref(fieldNames).label]), 9, _hoisted_3),
((_a = option[unref(fieldNames).children]) == null ? void 0 : _a.length) ? (openBlock(), createBlock(unref(RightOutlined), {
key: 0,
class: "inner-cascader-item-expand-icon"
})) : createCommentVNode("", true)
], 10, _hoisted_2);
}), 128))
]);
};
}
});
export {
_sfc_main as default
};