perf: 代码优化 layout/index
This commit is contained in:
parent
3953269006
commit
74f2f7b725
@ -12,14 +12,15 @@ const settingsStore = useSettingsStore()
|
|||||||
/** Layout 布局响应式 */
|
/** Layout 布局响应式 */
|
||||||
useResize()
|
useResize()
|
||||||
|
|
||||||
const classObj = computed(() => {
|
/** 定义计算属性 layoutClasses,用于控制布局的类名 */
|
||||||
|
const layoutClasses = computed(() => {
|
||||||
return {
|
return {
|
||||||
hideSidebar: !appStore.sidebar.opened,
|
hideSidebar: !appStore.sidebar.opened,
|
||||||
openSidebar: appStore.sidebar.opened,
|
openSidebar: appStore.sidebar.opened,
|
||||||
withoutAnimation: appStore.sidebar.withoutAnimation,
|
withoutAnimation: appStore.sidebar.withoutAnimation,
|
||||||
mobile: appStore.device === DeviceEnum.Mobile,
|
mobile: appStore.device === DeviceEnum.Mobile,
|
||||||
showGreyMode: showGreyMode.value,
|
showGreyMode: settingsStore.showGreyMode,
|
||||||
showColorWeakness: showColorWeakness.value
|
showColorWeakness: settingsStore.showColorWeakness
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -32,27 +33,29 @@ const showTagsView = computed(() => {
|
|||||||
const fixedHeader = computed(() => {
|
const fixedHeader = computed(() => {
|
||||||
return settingsStore.fixedHeader
|
return settingsStore.fixedHeader
|
||||||
})
|
})
|
||||||
const showGreyMode = computed(() => {
|
|
||||||
return settingsStore.showGreyMode
|
/** 用于处理点击 mobile 端侧边栏遮罩层的事件 */
|
||||||
})
|
|
||||||
const showColorWeakness = computed(() => {
|
|
||||||
return settingsStore.showColorWeakness
|
|
||||||
})
|
|
||||||
const handleClickOutside = () => {
|
const handleClickOutside = () => {
|
||||||
appStore.closeSidebar(false)
|
appStore.closeSidebar(false)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="classObj" class="app-wrapper">
|
<div :class="layoutClasses" class="app-wrapper">
|
||||||
<div v-if="classObj.mobile && classObj.openSidebar" class="drawer-bg" @click="handleClickOutside" />
|
<!-- mobile 端侧边栏遮罩层 -->
|
||||||
|
<div v-if="layoutClasses.mobile && layoutClasses.openSidebar" class="drawer-bg" @click="handleClickOutside" />
|
||||||
|
<!-- 左侧边栏 -->
|
||||||
<Sidebar class="sidebar-container" />
|
<Sidebar class="sidebar-container" />
|
||||||
|
<!-- 主容器 -->
|
||||||
<div :class="{ hasTagsView: showTagsView }" class="main-container">
|
<div :class="{ hasTagsView: showTagsView }" class="main-container">
|
||||||
|
<!-- 头部导航栏和标签栏 -->
|
||||||
<div :class="{ 'fixed-header': fixedHeader }">
|
<div :class="{ 'fixed-header': fixedHeader }">
|
||||||
<NavigationBar />
|
<NavigationBar />
|
||||||
<TagsView v-show="showTagsView" />
|
<TagsView v-show="showTagsView" />
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 页面主体内容 -->
|
||||||
<AppMain />
|
<AppMain />
|
||||||
|
<!-- 右侧设置面板 -->
|
||||||
<RightPanel v-if="showSettings">
|
<RightPanel v-if="showSettings">
|
||||||
<Settings />
|
<Settings />
|
||||||
</RightPanel>
|
</RightPanel>
|
||||||
@ -62,6 +65,7 @@ const handleClickOutside = () => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import "@/styles/mixins.scss";
|
@import "@/styles/mixins.scss";
|
||||||
|
$transition-time: 0.35s;
|
||||||
|
|
||||||
.app-wrapper {
|
.app-wrapper {
|
||||||
@include clearfix;
|
@include clearfix;
|
||||||
@ -89,13 +93,13 @@ const handleClickOutside = () => {
|
|||||||
|
|
||||||
.main-container {
|
.main-container {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
transition: margin-left 0.28s;
|
transition: margin-left $transition-time;
|
||||||
margin-left: var(--v3-sidebar-width);
|
margin-left: var(--v3-sidebar-width);
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-container {
|
.sidebar-container {
|
||||||
transition: width 0.28s;
|
transition: width $transition-time;
|
||||||
width: var(--v3-sidebar-width) !important;
|
width: var(--v3-sidebar-width) !important;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@ -113,7 +117,7 @@ const handleClickOutside = () => {
|
|||||||
right: 0;
|
right: 0;
|
||||||
z-index: 9;
|
z-index: 9;
|
||||||
width: calc(100% - var(--v3-sidebar-width));
|
width: calc(100% - var(--v3-sidebar-width));
|
||||||
transition: width 0.28s;
|
transition: width $transition-time;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hideSidebar {
|
.hideSidebar {
|
||||||
@ -128,13 +132,13 @@ const handleClickOutside = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for mobile response 适配移动端
|
// 适配 mobile 端
|
||||||
.mobile {
|
.mobile {
|
||||||
.main-container {
|
.main-container {
|
||||||
margin-left: 0px;
|
margin-left: 0px;
|
||||||
}
|
}
|
||||||
.sidebar-container {
|
.sidebar-container {
|
||||||
transition: transform 0.28s;
|
transition: transform $transition-time;
|
||||||
width: var(--v3-sidebar-width) !important;
|
width: var(--v3-sidebar-width) !important;
|
||||||
}
|
}
|
||||||
&.openSidebar {
|
&.openSidebar {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user