Skip to content

Commit

Permalink
feat(breadcrumb): support showIcon (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: FuckDoctors <zhbchwin@163.com>
  • Loading branch information
FuckDoctors and ujn-bin committed Oct 22, 2020
1 parent cc6c938 commit 9668f67
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/layouts/default/LayoutBreadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ import { PageEnum } from '/@/enums/pageEnum';
import { isBoolean } from '/@/utils/is';

import { compile } from 'path-to-regexp';
import Icon from '/@/components/Icon';

export default defineComponent({
name: 'BasicBreadcrumb',
setup() {
props: {
showIcon: {
type: Boolean,
default: false,
},
},
setup(props) {
const itemList = ref<AppRouteRecordRaw[]>([]);
const { currentRoute, push } = useRouter();

Expand Down Expand Up @@ -78,7 +85,14 @@ export default defineComponent({
isLink={isLink}
onClick={handleItemClick.bind(null, item)}
>
{() => item.meta.title}
{() => (
<>
{props.showIcon && item.meta.icon && item.meta.icon.trim() !== '' && (
<Icon icon={item.meta.icon} class="icon mr-1 mb-1" />
)}
{item.meta.title}
</>
)}
</BreadcrumbItem>
);
});
Expand Down
3 changes: 2 additions & 1 deletion src/layouts/default/LayoutHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default defineComponent({
},
menuSetting: { mode, type: menuType, split: splitMenu, topMenuAlign },
showBreadCrumb,
showBreadCrumbIcon,
} = getProjectConfig;

const isSidebarType = menuType === MenuTypeEnum.SIDEBAR;
Expand All @@ -106,7 +107,7 @@ export default defineComponent({
{showLogo && !isSidebarType && <Logo class={`layout-header__logo`} />}

{mode !== MenuModeEnum.HORIZONTAL && showBreadCrumb && !splitMenu && (
<LayoutBreadcrumb />
<LayoutBreadcrumb showIcon={showBreadCrumbIcon} />
)}
{unref(showTopMenu) && (
<div
Expand Down
13 changes: 13 additions & 0 deletions src/layouts/default/setting/SettingDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export default defineComponent({
menuSetting: { show: showMenu },
multiTabsSetting: { show: showMultiple, showQuick, showIcon: showTabIcon },
showBreadCrumb,
showBreadCrumbIcon,
} = unref(getProjectConfigRef);
return [
renderSwitchItem('面包屑', {
Expand All @@ -352,6 +353,13 @@ export default defineComponent({
def: showBreadCrumb,
disabled: !unref(getShowHeaderRef),
}),
renderSwitchItem('面包屑图标', {
handler: (e) => {
baseHandler('showBreadCrumbIcon', e);
},
def: showBreadCrumbIcon,
disabled: !unref(getShowHeaderRef),
}),
renderSwitchItem('标签页', {
handler: (e) => {
baseHandler('showMultiple', e);
Expand Down Expand Up @@ -449,6 +457,11 @@ export default defineComponent({
showBreadCrumb: value,
};
}
if (event === 'showBreadCrumbIcon') {
config = {
showBreadCrumbIcon: value,
};
}
if (event === 'collapsed') {
config = {
menuSetting: {
Expand Down
2 changes: 2 additions & 0 deletions src/settings/projectSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const setting: ProjectConfig = {
lockTime: 0,
// 显示面包屑
showBreadCrumb: true,
// 显示面包屑图标
showBreadCrumbIcon: false,

// 使用error-handler-plugin
useErrorHandle: isProdMode(),
Expand Down
2 changes: 2 additions & 0 deletions src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export interface ProjectConfig {
lockTime: number;
// 显示面包屑
showBreadCrumb: boolean;
// 显示面包屑图标
showBreadCrumbIcon: boolean;
// 使用error-handler-plugin
useErrorHandle: boolean;

Expand Down

0 comments on commit 9668f67

Please sign in to comment.