|
@@ -120,11 +120,13 @@ const { isAppLoading } = useProject()
|
|
|
// 在 setup 中添加
|
|
|
|
|
|
//渲染完成
|
|
|
-onMounted(() => {
|
|
|
+onMounted(async () => {
|
|
|
const layout = useRoutes?.query?.layout, layout2 = store.isLayout
|
|
|
isLayout.value = layout ?? layout2
|
|
|
annRefs.value = []
|
|
|
initButtons()
|
|
|
+ // 确保初始化时加载样式
|
|
|
+ currentStyle = await loadStyles()
|
|
|
})
|
|
|
|
|
|
//监听layout
|
|
@@ -388,27 +390,91 @@ onUnmounted(() => {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
// 动态加载样式
|
|
|
-const loadStyles = () => {
|
|
|
- const styleElement = document.createElement('style')
|
|
|
- styleElement.type = 'text/css'
|
|
|
- const styleContent = isYunNanProject.value
|
|
|
- ? import('./test-yn/index-yn.scss')
|
|
|
- : import('./index.scss')
|
|
|
- styleElement.textContent = styleContent
|
|
|
- document.head.appendChild(styleElement)
|
|
|
- return styleElement
|
|
|
+const loadStyles = async () => {
|
|
|
+ try {
|
|
|
+ // 确保先移除旧样式
|
|
|
+ if (currentStyle) {
|
|
|
+ document.head.removeChild(currentStyle)
|
|
|
+ currentStyle = null
|
|
|
+ }
|
|
|
+
|
|
|
+ const styleElement = document.createElement('style')
|
|
|
+ styleElement.type = 'text/css'
|
|
|
+
|
|
|
+ // 使用动态import加载样式模块
|
|
|
+ const module = isYunNanProject.value
|
|
|
+ ? await import('./test-yn/index-yn.scss?inline') // 添加?inline确保直接获取样式内容
|
|
|
+ : await import('./index.scss?inline')
|
|
|
+
|
|
|
+ styleElement.textContent = module.default
|
|
|
+ document.head.appendChild(styleElement)
|
|
|
+ currentStyle = styleElement
|
|
|
+
|
|
|
+ // 强制触发重绘
|
|
|
+ document.body.style.display = 'none'
|
|
|
+ document.body.offsetHeight // 触发重排
|
|
|
+ document.body.style.display = ''
|
|
|
+
|
|
|
+ return styleElement
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载样式失败:', error)
|
|
|
+ return null
|
|
|
+ }
|
|
|
}
|
|
|
let currentStyle = null
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// 监听项目类型变化,动态切换样式
|
|
|
-watch(() => isYunNanProject.value, () => {
|
|
|
+watch(() => isYunNanProject.value, async (newVal) => {
|
|
|
if (currentStyle) {
|
|
|
document.head.removeChild(currentStyle)
|
|
|
+ currentStyle = null
|
|
|
}
|
|
|
- currentStyle = loadStyles()
|
|
|
+
|
|
|
+ currentStyle = await loadStyles()
|
|
|
+ console.log('样式已更新:', newVal ? 'yunnan' : 'default')
|
|
|
}, { immediate: true })
|
|
|
+// 添加watch来更新isYunNanProject
|
|
|
+watch(() =>store.getProjectId, (newProjectId) => {
|
|
|
+ isYunNanProject.value = newProjectId === '1904814720589430785'
|
|
|
+ //重新加载菜单
|
|
|
+ let val = store.getMenus
|
|
|
+ if (!isYunNanProject.value) {
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const filterAndRenameMenus = (menus) => {
|
|
|
+ return menus.map(menu => {
|
|
|
+ // 创建新对象,而不是修改原对象
|
|
|
+ const newMenu = { ...menu }
|
|
|
+
|
|
|
+ // 过滤掉个人中心和系统设置
|
|
|
+ if (newMenu.name === '个人中心' || newMenu.name === '系统设置') {
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重命名档案收集为文件管理
|
|
|
+ if (newMenu.name === '档案收集') {
|
|
|
+ newMenu.name = '文件管理'
|
|
|
+ }
|
|
|
+
|
|
|
+ // 递归处理子菜单
|
|
|
+ if (newMenu.children && newMenu.children.length > 0) {
|
|
|
+ newMenu.children = filterAndRenameMenus(newMenu.children)
|
|
|
+ }
|
|
|
+
|
|
|
+ return newMenu
|
|
|
+ }).filter(Boolean) // 过滤掉null值
|
|
|
+ }
|
|
|
+
|
|
|
+ menuBarData.value = filterAndRenameMenus(getArrValue(val))
|
|
|
+ isAsideMenu.value = true
|
|
|
+
|
|
|
|
|
|
+})
|
|
|
// 组件卸载时清理样式
|
|
|
</script>
|
|
|
|