修改页面结构
This commit is contained in:
@@ -1,89 +1,193 @@
|
||||
<template>
|
||||
<view
|
||||
class="aside"
|
||||
:style="{ width: asideWidth + 'px' }"
|
||||
>
|
||||
<view class="aside-header">
|
||||
<view class="logo">
|
||||
<text class="logo-text"> 商城后台</text>
|
||||
</view>
|
||||
<view class="admin-aside" :class="{ collapsed: collapsed }" :style="{ width: asideWidth + 'px' }">
|
||||
<view class="aside-logo" @click="onLogoClick">
|
||||
<text class="logo-text">{{ collapsed ? 'M' : 'MALL' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="aside-menu">
|
||||
<view
|
||||
v-for="m in menuList"
|
||||
:key="m.id"
|
||||
class="aside-item"
|
||||
:class="{ active: activeMenuId === m.id }"
|
||||
@click="$emit('menu-click', m.id)"
|
||||
<scroll-view class="aside-menu" scroll-y="true">
|
||||
<view
|
||||
v-for="menu in topMenus"
|
||||
:key="menu.id"
|
||||
class="menu-item"
|
||||
:class="{ active: menu.id === activeTopMenuId }"
|
||||
@click="onMenuClick(menu)"
|
||||
>
|
||||
<image class="aside-icon" :src="m.icon" mode="aspectFit" />
|
||||
<text class="aside-title" v-if="!collapsed">{{ m.title }}</text>
|
||||
<view class="menu-icon">
|
||||
<text class="icon-text">{{ getIconText(menu.icon) }}</text>
|
||||
</view>
|
||||
<view v-if="!collapsed" class="menu-title">
|
||||
<text>{{ menu.title }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="aside-footer" @click="onToggle">
|
||||
<view class="toggle-btn">
|
||||
<text class="toggle-icon">{{ collapsed ? '>' : '<' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import type { MenuItem } from '../types.uts'
|
||||
import type { TopMenu } from '@/layouts/admin/router/adminRoutes.uts'
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
collapsed: boolean
|
||||
menuList: MenuItem[]
|
||||
activeMenuId: string
|
||||
asideWidth:number
|
||||
topMenus: TopMenu[]
|
||||
activeTopMenuId: string
|
||||
asideWidth: number
|
||||
}>()
|
||||
|
||||
defineEmits<{
|
||||
(e:'menu-click', menuId: string): void
|
||||
const emit = defineEmits<{
|
||||
(e: 'toggle'): void
|
||||
(e: 'menu-click', menu: TopMenu): void
|
||||
}>()
|
||||
|
||||
function getIconText(icon: string): string {
|
||||
const iconMap: Record<string, string> = {
|
||||
'home': 'H',
|
||||
'user': 'U',
|
||||
'product': 'P',
|
||||
'order': 'O',
|
||||
'marketing': 'M',
|
||||
'content': 'C',
|
||||
'finance': 'F',
|
||||
'statistic': 'S',
|
||||
'setting': 'T'
|
||||
}
|
||||
return iconMap[icon] || icon.charAt(0).toUpperCase()
|
||||
}
|
||||
|
||||
function onMenuClick(menu: TopMenu): void {
|
||||
emit('menu-click', menu)
|
||||
}
|
||||
|
||||
function onToggle(): void {
|
||||
emit('toggle')
|
||||
}
|
||||
|
||||
function onLogoClick(): void {
|
||||
const homeMenu = props.topMenus.find(m => m.id === 'home')
|
||||
if (homeMenu) {
|
||||
emit('menu-click', homeMenu)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.aside{
|
||||
background: #1f2a37;
|
||||
height: 100vh;
|
||||
<style scoped lang="scss">
|
||||
.admin-aside {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
display:flex;
|
||||
background: #001529;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: width 0.3s ease;
|
||||
z-index: 1000;
|
||||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
.aside-header{
|
||||
height: 56px;
|
||||
display:flex;
|
||||
flex-direction:row;
|
||||
align-items:center;
|
||||
justify-content: space-between;
|
||||
padding: 0 12px;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.08);
|
||||
}
|
||||
.logo-text{
|
||||
color:#fff;
|
||||
font-size:20px;
|
||||
font-weight:600;
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
text-align:center;
|
||||
}
|
||||
.collapse-btn{ width:28px; height:28px; display:flex; align-items:center; justify-content:center; }
|
||||
.collapse-text{ color:rgba(255,255,255,0.7); }
|
||||
|
||||
.aside-menu{ padding: 8px 0; }
|
||||
.aside-item{
|
||||
height: 54px;
|
||||
display:flex;
|
||||
flex-direction: column;
|
||||
align-items:center;
|
||||
justify-content:center;
|
||||
gap: 6px;
|
||||
margin: 6px 10px;
|
||||
border-radius: 8px;
|
||||
.aside-logo {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.logo-text {
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.aside-menu {
|
||||
flex: 1;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
height: 60px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
transition: all 0.3s;
|
||||
position: relative;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: #1890ff;
|
||||
color: #fff;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 3px;
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
font-size: 24px;
|
||||
margin-bottom: 4px;
|
||||
|
||||
.icon-text {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
|
||||
text {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.aside-footer {
|
||||
height: 48px;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-btn {
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
font-size: 18px;
|
||||
|
||||
.toggle-icon {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.admin-aside.collapsed {
|
||||
.menu-item {
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
.aside-item.active{ background:#1677ff; }
|
||||
.aside-icon{ width:22px; height:22px; }
|
||||
.aside-title{ color:#fff; font-size:12px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user