perf: layout style optimization

This commit is contained in:
vben
2020-10-31 19:51:24 +08:00
parent 05980a817e
commit 7702832181
27 changed files with 201 additions and 218 deletions

View File

@@ -4,7 +4,6 @@ import { Layout } from 'ant-design-vue';
import { ContentEnum } from '/@/enums/appEnum';
import { appStore } from '/@/store/modules/app';
// import { RouterView } from 'vue-router';
import PageLayout from '/@/layouts/page/index';
export default defineComponent({
name: 'DefaultLayoutContent',
@@ -15,9 +14,7 @@ export default defineComponent({
const wrapClass = contentMode === ContentEnum.FULL ? 'full' : 'fixed';
return (
<Layout.Content class={`layout-content ${wrapClass} `}>
{{
default: () => <PageLayout />,
}}
{() => <PageLayout />}
</Layout.Content>
);
};

View File

@@ -1,11 +1,12 @@
import { defineComponent, unref, computed, ref } from 'vue';
import { Layout, Tooltip, Badge } from 'ant-design-vue';
import Logo from '/@/layouts/Logo.vue';
import UserDropdown from './UserDropdown';
import LayoutMenu from './LayoutMenu';
import { appStore } from '/@/store/modules/app';
import { MenuModeEnum, MenuSplitTyeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
import LayoutBreadcrumb from './LayoutBreadcrumb';
import LockAction from './actions/LockActionItem';
import NoticeAction from './actions/notice/NoticeActionItem.vue';
import {
RedoOutlined,
FullscreenExitOutlined,
@@ -14,19 +15,24 @@ import {
LockOutlined,
BugOutlined,
} from '@ant-design/icons-vue';
import { useFullscreen } from '/@/hooks/web/useFullScreen';
import { useTabs } from '/@/hooks/web/useTabs';
import { GITHUB_URL } from '/@/settings/siteSetting';
import LockAction from './actions/LockActionItem';
import { useModal } from '/@/components/Modal/index';
import { errorStore } from '/@/store/modules/error';
import { useWindowSizeFn } from '/@/hooks/event/useWindowSize';
import NoticeAction from './actions/notice/NoticeActionItem.vue';
import { useRouter } from 'vue-router';
import { useModal } from '/@/components/Modal/index';
import { appStore } from '/@/store/modules/app';
import { errorStore } from '/@/store/modules/error';
import { MenuModeEnum, MenuSplitTyeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
import { GITHUB_URL } from '/@/settings/siteSetting';
export default defineComponent({
name: 'DefaultLayoutHeader',
setup() {
const widthRef = ref(200);
let logoEl: Element | null;
const { refreshPage } = useTabs();
const { push } = useRouter();
const [register, { openModal }] = useModal();
@@ -35,6 +41,7 @@ export default defineComponent({
const getProjectConfigRef = computed(() => {
return appStore.getProjectConfig;
});
const showTopMenu = computed(() => {
const getProjectConfig = unref(getProjectConfigRef);
const {
@@ -43,7 +50,6 @@ export default defineComponent({
return mode === MenuModeEnum.HORIZONTAL || splitMenu;
});
let logoEl: Element | null;
useWindowSizeFn(
() => {
if (!unref(showTopMenu)) return;
@@ -80,6 +86,7 @@ export default defineComponent({
function handleLockPage() {
openModal(true);
}
return () => {
const getProjectConfig = unref(getProjectConfigRef);
const {
@@ -99,7 +106,9 @@ export default defineComponent({
} = getProjectConfig;
const isSidebarType = menuType === MenuTypeEnum.SIDEBAR;
const width = unref(widthRef);
return (
<Layout.Header class={['layout-header', 'flex p-0 px-4 ', unref(headerClass)]}>
{() => (
@@ -112,10 +121,12 @@ export default defineComponent({
)}
{unref(showTopMenu) && (
<div
class={[`layout-header__menu `, `justify-${topMenuAlign}`]}
class={[`layout-header__menu `]}
style={{ width: `calc(100% - ${unref(width)}px)` }}
>
<LayoutMenu
isTop={true}
class={`justify-${topMenuAlign}`}
theme={headerTheme}
splitType={splitMenu ? MenuSplitTyeEnum.TOP : MenuSplitTyeEnum.NONE}
menuMode={splitMenu ? MenuModeEnum.HORIZONTAL : null}

View File

@@ -45,6 +45,10 @@ export default defineComponent({
type: Boolean as PropType<boolean>,
default: true,
},
isTop: {
type: Boolean as PropType<boolean>,
default: false,
},
menuMode: {
type: [String] as PropType<MenuModeEnum | null>,
default: '',
@@ -199,6 +203,7 @@ export default defineComponent({
flatItems={unref(flatMenusRef)}
onClickSearchInput={handleClickSearchInput}
appendClass={props.splitType === MenuSplitTyeEnum.TOP}
isTop={props.isTop}
>
{{
header: () =>

View File

@@ -7,7 +7,7 @@ import { menuStore } from '/@/store/modules/menu';
// import darkMiniIMg from '/@/assets/images/sidebar/dark-mini.png';
// import lightMiniImg from '/@/assets/images/sidebar/light-mini.png';
import darkImg from '/@/assets/images/sidebar/dark.png';
import lightImg from '/@/assets/images/sidebar/light.png';
// import lightImg from '/@/assets/images/sidebar/light.png';
import { appStore } from '/@/store/modules/app';
import { MenuModeEnum, MenuSplitTyeEnum, MenuThemeEnum } from '/@/enums/menuEnum';
import { SIDE_BAR_MINI_WIDTH, SIDE_BAR_SHOW_TIT_MINI_WIDTH } from '/@/enums/appEnum';
@@ -39,15 +39,16 @@ export default defineComponent({
// const collapse = unref(collapseRef);
const theme = unref(getProjectConfigRef).menuSetting.theme;
if (theme === MenuThemeEnum.LIGHT) {
// bg = lightImg;
return {};
}
let bg = '';
if (theme === MenuThemeEnum.DARK) {
// bg = collapse ? darkMiniIMg : darkImg;
bg = darkImg;
}
if (theme === MenuThemeEnum.LIGHT) {
bg = lightImg;
// bg = collapse ? lightMiniImg : lightImg;
}
return {
'background-image': `url(${bg})`,
};

View File

@@ -21,6 +21,11 @@ export default defineComponent({
return appStore.getProjectConfig;
});
const getUserInfo = computed(() => {
const { realName = '', desc } = userStore.getUserInfoState || {};
return { realName, desc };
});
/**
* @description: 退出登录
*/
@@ -41,10 +46,20 @@ export default defineComponent({
openDoc();
}
}
const getUserInfo = computed(() => {
const { realName = '', desc } = userStore.getUserInfoState || {};
return { realName, desc };
});
function renderItem({ icon, text, key }: { icon: string; text: string; key: string }) {
return (
<Menu.Item key={key}>
{() => (
<span class="flex items-center">
<Icon icon={icon} class="mr-1" />
<span>{text}</span>
</span>
)}
</Menu.Item>
);
}
return () => {
const { realName } = unref(getUserInfo);
const {
@@ -65,28 +80,13 @@ export default defineComponent({
<Menu slot="overlay" onClick={handleMenuClick}>
{() => (
<>
{showDoc && (
<Menu.Item key="doc">
{() => (
<span class="flex items-center">
<Icon icon="gg:loadbar-doc" class="mr-1" />
<span></span>
</span>
)}
</Menu.Item>
)}
{showDoc && renderItem({ key: 'doc', text: '文档', icon: 'gg:loadbar-doc' })}
{showDoc && <Divider />}
<Menu.Item key="loginOut">
{() => (
<>
<span class="flex items-center">
<Icon icon="ant-design:poweroff-outlined" class="mr-1" />
<span>退</span>
</span>
</>
)}
</Menu.Item>
{renderItem({
key: 'loginOut',
text: '退出系统',
icon: 'ant-design:poweroff-outlined',
})}
</>
)}
</Menu>

View File

@@ -1,9 +1,9 @@
.lock-modal {
&__entry {
position: relative;
width: 500px;
// width: 500px;
height: 240px;
padding: 80px 30px 0 30px;
padding: 130px 30px 60px 30px;
background: #fff;
border-radius: 10px;
}

View File

@@ -24,7 +24,7 @@ export default defineComponent({
schemas: [
{
field: 'password',
label: '锁屏密码',
label: '',
component: 'InputPassword',
componentProps: {
placeholder: '请输入锁屏密码',

View File

@@ -1,12 +1,6 @@
@import (reference) '../../design/index.less';
.default-layout {
// .ant-menu-submenu .ant-menu-sub {
// transition: none !important;
// // transition: background 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s,
// // padding 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s !important;
// }
&__content {
position: relative;
@@ -72,6 +66,10 @@
.layout-sidebar {
background-size: 100% 100%;
&:not(.ant-layout-sider-dark) {
border-right: 1px solid @border-color-light;
}
.ant-layout-sider-zero-width-trigger {
top: 40%;
z-index: 10;
@@ -99,25 +97,13 @@
}
}
.setting-button {
top: 45%;
right: 0;
padding: 8px;
border-radius: 6px 0 0 6px;
svg {
width: 1em;
height: 1em;
}
}
&__tabs {
z-index: 10;
height: @multiple-height;
padding: 0;
line-height: @multiple-height;
background: @border-color-shallow-light;
box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.08);
box-shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.12);
}
}
@@ -194,11 +180,17 @@
}
}
.ant-layout-header {
.ant-layout-header:not(.default-layout__tabs) {
height: @header-height;
line-height: @header-height;
}
.ant-layout-header.default-layout__tabs {
height: @multiple-height + 2;
line-height: @multiple-height + 2;
background: @white;
}
.layout-header {
display: flex;
height: @header-height;
@@ -351,22 +343,20 @@
}
&__menu {
// display: flex;
margin-left: 20px;
overflow: hidden;
align-items: center;
// flex-grow: 1;
}
&__user-dropdown {
height: 52px;
height: @header-height;
padding: 0 0 0 10px;
}
}
.user-dropdown {
display: flex;
height: 100%;
padding-right: 10px;
font-size: 12px;
cursor: pointer;
align-items: center;
@@ -374,49 +364,12 @@
img {
width: 26px;
height: 26px;
margin-right: 16px;
margin-right: 12px;
}
&__header {
border-radius: 50%;
}
&__divider {
width: 1px;
height: 30px;
margin-right: 20px;
background: #c6d9ee;
}
&__exit {
margin-top: -40px;
font-size: 12px;
color: #c6d9ee;
text-align: center;
> section {
height: 20px;
}
}
&__info {
display: flex;
margin-right: 12px;
flex-direction: column;
> section {
line-height: 1.8;
}
}
&__name {
font-size: 12px;
}
&__desc {
font-size: 12px;
.text-truncate();
}
}
.layout-breadcrumb {
@@ -425,8 +378,8 @@
}
.ant-layout-sider-trigger {
height: 30px;
line-height: 30px;
height: 36px;
line-height: 36px;
}
.hide-title {

View File

@@ -1,4 +1,4 @@
import { defineComponent, unref, onMounted, computed } from 'vue';
import { defineComponent, unref, computed } from 'vue';
import { Layout, BackTop } from 'ant-design-vue';
import LayoutHeader from './LayoutHeader';
@@ -30,6 +30,7 @@ export default defineComponent({
const getProjectConfigRef = computed(() => {
return appStore.getProjectConfig;
});
const getLockMainScrollStateRef = computed(() => {
return appStore.getLockMainScrollState;
});
@@ -40,6 +41,7 @@ export default defineComponent({
} = unref(getProjectConfigRef);
return show;
});
const isShowMixHeaderRef = computed(() => {
const {
menuSetting: { type },
@@ -54,12 +56,6 @@ export default defineComponent({
return show && mode !== MenuModeEnum.HORIZONTAL && !unref(getFullContent);
});
// const { currentRoute } = useRouter();
onMounted(() => {
// Each refresh will request the latest user information, if you dont need it, you can delete it
// userStore.getUserInfoAction({ userId: userStore.getUserInfoState.userId });
});
// Get project configuration
// const { getFullContent } = useFullContent(currentRoute);
function getTarget(): any {
@@ -68,6 +64,7 @@ export default defineComponent({
} = unref(getProjectConfigRef);
return document.querySelector(`.default-layout__${fixed ? 'main' : 'content'}`);
}
return () => {
const { getPageLoading, getLockInfo } = appStore;
const {
@@ -77,10 +74,11 @@ export default defineComponent({
multiTabsSetting: { show: showTabs },
headerSetting: { fixed },
} = unref(getProjectConfigRef);
// const fixedHeaderCls = fixed ? ('fixed' + getLockMainScrollState ? ' lock' : '') : '';
const fixedHeaderCls = fixed
? 'fixed' + (unref(getLockMainScrollStateRef) ? ' lock' : '')
: '';
const { isLock } = getLockInfo;
return (
<Layout class="default-layout relative">

View File

@@ -1,8 +1,6 @@
@import (reference) '../../../design/index.less';
.multiple-tabs {
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
.ant-tabs-small {
height: @multiple-height;
}
@@ -13,7 +11,7 @@
margin: 0;
background: @white;
border: 0;
box-shadow: 0 4px 26px 1px rgba(0, 0, 0, 0.08);
box-shadow: none;
.ant-tabs-nav-container {
height: @multiple-height;
@@ -22,17 +20,26 @@
.ant-tabs-tab {
height: calc(@multiple-height - 2px);
font-size: 14px;
line-height: calc(@multiple-height - 2px);
color: @text-color-call-out;
background: @white;
border: 1px solid darken(@border-color-light, 6%);
border-radius: 2px 2px 0 0;
border: 1px solid darken(@border-color-light, 8%);
border-radius: none !important;
transition: none;
.ant-tabs-close-x {
// display: none;
width: 12px;
height: 12px;
font-size: 12px;
color: inherit;
transition: none;
&:hover {
svg {
width: 0.8em;
transition: all 0.1s;
}
}
}
&:hover {
@@ -50,37 +57,12 @@
svg {
fill: @text-color-base;
}
&::before {
position: absolute;
top: -2px;
right: 0;
left: 0;
height: 4px;
background-color: @primary-color;
border-radius: 16px 6px 0 0;
content: '';
transform: scaleX(0);
transform-origin: bottom right;
}
&:hover::before {
transform: scaleX(1);
transition: transform 0.3s ease;
transform-origin: bottom left;
}
}
.ant-tabs-tab-active {
height: calc(@multiple-height - 3px);
color: @white;
background: linear-gradient(
118deg,
rgba(@primary-color, 0.8),
rgba(@primary-color, 1)
) !important;
background: fade(@primary-color, 100%);
border: 0;
box-shadow: 0 0 6px 1px rgba(@primary-color, 0.7);
&::before {
display: none;
@@ -88,6 +70,7 @@
svg {
fill: @white;
width: 0.7em;
}
}
}
@@ -95,12 +78,6 @@
.ant-tabs-nav > div:nth-child(1) {
padding: 0 10px;
}
.ant-tabs-tab-prev,
.ant-tabs-tab-next {
color: @border-color-dark;
background: @white;
}
}
.ant-tabs-tab:not(.ant-tabs-tab-active) {
@@ -108,20 +85,19 @@
font-size: 12px;
svg {
width: 0.8em;
}
}
&:hover {
.anticon-close {
color: @white;
width: 0.6em;
}
}
}
}
.ant-tabs-extra-content {
line-height: @multiple-height;
margin-top: 2px;
line-height: @multiple-height !important;
}
.ant-dropdown-trigger {
display: inline-flex;
}
.multiple-tabs-content {
@@ -133,7 +109,7 @@
color: @primary-color;
text-align: center;
cursor: pointer;
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
// box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
span[role='img'] {
transform: rotate(90deg);
@@ -143,8 +119,10 @@
&__content {
display: inline-block;
width: 100%;
padding-left: 10px;
height: @multiple-height - 2;
padding-left: 0;
margin-left: -10px;
font-size: 12px;
cursor: pointer;
user-select: none;
}

View File

@@ -159,7 +159,7 @@ export default defineComponent({
size="small"
animated={false}
hideAdd={true}
tabBarGutter={2}
tabBarGutter={4}
activeKey={unref(activeKeyRef)}
onChange={handleChange}
onEdit={handleEdit}

View File

@@ -28,13 +28,21 @@
.setting-button {
position: absolute;
top: 45%;
right: 0;
z-index: 10;
display: flex;
// padding: 10px;
padding: 10px;
color: @white;
cursor: pointer;
background: @primary-color;
border-radius: 6px 0 0 6px;
justify-content: center;
align-items: center;
svg {
width: 1em;
height: 1em;
}
}
</style>