Ver Fonte

成渝样式修改

duy há 2 meses atrás
pai
commit
af135f9df5

+ 93 - 17
src/layout/index.vue

@@ -106,16 +106,17 @@ const projectId = ref(store.getProjectId)
 const isYunNanProject = ref(projectId.value === '1904814720589430785')
 
 
-// 添加watch来更新isYunNanProject
-watch(() => projectId.value, (newProjectId) => {
-    isYunNanProject.value = newProjectId === '1904814720589430785'
-})
+
+
 //渲染完成
-onMounted(() => {
+onMounted(async () => {
     const layout = useRoutes?.query?.layout, layout2 = store.isLayout
     isLayout.value = layout ?? layout2
     annRefs.value = []
     initButtons()
+      
+    // 确保初始化时加载样式
+    currentStyle = await loadStyles()
 })
 
 //监听layout
@@ -138,6 +139,8 @@ watch(() => isAppLoading.value, (res) => {
             isAppLoadings.value = true
         }
     }
+
+    
 }, { immediate:true })
 
 //路由信息
@@ -360,25 +363,98 @@ onUnmounted(() => {
     closeAnnUpdate()
 })
 
-// / 动态加载样式
-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
+    }
+     let newVal = getArrValue(val)
+        let newArr = []
+        for (let index = 0; index < newVal.length; index++) {
+            const element = newVal[index]
+            if (element.parentId === '0' && ( element.code !== 'tasks' && element.code !== 'patrol-menu' && element.code !== 'tentative-menu' )) {
+                let arr2 = element.children
+                if (arr2) {
+                    for (let index = 0; index < arr2.length; index++) {
+                    const element2 = arr2[index]
+                    newArr.push(element2)
+                }
+                }
+               
+             
+            } else if (element.code === 'patrol-menu') {
+                newArr.push(element)
+            } else if (element.code === 'tasks') {
+                // 先跳过 tasks,最后再添加
+                newArr.push(element)
+            }
+
+            // 最后添加 tasks
+           
+
+            
+        }
+      
+       let obj1 = newArr[newArr.length - 1]
+       let obj2 = newArr[newArr.length - 2]
+       newArr[newArr.length - 1] = obj2
+       newArr[newArr.length - 2] = obj1
+        menuBarData.value = newArr
+        console.log(menuBarData.value, 'menuBarData.value')
+         isAsideMenu.value = true
+       
+
+})
 </script>
 

+ 1 - 1
src/layout/modules/MenuItem.vue

@@ -74,7 +74,7 @@ const isYunNanProject = ref(projectId.value === '1904814720589430785')
 
 
 // 添加watch来更新isYunNanProject
-watch(() => projectId.value, (newProjectId) => {
+watch(() =>store.getProjectId, (newProjectId) => {
     isYunNanProject.value = newProjectId === '1904814720589430785'
 })
 //监听

+ 1 - 1
src/layout/modules/UserInfoBar.vue

@@ -42,7 +42,7 @@ const isYunNanProject = ref(projectId.value === '1904814720589430785')
 
 
 // 添加watch来更新isYunNanProject
-watch(() => projectId.value, (newProjectId) => {
+watch(() => store.getProjectId, (newProjectId) => {
     isYunNanProject.value = newProjectId === '1904814720589430785'
 })
 //监听

+ 1 - 1
src/layout/test-yn/MenuItem-yn.vue

@@ -70,7 +70,7 @@ const isYunNanProject = ref(projectId.value === '1904814720589430785')
 
 
 // 添加watch来更新isYunNanProject
-watch(() => projectId.value, (newProjectId) => {
+watch(() =>store.getProjectId, (newProjectId) => {
     isYunNanProject.value = newProjectId === '1904814720589430785'
 })
 //初始变量