mock数据,AI对话,全部应用

This commit is contained in:
2025-12-12 18:17:38 +08:00
parent 8b211fbad6
commit 0a72416365
41 changed files with 5667 additions and 205 deletions

View File

@@ -113,8 +113,7 @@ interface MenuItem {
key: string
label: string
icon: string
path?: string
iframeUrl?: string
url?: string
type: 'route' | 'iframe'
}
@@ -126,57 +125,90 @@ const collapsed = ref(false)
const activeMenu = ref('home')
const iframeLoading = ref(false)
const iframeRef = ref<HTMLIFrameElement>()
const userName = ref('管理员')
// 菜单配置
const menuItems: MenuItem[] = [
{
key: 'home',
label: '工作台',
icon: 'Grid',
path: '/home',
type: 'route'
},
{
key: 'bidding',
label: '招标助手',
icon: 'Document',
iframeUrl: 'http://localhost:5002',
type: 'iframe'
},
{
key: 'service',
label: '泰豪小电',
icon: 'Service',
iframeUrl: 'http://localhost:5003',
type: 'iframe'
},
{
key: 'workflow',
label: '智能体编排',
icon: 'Connection',
iframeUrl: 'http://localhost:3000',
type: 'iframe'
},
{
key: 'chat',
label: 'AI助手',
icon: 'ChatDotRound',
path: '/chat',
type: 'route'
// 从 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 || []
console.log('📋 加载用户视图:', userViews)
// 过滤出 SidebarLayout 的顶级菜单(没有 parentId
const sidebarViews = userViews.filter((view: any) =>
view.layout === 'SidebarLayout' &&
!view.parentId &&
view.type === 1 // type 1 是侧边栏菜单
)
// 按 orderNum 排序
sidebarViews.sort((a: any, b: any) => (a.orderNum || 0) - (b.orderNum || 0))
// 转换为 MenuItem 格式
const menuItems: MenuItem[] = sidebarViews.map((view: any) => {
// 根据 viewType 或 iframeUrl 判断是 route 还是 iframe
const isIframe = view.viewType === 'iframe' || !!view.iframeUrl
// 确定菜单的路由路径
let menuUrl = view.url
if (isIframe && view.url && (view.url.startsWith('http://') || view.url.startsWith('https://'))) {
// iframe 类型且 url 是外部链接,使用 viewId 作为路由路径
menuUrl = `/${view.viewId}`
}
return {
key: view.viewId || view.name,
label: view.name,
icon: view.icon || 'Grid',
url: menuUrl,
type: isIframe ? 'iframe' : 'route'
}
})
console.log('✅ 侧边栏菜单:', menuItems)
return menuItems
} catch (error) {
console.error('❌ 加载菜单失败:', error)
return []
}
}
// 菜单配置(从 LocalStorage 加载)
const menuItems = ref<MenuItem[]>(loadMenuFromStorage())
// 当前菜单项
const currentMenuItem = computed(() => {
return menuItems.find(item => item.key === activeMenu.value)
return menuItems.value.find(item => item.key === activeMenu.value)
})
// 当前 iframe URL
// 当前 iframe URL(从路由 meta 读取)
const currentIframeUrl = computed(() => {
return currentMenuItem.value?.type === 'iframe'
? currentMenuItem.value.iframeUrl
: null
const meta = route.meta as any
return meta?.iframeUrl || null
})
// 切换侧边栏
@@ -188,11 +220,12 @@ const toggleSidebar = () => {
const handleMenuClick = (item: MenuItem) => {
activeMenu.value = item.key
if (item.type === 'route' && item.path) {
router.push(item.path)
} else if (item.type === 'iframe') {
iframeLoading.value = true
// iframe 模式不需要路由跳转
// 所有菜单都通过路由跳转
if (item.url) {
router.push(item.url)
if (item.type === 'iframe') {
iframeLoading.value = true
}
}
}
@@ -224,6 +257,7 @@ const handleUserCommand = (command: string) => {
router.push('/settings')
break
case 'logout':
localStorage.clear()
ElMessage.success('退出成功')
router.push('/login')
break
@@ -234,9 +268,16 @@ const handleUserCommand = (command: string) => {
watch(
() => route.path,
(newPath) => {
const menuItem = menuItems.find(item => item.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 }