yanzhen-design-vue
Version:
181 lines (180 loc) • 8.76 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const antDesignVue = require("ant-design-vue");
const index = require("../../../list/index.cjs");
const utilsVue = require("@yanzhen-libs/utils-vue");
require("../item/contacts-item.vue.cjs");
const useContactsSelectedData = require("../hook/use-contacts-selected-data.cjs");
const contactsItem = require("../item/contacts-item.cjs");
const contactsGroup = require("./contacts-group.cjs");
const contactsItem_vue_vue_type_script_setup_true_lang = require("../item/contacts-item.vue2.cjs");
const _hoisted_1 = { key: 1 };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
...{
name: contactsGroup.contactsGroupName
},
__name: "contacts-group",
props: contactsGroup.contactsGroupProps,
emits: contactsGroup.contactsGroupEmits,
setup(__props, { emit: __emit }) {
const { ns } = contactsGroup.contactsGroupOptions;
const props = __props;
const emit = __emit;
const { disableIds, dataSource } = vue.toRefs(props);
const activeKey = vue.ref();
const { selectedGroup } = useContactsSelectedData.useContactsSelectedGroup(dataSource);
const watcher = utilsVue.createWatcher();
watcher.set("activeKey", {
source: () => vue.unref(dataSource).length,
handler() {
if (!props.allExpand) {
const list = [...vue.unref(selectedGroup)].reverse();
const find = list.find(
({ value, children }) => value !== "-1" && children && children.length > 0
);
activeKey.value = find == null ? void 0 : find.value;
} else {
activeKey.value = [...vue.unref(selectedGroup)].map(({ value }) => value);
}
},
immediate: true,
deep: true,
debounce: 1e3
});
function handleItemClick(item) {
if (props.onItemClick) {
props.onItemClick(item);
} else {
emit("item-click", item);
}
}
function handleSuffixClick(item) {
if (props.onSuffixClick) {
props.onSuffixClick(item);
} else {
emit("suffix-click", item);
}
}
vue.onUnmounted(() => {
watcher.stop();
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Flex), {
vertical: "",
class: vue.normalizeClass([vue.unref(ns).b()]),
gap: 10
}, {
default: vue.withCtx(() => [
_ctx.$slots.title ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: vue.normalizeClass([vue.unref(ns).e("selected-title")])
}, [
vue.renderSlot(_ctx.$slots, "title")
], 2)) : vue.createCommentVNode("", true),
vue.createVNode(vue.unref(antDesignVue.Flex), {
flex: 1,
class: vue.normalizeClass([vue.unref(ns).e("main")])
}, {
default: vue.withCtx(() => [
Boolean(_ctx.$slots.loading || props.loading) ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: vue.normalizeClass([vue.unref(ns).e("main-loading")])
}, [
_ctx.$slots.loading ? vue.renderSlot(_ctx.$slots, "loading", { key: 0 }) : (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Spin), { key: 1 }))
], 2)) : vue.createCommentVNode("", true),
Boolean(_ctx.$slots.empty || props.emptyText) && vue.unref(dataSource).length === 0 ? (vue.openBlock(), vue.createElementBlock("div", {
key: 1,
class: vue.normalizeClass([vue.unref(ns).e("main-empty")])
}, [
_ctx.$slots.empty ? vue.renderSlot(_ctx.$slots, "empty", { key: 0 }) : (vue.openBlock(), vue.createElementBlock("span", _hoisted_1, vue.toDisplayString(props.emptyText), 1))
], 2)) : vue.createCommentVNode("", true),
vue.createVNode(vue.unref(antDesignVue.Collapse), {
"active-key": activeKey.value,
"onUpdate:activeKey": _cache[0] || (_cache[0] = ($event) => activeKey.value = $event),
class: vue.normalizeClass([vue.unref(ns).e("collapse")]),
"expand-icon-position": "end",
ghost: true,
accordion: false,
bordered: false,
"destroy-inactive-panel": false
}, {
default: vue.withCtx(() => [
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(selectedGroup), (item) => {
return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
item.children.length > 0 ? (vue.openBlock(), vue.createBlock(vue.unref(antDesignVue.Collapse).Panel, {
key: item.value,
header: item.label
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(index.YzList), {
class: vue.normalizeClass([vue.unref(ns).e("list-item")]),
loading: false,
"data-source": item.children,
height: "auto"
}, {
default: vue.withCtx(({ item: listItem }) => {
var _a, _b;
return [
listItem ? (vue.openBlock(), vue.createBlock(contactsItem_vue_vue_type_script_setup_true_lang.default, vue.mergeProps({
key: listItem.value,
type: listItem.type,
style: listItem.style,
ref_for: true
}, vue.unref(contactsItem.contactsItemOmitProps)(listItem), {
class: [
{
[vue.unref(ns).is("item-hover")]: props.onItemClick,
[vue.unref(ns).is("item-suffix-hover")]: props.onSuffixClick,
[vue.unref(ns).is("disabled")]: vue.unref(disableIds).includes(item.value)
},
listItem.class
],
onItemClick: ($event) => handleItemClick(listItem),
onSuffixClick: ($event) => handleSuffixClick(listItem)
}), vue.createSlots({ _: 2 }, [
((_a = _ctx.$slots) == null ? void 0 : _a.default) ? {
name: "default",
fn: vue.withCtx((slotProps) => [
vue.renderSlot(_ctx.$slots, "default", vue.mergeProps({
panel: item,
item: listItem,
ref_for: true
}, slotProps ?? {}))
]),
key: "0"
} : void 0,
((_b = _ctx.$slots) == null ? void 0 : _b.suffix) ? {
name: "suffix",
fn: vue.withCtx((slotProps) => [
vue.renderSlot(_ctx.$slots, "suffix", vue.mergeProps({
panel: item,
item: listItem,
ref_for: true
}, slotProps ?? {}))
]),
key: "1"
} : void 0
]), 1040, ["type", "style", "class", "onItemClick", "onSuffixClick"])) : vue.createCommentVNode("", true)
];
}),
_: 2
}, 1032, ["class", "data-source"])
]),
_: 2
}, 1032, ["header"])) : vue.createCommentVNode("", true)
], 64);
}), 256))
]),
_: 3
}, 8, ["active-key", "class"])
]),
_: 3
}, 8, ["class"])
]),
_: 3
}, 8, ["class"]);
};
}
});
exports.default = _sfc_main;