mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2026-01-17 16:57:16 +08:00
feat: 优化布局样式(同步gi-demo)
Co-authored-by: kiki1373639299<zkai0106@163.com> # message auto-generated for no-merge-commit merge: !14 merge type-fix into dev feat: 优化布局样式(同步gi-demo) Created-by: kiki1373639299 Commit-by: kiki1373639299 Merged-by: Charles_7c Description: <!-- 非常感谢您的 PR!在提交之前,请务必确保您 PR 的代码经过了完整测试,并且通过了代码规范检查。 --> <!-- 在 [] 中输入 x 来勾选) --> ## PR 类型 <!-- 您的 PR 引入了哪种类型的变更? --> <!-- 只支持选择一种类型,如果有多种类型,可以在更新日志中增加 “类型” 列。 --> - [X] 新 feature - [ ] Bug 修复 - [ ] 功能增强 - [ ] 文档变更 - [ ] 代码样式变更 - [ ] 重构 - [ ] 性能改进 - [ ] 单元测试 - [ ] CI/CD - [ ] 其他 ## PR 目的 <!-- 描述一下您的 PR 解决了什么问题。如果可以,请链接到相关 issues。 --> ## 解决方案 <!-- 详细描述您是如何解决的问题 --> ## PR 测试 <!-- 如果可以,请为您的 PR 添加或更新单元测试。 --> <!-- 请描述一下您是如何测试 PR 的。例如:创建/更新单元测试或添加相关的截图。 --> ## Changelog | 模块 | Changelog | Related issues | |-----|-----------| -------------- | | | | | <!-- 如果有多种类型的变更,可以在变更日志表中增加 “类型” 列,该列的值与上方 “PR 类型” 相同。 --> <!-- Related issues 格式为 Closes #<issue号>,或者 Fixes #<issue号>,或者 Resolves #<issue号>。 --> ## 其他信息 <!-- 请描述一下还有哪些注意事项。例如:如果引入了一个不向下兼容的变更,请描述其影响。 --> ## 提交前确认 - [X] PR 代码经过了完整测试,并且通过了代码规范检查 - [ ] 已经完整填写 Changelog,并链接到了相关 issues - [X] PR 代码将要提交到 dev 分支 See merge request: continew/continew-admin-ui!14
This commit is contained in:
@@ -1,143 +1,75 @@
|
||||
<!--
|
||||
@file LayoutMix 组件
|
||||
@description 混合布局组件,支持顶部导航和左侧菜单组合的布局方式
|
||||
-->
|
||||
<template>
|
||||
<div class="layout-mix">
|
||||
<!-- 左侧菜单区域 -->
|
||||
<section
|
||||
v-if="isDesktop" class="layout-mix-left" :class="{ 'app-menu-dark': appStore.menuDark }"
|
||||
:style="appStore.menuDark ? appStore.themeCSSVar : undefined"
|
||||
>
|
||||
<Logo :collapsed="appStore.menuCollapse"></Logo>
|
||||
<div class="menu-container">
|
||||
<Menu :menus="leftMenus" :menu-style="{ width: '220px', flex: 1 }"></Menu>
|
||||
</div>
|
||||
<WwAds class="ads" />
|
||||
<Logo :collapsed="appStore.menuCollapse" />
|
||||
<Menu :menus="twoLevelMenus" :menu-style="{ width: '200px', flex: 1 }" />
|
||||
</section>
|
||||
|
||||
<!-- 右侧内容区域 -->
|
||||
<section class="layout-mix-right">
|
||||
<header class="header">
|
||||
<MenuFoldBtn></MenuFoldBtn>
|
||||
<MenuFoldBtn />
|
||||
<a-menu
|
||||
v-if="isDesktop" mode="horizontal" :selected-keys="activeMenu" :auto-open-selected="false"
|
||||
:trigger-props="{ animationName: 'slide-dynamic-origin' }" @menu-item-click="onMenuItemClick"
|
||||
:trigger-props="menuTriggerProps" @menu-item-click="handleMenuItemClickByPath"
|
||||
>
|
||||
<a-menu-item v-for="item in topMenus" :key="item.path">
|
||||
<a-menu-item v-for="item in oneLevelMenus" :key="item.path">
|
||||
<template #icon>
|
||||
<GiSvgIcon :name="getMenuIcon(item)" :size="24" />
|
||||
<GiSvgIcon :name="getMenuIcon(item) || ''" :size="24" />
|
||||
</template>
|
||||
<span>{{ item.meta?.title || item.children?.[0]?.meta?.title || '' }}</span>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
<HeaderRightBar></HeaderRightBar>
|
||||
<HeaderRightBar />
|
||||
</header>
|
||||
|
||||
<Tabs></Tabs>
|
||||
<Main></Main>
|
||||
<GiFooter v-if="appStore.copyrightDisplay" />
|
||||
<Tabs v-if="appStore.tab" />
|
||||
<Main />
|
||||
</section>
|
||||
|
||||
<!-- 公告弹窗 -->
|
||||
<NoticePopup ref="noticePopupRef" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { searchTree } from 'xe-utils'
|
||||
import Main from './components/Main.vue'
|
||||
import Tabs from './components/Tabs/index.vue'
|
||||
import Menu from './components/Menu/index.vue'
|
||||
import HeaderRightBar from './components/HeaderRightBar/index.vue'
|
||||
import Logo from './components/Logo.vue'
|
||||
import Main from './components/Main.vue'
|
||||
import Menu from './components/Menu/index.vue'
|
||||
import MenuFoldBtn from './components/MenuFoldBtn.vue'
|
||||
import WwAds from './components/WwAds.vue'
|
||||
import GiFooter from '@/components/GiFooter/index.vue'
|
||||
import NoticePopup from '@/views/user/message/components/NoticePopup.vue'
|
||||
import { useAppStore, useRouteStore } from '@/stores'
|
||||
import { isExternal } from '@/utils/validate'
|
||||
import { filterTree } from '@/utils'
|
||||
import Tabs from './components/Tabs/index.vue'
|
||||
import { useAppStore } from '@/stores'
|
||||
import { useLevelMenu } from '@/layout/hooks/useLevelMenu'
|
||||
import { useDevice } from '@/hooks'
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
/** 组件名称 */
|
||||
defineOptions({ name: 'LayoutMix' })
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const appStore = useAppStore()
|
||||
const routeStore = useRouteStore()
|
||||
const { isDesktop } = useDevice()
|
||||
// 过滤是菜单的路由
|
||||
const cloneRoutes = JSON.parse(JSON.stringify(routeStore.routes)) as RouteRecordRaw[]
|
||||
const menuRoutes = filterTree(cloneRoutes, (i) => i.meta?.hidden === false)
|
||||
|
||||
// 顶部一级菜单
|
||||
const topMenus = ref<RouteRecordRaw[]>([])
|
||||
topMenus.value = JSON.parse(JSON.stringify(menuRoutes))
|
||||
|
||||
// 公告弹窗引用
|
||||
const noticePopupRef = ref<InstanceType<typeof NoticePopup>>()
|
||||
|
||||
// 检查并显示未读公告
|
||||
const checkAndShowNotices = () => {
|
||||
const token = getToken()
|
||||
|
||||
// 如果有token,检查未读公告
|
||||
if (token) {
|
||||
setTimeout(() => {
|
||||
noticePopupRef.value?.open()
|
||||
}, 1000) // 延迟1秒显示,让页面先加载完成
|
||||
}
|
||||
/** 菜单配置 */
|
||||
const menuTriggerProps = {
|
||||
animationName: 'slide-dynamic-origin',
|
||||
}
|
||||
|
||||
const { oneLevelMenus, twoLevelMenus, oneLevelMenuActiveRoute, getOneLevelMenus, handleMenuItemClickByPath } = useLevelMenu()
|
||||
getOneLevelMenus()
|
||||
|
||||
const activeMenu = computed(() => [oneLevelMenuActiveRoute.value?.path ?? ''])
|
||||
|
||||
const getMenuIcon = (item: RouteRecordRaw) => {
|
||||
return item.meta?.icon || item.children?.[0].meta?.icon
|
||||
return item.meta?.icon || item.children?.[0]?.meta?.icon
|
||||
}
|
||||
|
||||
// 克隆是菜单的路由
|
||||
const cloneMenuRoutes: RouteRecordRaw[] = JSON.parse(JSON.stringify(menuRoutes))
|
||||
// 顶部一级菜单选中的
|
||||
const activeMenu = ref<string[]>([])
|
||||
// 左侧的菜单
|
||||
const leftMenus = ref<RouteRecordRaw[]>([])
|
||||
// 获取左侧菜单
|
||||
const getLeftMenus = (currentRoute?: RouteRecordRaw, key?: string) => {
|
||||
// 优先从路由的 meta.activeMenu 获取key,如果没有则使用path
|
||||
const menuKey = currentRoute
|
||||
? (currentRoute.meta?.activeMenu as string) || currentRoute.path
|
||||
: key || ''
|
||||
|
||||
const arr = searchTree(cloneMenuRoutes, (i) => i.path === menuKey, { children: 'children' })
|
||||
const rootPath = arr.length ? arr[0].path : ''
|
||||
const obj = cloneMenuRoutes.find((i) => i.path === rootPath)
|
||||
activeMenu.value = obj ? [obj.path] : ['']
|
||||
leftMenus.value = obj ? (obj.children as RouteRecordRaw[]) : []
|
||||
}
|
||||
|
||||
const onMenuItemClick = (key: string) => {
|
||||
if (isExternal(key)) {
|
||||
window.open(key)
|
||||
return
|
||||
}
|
||||
setTimeout(() => getLeftMenus(undefined, key))
|
||||
const obj = topMenus.value.find((i) => i.path === key)
|
||||
if (obj && obj.redirect === 'noRedirect') return
|
||||
router.push({ path: key })
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
() => {
|
||||
nextTick(() => {
|
||||
getLeftMenus(route)
|
||||
})
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
checkAndShowNotices()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
<style lang="scss" scoped>
|
||||
:deep(.arco-menu-pop) {
|
||||
white-space: nowrap;
|
||||
}
|
||||
@@ -146,13 +78,13 @@ onMounted(() => {
|
||||
|
||||
// Menu菜单组件修改
|
||||
.arco-menu-icon {
|
||||
margin-right: 0;
|
||||
padding: 10px 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.arco-menu-has-icon {
|
||||
padding: 0;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.arco-menu-title {
|
||||
@@ -174,43 +106,36 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
.layout-mix {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
&-left {
|
||||
border-right: 1px solid var(--color-border);
|
||||
background-color: var(--color-bg-1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
height: 100vh;
|
||||
|
||||
.menu-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
background-color: var(--color-bg-1);
|
||||
border-right: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
&-right {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.header {
|
||||
padding: 0 $padding;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 56px;
|
||||
padding: 0 $padding;
|
||||
overflow: hidden;
|
||||
color: var(--color-text-1);
|
||||
background: var(--color-bg-1);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user