Commit b9000e34 by Lin

feat: 基座layout布局修改/路由菜单渲染修改

1 parent 9d6ebd1a
<div align="center">
<a href="https://github.com/anncwb/vue-venus-admin">
<img alt="venusAdmin Logo" width="215" src="https://unpkg.com/@venusjs/static-source@0.1.7/source/logo-v1.webp">
</a>
<br>
<br>
[![license](https://img.shields.io/github/license/anncwb/vue-venus-admin.svg)](LICENSE)
<h1>Vue venus Admin</h1>
</div>
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=venusjs_vue-venus-admin&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=venusjs_vue-venus-admin) ![codeql](https://github.com/venusjs/vue-venus-admin/actions/workflows/codeql.yml/badge.svg) ![build](https://github.com/venusjs/vue-venus-admin/actions/workflows/build.yml/badge.svg) ![ci](https://github.com/venusjs/vue-venus-admin/actions/workflows/ci.yml/badge.svg) ![deploy](https://github.com/venusjs/vue-venus-admin/actions/workflows/deploy.yml/badge.svg)
**日本語** | [English](./README.md) | [中文](./README.zh-CN.md)
## 紹介
Vue venus Adminは、最新の`vue3`、`vite`、`TypeScript`などの主流技術を使用して開発された、無料でオープンソースの中・後端テンプレートです。すぐに使える中・後端のフロントエンドソリューションとして、学習の参考にもなります。
## アップグレード通知
これは最新バージョン `5.0` であり、以前のバージョンとは互換性がありません。新しいプロジェクトを開始する場合は、最新バージョンを使用することをお勧めします。古いバージョンを表示したい場合は、[v2ブランチ](https://github.com/venusjs/vue-venus-admin/tree/v2)を使用してください。
## 特徴
- **最新技術スタック**:Vue 3やViteなどの最先端フロントエンド技術で開発
- **TypeScript**:アプリケーション規模のJavaScriptのための言語
- **テーマ**:複数のテーマカラーが利用可能で、カスタマイズオプションも豊富
- **国際化**:完全な内蔵国際化サポート
- **権限管理**:動的ルートベースの権限生成ソリューションを内蔵
## プレビュー
- [venus Admin](https://venus.pro/) - フルバージョンの中国語サイト
テストアカウント:venus/123456
<div align="center">
<img alt="venusAdmin Logo" width="100%" src="https://anncwb.github.io/anncwb/images/preview1.png">
<img alt="venusAdmin Logo" width="100%" src="https://anncwb.github.io/anncwb/images/preview2.png">
<img alt="venusAdmin Logo" width="100%" src="https://anncwb.github.io/anncwb/images/preview3.png">
</div>
### Gitpodを使用
Gitpod(GitHub用の無料オンライン開発環境)でプロジェクトを開き、すぐにコーディングを開始します。
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/venusjs/vue-venus-admin)
## ドキュメント
[ドキュメント](https://doc.venus.pro/)
## インストールと使用
1. プロジェクトコードを取得
```bash
git clone https://github.com/venusjs/vue-venus-admin.git
```
2. 依存関係のインストール
```bash
cd vue-venus-admin
npm i -g corepack
pnpm install
```
3. 実行
```bash
pnpm dev
```
4. ビルド
```bash
pnpm build
```
## 変更ログ
[CHANGELOG](https://github.com/venusjs/vue-venus-admin/releases)
## 貢献方法
ご参加をお待ちしております![Issueを提出](https://github.com/anncwb/vue-venus-admin/issues/new/choose)するか、Pull Requestを送信してください。
**Pull Request プロセス:**
1. コードをフォーク
2. 自分のブランチを作成:`git checkout -b feat/xxxx`
3. 変更をコミット:`git commit -am 'feat(function): add xxxxx'`
4. ブランチをプッシュ:`git push origin feat/xxxx`
5. `pull request`を送信
## Git貢献提出規則
参考 [vue](https://github.com/vuejs/vue/blob/dev/.github/COMMIT_CONVENTION.md) 規則 ([Angular](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular))
- `feat` 新機能の追加
- `fix` 問題/バグの修正
- `style` コードスタイルに関連し、実行結果に影響しない
- `perf` 最適化/パフォーマンス向上
- `refactor` リファクタリング
- `revert` 変更の取り消し
- `test` テスト関連
- `docs` ドキュメント/注釈
- `chore` 依存関係の更新/スキャフォールディング設定の変更など
- `ci` 継続的インテグレーション
- `types` 型定義ファイルの変更
## ブラウザサポート
ローカル開発には `Chrome 80+` ブラウザを推奨します
モダンブラウザをサポートし、IEはサポートしません
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari |
| :-: | :-: | :-: | :-: |
| 最新2バージョン | 最新2バージョン | 最新2バージョン | 最新2バージョン |
## メンテナー
[@venus](https://github.com/anncwb)
## スター歴史
[![Star History Chart](https://api.star-history.com/svg?repos=venusjs/vue-venus-admin&type=Date)](https://star-history.com/#venusjs/vue-venus-admin&Date)
## 寄付
このプロジェクトが役に立つと思われた場合、作者にコーヒーを一杯おごってサポートを示すことができます!
![donate](https://unpkg.com/@venusjs/static-source@0.1.7/source/sponsor.png)
<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aed;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvenus">Paypal Me</a>
## 貢献者
<a href="https://openomy.app/github/venusjs/vue-venus-admin" target="_blank" style="display: block; width: 100%;" align="center">
<img src="https://openomy.app/svg?repo=venusjs/vue-venus-admin&chart=bubble&latestMonth=3" target="_blank" alt="Contribution Leaderboard" style="display: block; width: 100%;" />
</a>
<a href="https://github.com/venusjs/vue-venus-admin/graphs/contributors">
<img alt="Contributors" src="https://contrib.rocks/image?repo=venusjs/vue-venus-admin" />
</a>
## Discord
- [Github Discussions](https://github.com/anncwb/vue-venus-admin/discussions)
## ライセンス
[MIT © venus-2020](./LICENSE)
...@@ -13,21 +13,21 @@ export const homeMenus: MenuItem[] = [ ...@@ -13,21 +13,21 @@ export const homeMenus: MenuItem[] = [
path: '/home/dashboard', path: '/home/dashboard',
icon: '📊', icon: '📊',
level: 1, level: 1,
}, }
]; ];
// Vue 微应用侧边栏菜单(多级示例) // Vue 微应用侧边栏菜单(多级示例)
export const vueAppMenus: MenuItem[] = [ export const vueAppMenus: MenuItem[] = [
{ {
id: 'contacts', id: 'contacts',
title: '子菜单示例', title: '智能助理',
path: '/subapp-vue/contacts', path: '/subapp-vue/contacts',
icon: '📞', icon: '📥',
level: 1, level: 1,
children: [ children: [
{ {
id: 'contacts-list', id: 'contacts-list',
title: '关于', title: '岗位助理配置',
path: '/subapp-vue/about', path: '/subapp-vue/about',
icon: '📝', icon: '📝',
level: 2, level: 2,
...@@ -35,102 +35,21 @@ export const vueAppMenus: MenuItem[] = [ ...@@ -35,102 +35,21 @@ export const vueAppMenus: MenuItem[] = [
}, },
{ {
id: 'contacts-import', id: 'contacts-import',
title: '通信示例', title: '知识管理',
path: '/subapp-vue/communication', path: '/subapp-vue/communication',
icon: '📥', icon: '📥',
level: 2, level: 2,
parentId: 'contacts', parentId: 'contacts',
}, },{
], id: 'contacts-import',
}, title: '智能体管理',
{ path: '/subapp-vue/communications',
id: 'marketing', icon: '📥',
title: '用户管理',
path: '/subapp-vue/user',
icon: '🎯',
level: 1,
children: [],
},
{
id: 'marketing',
title: '系统管理',
path: '/subapp-vue/settings',
icon: '🎯',
level: 1,
children: [],
},
];
// React 微应用侧边栏菜单(多级示例)
export const reactAppMenus: MenuItem[] = [
{
id: 'data-analysis',
title: '数据分析',
path: '/subapp-react/analysis',
icon: '📊',
level: 1,
children: [
{
id: 'sales-analysis',
title: '销售分析',
path: '/subapp-react/analysis/sales',
icon: '💰',
level: 2,
parentId: 'data-analysis',
children: [
{
id: 'sales-overview',
title: '销售概览',
path: '/subapp-react/analysis/sales/overview',
icon: '📈',
level: 3,
parentId: 'sales-analysis',
},
{
id: 'sales-trend',
title: '销售趋势',
path: '/subapp-react/analysis/sales/trend',
icon: '📉',
level: 3,
parentId: 'sales-analysis',
},
],
},
{
id: 'customer-analysis',
title: '客户分析',
path: '/subapp-react/analysis/customer',
icon: '👤',
level: 2,
parentId: 'data-analysis',
},
],
},
{
id: 'reports',
title: '报表中心',
path: '/subapp-react/reports',
icon: '📑',
level: 1,
children: [
{
id: 'reports-custom',
title: '自定义报表',
path: '/subapp-react/reports/custom',
icon: '⚙️',
level: 2,
parentId: 'reports',
},
{
id: 'reports-export',
title: '报表导出',
path: '/subapp-react/reports/export',
icon: '📤',
level: 2, level: 2,
parentId: 'reports', parentId: 'contacts',
}, },
], ],
}, }
]; ];
/** /**
...@@ -141,24 +60,17 @@ export const topMenus: TopMenuItem[] = [ ...@@ -141,24 +60,17 @@ export const topMenus: TopMenuItem[] = [
{ {
id: 'home', id: 'home',
title: '首页', title: '首页',
path: '/home', path: '/home/dashboard',
icon: '🏠', icon: '',
sidebarMenus: homeMenus, sidebarMenus: homeMenus,
}, },
{ {
id: 'vue-app', id: 'vue-app',
title: 'Vue 微应用', title: '微应用',
path: '/subapp-vue', path: '/subapp-vue',
icon: '💚', icon: '',
sidebarMenus: vueAppMenus, sidebarMenus: vueAppMenus,
}, },
{
id: 'react-app',
title: '子应用模板',
path: '/subapp-react',
icon: '⚛️',
sidebarMenus: reactAppMenus,
},
]; ];
/** /**
......
<script setup lang="ts"> <script setup lang="ts">
import type { BreadcrumbItem, MenuItem } from '@/types/menu'; import type { BreadcrumbItem, MenuItem } from '@/types/menu';
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import Breadcrumb from './components/Breadcrumb.vue';
import NotificationCenter from '@/components/NotificationCenter.vue'; import NotificationCenter from './components/NotificationCenter.vue';
import SidebarMenuItem from '@/components/SidebarMenuItem.vue'; import SidebarMenuItem from './components/SidebarMenuItem.vue';
import UserInfo from '@/components/UserInfo.vue'; import UserInfo from './components/UserInfo.vue';
import { Download } from '@element-plus/icons-vue';
import { getMenuParentPaths, topMenus } from '@/config/menus'; import { getMenuParentPaths, topMenus } from '@/config/menus';
import { microApps } from '@/qiankun/apps'; import { microApps } from '@/qiankun/apps';
import { communicationManager } from '@/qiankun/communication'; import { communicationManager } from '@/qiankun/communication';
...@@ -14,6 +14,9 @@ import { communicationManager } from '@/qiankun/communication'; ...@@ -14,6 +14,9 @@ import { communicationManager } from '@/qiankun/communication';
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
// 应用名称(从环境变量读取)
const appName ='汽车销售智能体';
// 展开的菜单项 keys // 展开的菜单项 keys
const expandedKeys = ref<Set<string>>(new Set()); const expandedKeys = ref<Set<string>>(new Set());
...@@ -170,78 +173,51 @@ watch( ...@@ -170,78 +173,51 @@ watch(
<template> <template>
<div class="basic-layout"> <div class="basic-layout">
<!-- 顶部导航已隐藏,所有菜单移至侧边栏 --> <!-- 侧边栏 - 显示所有菜单 -->
<header class="layout-header"> <aside class="layout-sidebar">
<div class="header-left"> <!-- Logo和标题 -->
<div class="sidebar-header">
<div class="logo"> <div class="logo">
<span class="logo-text">SCRM 微前端平台</span>
</div> </div>
<div class="title">{{ appName }}</div>
</div> </div>
<div class="header-right"> <div class="sidebar-menu">
<NotificationCenter /> <!-- 直接渲染所有侧边栏菜单,不显示 topMenus 分组标题 -->
<UserInfo /> <template v-for="topMenu in topMenus" :key="topMenu.id">
<template v-if="topMenu.sidebarMenus && topMenu.sidebarMenus.length > 0">
<template v-for="item in topMenu.sidebarMenus" :key="item.id">
<SidebarMenuItem
:menu="item"
:active-path="route.path"
:expanded-keys="expandedKeys"
@click="handleMenuClick"
@toggle="handleMenuToggle"
/>
</template>
</template>
</template>
</div> </div>
</header> </aside>
<!-- 主体区域 --> <!-- 主体区域 -->
<main class="layout-main"> <main class="layout-main">
<!-- 侧边栏 - 显示所有菜单 --> <!-- 顶部导航 -->
<aside class="layout-sidebar"> <header class="layout-header">
<div class="sidebar-menu"> <div class="header-left">
<!-- 按顶部菜单分组显示所有菜单 --> <Breadcrumb :breadcrumbs="breadcrumbs" />
<template v-for="topMenu in topMenus" :key="topMenu.id">
<div
v-if="topMenu.sidebarMenus && topMenu.sidebarMenus.length > 0"
class="menu-group"
>
<div
class="menu-group-title"
:class="{ active: isTopMenuActive(topMenu.id) }"
@click="handleTopMenuClick(topMenu.id, topMenu.path)"
>
<span v-if="topMenu.icon" class="group-icon">{{
topMenu.icon
}}</span>
<span>{{ topMenu.title }}</span>
</div>
<template v-for="item in topMenu.sidebarMenus" :key="item.id">
<SidebarMenuItem
:menu="item"
:active-path="route.path"
:expanded-keys="expandedKeys"
@click="handleMenuClick"
@toggle="handleMenuToggle"
/>
</template>
</div>
</template>
</div> </div>
</aside> <div class="header-right">
<div class="top-tools">
<el-icon size="16" style="margin-right: 6px;"><Download /></el-icon>
<span>下载中心</span>
</div>
<NotificationCenter />
<UserInfo />
</div>
</header>
<!-- 内容区域 --> <!-- 内容区域 -->
<section class="layout-content"> <section class="layout-content">
<!-- 面包屑导航 -->
<div v-if="breadcrumbs.length > 0" class="breadcrumb">
<template v-for="(crumb, index) in breadcrumbs" :key="index">
<span
class="breadcrumb-item"
:class="{
clickable: crumb.path && index < breadcrumbs.length - 1,
}"
@click="
crumb.path &&
index < breadcrumbs.length - 1 &&
router.push(crumb.path)
"
>
{{ crumb.title }}
</span>
<span
v-if="index < breadcrumbs.length - 1"
class="breadcrumb-separator"
>/</span>
</template>
</div>
<!-- 微应用内容 --> <!-- 微应用内容 -->
<div class="content-wrapper"> <div class="content-wrapper">
...@@ -260,25 +236,52 @@ watch( ...@@ -260,25 +236,52 @@ watch(
</div> </div>
</section> </section>
</main> </main>
<!-- 页脚 -->
<footer class="layout-footer">
<div class="footer-content">
<span>(C) 2024 SCRM 微前端平台. All Rights Reserved.</span>
</div>
</footer>
</div> </div>
</template> </template>
<style scoped> <style scoped>
.basic-layout { .basic-layout {
display: flex; display: flex;
flex-direction: column; flex-direction: row;
height: 100vh; height: 100vh;
overflow: hidden; overflow: hidden;
background-color: #f0f2f5; background-color: #f0f2f5;
} }
/* 侧边栏样式 */
.layout-sidebar {
flex-shrink: 0;
width: 228px;
overflow-y: auto;
background: #F7F8F9;
border-radius: 4px;
box-shadow: 0 2px 8px rgb(0 0 0 / 6%);
font-size: 14px;
.sidebar-header {
width: 228px;
height: 56px;
display: flex;
gap: 8px;
align-items: center;
color: #0d162a;
font-size: 20px;
font-weight: 600;
background: #FFFFFF;
border-right: 1px solid #f2f4f7;
padding-left: 24px;
}
}
/* 主体区域 */
.layout-main {
display: flex;
flex: 1;
flex-direction: column;
min-width: 0;
min-height: 0;
overflow: hidden;
}
/* 头部样式 */ /* 头部样式 */
.layout-header { .layout-header {
z-index: 100; z-index: 100;
...@@ -286,10 +289,10 @@ watch( ...@@ -286,10 +289,10 @@ watch(
flex-shrink: 0; flex-shrink: 0;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
height: 64px; height: 56px;
padding: 0 24px; padding: 0 24px;
background: #fff; background: #fff;
box-shadow: 0 2px 8px rgb(0 0 0 / 6%); border-bottom: 1px solid #f2f4f7;
} }
.header-left { .header-left {
...@@ -297,12 +300,7 @@ watch( ...@@ -297,12 +300,7 @@ watch(
} }
.logo { .logo {
display: flex;
gap: 8px;
align-items: center;
font-size: 18px;
font-weight: 600;
color: #1890ff;
} }
.logo-icon { .logo-icon {
...@@ -316,26 +314,6 @@ watch( ...@@ -316,26 +314,6 @@ watch(
align-items: center; align-items: center;
} }
/* 主体区域 */
.layout-main {
display: flex;
flex: 1;
min-height: 0;
margin-top: 16px;
overflow: hidden;
}
/* 侧边栏样式 */
.layout-sidebar {
flex-shrink: 0;
width: 240px;
margin-left: 16px;
overflow-y: auto;
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 8px rgb(0 0 0 / 6%);
}
.layout-sidebar::-webkit-scrollbar { .layout-sidebar::-webkit-scrollbar {
width: 6px; width: 6px;
} }
...@@ -349,13 +327,9 @@ watch( ...@@ -349,13 +327,9 @@ watch(
background-color: transparent; background-color: transparent;
} }
.sidebar-menu { /* .sidebar-menu {
padding: 8px 0; padding: 8px 0;
} } */
.menu-group {
margin-bottom: 16px;
}
.menu-group:last-child { .menu-group:last-child {
margin-bottom: 0; margin-bottom: 0;
...@@ -382,10 +356,7 @@ watch( ...@@ -382,10 +356,7 @@ watch(
} }
.menu-group-title.active { .menu-group-title.active {
font-weight: 700; color: #1956FE;
color: #1890ff;
background-color: #e6f7ff;
border-left-color: #1890ff;
} }
.group-icon { .group-icon {
...@@ -398,40 +369,10 @@ watch( ...@@ -398,40 +369,10 @@ watch(
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
min-width: 0; min-width: 0;
margin: 0 16px; min-height: 0;
overflow-y: auto; overflow-y: auto;
} }
.breadcrumb {
display: flex;
flex-shrink: 0;
flex-wrap: wrap;
align-items: center;
padding: 12px 0;
margin-bottom: 16px;
font-size: 14px;
color: #666;
}
.breadcrumb-item {
color: #666;
}
.breadcrumb-item.clickable {
color: #1890ff;
cursor: pointer;
transition: color 0.3s;
}
.breadcrumb-item.clickable:hover {
color: #40a9ff;
}
.breadcrumb-separator {
margin: 0 8px;
color: #999;
}
.content-wrapper { .content-wrapper {
flex: 1; flex: 1;
min-height: 0; min-height: 0;
...@@ -440,19 +381,16 @@ watch( ...@@ -440,19 +381,16 @@ watch(
border-radius: 4px; border-radius: 4px;
box-shadow: 0 2px 8px rgb(0 0 0 / 6%); box-shadow: 0 2px 8px rgb(0 0 0 / 6%);
} }
.top-tools {
/* 页脚样式 */ position: relative;
.layout-footer { display: flex;
flex-shrink: 0; align-items: center;
padding: 16px 0; justify-content: center;
text-align: center; cursor: pointer;
background: #fff; border-radius: 50%;
border-top: 1px solid #f0f0f0; transition: background-color 0.2s;
} font-size: 12px;
margin-right: 16px;
.footer-content {
font-size: 14px;
color: #999;
} }
/* 过渡动画 */ /* 过渡动画 */
......
<script setup lang="ts">
import type { BreadcrumbItem } from '@/types/menu';
import { useRouter } from 'vue-router';
defineProps<{
breadcrumbs: BreadcrumbItem[];
}>();
const router = useRouter();
const handleBreadcrumbClick = (crumb: BreadcrumbItem, index: number, breadcrumbs: BreadcrumbItem[]) => {
if (crumb.path && index < breadcrumbs.length - 1) {
router.push(crumb.path);
}
};
</script>
<template>
<div v-if="breadcrumbs.length > 0" class="breadcrumb">
<template v-for="(crumb, index) in breadcrumbs" :key="index">
<span
class="breadcrumb-item"
:class="{
clickable: crumb.path && index < breadcrumbs.length - 1,
}"
@click="handleBreadcrumbClick(crumb, index, breadcrumbs)"
>
{{ crumb.title }}
</span>
<span
v-if="index < breadcrumbs.length - 1"
class="breadcrumb-separator"
>/</span>
</template>
</div>
</template>
<style scoped>
.breadcrumb {
display: flex;
flex-shrink: 0;
flex-wrap: wrap;
align-items: center;
font-size: 12px;
color: #2f3133;
}
.breadcrumb-item {
color: #2f3133;
}
.breadcrumb-item.clickable {
color: #969aa3;
cursor: pointer;
transition: color 0.3s;
}
.breadcrumb-item.clickable:hover {
color: #2f3133;
}
.breadcrumb-separator {
margin: 0 8px;
color: #999;
}
</style>
<script setup lang="ts">
import type { GlobalState } from '@/qiankun/communication';
import { computed, onMounted, onUnmounted, ref } from 'vue';
import { communicationManager } from '@/qiankun/communication';
import { Bell } from '@element-plus/icons-vue';
// 显示面板
const showPanel = ref(false);
// 通知列表
const notifications = ref<GlobalState['notifications']>([]);
// 未读数量
const unreadCount = computed(() => notifications.value.length);
// 切换面板显示
const togglePanel = () => {
showPanel.value = !showPanel.value;
};
// 获取图标
const getIcon = (type: string) => {
const icons: Record<string, string> = {
success: '✅',
warning: '⚠️',
error: '❌',
info: 'ℹ️',
};
return icons[type] || 'ℹ️';
};
// 格式化时间
const formatTime = (timestamp: number) => {
const now = Date.now();
const diff = now - timestamp;
if (diff < 60_000) return '刚刚';
if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}分钟前`;
if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)}小时前`;
return new Date(timestamp).toLocaleString('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
});
};
// 移除通知
const removeNotification = (id: string) => {
communicationManager.removeNotification(id);
};
// 清空所有通知
const clearAll = () => {
communicationManager.clearNotifications();
showPanel.value = false;
};
// 监听全局状态变化
let unsubscribe: (() => void) | null = null;
onMounted(() => {
// 初始化通知列表
const state = communicationManager.getGlobalState();
notifications.value = state.notifications || [];
// 监听状态变化
unsubscribe = communicationManager.onStateChange((state) => {
notifications.value = state.notifications || [];
});
});
onUnmounted(() => {
if (unsubscribe) {
unsubscribe();
}
});
</script>
<template>
<div class="notification-center">
<!-- 通知图标按钮 -->
<div class="notification-badge" @click="togglePanel">
<!-- <span class="icon">🔔</span>
<span v-if="unreadCount > 0" class="badge">{{ unreadCount }}</span> -->
<el-icon size="16" style="margin-right: 6px;"><Bell /></el-icon>
<span>消息通知</span>
</div>
<!-- 通知面板 -->
<transition name="slide">
<div v-if="showPanel" class="notification-panel">
<div class="panel-header">
<h3>通知中心</h3>
<button
v-if="notifications.length > 0"
@click="clearAll"
class="clear-btn"
>
清空
</button>
</div>
<div class="notification-list">
<div
v-for="notification in notifications"
:key="notification.id"
class="notification-item"
:class="[`type-${notification.type}`]"
>
<div class="notification-icon">
{{ getIcon(notification.type) }}
</div>
<div class="notification-content">
<div class="notification-title">{{ notification.title }}</div>
<div class="notification-message">{{ notification.message }}</div>
<div class="notification-meta">
<span v-if="notification.from" class="from"
>来自: {{ notification.from }}</span
>
<span class="time">{{
formatTime(notification.timestamp)
}}</span>
</div>
</div>
<button
@click="removeNotification(notification.id)"
class="close-btn"
>
✕
</button>
</div>
<div v-if="notifications.length === 0" class="empty-state">
<div class="empty-icon">📭</div>
<div class="empty-text">暂无通知</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<style scoped>
.notification-center {
position: relative;
}
.notification-badge {
position: relative;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
border-radius: 50%;
transition: background-color 0.2s;
font-size: 12px;
}
.notification-badge:hover {
background-color: rgb(0 0 0 / 5%);
}
.badge {
position: absolute;
top: 4px;
right: 4px;
display: flex;
align-items: center;
justify-content: center;
min-width: 18px;
height: 18px;
padding: 0 4px;
font-size: 12px;
color: white;
background-color: #ff4d4f;
border-radius: 9px;
}
.notification-panel {
position: absolute;
top: 50px;
right: 0;
z-index: 1000;
display: flex;
flex-direction: column;
width: 400px;
max-height: 600px;
background: white;
border-radius: 8px;
box-shadow: 0 4px 20px rgb(0 0 0 / 15%);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid #f0f0f0;
}
.panel-header h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
}
.clear-btn {
padding: 4px 12px;
font-size: 14px;
cursor: pointer;
background: transparent;
border: 1px solid #d9d9d9;
border-radius: 4px;
transition: all 0.2s;
}
.clear-btn:hover {
color: #1890ff;
border-color: #1890ff;
}
.notification-list {
max-height: 500px;
overflow-y: auto;
}
.notification-item {
display: flex;
gap: 12px;
padding: 16px 20px;
border-bottom: 1px solid #f0f0f0;
transition: background-color 0.2s;
}
.notification-item:hover {
background-color: #f5f5f5;
}
.notification-icon {
flex-shrink: 0;
font-size: 24px;
}
.notification-content {
flex: 1;
min-width: 0;
}
.notification-title {
margin-bottom: 4px;
font-size: 14px;
font-weight: 600;
color: #262626;
}
.notification-message {
margin-bottom: 8px;
font-size: 14px;
line-height: 1.5;
color: #595959;
}
.notification-meta {
display: flex;
gap: 12px;
font-size: 12px;
color: #8c8c8c;
}
.close-btn {
flex-shrink: 0;
width: 24px;
height: 24px;
font-size: 16px;
color: #8c8c8c;
cursor: pointer;
background: transparent;
border: none;
border-radius: 4px;
transition: all 0.2s;
}
.close-btn:hover {
color: #262626;
background-color: rgb(0 0 0 / 6%);
}
.empty-state {
padding: 60px 20px;
text-align: center;
}
.empty-icon {
margin-bottom: 12px;
font-size: 48px;
}
.empty-text {
font-size: 14px;
color: #8c8c8c;
}
/* 不同类型的通知样式 */
.type-success .notification-icon {
color: #52c41a;
}
.type-warning .notification-icon {
color: #faad14;
}
.type-error .notification-icon {
color: #ff4d4f;
}
.type-info .notification-icon {
color: #1890ff;
}
/* 过渡动画 */
.slide-enter-active,
.slide-leave-active {
transition: all 0.3s ease;
}
.slide-enter-from {
opacity: 0;
transform: translateY(-10px);
}
.slide-leave-to {
opacity: 0;
transform: translateY(-10px);
}
</style>
<script setup lang="ts">
import type { MenuItem } from '@/types/menu';
import { computed } from 'vue';
import SidebarMenuItem from './SidebarMenuItem.vue';
import { ArrowDown,ArrowRight } from '@element-plus/icons-vue';
interface Props {
menu: MenuItem;
activePath: string;
expandedKeys: Set<string>;
}
const props = defineProps<Props>();
const emit = defineEmits<{
click: [menu: MenuItem];
toggle: [menuId: string];
}>();
// 是否有子菜单
const hasChildren = computed(() => {
return props.menu.children && props.menu.children.length > 0;
});
// 是否展开
const isExpanded = computed(() => {
return props.expandedKeys.has(props.menu.id);
});
// 递归检查菜单或其子菜单是否激活
const checkMenuActive = (menu: MenuItem): boolean => {
// 当前菜单路径匹配
if (props.activePath === menu.path || props.activePath.startsWith(`${menu.path}/`)) {
return true;
}
// 如果有子菜单,递归检查子菜单是否有激活的
if (menu.children && menu.children.length > 0) {
return menu.children.some((child) => checkMenuActive(child));
}
return false;
};
// 是否激活(当前路由或子路由激活,包括子菜单激活时父菜单也激活)
const isActive = computed(() => {
return checkMenuActive(props.menu);
});
// 点击菜单项
const handleClick = () => {
if (hasChildren.value) {
handleToggle();
} else {
emit('click', props.menu);
}
};
// 展开/收起子菜单
const handleToggle = () => {
emit('toggle', props.menu.id);
};
</script>
<template>
<div class="sidebar-menu-item">
<!-- 菜单项本身 -->
<div
class="menu-item-content"
:class="{
active: isActive,
'has-children': hasChildren,
[`level-${menu.level || 1}`]: true,
}"
@click="handleClick"
>
<!-- 菜单图标 -->
<span v-if="menu.icon && (menu.level == 1)" class="menu-icon">{{ menu.icon || '' }}</span>
<!-- 菜单标题 -->
<span class="menu-title">{{ menu.title }}</span>
<!-- 展开/收起图标 -->
<span v-if="hasChildren" class="expand-icon" @click.stop="handleToggle">
<el-icon v-if="isExpanded"><ArrowDown /></el-icon>
<el-icon v-else><ArrowRight /></el-icon>
</span>
<!-- 徽章 -->
<span v-if="menu.meta?.badge" class="menu-badge">
{{ menu.meta.badge }}
</span>
</div>
<!-- 子菜单 -->
<transition name="submenu-expand">
<div v-if="hasChildren && isExpanded" class="submenu">
<SidebarMenuItem
v-for="child in menu.children"
:key="child.id"
:menu="child"
:active-path="activePath"
:expanded-keys="expandedKeys"
@click="$emit('click', $event)"
@toggle="$emit('toggle', $event)"
/>
</div>
</transition>
</div>
</template>
<style scoped>
.sidebar-menu-item {
width: 100%;
padding: 0 8px;
}
.menu-item-content {
position: relative;
display: flex;
gap: 8px;
align-items: center;
padding: 8px 16px;
color: #333;
cursor: pointer;
user-select: none;
transition: all 0.3s;
margin-top: 8px;
}
/* 层级缩进 */
.menu-item-content.level-1 {
padding-left: 14px;
}
.menu-item-content.level-2 {
padding-left: 32px;
font-size: 14px;
}
.menu-item-content.level-3 {
padding-left: 48px;
font-size: 14px;
}
.menu-item-content:hover {
color: #1956FE;
background-color: #f5f5f5;
}
.menu-item-content.active {
color: #1956FE;
}
/* 一级菜单选中样式:仅改变文字颜色,无背景色和边框 */
.menu-item-content.level-1.active {
background-color: transparent !important;
}
.menu-item-content.level-1.active:hover {
background-color: transparent !important;
}
.menu-item-content.level-1.active::before {
display: none;
}
/* 子菜单选中样式:保留背景色,移除边框 */
.menu-item-content.level-2.active,
.menu-item-content.level-3.active {
border-radius: 6px;
background-color: #E8F0FF;
}
.menu-item-content.level-2.active::before,
.menu-item-content.level-3.active::before {
display: none;
}
.expand-icon {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
font-size: 10px;
color: #666;
transition: transform 0.3s;
}
.menu-icon {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
font-size: 16px;
background: #1956FE;
}
.menu-title {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.menu-badge {
flex-shrink: 0;
min-width: 18px;
height: 18px;
padding: 0 6px;
font-size: 11px;
line-height: 18px;
color: #fff;
text-align: center;
background-color: #ff4d4f;
border-radius: 9px;
}
.submenu {
overflow: hidden;
padding-left: 3px;
}
/* 子菜单展开动画 */
.submenu-expand-enter-active,
.submenu-expand-leave-active {
transition: all 0.3s ease;
}
.submenu-expand-enter-from,
.submenu-expand-leave-to {
max-height: 0;
opacity: 0;
transform: translateY(-10px);
}
.submenu-expand-enter-to,
.submenu-expand-leave-from {
max-height: 1000px;
opacity: 1;
transform: translateY(0);
}
/* 有子菜单的项目样式 */
.menu-item-content.has-children {
font-weight: 500;
}
/* 二级菜单样式 */
.level-2 .menu-item-content {
background-color: rgb(0 0 0 / 2%);
}
.level-2 .menu-item-content:hover {
background-color: #f0f0f0;
}
/* 三级菜单样式 */
.level-3 .menu-item-content {
background-color: rgb(0 0 0 / 4%);
}
.level-3 .menu-item-content:hover {
background-color: #ebebeb;
}
</style>
...@@ -17,18 +17,7 @@ export const microApps: MicroAppConfig[] = [ ...@@ -17,18 +17,7 @@ export const microApps: MicroAppConfig[] = [
routerBase: '/subapp-vue', routerBase: '/subapp-vue',
communicationManager: createSubAppAdapter(), communicationManager: createSubAppAdapter(),
}, },
}, }
{
name: 'subapp-react',
// entry: getAppEntry('subapp-react', 'http://192.168.1.93:8082'),
entry: getAppEntry('subapp-react', 'http://192.168.10.36:8082'),
container: '#subapp-container',
activeRule: '/subapp-react',
props: {
routerBase: '/subapp-react',
communicationManager: createSubAppAdapter(),
},
},
]; ];
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!