style:修改相关样式
This commit is contained in:
@@ -35,6 +35,9 @@ const { title } = defineProps<{
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 1px;
|
width: 1px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
margin: 0 18px;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-bottom: 2px;
|
||||||
background-color: #E2E8F0;
|
background-color: #E2E8F0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,31 @@
|
|||||||
<!-- 顶部company公司标记 -->
|
<!-- 顶部company公司标记 -->
|
||||||
<div class="mj-aside-company"></div>
|
<div class="mj-aside-company"></div>
|
||||||
<div class="mj-aside-menu">
|
<div class="mj-aside-menu">
|
||||||
<div class="mj-aside-title" v-show="!isCollapse">{{ topTitle }}</div>
|
<div class="mj-aside-title" v-show="!isCollapse">
|
||||||
<mjMenus class="mj-aside_menu" :isCollapse="isCollapse" :menuList="sideMenuList" :active-menu="selectedActiveMenu"
|
{{ topTitle }}
|
||||||
@menu-select="handleSideMenuSelect" />
|
</div>
|
||||||
|
<mjMenus
|
||||||
|
class="mj-aside_menu"
|
||||||
|
:isCollapse="isCollapse"
|
||||||
|
:menuList="sideMenuList"
|
||||||
|
:active-menu="selectedActiveMenu"
|
||||||
|
@menu-select="handleSideMenuSelect"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<!-- 展开收缩左侧菜单按钮 -->
|
<!-- 展开收缩左侧菜单按钮 -->
|
||||||
<div class="mj-collapse" @click="showCollapse"></div>
|
<div class="mj-collapse" @click="showCollapse">
|
||||||
|
<el-icon><component :is="isCollapse ? DArrowRight : DArrowLeft" /></el-icon>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-aside>
|
</el-aside>
|
||||||
<el-container>
|
<el-container>
|
||||||
<el-header class="mj-header-content">
|
<el-header class="mj-header-content">
|
||||||
<mjMenus :menuList="topLevelMenuList" mode="horizontal" :active-menu="selectedTopMenu"
|
<mjMenus
|
||||||
@menu-select="handleTopMenuSelect" />
|
:menuList="topLevelMenuList"
|
||||||
|
mode="horizontal"
|
||||||
|
:active-menu="selectedTopMenu"
|
||||||
|
@menu-select="handleTopMenuSelect"
|
||||||
|
/>
|
||||||
</el-header>
|
</el-header>
|
||||||
<el-main>
|
<el-main>
|
||||||
<!-- <card-item :list="[1,2,3,4,5,6]"/> -->
|
<!-- <card-item :list="[1,2,3,4,5,6]"/> -->
|
||||||
@@ -28,13 +41,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import mjMenus from '@/components/standardMenu/index.vue';
|
import mjMenus from "@/components/standardMenu/index.vue";
|
||||||
import { useUserStore } from '@/store'
|
import { useUserStore } from "@/store";
|
||||||
|
import { DArrowLeft, DArrowRight } from "@element-plus/icons-vue";
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "Layout",
|
name: "Layout",
|
||||||
});
|
});
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore();
|
||||||
|
|
||||||
// 响应式断点(小屏阈值,小于此值视为小屏)
|
// 响应式断点(小屏阈值,小于此值视为小屏)
|
||||||
const BREAKPOINT = 1024;
|
const BREAKPOINT = 1024;
|
||||||
@@ -66,89 +80,93 @@ const showCollapse = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 返回菜单数据
|
// 返回菜单数据
|
||||||
const menuList = computed(() => {
|
const menuList = computed(() => {
|
||||||
return userStore.routes || []
|
return userStore.routes || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获取一级菜单数据(不包含 children)
|
// 获取一级菜单数据(不包含 children)
|
||||||
const topLevelMenuList = computed(() => {
|
const topLevelMenuList = computed(() => {
|
||||||
return menuList.value.map(item => {
|
return menuList.value.map((item) => {
|
||||||
const { children, ...rest } = item
|
const { children, ...rest } = item;
|
||||||
return rest
|
return rest;
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
const topTitle = computed(() => {
|
const topTitle = computed(() => {
|
||||||
return topLevelMenuList.value.find(path => path.path === selectedTopMenu.value)?.meta?.title || '-'
|
return (
|
||||||
})
|
topLevelMenuList.value.find((path) => path.path === selectedTopMenu.value)
|
||||||
|
?.meta?.title || "-"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// 当前选中的顶部菜单
|
// 当前选中的顶部菜单
|
||||||
const selectedTopMenu = ref<string>('')
|
const selectedTopMenu = ref<string>("");
|
||||||
const selectedActiveMenu = ref<string>('');
|
const selectedActiveMenu = ref<string>("");
|
||||||
|
|
||||||
// 根据选中的顶部菜单,获取左侧菜单列表
|
// 根据选中的顶部菜单,获取左侧菜单列表
|
||||||
const sideMenuList = computed(() => {
|
const sideMenuList = computed(() => {
|
||||||
if (!selectedTopMenu.value) {
|
if (!selectedTopMenu.value) {
|
||||||
// 默认选中第一个有 children 的菜单
|
// 默认选中第一个有 children 的菜单
|
||||||
const firstMenuWithChildren = menuList.value.find(item => item.children && item.children.length > 0)
|
const firstMenuWithChildren = menuList.value.find(
|
||||||
|
(item) => item.children && item.children.length > 0
|
||||||
|
);
|
||||||
if (firstMenuWithChildren) {
|
if (firstMenuWithChildren) {
|
||||||
return (firstMenuWithChildren.children || []).map(child=>{
|
return (firstMenuWithChildren.children || []).map((child) => {
|
||||||
const fullPath = child.path.startsWith('/')
|
const fullPath = child.path.startsWith("/")
|
||||||
? child.path
|
? child.path
|
||||||
: `${firstMenuWithChildren.path}/${child.path}`
|
: `${firstMenuWithChildren.path}/${child.path}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...child,
|
...child,
|
||||||
path: fullPath
|
path: fullPath,
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
return [];
|
||||||
}
|
|
||||||
return []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据选中的顶部菜单路径,找到对应的菜单项
|
// 根据选中的顶部菜单路径,找到对应的菜单项
|
||||||
const selectedMenu = menuList.value.find(item => item.path === selectedTopMenu.value)
|
const selectedMenu = menuList.value.find(
|
||||||
|
(item) => item.path === selectedTopMenu.value
|
||||||
|
);
|
||||||
if (selectedMenu && selectedMenu.children) {
|
if (selectedMenu && selectedMenu.children) {
|
||||||
return selectedMenu.children.map(child=>{
|
return selectedMenu.children.map((child) => {
|
||||||
const fullPath = child.path.startsWith('/')
|
const fullPath = child.path.startsWith("/")
|
||||||
? child.path
|
? child.path
|
||||||
: `${selectedMenu.path}/${child.path}`
|
: `${selectedMenu.path}/${child.path}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...child,
|
...child,
|
||||||
path: fullPath
|
path: fullPath,
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
});
|
||||||
return []
|
|
||||||
})
|
|
||||||
|
|
||||||
// 处理顶部菜单选中事件
|
// 处理顶部菜单选中事件
|
||||||
const handleTopMenuSelect = (menuPath: string) => {
|
const handleTopMenuSelect = (menuPath: string) => {
|
||||||
selectedTopMenu.value = menuPath
|
selectedTopMenu.value = menuPath;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 左侧菜单选中事件
|
// 左侧菜单选中事件
|
||||||
const handleSideMenuSelect = (menuPath: string) => {
|
const handleSideMenuSelect = (menuPath: string) => {
|
||||||
selectedActiveMenu.value = menuPath;
|
selectedActiveMenu.value = menuPath;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 初始化:默认选中第一个菜单
|
// 初始化:默认选中第一个菜单
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (topLevelMenuList.value.length > 0) {
|
if (topLevelMenuList.value.length > 0) {
|
||||||
const firstMenu = topLevelMenuList.value[0]
|
const firstMenu = topLevelMenuList.value[0];
|
||||||
if (firstMenu && firstMenu.path) {
|
if (firstMenu && firstMenu.path) {
|
||||||
selectedTopMenu.value = firstMenu.path
|
selectedTopMenu.value = firstMenu.path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听窗口大小变化
|
// 监听窗口大小变化
|
||||||
window.addEventListener('resize', handleResize);
|
window.addEventListener("resize", handleResize);
|
||||||
|
|
||||||
// 初始化时根据屏幕大小设置菜单状态
|
// 初始化时根据屏幕大小设置菜单状态
|
||||||
handleResize();
|
handleResize();
|
||||||
@@ -156,7 +174,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 组件卸载时移除监听
|
// 组件卸载时移除监听
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener('resize', handleResize);
|
window.removeEventListener("resize", handleResize);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@@ -204,6 +222,8 @@ onUnmounted(() => {
|
|||||||
.mj-collapse {
|
.mj-collapse {
|
||||||
width: 24px;
|
width: 24px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
|
line-height: 24px;
|
||||||
|
text-align: center;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user