plus-pro-components
Version:
Page level components developed based on Element Plus.
281 lines (278 loc) • 12.5 kB
JavaScript
import { defineComponent, useAttrs, getCurrentInstance, resolveComponent, openBlock, createElementBlock, Fragment, createCommentVNode, createBlock, unref, withCtx, createElementVNode, resolveDynamicComponent, normalizeProps, mergeProps, renderSlot, guardReactiveProps, createTextVNode, toDisplayString, renderList, createSlots } from 'vue';
import { ElMenuItem, ElIcon, ElSubMenu } from 'element-plus';
import { removeChildrenField } from '../../utils/index.mjs';
import { isFunction, isUrl } from '../../utils/is.mjs';
const _hoisted_1 = { class: "plus-sidebar__item-title" };
const _hoisted_2 = { class: "plus-sidebar__item-title" };
var _sfc_main = /* @__PURE__ */ defineComponent({
...{
name: "PlusSidebarItem",
inheritAttrs: false
},
__name: "sidebar-item",
props: {
parent: {},
item: {},
collapse: { type: Boolean, default: false },
renderMenuItem: { type: Function, default: void 0 },
renderSubMenuItem: { type: Function, default: void 0 },
renderTitle: { type: Function, default: void 0 }
},
setup(__props) {
const props = __props;
const onClickMenuItem = useAttrs().onClickMenuItem;
const instance = getCurrentInstance();
const router = instance.appContext.config.globalProperties.$router;
const resolveMenuItem = (item) => {
var _a;
if (!((_a = item.children) == null ? void 0 : _a.length)) return true;
const children = item.children.filter((i) => {
var _a2;
return ((_a2 = i.meta) == null ? void 0 : _a2.hideInMenu) !== true;
});
if (!children.length) {
return true;
}
return false;
};
const replacePath = (path) => path.replace("/http", "http");
const getIndex = (item) => {
return item.redirect || item.path;
};
const handleClickItem = (item) => {
if (isFunction(onClickMenuItem)) {
onClickMenuItem(item, props.parent);
return;
}
if (isUrl(replacePath(item.path))) {
const url = replacePath(item.path);
window.open(url);
} else {
router && router.push(getIndex(item));
}
};
return (_ctx, _cache) => {
var _a, _b;
const _component_PlusSidebarItem = resolveComponent("PlusSidebarItem");
return ((_a = _ctx.item.meta) == null ? void 0 : _a.hideInMenu) !== true ? (openBlock(), createElementBlock(
Fragment,
{ key: 0 },
[
createCommentVNode(" \u6CA1\u6709\u5B50\u83DC\u5355\u7684\u60C5\u51B5 "),
resolveMenuItem(_ctx.item) ? (openBlock(), createBlock(unref(ElMenuItem), {
key: getIndex(_ctx.item),
class: "plus-sidebar__item",
index: getIndex(_ctx.item),
disabled: (_b = _ctx.item.meta) == null ? void 0 : _b.disabled,
onClick: _cache[0] || (_cache[0] = ($event) => handleClickItem(_ctx.item))
}, {
title: withCtx(() => {
var _a2;
return [
createElementVNode("span", _hoisted_1, [
_ctx.renderTitle && unref(isFunction)(_ctx.renderTitle) ? (openBlock(), createBlock(
resolveDynamicComponent(_ctx.renderTitle),
normalizeProps(mergeProps({ key: 0 }, unref(removeChildrenField)(_ctx.item))),
null,
16
/* FULL_PROPS */
)) : _ctx.$slots["sidebar-item-title"] ? (openBlock(), createElementBlock(
Fragment,
{ key: 1 },
[
createCommentVNode(" menu-item title \u63D2\u69FD "),
renderSlot(_ctx.$slots, "sidebar-item-title", normalizeProps(guardReactiveProps(_ctx.item)))
],
2112
/* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
)) : (openBlock(), createElementBlock(
Fragment,
{ key: 2 },
[
createTextVNode(
toDisplayString(((_a2 = _ctx.item.meta) == null ? void 0 : _a2.title) || _ctx.item.name || _ctx.item.path),
1
/* TEXT */
)
],
64
/* STABLE_FRAGMENT */
))
])
];
}),
default: withCtx(() => [
_ctx.renderMenuItem && unref(isFunction)(_ctx.renderMenuItem) ? (openBlock(), createBlock(
resolveDynamicComponent(_ctx.renderMenuItem),
normalizeProps(mergeProps({ key: 0 }, unref(removeChildrenField)(_ctx.item))),
null,
16
/* FULL_PROPS */
)) : _ctx.$slots["sidebar-item"] ? (openBlock(), createElementBlock(
Fragment,
{ key: 1 },
[
createCommentVNode(" menu-item \u63D2\u69FD "),
renderSlot(_ctx.$slots, "sidebar-item", normalizeProps(guardReactiveProps(_ctx.item)))
],
2112
/* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
)) : _ctx.item.meta && _ctx.item.meta.icon ? (openBlock(), createBlock(unref(ElIcon), {
key: 2,
class: "plus-sidebar__item-icon"
}, {
default: withCtx(() => [
(openBlock(), createBlock(
resolveDynamicComponent(_ctx.item.meta.icon),
normalizeProps(guardReactiveProps(unref(removeChildrenField)(_ctx.item))),
null,
16
/* FULL_PROPS */
))
]),
_: 1
/* STABLE */
})) : createCommentVNode("v-if", true)
]),
_: 3
/* FORWARDED */
}, 8, ["index", "disabled"])) : (openBlock(), createElementBlock(
Fragment,
{ key: 1 },
[
createCommentVNode(" \u6709\u5B50\u83DC\u5355\u7684\u60C5\u51B5 "),
(openBlock(), createBlock(unref(ElSubMenu), {
key: getIndex(_ctx.item),
index: getIndex(_ctx.item),
class: "plus-sidebar__item-sub"
}, {
title: withCtx(() => {
var _a2, _b2;
return [
createCommentVNode(" \u81EA\u5B9A\u4E49\u663E\u793A "),
_ctx.renderSubMenuItem && unref(isFunction)(_ctx.renderSubMenuItem) ? (openBlock(), createBlock(
resolveDynamicComponent(_ctx.renderSubMenuItem),
normalizeProps(mergeProps({ key: 0 }, unref(removeChildrenField)(_ctx.item))),
null,
16
/* FULL_PROPS */
)) : _ctx.$slots["sidebar-sub"] ? (openBlock(), createElementBlock(
Fragment,
{ key: 1 },
[
createCommentVNode(" sub-menu \u63D2\u69FD "),
renderSlot(_ctx.$slots, "sidebar-sub", normalizeProps(guardReactiveProps(_ctx.item)))
],
2112
/* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
)) : ((_a2 = _ctx.item.meta) == null ? void 0 : _a2.icon) ? (openBlock(), createBlock(unref(ElIcon), {
key: 2,
class: "plus-sidebar__item-icon"
}, {
default: withCtx(() => {
var _a3;
return [
(openBlock(), createBlock(
resolveDynamicComponent((_a3 = _ctx.item.meta) == null ? void 0 : _a3.icon),
normalizeProps(guardReactiveProps(unref(removeChildrenField)(_ctx.item))),
null,
16
/* FULL_PROPS */
))
];
}),
_: 1
/* STABLE */
})) : createCommentVNode("v-if", true),
createElementVNode("span", _hoisted_2, [
_ctx.renderTitle && unref(isFunction)(_ctx.renderTitle) ? (openBlock(), createBlock(
resolveDynamicComponent(_ctx.renderTitle),
normalizeProps(mergeProps({ key: 0 }, unref(removeChildrenField)(_ctx.item))),
null,
16
/* FULL_PROPS */
)) : _ctx.$slots["sidebar-item-title"] ? (openBlock(), createElementBlock(
Fragment,
{ key: 1 },
[
createCommentVNode(" sub-menu title \u63D2\u69FD "),
renderSlot(_ctx.$slots, "sidebar-item-title", normalizeProps(guardReactiveProps(_ctx.item)))
],
2112
/* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
)) : (openBlock(), createElementBlock(
Fragment,
{ key: 2 },
[
createTextVNode(
toDisplayString(((_b2 = _ctx.item.meta) == null ? void 0 : _b2.title) || _ctx.item.name || _ctx.item.path),
1
/* TEXT */
)
],
64
/* STABLE_FRAGMENT */
))
])
];
}),
default: withCtx(() => [
(openBlock(true), createElementBlock(
Fragment,
null,
renderList(_ctx.item.children, (child) => {
return openBlock(), createBlock(_component_PlusSidebarItem, {
key: child.path,
item: child,
parent: _ctx.item,
collapse: _ctx.collapse,
"render-menu-item": _ctx.renderMenuItem,
"render-sub-menu-item": _ctx.renderSubMenuItem,
"render-title": _ctx.renderTitle,
onClickMenuItem: unref(onClickMenuItem)
}, createSlots({
_: 2
/* DYNAMIC */
}, [
_ctx.$slots["sidebar-item"] ? {
name: "sidebar-item",
fn: withCtx((data) => [
renderSlot(_ctx.$slots, "sidebar-item", normalizeProps(guardReactiveProps(data)))
]),
key: "0"
} : void 0,
_ctx.$slots["sidebar-sub"] ? {
name: "sidebar-sub",
fn: withCtx((data) => [
renderSlot(_ctx.$slots, "sidebar-sub", normalizeProps(guardReactiveProps(data)))
]),
key: "1"
} : void 0,
_ctx.$slots["sidebar-item-title"] ? {
name: "sidebar-item-title",
fn: withCtx((data) => [
renderSlot(_ctx.$slots, "sidebar-item-title", normalizeProps(guardReactiveProps(data)))
]),
key: "2"
} : void 0
]), 1032, ["item", "parent", "collapse", "render-menu-item", "render-sub-menu-item", "render-title", "onClickMenuItem"]);
}),
128
/* KEYED_FRAGMENT */
))
]),
_: 3
/* FORWARDED */
}, 8, ["index"]))
],
2112
/* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
))
],
64
/* STABLE_FRAGMENT */
)) : createCommentVNode("v-if", true);
};
}
});
export { _sfc_main as default };