Files
zhibo/node_modules/ele-admin/es/ele-pro-layout/index.js
T
xiaoyu 5488f5f0a2 init
2023-05-22 14:07:59 +08:00

686 lines
24 KiB
JavaScript

import { LicenseMixin } from "../utils/license-util";
import { screenWidth, formatTreeData } from "../utils/core";
import ProHeader from "./components/pro-header";
import ProSidebar from "./components/pro-sidebar";
import ProSidebarNav from "./components/pro-sidebar-nav";
import ProTabBar from "./components/pro-tab-bar";
import { CONTENT_SELECTOR, isHomeRoute, getRouteMatched, getMatchedLevels, getMatchedComponents, findTabByPath, menuTitleI18n, getRouteMenu, useWindowListener } from "./util";
import props from "./props";
function normalizeComponent(scriptExports, render2, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
if (render2) {
options.render = render2;
options.staticRenderFns = staticRenderFns;
options._compiled = true;
}
if (functionalTemplate) {
options.functional = true;
}
if (scopeId) {
options._scopeId = "data-v-" + scopeId;
}
var hook;
if (moduleIdentifier) {
hook = function(context) {
context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
context = __VUE_SSR_CONTEXT__;
}
if (injectStyles) {
injectStyles.call(this, context);
}
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
options._ssrRegister = hook;
} else if (injectStyles) {
hook = shadowMode ? function() {
injectStyles.call(
this,
(options.functional ? this.parent : this).$root.$options.shadowRoot
);
} : injectStyles;
}
if (hook) {
if (options.functional) {
options._injectStyles = hook;
var originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
} else {
var existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return {
exports: scriptExports,
options
};
}
const _sfc_main = {
name: "EleProLayout",
mixins: [LicenseMixin],
components: {
ProHeader,
ProSidebar,
ProSidebarNav,
ProTabBar
},
props,
emits: [
"update:collapse",
"update:side-nav-collapse",
"update:body-fullscreen",
"tab-add",
"tab-remove",
"tab-remove-all",
"tab-remove-left",
"tab-remove-right",
"tab-remove-other",
"tab-dropdown-menu",
"tab-context-menu",
"logo-click",
"reload-page",
"screen-size-change",
"set-home-components",
"head-menu-open",
"head-menu-close",
"side-menu-open",
"side-menu-close",
"side-nav-open",
"side-nav-close",
"update-document-title"
],
provide() {
return {
proLayout: this.layoutData
};
},
data() {
var _a;
const isMobile = this.styleResponsive ? screenWidth() < 768 : false;
return {
isMobile,
CONTENT_SELECTOR,
removeWindowListener: null,
menuData: [],
tabData: [],
levelData: [],
sideNavData: [],
sideNavActive: null,
sideMenuData: [],
sideMenuActive: null,
headMenuData: [],
headMenuActive: null,
tabActive: this.homePath,
hideSidebar: false,
hideFooter: false,
homeRouteTitle: (_a = this.homeTitle) != null ? _a : "",
backTopEnable: this.showBackTop,
layoutData: {
isMobile,
collapse: this.collapse,
sideNavCollapse: this.sideNavCollapse,
isTopMenu: this.layoutStyle === "top",
isMixSideMenu: this.sideMenuStyle === "mix",
bodyFullscreen: this.bodyFullscreen,
contentFullscreen: this.contentFullscreen,
showTabs: this.showTabs,
styleResponsive: this.styleResponsive,
haveSideMenuData: false
}
};
},
computed: {
isTopMenu() {
return this.layoutStyle === "top";
},
isMixMenu() {
return this.layoutStyle === "mix";
},
isMixSideMenu() {
return this.sideMenuStyle === "mix";
},
showSideNav() {
return !(!this.isMixSideMenu || this.isMobile || this.isTopMenu || this.sideNavData.length === 0 && this.menuData.length !== 0 || this.hideSidebar);
},
showSideMenu() {
const haveSideMenu = this.sideMenuData.filter((d) => {
var _a;
return !((_a = d.meta) == null ? void 0 : _a.hide);
}).length === 0;
return this.isMobile || !(this.isTopMenu || haveSideMenu && this.menuData.length !== 0 || this.hideSidebar);
},
showSidebar() {
return this.showSideNav || this.showSideMenu;
},
layoutClass() {
return [
"ele-admin-layout",
{ "ele-admin-collapse": this.collapse },
{ "ele-admin-fixed-header": this.fixedHeader && !this.fixedBody },
{
"ele-admin-fixed-sidebar": this.fixedSidebar && !this.fixedBody && this.showSidebar
},
{ "ele-admin-fixed-body": this.fixedBody },
{ "ele-admin-head-dark": this.headStyle !== "light" },
{ "ele-admin-side-dark": this.sideStyle === "dark" },
{ "ele-admin-side-mix": this.isMixSideMenu && this.showSideNav },
{ "ele-admin-side-colorful": this.colorfulIcon },
{
"ele-admin-logo-auto": (this.logoAutoSize || this.isTopMenu || !this.showSidebar) && !this.isMobile
},
{ "ele-admin-show-tabs": this.showTabs },
{ "ele-admin-tab-dot": this.tabStyle === "dot" },
{ "ele-admin-tab-card": this.tabStyle === "card" },
{ "ele-admin-body-limit": !this.bodyFull },
{ "ele-admin-body-fullscreen": this.bodyFullscreen },
{
"ele-admin-content-fullscreen": this.bodyFullscreen && this.contentFullscreen
},
{
"ele-admin-nav-collapse": this.sideNavCollapse && this.showSideNav
},
{ "ele-admin-responsive": this.styleResponsive }
];
},
sideMenuCollapse() {
return this.isMobile || this.isMixSideMenu ? false : this.collapse;
},
sideNavThemeClass() {
return this.sideStyle === "dark" ? "ele-menu-dark" : "";
},
sideMenuThemeClass() {
return this.isMixSideMenu && !this.isMobile ? "" : this.sideNavThemeClass;
},
showHeadLeftTool() {
return this.isMobile || !this.isTopMenu;
},
showTabRefresh() {
return this.bodyFullscreen || this.isTopMenu && !this.isMobile;
}
},
methods: {
updateCollapse(value) {
const collapse = typeof value === "boolean" ? value : !this.collapse;
this.$emit("update:collapse", collapse);
this.$emit("update-collapse", collapse);
},
updateSideNavCollapse(value) {
const collapse = typeof value === "boolean" ? value : !this.sideNavCollapse;
this.$emit("update:side-nav-collapse", collapse);
},
updateBodyFullscreen(value) {
const fullscreen = typeof value === "boolean" ? value : !this.bodyFullscreen;
this.$emit("update:body-fullscreen", fullscreen);
},
onTabChange({ fullPath, key }) {
const path = fullPath || key;
if (path) {
this.$router.push(path);
}
},
tabAdd(data) {
this.$emit("tab-add", data);
},
onTabRemove(option) {
this.$emit("tab-remove", option);
},
onTabRemoveLeft(option) {
this.$emit("tab-remove-left", option);
},
onTabRemoveRight(option) {
this.$emit("tab-remove-right", option);
},
onTabRemoveOther(option) {
this.$emit("tab-remove-other", option);
},
onTabRemoveAll(active) {
this.$emit("tab-remove-all", active);
},
onTabDropdownMenu(option) {
this.$emit("tab-dropdown-menu", option);
},
onTabContextMenu(option) {
this.$emit("tab-context-menu", option);
},
reloadPage() {
this.$emit("reload-page");
},
onLogoClick() {
this.$emit(
"logo-click",
isHomeRoute(this.$route, this.homePath, this.layoutPath)
);
},
onSideMenuOpen(index2, indexPath) {
this.$emit("side-menu-open", index2, indexPath);
},
onSideMenuClose(index2, indexPath) {
this.$emit("side-menu-close", index2, indexPath);
},
onSideNavOpen(index2, indexPath) {
this.$emit("side-nav-open", index2, indexPath);
},
onSideNavClose(index2, indexPath) {
this.$emit("side-nav-close", index2, indexPath);
},
onHeadMenuOpen(index2, indexPath) {
this.$emit("head-menu-open", index2, indexPath);
},
onHeadMenuClose(index2, indexPath) {
this.$emit("head-menu-close", index2, indexPath);
},
getContentElem() {
return this.$refs.contentRef;
},
onRouteChange(current) {
var _a, _b, _c;
const { path, fullPath, meta } = current;
const contentEl = this.getContentElem();
if (this.autoScrollTop && contentEl) {
contentEl.scrollTop = 0;
}
if ((_a = this.hideSidebars) == null ? void 0 : _a.includes(path)) {
this.hideSidebar = true;
} else {
this.hideSidebar = !!meta.hideSidebar;
}
if ((_b = this.hideFooters) == null ? void 0 : _b.includes(path)) {
this.hideFooter = true;
} else {
this.hideFooter = !!meta.hideFooter;
}
if (path.includes(this.redirectPath)) {
return;
}
this.setDocumentTitle(path, fullPath);
const { active, matched, title, activeOther } = getRouteMatched(
path,
fullPath,
meta,
this.menuData
);
const isHome = isHomeRoute(current, this.homePath, this.layoutPath);
this.levelData = getMatchedLevels(
isHome,
this.homePath,
this.homeRouteTitle,
matched,
activeOther,
this.routeI18n,
path,
fullPath,
meta,
this.menuData,
this.tabData
);
const components = getMatchedComponents(current.matched);
if (isHome) {
this.tabActive = this.homePath;
this.$emit("set-home-components", components);
} else {
const isUnique = meta.tabUnique === false || ((_c = this.repeatableTabs) == null ? void 0 : _c.includes(path));
const key = isUnique ? fullPath : path;
if (meta.title) {
this.tabAdd({
key,
path,
fullPath,
components,
closable: meta.closable !== false,
title,
meta
});
}
this.tabActive = key;
}
this.updateMenuActive(active, matched);
if (this.isMixMenu || this.isMixSideMenu) {
this.splitMenuData();
}
if (this.styleResponsive && this.isMobile) {
this.updateCollapse(true);
}
},
updateMenuActive(active, matched) {
const { active1, active2 } = (() => {
if (!(matched == null ? void 0 : matched.length)) {
return { active1: void 0, active2: void 0 };
}
const match1 = matched[0];
const match2 = matched.length > 1 ? matched[1] : match1;
return { active1: match1.path, active2: match2.path };
})();
if (this.isTopMenu) {
this.headMenuActive = active;
this.sideNavActive = null;
} else if (this.isMixMenu) {
this.headMenuActive = active1;
this.sideNavActive = active2;
} else {
this.headMenuActive = null;
this.sideNavActive = active1;
}
this.sideMenuActive = active;
},
splitMenuData() {
var _a;
if (!((_a = this.menuData) == null ? void 0 : _a.length)) {
this.headMenuData = [];
this.sideNavData = [];
this.sideMenuData = [];
} else if (this.isMobile) {
this.headMenuData = [];
this.sideNavData = [];
this.sideMenuData = this.menuData;
} else if (this.isTopMenu) {
this.headMenuData = this.menuData;
this.sideNavData = [];
this.sideMenuData = [];
} else if (this.isMixMenu) {
this.headMenuData = this.menuData.map((d) => {
return { path: d.path, component: d.component, meta: d.meta };
});
const sideMenus = (() => {
const temp = this.headMenuActive ? this.menuData.filter((d) => {
return this.headMenuActive === d.path;
}) : [];
return (temp.length ? temp[0].children : this.menuData[0].children) || [];
})();
if (!sideMenus.length) {
this.sideNavData = [];
this.sideMenuData = [];
} else if (this.isMixSideMenu) {
this.sideNavData = sideMenus.map((d) => {
return {
path: d.path,
component: d.component,
meta: d.meta,
children: this.collapse ? d.children : null,
tempChildren: d.children
};
});
const temps = this.sideNavActive ? sideMenus.filter((d) => {
return this.sideNavActive === d.path;
}) : [];
this.sideMenuData = (temps.length ? temps[0].children : sideMenus[0].children) || [];
} else {
this.sideNavData = [];
this.sideMenuData = sideMenus;
}
} else {
this.headMenuData = [];
if (this.isMixSideMenu) {
this.sideNavData = this.menuData.map((d) => {
return {
path: d.path,
component: d.component,
meta: d.meta,
children: this.collapse ? d.children : null,
tempChildren: d.children
};
});
const temps = this.sideNavActive ? this.menuData.filter((d) => {
return this.sideNavActive === d.path;
}) : [];
this.sideMenuData = (temps.length ? temps[0].children : this.menuData[0].children) || [];
} else {
this.sideNavData = [];
this.sideMenuData = this.menuData;
}
}
},
updateMenuData() {
var _a, _b;
let tempTitle;
this.menuData = formatTreeData(this.menus, (item) => {
var _a2, _b2;
const title = (_a2 = item.meta) == null ? void 0 : _a2.title;
if (!tempTitle && !((_b2 = item.children) == null ? void 0 : _b2.length)) {
tempTitle = title;
}
return {
...item,
meta: {
...item.meta,
title: this.routeI18n(item.path, item) || title
}
};
});
this.splitMenuData();
this.homeRouteTitle = (_b = (_a = this.homeTitle) != null ? _a : tempTitle) != null ? _b : "";
},
updateTabData() {
this.tabData = this.tabs.map((item) => {
return {
...item,
title: this.routeI18n(item.path) || item.title
};
});
},
updateLevelData() {
this.levelData = this.levelData.map((d) => {
const title = (() => {
if (d.home) {
return this.homeRouteTitle;
}
const t = findTabByPath(d.fullPath, this.tabData);
return this.routeI18n(d.path) || (t == null ? void 0 : t.title) || d.title;
})();
return { ...d, title };
});
},
routeI18n(path, menu) {
return menuTitleI18n({
path,
locale: this.locale,
i18n: this.i18n,
menu,
menus: this.menuData
});
},
screenIsMobile() {
return this.styleResponsive ? screenWidth() < 768 : false;
},
setDocumentTitle(path, fullPath) {
var _a;
const m = getRouteMenu(path, fullPath, this.menuData);
const t = findTabByPath(fullPath, this.tabData);
this.$emit(
"update-document-title",
this.routeI18n((m == null ? void 0 : m.path) || path, m) || (t == null ? void 0 : t.title) || ((_a = m == null ? void 0 : m.meta) == null ? void 0 : _a.title)
);
}
},
watch: {
menus: {
handler() {
this.updateMenuData();
},
deep: true
},
tabs: {
handler() {
this.updateTabData();
this.updateLevelData();
},
deep: true
},
homeTitle(value) {
if (value) {
this.homeRouteTitle = value;
} else {
this.updateMenuData();
}
this.updateTabData();
this.updateLevelData();
},
layoutStyle(layoutStyle) {
this.layoutData.isTopMenu = layoutStyle === "top";
const { path, fullPath, meta } = this.$route;
const { active, matched } = getRouteMatched(
path,
fullPath,
meta,
this.menuData
);
this.updateMenuActive(active, matched);
this.splitMenuData();
},
sideMenuStyle(sideMenuStyle) {
this.layoutData.isMixSideMenu = sideMenuStyle === "mix";
this.splitMenuData();
},
isMobile(isMobile) {
this.layoutData.isMobile = isMobile;
this.splitMenuData();
},
collapse(collapse) {
this.layoutData.collapse = collapse;
if (this.isMixSideMenu) {
if (collapse) {
this.sideNavData = this.sideNavData.map((d) => {
return { ...d, children: d.tempChildren };
});
} else {
this.sideNavData = this.sideNavData.map((d) => {
return { ...d, children: null };
});
}
}
},
sideNavCollapse(sideNavCollapse) {
this.layoutData.sideNavCollapse = sideNavCollapse;
},
locale: {
handler() {
this.updateMenuData();
this.updateTabData();
this.updateLevelData();
const { path, fullPath } = this.$route;
this.setDocumentTitle(path, fullPath);
},
immediate: true
},
fixedBody() {
if (this.showBackTop) {
this.backTopEnable = false;
}
this.$nextTick(() => {
var _a, _b;
(_a = this.$refs.sidebar) == null ? void 0 : _a.updateScrollbar();
(_b = this.$refs.sidebarNav) == null ? void 0 : _b.updateScrollbar();
this.backTopEnable = this.showBackTop;
});
},
fixedSidebar() {
this.$nextTick(() => {
var _a, _b;
(_a = this.$refs.sidebar) == null ? void 0 : _a.updateScrollbar();
(_b = this.$refs.sidebarNav) == null ? void 0 : _b.updateScrollbar();
});
},
fixedHeader() {
this.$nextTick(() => {
var _a, _b;
(_a = this.$refs.sidebar) == null ? void 0 : _a.updateScrollbar();
(_b = this.$refs.sidebarNav) == null ? void 0 : _b.updateScrollbar();
});
},
showBackTop() {
this.backTopEnable = this.showBackTop;
},
bodyFullscreen(bodyFullscreen) {
this.layoutData.bodyFullscreen = bodyFullscreen;
},
contentFullscreen(contentFullscreen) {
this.layoutData.contentFullscreen = contentFullscreen;
},
showTabs(showTabs) {
this.layoutData.showTabs = showTabs;
},
styleResponsive(styleResponsive) {
this.layoutData.styleResponsive = styleResponsive;
this.isMobile = this.screenIsMobile();
},
sideMenuData(sideMenuData) {
this.layoutData.haveSideMenuData = sideMenuData.length > 0;
},
$route: {
handler(route) {
this.onRouteChange(route);
},
immediate: true
}
},
created() {
this.removeWindowListener = useWindowListener({
onResize: () => {
var _a, _b, _c;
const isMobileTemp = this.screenIsMobile();
if (isMobileTemp) {
if (!this.isMobile && !this.collapse) {
this.updateCollapse(true);
}
} else if (this.isMobile && this.collapse) {
this.updateCollapse(false);
}
this.isMobile = isMobileTemp;
(_a = this.$refs.header) == null ? void 0 : _a.updateScrollbar();
(_b = this.$refs.sidebar) == null ? void 0 : _b.updateScrollbar();
(_c = this.$refs.sidebarNav) == null ? void 0 : _c.updateScrollbar();
this.$emit("screen-size-change");
this.$emit("update-screen");
},
onEscKeydown: (e) => {
if (this.fullscreenExitOnEsc && this.bodyFullscreen) {
e.stopPropagation();
this.updateBodyFullscreen(false);
}
}
});
},
beforeDestroy() {
this.removeWindowListener && this.removeWindowListener();
}
};
var _sfc_render = function render() {
var _vm = this, _c = _vm._self._c;
return _vm.authenticated ? _c("div", { class: _vm.layoutClass }, [_c("ProHeader", { ref: "header", attrs: { "levels": _vm.levelData, "collapse": _vm.collapse, "menus": _vm.headMenuData, "head-style": _vm.headStyle, "active": _vm.headMenuActive, "project-name": _vm.projectName, "show-refresh": _vm.showRefresh, "show-left-tool": _vm.showHeadLeftTool, "breadcrumb-separator": _vm.breadcrumbSeparator, "show-collapse": _vm.showCollapse && _vm.showSideMenu, "show-breadcrumb": _vm.showBreadcrumb && _vm.layoutStyle === "side" }, on: { "toggle-collapse": _vm.updateCollapse, "reload-page": _vm.reloadPage, "logo-click": _vm.onLogoClick, "clsoe": _vm.onHeadMenuClose, "open": _vm.onHeadMenuOpen }, scopedSlots: _vm._u([_vm._l(Object.keys(_vm.$scopedSlots), function(name) {
return { key: name, fn: function(props2) {
return [_vm._t(name, null, null, props2 || {})];
} };
})], null, true) }), _c("div", { staticClass: "ele-admin-main" }, [_vm.showSideNav ? _c("ProSidebarNav", { ref: "sidebarNav", attrs: { "data": _vm.sideNavData, "collapse": _vm.sideNavCollapse, "theme-class": _vm.sideNavThemeClass, "show-nav-collapse": _vm.showNavCollapse, "active": _vm.collapse ? _vm.sideMenuActive : _vm.sideNavActive }, on: { "toggle-collapse": _vm.updateSideNavCollapse, "clsoe": _vm.onSideNavClose, "open": _vm.onSideNavOpen }, scopedSlots: _vm._u([_vm._l(Object.keys(_vm.$scopedSlots), function(name) {
return { key: name, fn: function(props2) {
return [_vm._t(name, null, null, props2 || {})];
} };
})], null, true) }) : _vm._e(), _vm.showSideMenu ? _c("ProSidebar", { ref: "sidebar", attrs: { "data": _vm.sideMenuData, "active": _vm.sideMenuActive, "collapse": _vm.sideMenuCollapse, "unique-open": _vm.sideUniqueOpen, "theme-class": _vm.sideMenuThemeClass, "default-openeds": _vm.sideDefaultOpeneds }, on: { "clsoe": _vm.onSideMenuClose, "open": _vm.onSideMenuOpen }, scopedSlots: _vm._u([_vm._l(Object.keys(_vm.$scopedSlots), function(name) {
return { key: name, fn: function(props2) {
return [_vm._t(name, null, null, props2 || {})];
} };
})], null, true) }) : _vm._e(), _c("div", { staticClass: "ele-admin-body" }, [_vm.showTabs ? _c("ProTabBar", { attrs: { "tabs": _vm.tabData, "active": _vm.tabActive, "home-path": _vm.homePath, "home-title": _vm.homeRouteTitle, "click-reload": _vm.clickReload, "show-refresh": _vm.showTabRefresh, "body-fullscreen": _vm.bodyFullscreen, "tab-context-menu": _vm.tabContextMenu }, on: { "tab-change": _vm.onTabChange, "tab-remove": _vm.onTabRemove, "tab-remove-all": _vm.onTabRemoveAll, "tab-remove-left": _vm.onTabRemoveLeft, "tab-remove-right": _vm.onTabRemoveRight, "tab-remove-other": _vm.onTabRemoveOther, "fullscreen-body": _vm.updateBodyFullscreen, "dropdown-menu": _vm.onTabDropdownMenu, "context-menu": _vm.onTabContextMenu, "reload-page": _vm.reloadPage }, scopedSlots: _vm._u([_vm._l(Object.keys(_vm.$scopedSlots), function(name) {
return { key: name, fn: function(props2) {
return [_vm._t(name, null, null, props2 || {})];
} };
})], null, true) }) : _vm._e(), _c("div", { ref: "contentRef", staticClass: "ele-admin-content" }, [_c("div", { staticClass: "ele-admin-content-view" }, [_vm._t("default")], 2), _vm.showFooter && !_vm.hideFooter ? [_vm._t("footer")] : _vm._e()], 2)], 1)], 1), _c("div", { staticClass: "ele-admin-shade", on: { "click": _vm.updateCollapse } }), _vm.backTopEnable ? _c("el-backtop", { attrs: { "right": _vm.backTopRight, "bottom": _vm.backTopBottom, "visibility-height": _vm.backTopVisibilityHeight, "target": _vm.fixedBody ? _vm.CONTENT_SELECTOR : void 0 } }) : _vm._e()], 1) : _vm._e();
};
var _sfc_staticRenderFns = [];
var __component__ = /* @__PURE__ */ normalizeComponent(
_sfc_main,
_sfc_render,
_sfc_staticRenderFns,
false,
null,
null,
null,
null
);
const index = __component__.exports;
export {
index as default
};