2级sidebar
This commit is contained in:
4
urbanLifelineWeb/.gitignore
vendored
4
urbanLifelineWeb/.gitignore
vendored
@@ -42,6 +42,10 @@ pnpm-debug.log*
|
||||
.temp/
|
||||
.turbo/
|
||||
|
||||
# Module Federation
|
||||
**/__mf__temp/
|
||||
**/.__mf__temp/
|
||||
|
||||
# Testing
|
||||
coverage/
|
||||
**/coverage/
|
||||
|
||||
@@ -181,4 +181,5 @@ declare module 'shared/layouts' {
|
||||
import { DefineComponent } from 'vue'
|
||||
|
||||
export const BlankLayout: DefineComponent<{}, {}, any>
|
||||
export const AdminSidebarLayout: DefineComponent<{}, {}, any>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
.sidebar-layout {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// ==================== 侧边栏 ====================
|
||||
.sidebar {
|
||||
width: 220px;
|
||||
height: 100%;
|
||||
background: #F0EAF4;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
color: #333;
|
||||
flex-shrink: 0;
|
||||
transition: width 0.3s ease;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.08);
|
||||
|
||||
&.collapsed {
|
||||
width: 64px;
|
||||
|
||||
.sidebar-header {
|
||||
padding: 16px 12px;
|
||||
justify-content: center;
|
||||
|
||||
.logo {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.collapse-btn {
|
||||
position: static;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
justify-content: center;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.user-section {
|
||||
justify-content: center;
|
||||
padding: 16px 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 侧边栏头部
|
||||
.sidebar-header {
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.collapse-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #888;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: rgba(124, 58, 237, 0.1);
|
||||
color: #7c3aed;
|
||||
}
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
|
||||
.logo-img {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 6px;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
// 导航菜单
|
||||
.nav-menu {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px 0;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-section {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
margin-bottom: 4px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
color: #555;
|
||||
font-size: 14px;
|
||||
|
||||
&:hover {
|
||||
background: rgba(124, 58, 237, 0.1);
|
||||
color: #7c3aed;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: rgba(124, 58, 237, 0.15);
|
||||
color: #7c3aed;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.el-icon {
|
||||
font-size: 18px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
|
||||
// 用户信息
|
||||
.user-section {
|
||||
padding: 16px;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.08);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.user-avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
:deep(.el-avatar) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.user-name {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.back-icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #606266;
|
||||
transition: all 0.2s;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
color: #7c3aed;
|
||||
background: rgba(124, 58, 237, 0.1);
|
||||
}
|
||||
|
||||
.el-icon {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 主内容区 ====================
|
||||
.main-content {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
// iframe 容器
|
||||
.iframe-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.iframe-header {
|
||||
height: 56px;
|
||||
padding: 0 24px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
background: #fafafa;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.iframe-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.content-iframe {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.iframe-loading {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
color: #7c3aed;
|
||||
font-size: 14px;
|
||||
z-index: 10;
|
||||
|
||||
.el-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 响应式 ====================
|
||||
@media (max-width: 768px) {
|
||||
.sidebar {
|
||||
width: 64px;
|
||||
|
||||
&:not(.collapsed) {
|
||||
width: 220px;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 1000;
|
||||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.iframe-header {
|
||||
padding: 0 16px;
|
||||
|
||||
.iframe-title {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,13 +143,12 @@ function loadMenuFromStorage(): MenuItem[] {
|
||||
const userViews = loginDomain.userViews || []
|
||||
|
||||
|
||||
// 过滤出 SidebarLayout 的顶级菜单(没有 parentId,且属于 platform 服务,且不是admin路由)
|
||||
// 过滤出 AdminIframeSidebarLayout 的菜单(3个 iframe 管理后台入口)
|
||||
const sidebarViews = userViews.filter((view: any) =>
|
||||
view.layout === 'SidebarLayout' &&
|
||||
!view.parentId &&
|
||||
view.layout === 'AdminIframeSidebarLayout' && // AdminIframeSidebarLayout 布局
|
||||
view.viewType === 'iframe' && // iframe 类型
|
||||
view.type === 1 && // type 1 是侧边栏菜单
|
||||
view.service === 'platform' && // 只显示 platform 服务的视图
|
||||
view.url?.startsWith('/admin') // 只留admin 路由(由 AdminSidebar 管理)
|
||||
view.service === 'platform' // platform 服务
|
||||
)
|
||||
|
||||
// 按 orderNum 排序
|
||||
@@ -288,5 +287,5 @@ watch(
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import url("./SidebarLayout.scss");
|
||||
@import url("./AdminIframeSidebarLayout.scss");
|
||||
</style>
|
||||
@@ -165,7 +165,7 @@ function loadMenuFromStorage(): MenuItem[] {
|
||||
!view.url?.startsWith('/admin') // 排除 admin 路由(由 AdminSidebar 管理)
|
||||
)
|
||||
hasAdmin.value = userViews.filter((view: any) =>
|
||||
view.layout === 'SidebarLayout' &&
|
||||
view.layout === 'AdminIframeSidebarLayout' &&
|
||||
!view.parentId &&
|
||||
view.type === 1 && // type 1 是侧边栏菜单
|
||||
view.service === 'platform' && // 只显示 platform 服务的视图
|
||||
@@ -266,7 +266,7 @@ const handleUserCommand = (command: string) => {
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
const userViews = loginDomain.userViews || []
|
||||
const adminViews = userViews.filter((view: any) =>
|
||||
view.service === 'platform' && view.url?.startsWith('/admin')
|
||||
view.service === 'platform' && view.url?.startsWith('/admin') && view.viewType === 'iframe'
|
||||
)
|
||||
if (adminViews.length > 0) {
|
||||
// 按 orderNum 排序,跳转到第一个
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export { default as SidebarLayout } from "./SidebarLayout/SidebarLayout.vue";
|
||||
export { default as AdminIframeSidebarLayout } from "./AdminIframeSidebarLayout/AdminIframeSidebarLayout.vue";
|
||||
// BlankLayout从shared导入
|
||||
export { BlankLayout } from 'shared/layouts';
|
||||
export { BlankLayout, AdminSidebarLayout } from 'shared/layouts';
|
||||
@@ -18,14 +18,15 @@ import {
|
||||
import type { TbSysViewDTO } from 'shared/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import router from './index'
|
||||
import { SidebarLayout, BlankLayout } from '@/layouts'
|
||||
import { SidebarLayout, BlankLayout, AdminIframeSidebarLayout } from '@/layouts'
|
||||
|
||||
// Platform 布局组件映射
|
||||
const platformLayoutMap: Record<string, () => Promise<any>> = {
|
||||
'SidebarLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
'BlankLayout': () => Promise.resolve({ default: BlankLayout }),
|
||||
'NavigationLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
'BasicLayout': () => Promise.resolve({ default: SidebarLayout })
|
||||
'BasicLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
'AdminIframeSidebarLayout': () => Promise.resolve({ default: AdminIframeSidebarLayout })
|
||||
}
|
||||
|
||||
// 视图组件加载器
|
||||
|
||||
@@ -54,9 +54,34 @@ router.beforeEach((to, from, next) => {
|
||||
dynamicRoutesLoaded = true
|
||||
const loaded = loadRoutesFromStorage()
|
||||
|
||||
if (loaded && to.path !== '/') {
|
||||
// 动态路由已加载,重新导航到目标路由
|
||||
next({ ...to, replace: true })
|
||||
if (loaded) {
|
||||
if (to.path === '/') {
|
||||
// 访问根路径,重定向到第一个可用路由
|
||||
const firstRoute = getFirstAvailableRoute()
|
||||
if (firstRoute && firstRoute !== '/') {
|
||||
// 只有当第一个路由不是 / 时才重定向,避免无限循环
|
||||
console.log('[Platform Router] 根路径重定向到:', firstRoute)
|
||||
next({ path: firstRoute, replace: true })
|
||||
return
|
||||
} else {
|
||||
// 第一个路由就是 /,直接放行
|
||||
console.log('[Platform Router] 第一个路由就是根路径,直接放行')
|
||||
}
|
||||
} else {
|
||||
// 动态路由已加载,重新导航到目标路由
|
||||
next({ ...to, replace: true })
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果已登录且访问根路径,但动态路由已加载,重定向到第一个可用路由
|
||||
if (hasToken && to.path === '/' && dynamicRoutesLoaded) {
|
||||
const firstRoute = getFirstAvailableRoute()
|
||||
if (firstRoute && firstRoute !== '/') {
|
||||
// 只有当第一个路由不是 / 时才重定向,避免无限循环
|
||||
console.log('[Platform Router] 已登录访问根路径,重定向到:', firstRoute)
|
||||
next({ path: firstRoute, replace: true })
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -64,6 +89,52 @@ router.beforeEach((to, from, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取第一个可用的路由路径
|
||||
*/
|
||||
function getFirstAvailableRoute(): string | null {
|
||||
try {
|
||||
console.log('[Platform Router] 开始获取第一个可用路由...')
|
||||
|
||||
const loginDomainStr = localStorage.getItem('loginDomain')
|
||||
if (!loginDomainStr) {
|
||||
console.warn('[Platform Router] localStorage 中没有 loginDomain')
|
||||
return null
|
||||
}
|
||||
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
const userViews = loginDomain.userViews || []
|
||||
|
||||
console.log('[Platform Router] 所有用户视图:', userViews.length)
|
||||
|
||||
// 过滤出 platform 服务的非 admin 视图
|
||||
// 注意:不限制 type,因为首页路由可能是 type=3(路由类型)而不是 type=1(菜单类型)
|
||||
const platformViews = userViews.filter((view: any) =>
|
||||
view.service === 'platform' &&
|
||||
!view.url?.startsWith('/admin') &&
|
||||
view.url // 必须有 url 字段
|
||||
)
|
||||
|
||||
console.log('[Platform Router] Platform 服务视图:', platformViews)
|
||||
|
||||
if (platformViews.length === 0) {
|
||||
console.warn('[Platform Router] 没有找到 platform 服务的视图')
|
||||
return null
|
||||
}
|
||||
|
||||
// 按 orderNum 排序
|
||||
platformViews.sort((a: any, b: any) => (a.orderNum || 0) - (b.orderNum || 0))
|
||||
|
||||
const firstRoute = platformViews[0].url
|
||||
console.log('[Platform Router] 第一个路由:', firstRoute, '视图:', platformViews[0].name)
|
||||
|
||||
return firstRoute
|
||||
} catch (error) {
|
||||
console.error('[Platform Router] 获取首页路由失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// 导出动态路由生成函数
|
||||
export { addDynamicRoutes, loadRoutesFromStorage } from './dynamicRoute'
|
||||
|
||||
|
||||
@@ -181,4 +181,6 @@ declare module 'shared/layouts' {
|
||||
import { DefineComponent } from 'vue'
|
||||
|
||||
export const BlankLayout: DefineComponent<{}, {}, any>
|
||||
export const AdminSidebarLayout: DefineComponent<{}, {}, any>
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="overview">
|
||||
<!-- 数据概览视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./OverviewView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="user-management">
|
||||
<!-- 用户管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./UserManagementView.scss");
|
||||
</style>
|
||||
@@ -1,90 +0,0 @@
|
||||
<template>
|
||||
<div class="iframe-view">
|
||||
<iframe
|
||||
v-if="iframeUrl"
|
||||
:src="iframeUrl"
|
||||
class="iframe-content"
|
||||
frameborder="0"
|
||||
@load="handleLoad"
|
||||
/>
|
||||
<div v-else class="iframe-error">
|
||||
<el-icon class="error-icon"><WarningFilled /></el-icon>
|
||||
<p>无效的 iframe 地址</p>
|
||||
</div>
|
||||
<div v-if="loading" class="iframe-loading">
|
||||
<el-icon class="is-loading"><Loading /></el-icon>
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { Loading, WarningFilled } from '@element-plus/icons-vue'
|
||||
|
||||
const route = useRoute()
|
||||
const loading = ref(true)
|
||||
|
||||
// 从路由 meta 中获取 iframe URL
|
||||
const iframeUrl = computed(() => {
|
||||
return route.meta.iframeUrl as string || ''
|
||||
})
|
||||
|
||||
function handleLoad() {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
console.log('[IframeView] 加载 iframe:', iframeUrl.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.iframe-view {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.iframe-content {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.iframe-error {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
color: var(--el-text-color-secondary);
|
||||
|
||||
.error-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 16px;
|
||||
color: var(--el-color-warning);
|
||||
}
|
||||
}
|
||||
|
||||
.iframe-loading {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--el-bg-color);
|
||||
gap: 12px;
|
||||
|
||||
.el-icon {
|
||||
font-size: 32px;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
BIN
urbanLifelineWeb/packages/shared/public/logo.jpg
Normal file
BIN
urbanLifelineWeb/packages/shared/public/logo.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -5,17 +5,17 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// ==================== 侧边栏 ====================
|
||||
// ==================== 侧边栏(内层子导航样式)====================
|
||||
.sidebar {
|
||||
width: 220px;
|
||||
width: 180px;
|
||||
height: 100%;
|
||||
background: #F0EAF4;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
color: #333;
|
||||
flex-shrink: 0;
|
||||
transition: width 0.3s ease;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-right: 1px solid #e4e7ed;
|
||||
|
||||
&.collapsed {
|
||||
width: 64px;
|
||||
@@ -49,7 +49,7 @@
|
||||
// 侧边栏头部
|
||||
.sidebar-header {
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
@@ -63,7 +63,7 @@
|
||||
justify-content: center;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #888;
|
||||
color: #909399;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
@@ -78,18 +78,16 @@
|
||||
gap: 10px;
|
||||
|
||||
.logo-img {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 6px;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
color: #303133;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,31 +95,31 @@
|
||||
.nav-menu {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px 0;
|
||||
padding: 16px 0;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-section {
|
||||
padding: 8px 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
margin-bottom: 4px;
|
||||
gap: 10px;
|
||||
padding: 10px 20px;
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
color: #555;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
|
||||
&:hover {
|
||||
@@ -132,11 +130,11 @@
|
||||
&.active {
|
||||
background: rgba(124, 58, 237, 0.15);
|
||||
color: #7c3aed;
|
||||
font-weight: 500;
|
||||
border-right: 3px solid #7c3aed;
|
||||
}
|
||||
|
||||
.el-icon {
|
||||
font-size: 18px;
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -150,7 +148,7 @@
|
||||
// 用户信息
|
||||
.user-section {
|
||||
padding: 16px 20px;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-top: 1px solid #e4e7ed;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
|
||||
@@ -171,7 +169,7 @@
|
||||
.user-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
@@ -245,7 +243,7 @@
|
||||
width: 64px;
|
||||
|
||||
&:not(.collapsed) {
|
||||
width: 220px;
|
||||
width: 180px;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
@@ -0,0 +1,368 @@
|
||||
<template>
|
||||
<div class="sidebar-layout">
|
||||
<!-- 侧边栏 -->
|
||||
<aside class="sidebar" :class="{ collapsed: collapsed }">
|
||||
<div class="sidebar-header">
|
||||
<div class="logo">
|
||||
<img src="/logo.jpg" alt="Logo" class="logo-img" />
|
||||
<span v-if="!collapsed" class="logo-text">城市生命线</span>
|
||||
</div>
|
||||
<div class="collapse-btn" @click="toggleSidebar">
|
||||
<el-icon>
|
||||
<DArrowLeft v-if="!collapsed" />
|
||||
<DArrowRight v-else />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="nav-menu">
|
||||
<div class="nav-section">
|
||||
<template v-for="item in menuItems" :key="item.key">
|
||||
<!-- 父菜单 -->
|
||||
<div
|
||||
class="nav-item"
|
||||
:class="{ active: activeMenu === item.key, 'has-children': item.children }"
|
||||
@click="item.children ? toggleMenu(item) : handleMenuClick(item)"
|
||||
>
|
||||
<el-icon><component :is="item.icon" /></el-icon>
|
||||
<span v-if="!collapsed">{{ item.label }}</span>
|
||||
<!-- 展开/折叠图标 -->
|
||||
<el-icon v-if="item.children && !collapsed" class="expand-icon">
|
||||
<ArrowDown v-if="item.expanded" />
|
||||
<ArrowRight v-else />
|
||||
</el-icon>
|
||||
</div>
|
||||
<!-- 子菜单 -->
|
||||
<template v-if="item.children && item.expanded && !collapsed">
|
||||
<div
|
||||
v-for="child in item.children"
|
||||
:key="child.key"
|
||||
class="nav-item nav-child-item"
|
||||
:class="{ active: activeMenu === child.key }"
|
||||
@click="handleMenuClick(child)"
|
||||
>
|
||||
<el-icon><component :is="child.icon" /></el-icon>
|
||||
<span>{{ child.label }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
</aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<main class="main-content">
|
||||
<!-- iframe 模式 -->
|
||||
<div v-if="currentIframeUrl" class="iframe-container">
|
||||
<div class="iframe-header">
|
||||
<span class="iframe-title">{{ currentMenuItem?.label }}</span>
|
||||
<el-button
|
||||
text
|
||||
@click="handleRefreshIframe"
|
||||
:icon="Refresh"
|
||||
>
|
||||
刷新
|
||||
</el-button>
|
||||
</div>
|
||||
<iframe
|
||||
ref="iframeRef"
|
||||
:src="currentIframeUrl"
|
||||
class="content-iframe"
|
||||
frameborder="0"
|
||||
@load="handleIframeLoad"
|
||||
/>
|
||||
<div v-if="iframeLoading" class="iframe-loading">
|
||||
<el-icon class="is-loading"><Loading /></el-icon>
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 路由模式 -->
|
||||
<router-view v-else />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import {
|
||||
ChatDotRound,
|
||||
Grid,
|
||||
Connection,
|
||||
Document,
|
||||
Service,
|
||||
DArrowLeft,
|
||||
DArrowRight,
|
||||
User,
|
||||
Setting,
|
||||
SwitchButton,
|
||||
Refresh,
|
||||
Loading,
|
||||
ArrowDown,
|
||||
ArrowRight
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
interface Props {
|
||||
service?: string // 服务名称:platform, bidding, workcase
|
||||
}
|
||||
|
||||
interface MenuItem {
|
||||
key: string
|
||||
label: string
|
||||
icon: string
|
||||
url?: string
|
||||
type: 'route' | 'iframe'
|
||||
children?: MenuItem[] // 子菜单
|
||||
expanded?: boolean // 是否展开
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
service: undefined // 不设默认值,从路由自动检测
|
||||
})
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
// 自动检测当前服务
|
||||
const currentService = computed(() => {
|
||||
// 优先使用 props
|
||||
if (props.service) {
|
||||
return props.service
|
||||
}
|
||||
// 从 route.meta 获取
|
||||
const meta = route.meta as any
|
||||
if (meta?.service) {
|
||||
return meta.service
|
||||
}
|
||||
// 从 URL 路径推断服务(最可靠的方式)
|
||||
const hostname = window.location.hostname
|
||||
const pathname = window.location.pathname
|
||||
|
||||
// 根据 URL 路径判断服务
|
||||
// localhost/workcase/... -> workcase
|
||||
// localhost/platform/... -> platform
|
||||
// localhost/bidding/... -> bidding
|
||||
if (pathname.includes('/workcase/')) {
|
||||
return 'workcase'
|
||||
}
|
||||
if (pathname.includes('/platform/')) {
|
||||
return 'platform'
|
||||
}
|
||||
if (pathname.includes('/bidding/')) {
|
||||
return 'bidding'
|
||||
}
|
||||
|
||||
// 从 localStorage 的 loginDomain 中推断(基于当前路由匹配的视图)
|
||||
try {
|
||||
const loginDomainStr = localStorage.getItem('loginDomain')
|
||||
if (loginDomainStr) {
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
const userViews = loginDomain.userViews || []
|
||||
// 找到当前路由对应的视图
|
||||
const currentView = userViews.find((v: any) =>
|
||||
v.layout === 'AdminSidebarLayout' &&
|
||||
v.url === route.path
|
||||
)
|
||||
if (currentView?.service) {
|
||||
return currentView.service
|
||||
}
|
||||
// 如果没找到精确匹配,尝试前缀匹配
|
||||
const matchedView = userViews.find((v: any) =>
|
||||
v.layout === 'AdminSidebarLayout' &&
|
||||
route.path.startsWith(v.url)
|
||||
)
|
||||
if (matchedView?.service) {
|
||||
return matchedView.service
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('自动检测服务失败:', error)
|
||||
}
|
||||
// 默认返回 workcase
|
||||
return 'workcase'
|
||||
})
|
||||
|
||||
// 状态管理
|
||||
const collapsed = ref(false)
|
||||
const activeMenu = ref('home')
|
||||
const iframeLoading = ref(false)
|
||||
const iframeRef = ref<HTMLIFrameElement>()
|
||||
|
||||
// 从 LocalStorage 获取用户名
|
||||
function getUserName(): string {
|
||||
try {
|
||||
const loginDomainStr = localStorage.getItem('loginDomain')
|
||||
if (loginDomainStr) {
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
return loginDomain.user?.username || loginDomain.userInfo?.username || '管理员'
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ 获取用户名失败:', error)
|
||||
}
|
||||
return '管理员'
|
||||
}
|
||||
|
||||
const userName = ref(getUserName())
|
||||
|
||||
/**
|
||||
* 从 LocalStorage 加载菜单
|
||||
*/
|
||||
function loadMenuFromStorage(): MenuItem[] {
|
||||
try {
|
||||
const loginDomainStr = localStorage.getItem('loginDomain')
|
||||
if (!loginDomainStr) {
|
||||
console.warn('⚠️ 未找到 loginDomain')
|
||||
return []
|
||||
}
|
||||
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
const userViews = loginDomain.userViews || []
|
||||
|
||||
const service = currentService.value
|
||||
console.log(`📋 [${service}] 加载用户视图:`, userViews)
|
||||
|
||||
// 过滤出 AdminSidebarLayout 的菜单(使用当前服务动态过滤)
|
||||
const allSidebarViews = userViews.filter((view: any) =>
|
||||
view.layout === 'AdminSidebarLayout' &&
|
||||
(view.type === 0 || view.type === 1) && // type 0=目录 1=菜单
|
||||
view.service === service && // 动态匹配服务
|
||||
view.url?.startsWith('/admin') // 只留 admin 路由
|
||||
)
|
||||
|
||||
// 分离顶级菜单和子菜单
|
||||
const topLevelViews = allSidebarViews.filter((view: any) => !view.parentId)
|
||||
const childViews = allSidebarViews.filter((view: any) => view.parentId)
|
||||
|
||||
console.log(`🔍 [${service}] 顶级视图:`, topLevelViews)
|
||||
console.log(`🔍 [${service}] 子视图:`, childViews)
|
||||
|
||||
// 按 orderNum 排序
|
||||
topLevelViews.sort((a: any, b: any) => (a.orderNum || 0) - (b.orderNum || 0))
|
||||
|
||||
// 转换为 MenuItem 格式并构建树形结构
|
||||
const menuItems: MenuItem[] = topLevelViews.map((view: any) => {
|
||||
const isIframe = view.viewType === 'iframe' || !!view.iframeUrl
|
||||
|
||||
let menuUrl = view.url
|
||||
if (isIframe && view.url && (view.url.startsWith('http://') || view.url.startsWith('https://'))) {
|
||||
menuUrl = `/${view.viewId}`
|
||||
}
|
||||
|
||||
// 查找子菜单
|
||||
const children = childViews
|
||||
.filter((child: any) => child.parentId === view.viewId)
|
||||
.sort((a: any, b: any) => (a.orderNum || 0) - (b.orderNum || 0))
|
||||
.map((child: any) => ({
|
||||
key: child.viewId || child.name,
|
||||
label: child.name,
|
||||
icon: child.icon || 'Document',
|
||||
url: child.url,
|
||||
type: (child.viewType === 'iframe' || !!child.iframeUrl) ? 'iframe' : 'route' as 'iframe' | 'route'
|
||||
}))
|
||||
|
||||
return {
|
||||
key: view.viewId || view.name,
|
||||
label: view.name,
|
||||
icon: view.icon || 'Grid',
|
||||
url: menuUrl,
|
||||
type: isIframe ? 'iframe' : 'route',
|
||||
children: children.length > 0 ? children : undefined,
|
||||
expanded: false // 默认折叠
|
||||
}
|
||||
})
|
||||
|
||||
console.log('✅ 侧边栏菜单:', menuItems)
|
||||
return menuItems
|
||||
} catch (error) {
|
||||
console.error('❌ 加载菜单失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 菜单配置(从 LocalStorage 加载)
|
||||
const menuItems = ref<MenuItem[]>(loadMenuFromStorage())
|
||||
|
||||
// 当前菜单项
|
||||
const currentMenuItem = computed(() => {
|
||||
return menuItems.value.find(item => item.key === activeMenu.value)
|
||||
})
|
||||
|
||||
// 当前 iframe URL(从路由 meta 读取)
|
||||
const currentIframeUrl = computed(() => {
|
||||
const meta = route.meta as any
|
||||
return meta?.iframeUrl || null
|
||||
})
|
||||
|
||||
// 切换侧边栏
|
||||
const toggleSidebar = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
}
|
||||
|
||||
// 切换菜单展开/折叠
|
||||
const toggleMenu = (item: MenuItem) => {
|
||||
if (item.children) {
|
||||
item.expanded = !item.expanded
|
||||
}
|
||||
}
|
||||
|
||||
// 处理菜单点击
|
||||
const handleMenuClick = (item: MenuItem) => {
|
||||
activeMenu.value = item.key
|
||||
|
||||
// 所有菜单都通过路由跳转
|
||||
if (item.url) {
|
||||
router.push(item.url)
|
||||
if (item.type === 'iframe') {
|
||||
iframeLoading.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iframe 加载完成
|
||||
const handleIframeLoad = () => {
|
||||
iframeLoading.value = false
|
||||
}
|
||||
|
||||
// 刷新 iframe
|
||||
const handleRefreshIframe = () => {
|
||||
if (iframeRef.value) {
|
||||
iframeLoading.value = true
|
||||
iframeRef.value.src = iframeRef.value.src
|
||||
}
|
||||
}
|
||||
|
||||
// 监听服务变化,重新加载菜单
|
||||
watch(
|
||||
currentService,
|
||||
() => {
|
||||
console.log(`🔄 服务切换到: ${currentService.value},重新加载菜单`)
|
||||
menuItems.value = loadMenuFromStorage()
|
||||
}
|
||||
)
|
||||
|
||||
// 监听路由变化,同步激活菜单
|
||||
watch(
|
||||
() => route.path,
|
||||
(newPath) => {
|
||||
// 查找匹配的菜单项(route 或 iframe 类型)
|
||||
const menuItem = menuItems.value.find((item: MenuItem) => item.url === newPath)
|
||||
if (menuItem) {
|
||||
activeMenu.value = menuItem.key
|
||||
} else {
|
||||
// 如果路径不匹配,尝试通过 route.name 匹配 viewId
|
||||
const menuByName = menuItems.value.find((item: MenuItem) => item.key === route.name)
|
||||
if (menuByName) {
|
||||
activeMenu.value = menuByName.key
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import url("./AdminSidebarLayout.scss");
|
||||
</style>
|
||||
@@ -1 +1,2 @@
|
||||
export { default as BlankLayout } from './BlankLayout/BlankLayout.vue'
|
||||
export { default as AdminSidebarLayout } from './AdminSidebarLayout/AdminSidebarLayout.vue'
|
||||
@@ -14,9 +14,10 @@ type SysMenu = TbSysViewDTO
|
||||
|
||||
// 视图类型常量(对应后端的 type 字段)
|
||||
const ViewType = {
|
||||
MENU: 1, // 菜单
|
||||
PAGE: 2, // 页面
|
||||
BUTTON: 3 // 按钮
|
||||
NAVBAR: 0, // 导航栏
|
||||
SIDEBAR: 1, // 侧边栏
|
||||
BUTTON: 2, // 按钮
|
||||
ROUTE: 3 // 空白页(路由页面)
|
||||
} as const
|
||||
|
||||
/**
|
||||
@@ -74,33 +75,33 @@ export function generateRoutes(
|
||||
if (route) {
|
||||
routes.push(route)
|
||||
|
||||
// 递归提取所有 PAGE 类型的子菜单
|
||||
// 递归提取所有 ROUTE 类型的子菜单
|
||||
extractPageChildren(route, pageRoutes, config)
|
||||
}
|
||||
})
|
||||
|
||||
// 将 PAGE 类型的路由添加到路由列表
|
||||
// 将 ROUTE 类型的路由添加到路由列表
|
||||
routes.push(...pageRoutes)
|
||||
|
||||
return routes
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归提取路由中的 PAGE 类型子菜单
|
||||
* 递归提取路由中的 ROUTE 类型子菜单
|
||||
*/
|
||||
function extractPageChildren(
|
||||
route: any,
|
||||
pageRoutes: RouteRecordRaw[],
|
||||
config: RouteGeneratorConfig
|
||||
) {
|
||||
// 检查当前路由是否有 PAGE 类型的子菜单
|
||||
// 检查当前路由是否有 ROUTE 类型的子菜单
|
||||
if (route.meta?.pageChildren && Array.isArray(route.meta.pageChildren)) {
|
||||
route.meta.pageChildren.forEach((pageMenu: SysMenu) => {
|
||||
const pageRoute = generateRouteFromMenu(pageMenu, config, true)
|
||||
if (pageRoute) {
|
||||
pageRoutes.push(pageRoute)
|
||||
} else {
|
||||
console.error(`[路由生成] 生成独立PAGE路由失败: ${pageMenu.name}`)
|
||||
console.error(`[路由生成] 生成独立ROUTE路由失败: ${pageMenu.name}`)
|
||||
}
|
||||
})
|
||||
// 清理临时数据
|
||||
@@ -171,7 +172,7 @@ function generateRouteFromMenu(
|
||||
route.component = config.layoutMap[menu.component]
|
||||
} else if (hasChildren && isTopLevel) {
|
||||
// 如果有子菜单但没有指定布局,根据菜单类型选择默认布局
|
||||
if (menu.type === ViewType.MENU && !menu.parentId) {
|
||||
if (menu.type === ViewType.SIDEBAR && !menu.parentId) {
|
||||
route.component = config.layoutMap['SidebarLayout']
|
||||
} else {
|
||||
route.component = config.layoutMap['BasicLayout']
|
||||
@@ -220,7 +221,7 @@ function generateRouteFromMenu(
|
||||
const normalChildren: SysMenu[] = []
|
||||
|
||||
menu.children!.forEach((child: SysMenu) => {
|
||||
if (child.type === ViewType.PAGE) {
|
||||
if (child.type === ViewType.ROUTE) {
|
||||
pageChildren.push(child)
|
||||
} else {
|
||||
normalChildren.push(child)
|
||||
@@ -235,7 +236,7 @@ function generateRouteFromMenu(
|
||||
}
|
||||
})
|
||||
|
||||
// PAGE 类型的菜单保存到 meta
|
||||
// ROUTE 类型的菜单保存到 meta
|
||||
if (pageChildren.length > 0) {
|
||||
route.meta.pageChildren = pageChildren
|
||||
}
|
||||
@@ -244,12 +245,12 @@ function generateRouteFromMenu(
|
||||
// 处理有子菜单的情况
|
||||
route.children = []
|
||||
|
||||
// 分离 PAGE 类型的子菜单和普通子菜单
|
||||
// 分离 ROUTE 类型的子菜单和普通子菜单
|
||||
const pageChildren: SysMenu[] = []
|
||||
const normalChildren: SysMenu[] = []
|
||||
|
||||
menu.children!.forEach((child: SysMenu) => {
|
||||
if (child.type === ViewType.PAGE) {
|
||||
if (child.type === ViewType.ROUTE) {
|
||||
pageChildren.push(child)
|
||||
} else {
|
||||
normalChildren.push(child)
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// ==================== 侧边栏 ====================
|
||||
// ==================== 侧边栏(内层子导航样式)====================
|
||||
.sidebar {
|
||||
width: 220px;
|
||||
width: 180px;
|
||||
height: 100%;
|
||||
background: #F0EAF4;
|
||||
background: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
color: #333;
|
||||
flex-shrink: 0;
|
||||
transition: width 0.3s ease;
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-right: 1px solid #e4e7ed;
|
||||
|
||||
&.collapsed {
|
||||
width: 64px;
|
||||
@@ -49,7 +49,7 @@
|
||||
// 侧边栏头部
|
||||
.sidebar-header {
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
@@ -63,7 +63,7 @@
|
||||
justify-content: center;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #888;
|
||||
color: #909399;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
@@ -78,18 +78,16 @@
|
||||
gap: 10px;
|
||||
|
||||
.logo-img {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 6px;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
color: #303133;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,31 +95,31 @@
|
||||
.nav-menu {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px 0;
|
||||
padding: 16px 0;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-section {
|
||||
padding: 8px 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 20px;
|
||||
margin-bottom: 4px;
|
||||
gap: 10px;
|
||||
padding: 10px 20px;
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
color: #555;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
|
||||
&:hover {
|
||||
@@ -132,11 +130,11 @@
|
||||
&.active {
|
||||
background: rgba(124, 58, 237, 0.15);
|
||||
color: #7c3aed;
|
||||
font-weight: 500;
|
||||
border-right: 3px solid #7c3aed;
|
||||
}
|
||||
|
||||
.el-icon {
|
||||
font-size: 18px;
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -150,7 +148,7 @@
|
||||
// 用户信息
|
||||
.user-section {
|
||||
padding: 16px 20px;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-top: 1px solid #e4e7ed;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
|
||||
@@ -171,7 +169,7 @@
|
||||
.user-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
@@ -245,7 +243,7 @@
|
||||
width: 64px;
|
||||
|
||||
&:not(.collapsed) {
|
||||
width: 220px;
|
||||
width: 180px;
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
|
||||
@@ -30,31 +30,6 @@
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- 用户信息 -->
|
||||
<el-dropdown class="user-section" trigger="click" @command="handleUserCommand">
|
||||
<div class="user-info-wrapper">
|
||||
<div class="user-avatar">
|
||||
<el-avatar :size="36" src="/avatar.svg" @error="handleAvatarError" />
|
||||
</div>
|
||||
<span v-if="!collapsed" class="user-name">{{ userName }}</span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="profile">
|
||||
<el-icon><User /></el-icon>
|
||||
个人中心
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="settings" divided>
|
||||
<el-icon><Setting /></el-icon>
|
||||
系统设置
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="logout" divided>
|
||||
<el-icon><SwitchButton /></el-icon>
|
||||
退出登录
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export { default as SidebarLayout } from './SidebarLayout/SidebarLayout.vue'
|
||||
|
||||
// BlankLayout从shared导入
|
||||
export { BlankLayout } from 'shared/layouts'
|
||||
export { BlankLayout, AdminSidebarLayout } from 'shared/layouts';
|
||||
@@ -18,14 +18,15 @@ import {
|
||||
import type { TbSysViewDTO } from 'shared/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import router from './index'
|
||||
import { SidebarLayout, BlankLayout } from '@/layouts'
|
||||
import { SidebarLayout, BlankLayout, AdminSidebarLayout } from '@/layouts'
|
||||
|
||||
// Workcase 布局组件映射
|
||||
const workcaseLayoutMap: Record<string, () => Promise<any>> = {
|
||||
'SidebarLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
'BlankLayout': () => Promise.resolve({ default: BlankLayout }),
|
||||
'NavigationLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
'BasicLayout': () => Promise.resolve({ default: SidebarLayout })
|
||||
'BasicLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
'AdminSidebarLayout': () => Promise.resolve({ default: AdminSidebarLayout })
|
||||
}
|
||||
|
||||
// 视图组件加载器
|
||||
|
||||
@@ -73,19 +73,153 @@ router.beforeEach((to, from, next) => {
|
||||
console.log('[Workcase Router] 所有路由:', router.getRoutes().map(r => r.path))
|
||||
|
||||
if (loaded) {
|
||||
// 动态路由加载成功,重新导航以匹配新添加的路由
|
||||
console.log('[Workcase Router] 动态路由加载成功,重新导航到:', to.path)
|
||||
next({ ...to, replace: true })
|
||||
return
|
||||
if (to.path === '/') {
|
||||
// 访问根路径,重定向到第一个可用路由
|
||||
const firstRoute = getFirstAvailableRoute()
|
||||
if (firstRoute && firstRoute !== '/') {
|
||||
// 只有当第一个路由不是 / 时才重定向,避免无限循环
|
||||
console.log('[Workcase Router] 根路径重定向到:', firstRoute)
|
||||
next({ path: firstRoute, replace: true })
|
||||
return
|
||||
} else {
|
||||
// 第一个路由就是 /,直接放行
|
||||
console.log('[Workcase Router] 第一个路由就是根路径,直接放行')
|
||||
}
|
||||
} else if (to.path === '/admin') {
|
||||
// 访问 /admin 路径,重定向到第一个 admin 路由
|
||||
const firstAdminRoute = getFirstAdminRoute()
|
||||
if (firstAdminRoute) {
|
||||
console.log('[Workcase Router] /admin 重定向到:', firstAdminRoute)
|
||||
next({ path: firstAdminRoute, replace: true })
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 动态路由加载成功,重新导航以匹配新添加的路由
|
||||
console.log('[Workcase Router] 动态路由加载成功,重新导航到:', to.path)
|
||||
next({ ...to, replace: true })
|
||||
return
|
||||
}
|
||||
} else {
|
||||
console.warn('[Workcase Router] 动态路由加载失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 如果已登录且访问根路径,但动态路由已加载,重定向到第一个可用路由
|
||||
if (hasToken && to.path === '/' && dynamicRoutesLoaded) {
|
||||
const firstRoute = getFirstAvailableRoute()
|
||||
if (firstRoute && firstRoute !== '/') {
|
||||
// 只有当第一个路由不是 / 时才重定向,避免无限循环
|
||||
console.log('[Workcase Router] 已登录访问根路径,重定向到:', firstRoute)
|
||||
next({ path: firstRoute, replace: true })
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 如果访问 /admin,重定向到第一个 admin 路由
|
||||
if (hasToken && to.path === '/admin' && dynamicRoutesLoaded) {
|
||||
const firstAdminRoute = getFirstAdminRoute()
|
||||
if (firstAdminRoute) {
|
||||
console.log('[Workcase Router] 访问 /admin,重定向到:', firstAdminRoute)
|
||||
next({ path: firstAdminRoute, replace: true })
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[Workcase Router] 继续正常导航')
|
||||
next()
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取第一个可用的路由路径
|
||||
*/
|
||||
function getFirstAvailableRoute(): string | null {
|
||||
try {
|
||||
console.log('[Workcase Router] 开始获取第一个可用路由...')
|
||||
|
||||
const loginDomainStr = localStorage.getItem('loginDomain')
|
||||
if (!loginDomainStr) {
|
||||
console.warn('[Workcase Router] localStorage 中没有 loginDomain')
|
||||
return null
|
||||
}
|
||||
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
const userViews = loginDomain.userViews || []
|
||||
|
||||
console.log('[Workcase Router] 所有用户视图:', userViews.length)
|
||||
|
||||
// 过滤出 workcase 服务的非 admin 视图
|
||||
// 注意:不限制 type,因为首页路由可能是 type=3(路由类型)而不是 type=1(菜单类型)
|
||||
const workcaseViews = userViews.filter((view: any) =>
|
||||
view.service === 'workcase' &&
|
||||
!view.url?.startsWith('/admin') &&
|
||||
view.url // 必须有 url 字段
|
||||
)
|
||||
|
||||
console.log('[Workcase Router] Workcase 服务视图:', workcaseViews)
|
||||
|
||||
if (workcaseViews.length === 0) {
|
||||
console.warn('[Workcase Router] 没有找到 workcase 服务的菜单视图')
|
||||
return null
|
||||
}
|
||||
|
||||
// 按 orderNum 排序
|
||||
workcaseViews.sort((a: any, b: any) => (a.orderNum || 0) - (b.orderNum || 0))
|
||||
|
||||
const firstRoute = workcaseViews[0].url
|
||||
console.log('[Workcase Router] 第一个路由:', firstRoute, '视图:', workcaseViews[0].name)
|
||||
|
||||
return firstRoute
|
||||
} catch (error) {
|
||||
console.error('[Workcase Router] 获取首页路由失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一个 admin 路由
|
||||
*/
|
||||
function getFirstAdminRoute(): string | null {
|
||||
try {
|
||||
console.log('[Workcase Router] 开始获取第一个 admin 路由...')
|
||||
|
||||
const loginDomainStr = localStorage.getItem('loginDomain')
|
||||
if (!loginDomainStr) {
|
||||
console.warn('[Workcase Router] localStorage 中没有 loginDomain')
|
||||
return null
|
||||
}
|
||||
|
||||
const loginDomain = JSON.parse(loginDomainStr)
|
||||
const userViews = loginDomain.userViews || []
|
||||
|
||||
// 过滤出 workcase 服务的 admin 路由(排除目录类型)
|
||||
const adminViews = userViews.filter((view: any) =>
|
||||
view.service === 'workcase' &&
|
||||
view.url?.startsWith('/admin') &&
|
||||
view.layout === 'AdminSidebarLayout' &&
|
||||
!view.parentId && // 顶级菜单
|
||||
view.url // 必须有 url 字段
|
||||
)
|
||||
|
||||
console.log('[Workcase Router] Admin 视图:', adminViews)
|
||||
|
||||
if (adminViews.length === 0) {
|
||||
console.warn('[Workcase Router] 没有找到 workcase admin 路由')
|
||||
return null
|
||||
}
|
||||
|
||||
// 按 orderNum 排序
|
||||
adminViews.sort((a: any, b: any) => (a.orderNum || 0) - (b.orderNum || 0))
|
||||
|
||||
const firstRoute = adminViews[0].url
|
||||
console.log('[Workcase Router] 第一个 admin 路由:', firstRoute, '视图:', adminViews[0].name)
|
||||
|
||||
return firstRoute
|
||||
} catch (error) {
|
||||
console.error('[Workcase Router] 获取 admin 路由失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// 重置动态路由加载状态
|
||||
export function resetDynamicRoutes() {
|
||||
dynamicRoutesLoaded = false
|
||||
|
||||
@@ -176,4 +176,5 @@ declare module 'shared/layouts' {
|
||||
import { DefineComponent } from 'vue'
|
||||
|
||||
export const BlankLayout: DefineComponent<{}, {}, any>
|
||||
export const AdminSidebarLayout: DefineComponent<{}, {}, any>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="agent">
|
||||
<!-- 智能体管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./AgentView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="customer-chat">
|
||||
<!-- 客服对话管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./CustomerChatView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="knowledge">
|
||||
<!-- 知识库管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./KnowLedgeView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="knowledge-log">
|
||||
<!-- 知识库日志管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./KnowledgeLogView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="system-log">
|
||||
<!-- 系统日志管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./SystemLogView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="workcase-log">
|
||||
<!-- 工单日志管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./WorkcaseLogView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="overview">
|
||||
<!-- 数据概览视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./OverviewView.scss");
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div class="workcase">
|
||||
<!-- 工单管理视图 -->
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./WorkcaseView.scss");
|
||||
</style>
|
||||
Reference in New Issue
Block a user