init
This commit is contained in:
parent
c3c1189c08
commit
401d12efda
|
|
@ -1,9 +1,37 @@
|
|||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { RouterLink } from 'vue-router'
|
||||
import { useMenuStore } from '../stores/menu'
|
||||
|
||||
const menuStore = useMenuStore()
|
||||
const expandedMenus = ref(new Set())
|
||||
|
||||
function toggleMenu(menuId) {
|
||||
if (expandedMenus.value.has(menuId)) {
|
||||
expandedMenus.value.delete(menuId)
|
||||
} else {
|
||||
expandedMenus.value.add(menuId)
|
||||
}
|
||||
}
|
||||
|
||||
function hasChildren(menu) {
|
||||
return menu.children && menu.children.length > 0
|
||||
}
|
||||
|
||||
function getIcon(iconName) {
|
||||
const iconMap = {
|
||||
'home': '🏠',
|
||||
'team': '🏢',
|
||||
'setting': '⚙️',
|
||||
'project': '📋',
|
||||
'profile': '📝',
|
||||
'environment': '📍',
|
||||
'database': '📊',
|
||||
'cluster': '🔧',
|
||||
'default': '📄'
|
||||
}
|
||||
return iconMap[iconName] || iconMap['default']
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
menuStore.loadMenus()
|
||||
|
|
@ -12,9 +40,40 @@ onMounted(() => {
|
|||
|
||||
<template>
|
||||
<nav class="menu">
|
||||
<RouterLink v-for="menu in menuStore.menus" :key="menu.id" class="item" active-class="is-active" :to="menu.path">
|
||||
{{ menu.name }}
|
||||
</RouterLink>
|
||||
<div v-for="menu in menuStore.menus" :key="menu.id" class="menu-item">
|
||||
<RouterLink
|
||||
v-if="menu.path"
|
||||
class="item"
|
||||
active-class="is-active"
|
||||
:to="menu.path"
|
||||
>
|
||||
<span class="icon">{{ getIcon(menu.icon) }}</span>
|
||||
<span class="name">{{ menu.name }}</span>
|
||||
</RouterLink>
|
||||
<div
|
||||
v-else
|
||||
class="item"
|
||||
:class="{ 'is-expanded': expandedMenus.has(menu.id) }"
|
||||
@click="toggleMenu(menu.id)"
|
||||
>
|
||||
<span class="icon">{{ getIcon(menu.icon) }}</span>
|
||||
<span class="name">{{ menu.name }}</span>
|
||||
<span class="arrow" :class="{ 'is-expanded': expandedMenus.has(menu.id) }">▾</span>
|
||||
</div>
|
||||
|
||||
<div v-if="hasChildren(menu) && expandedMenus.has(menu.id)" class="submenu">
|
||||
<RouterLink
|
||||
v-for="child in menu.children"
|
||||
:key="child.id"
|
||||
class="submenu-item"
|
||||
active-class="is-active"
|
||||
:to="child.path"
|
||||
>
|
||||
<span class="icon">{{ getIcon(child.icon) }}</span>
|
||||
<span class="name">{{ child.name }}</span>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
|
|
@ -25,6 +84,12 @@ onMounted(() => {
|
|||
gap: 6px;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.item {
|
||||
height: 36px;
|
||||
padding: 0 12px;
|
||||
|
|
@ -34,6 +99,8 @@ onMounted(() => {
|
|||
text-decoration: none;
|
||||
color: var(--muted);
|
||||
border: 1px solid transparent;
|
||||
cursor: pointer;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.item:hover {
|
||||
|
|
@ -49,11 +116,91 @@ onMounted(() => {
|
|||
font-weight: 800;
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 18px;
|
||||
width: 24px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.name {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 10px;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.arrow.is-expanded {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.submenu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding-left: 24px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.submenu-item {
|
||||
height: 32px;
|
||||
padding: 0 10px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
color: var(--muted);
|
||||
border: 1px solid transparent;
|
||||
cursor: pointer;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.submenu-item:hover {
|
||||
color: var(--text);
|
||||
border-color: rgba(180, 128, 64, 0.25);
|
||||
background: rgba(180, 128, 64, 0.08);
|
||||
}
|
||||
|
||||
.submenu-item.is-active {
|
||||
color: var(--text);
|
||||
border-color: rgba(32, 92, 64, 0.28);
|
||||
background: rgba(32, 92, 64, 0.1);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.submenu-item .icon {
|
||||
font-size: 16px;
|
||||
width: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
@media (max-width: 980px) {
|
||||
.item {
|
||||
.item,
|
||||
.submenu-item {
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.name,
|
||||
.arrow {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 100%;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.submenu {
|
||||
padding-left: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
|
|
@ -61,10 +208,25 @@ onMounted(() => {
|
|||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.item {
|
||||
.item,
|
||||
.submenu-item {
|
||||
justify-content: center;
|
||||
padding: 0 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.name,
|
||||
.arrow {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 100%;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.submenu {
|
||||
padding-left: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { RouterLink, RouterView, useRouter } from 'vue-router'
|
||||
import { apiFetch } from '../../lib/api'
|
||||
import { clearAuth, getToken } from '../../lib/auth'
|
||||
import { useUserStore } from '../../stores/user'
|
||||
import DynamicMenu from '../../components/DynamicMenu.vue'
|
||||
|
||||
|
|
@ -107,7 +106,7 @@ onBeforeUnmount(() => {
|
|||
<template>
|
||||
<div class="admin">
|
||||
<aside class="sider">
|
||||
<RouterLink class="sider__brand" to="/admin">
|
||||
<RouterLink class="sider__brand" to="/admin/home">
|
||||
<div class="mark">遗</div>
|
||||
<div>
|
||||
<div class="title">管理后台</div>
|
||||
|
|
@ -120,7 +119,7 @@ onBeforeUnmount(() => {
|
|||
|
||||
<div class="main">
|
||||
<header class="header">
|
||||
<div class="header__left">古建筑保护信息化平台 · 管理后台</div>
|
||||
<div class="header__left">古建筑保护信息化平台 </div>
|
||||
<div class="header__right">
|
||||
<div ref="menuRoot" class="userbox">
|
||||
<button class="userbtn" type="button" @click.stop="menuOpen = !menuOpen">
|
||||
|
|
@ -551,9 +550,11 @@ onBeforeUnmount(() => {
|
|||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 0 12px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 980px) {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,10 @@ onMounted(() => {
|
|||
<div v-else-if="error" class="error">{{ error }}</div>
|
||||
<div v-else class="org-list">
|
||||
<div v-for="org in orgs" :key="org.id" class="org-item">
|
||||
<div class="org-name">{{ org.name }}</div>
|
||||
<div class="org-code">{{ org.code }}</div>
|
||||
<div class="org-info">
|
||||
<div class="org-name">{{ org.name }}</div>
|
||||
<div class="org-code">{{ org.code }}</div>
|
||||
</div>
|
||||
<div class="org-actions">
|
||||
<button class="btn2">编辑</button>
|
||||
<button class="btn2">删除</button>
|
||||
|
|
@ -94,14 +96,18 @@ onMounted(() => {
|
|||
align-items: center;
|
||||
}
|
||||
|
||||
.org-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.org-name {
|
||||
font-weight: 800;
|
||||
flex: 1;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.org-code {
|
||||
color: var(--muted);
|
||||
margin: 0 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.org-actions {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import Home from '../pages/Home.vue'
|
||||
import Index from '../pages/index.vue'
|
||||
import Archives from '../pages/Archives.vue'
|
||||
import Inspections from '../pages/Inspections.vue'
|
||||
import Projects from '../pages/Projects.vue'
|
||||
import Analytics from '../pages/Analytics.vue'
|
||||
import QrLogin from '../pages/QrLogin.vue'
|
||||
import AdminLayout from '../pages/admin/AdminLayout.vue'
|
||||
import AdminHome from '../pages/admin/Home.vue'
|
||||
import { getToken } from '../lib/auth'
|
||||
|
||||
const router = createRouter({
|
||||
|
|
@ -13,8 +14,8 @@ const router = createRouter({
|
|||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: Home,
|
||||
name: 'index',
|
||||
component: Index,
|
||||
},
|
||||
{
|
||||
path: '/archives',
|
||||
|
|
@ -45,12 +46,12 @@ const router = createRouter({
|
|||
path: '/admin',
|
||||
component: AdminLayout,
|
||||
children: [
|
||||
{ path: '', redirect: '/admin/archives' },
|
||||
{ path: 'dashboard', component: Home },
|
||||
{ path: '', redirect: '/admin/home' },
|
||||
{ path: 'home', component: AdminHome },
|
||||
{ path: 'archives', name: 'admin-archives', component: Archives },
|
||||
{ path: 'inspections', name: 'admin-inspections', component: Inspections },
|
||||
{ path: 'projects', name: 'admin-projects', component: Projects },
|
||||
{ path: 'analytics', name: 'admin-analytics', component: Analytics },
|
||||
{ path: 'system', name: 'admin-analytics', component: Analytics },
|
||||
{ path: 'org/list', name: 'admin-org', component: () => import('../pages/org/list.vue') },
|
||||
],
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue