首页增加三级菜单

This commit is contained in:
weiwei committed 2025-03-01 15:00:44 +08:00
1 parent 3409a58571
commit 4880e625c9
2 files changed
+35 -16

No files matched your search

+3 -3
View File
@@ -1,5 +1,5 @@
<template> <template>
<navMmenu /> <nav-menu />
<!-- <div v-if="pageLoading"> <!-- <div v-if="pageLoading">
<el-main> <el-main>
<el-card shadow="never"> <el-card shadow="never">
@@ -13,8 +13,8 @@
<widgets /> --> <widgets /> -->
</template> </template>
<script setup lang="ts" name="dashboard"> <script setup lang="ts">
const navMmenu = defineAsyncComponent(() => import('./navMenu/index.vue')); const NavMenu = defineAsyncComponent(() => import("./navMenu/index.vue"))
// const Widgets = defineAsyncComponent(() => import('./widgets/index.vue')); // const Widgets = defineAsyncComponent(() => import('./widgets/index.vue'));
// const pageLoading = ref(true); // const pageLoading = ref(true);
+32 -13
View File
@@ -1,7 +1,7 @@
<template> <template>
<el-card class="card" v-loading="loading"> <el-card class="card" v-loading="loading">
<el-row> <el-row>
<el-col :span="4" v-for="(item, index) in navMenuList" :key="index"> <el-col :span="3" v-for="(item, index) in navMenuList" :key="index">
<div <div
:class="['nav-menu-item-top', item.id == currentActiveMenuId ? 'nav-menu-item-active' : '']" :class="['nav-menu-item-top', item.id == currentActiveMenuId ? 'nav-menu-item-active' : '']"
@click="currentActiveMenuId = item.id" @click="currentActiveMenuId = item.id"
@@ -12,19 +12,28 @@
</el-col> </el-col>
</el-row> </el-row>
<br /> <br />
<el-row v-if="currentActiveMenuId" style="background-color: #e2eff677; border-radius: 1rem; padding: 2rem 6rem"> <el-row v-if="currentActiveMenuId" style="background-color: #e2eff677; border-radius: 1rem; padding: 2rem">
<el-col v-for="(item, index) in navMenuListBottom" :key="index" :span="!item.meta?.isHide ? 4 : 0"> <el-col v-for="(item, index) in navMenuListBottom" :key="index" :span="!item.meta?.isHide ? 2.4 : 0">
<div v-if="!item.meta?.isHide" class="nav-menu-item-bottom" @click="handleClickBottomMenu(item)"> <div v-if="!item.meta?.isHide" class="nav-menu-item-bottom" @click="handleClickBottomMenu(item)">
<el-image class="nav-menu-item-icon" :src="imageBaseUrl + item.menuPic" fit="cover" /> <el-image class="nav-menu-item-icon" :src="imageBaseUrl + item.menuPic" fit="cover" />
<div class="nav-menu-item-name">{{ $t(item.name) }}</div> <div class="nav-menu-item-name">{{ $t(item.name) }}</div>
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
<br />
<el-row v-if="navMenuLevel3.length > 0" style="background-color: #e2eff677; border-radius: 1rem; padding: 2rem">
<el-col v-for="(item, index) in navMenuLevel3" :key="index" :span="!item.meta?.isHide ? 3 : 0">
<div v-if="!item.meta?.isHide" class="nav-menu-item-bottom" @click="handleClickNavMenuLevel3(item)">
<el-image class="nav-menu-item-icon" :src="imageBaseUrl + item.menuPic" fit="cover" />
<div class="nav-menu-item-name">{{ $t(item.name) }}</div>
</div>
</el-col>
</el-row>
</el-card> </el-card>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue" import { ref, onMounted, onActivated } from "vue"
import { ElMessage } from "element-plus" import { ElMessage } from "element-plus"
import { useMenuApi } from "/@/api/admin/menu" import { useMenuApi } from "/@/api/admin/menu"
@@ -33,6 +42,7 @@ const menuApi = useMenuApi()
const loading = ref(false) const loading = ref(false)
const navMenuList = ref<any>([]) const navMenuList = ref<any>([])
const currentActiveMenuId = ref("") const currentActiveMenuId = ref("")
const navMenuLevel3 = ref<any>([])
const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH
// 获取菜单列表 // 获取菜单列表
@@ -52,6 +62,7 @@ const getNavMenuList = async () => {
const navMenuListBottom = computed(() => { const navMenuListBottom = computed(() => {
if (navMenuList.value) { if (navMenuList.value) {
navMenuLevel3.value = []
const currentMenuItem = navMenuList.value.find((item: any) => item.id == currentActiveMenuId.value) const currentMenuItem = navMenuList.value.find((item: any) => item.id == currentActiveMenuId.value)
if (currentMenuItem && currentMenuItem.children) return currentMenuItem.children if (currentMenuItem && currentMenuItem.children) return currentMenuItem.children
} else { } else {
@@ -61,9 +72,16 @@ const navMenuListBottom = computed(() => {
// 点击菜单项 // 点击菜单项
const handleClickBottomMenu = (item: any) => { const handleClickBottomMenu = (item: any) => {
router.push(item.path) if (item.children && item.children.length > 0) {
navMenuLevel3.value = item.children
} else {
router.push(item.path)
}
} }
// 点击三级菜单
const handleClickNavMenuLevel3 = (item: any) => router.push(item.path)
onMounted(async () => { onMounted(async () => {
await getNavMenuList() await getNavMenuList()
}) })
@@ -71,12 +89,13 @@ onMounted(async () => {
<style scoped lang="scss"> <style scoped lang="scss">
.card { .card {
padding: 5vw; padding: 1vh 3vw 0;
height: calc(100vh - 85px); height: calc(100vh - 85px);
background-image: linear-gradient(0deg, #ffffff 0%, #e4ebff 100%); background-image: linear-gradient(0deg, #ffffff 0%, #e4ebff 100%);
overflow-y: auto;
} }
.nav-menu-item-top { .nav-menu-item-top {
height: 6.5vw; height: 6vw;
padding: 0.5vw; padding: 0.5vw;
margin: 0.5vw; margin: 0.5vw;
display: flex; display: flex;
@@ -89,8 +108,8 @@ onMounted(async () => {
cursor: pointer; cursor: pointer;
.nav-menu-item-icon { .nav-menu-item-icon {
width: 2.5vw; width: 2.2vw;
height: 2.5vw; height: 2.2vw;
} }
.nav-menu-item-name { .nav-menu-item-name {
font-size: 1.2vw; font-size: 1.2vw;
@@ -105,8 +124,8 @@ onMounted(async () => {
} }
.nav-menu-item-bottom { .nav-menu-item-bottom {
min-height: 4vw; min-height: 3vw;
margin: 1vw 2vw; margin: 1vw;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
@@ -115,8 +134,8 @@ onMounted(async () => {
cursor: pointer; cursor: pointer;
.nav-menu-item-icon { .nav-menu-item-icon {
width: 2.3vw; width: 2vw;
height: 2.3vw; height: 2vw;
} }
.nav-menu-item-name { .nav-menu-item-name {
font-size: 1vw; font-size: 1vw;