Explorar el Código

标题修改为动态数据

丸子 hace 7 meses
padre
commit
663f157f2d
Se han modificado 1 ficheros con 23 adiciones y 6 borrados
  1. 23 6
      src/components/HomePage.vue

+ 23 - 6
src/components/HomePage.vue

@@ -2,7 +2,7 @@
   <div class="home-container">
     <div class="box-1">
       <div class="inner-box left-box">
-        <span>人工智能通识课平台</span>
+        <span>{{ platformTitle }}</span>
         <div class="dropdown-box">
           <!-- 下拉菜单 -->
           <el-dropdown v-model="selectedGrade" @command="handleGradeSelect" popper-class="no-arrow-dropdown">
@@ -115,6 +115,13 @@ import studyImg from '@/assets/images/study.png'
 import logoutIcon from '@/assets/icon/logout.png'
 import { Message } from '@/utils/message/Message.js'
 
+// 平台标题响应式变量
+const platformTitle = ref('')
+// 更新平台标题
+const updatePlatformTitle = () => {
+  platformTitle.value = localStorage.getItem('tenantName') || import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT || '人工智能通识课平台'
+}
+
 // 获取当前路由对象
 const router = useRouter()
 // 退出登录
@@ -158,17 +165,15 @@ const goToPersonalized = () =>{
   })
 }
 
-// 添加下拉菜单选中项
+// 下拉菜单选中项
 const selectedGrade = ref(localStorage.getItem('selectedGrade') || '')
-// 添加年级ID存储变量
+// 年级ID存储变量
 const selectedGradeId = ref(localStorage.getItem('selectedGradeId') || '')
 // 获取年级
 const classData = ref([])
 const fetchCtTypes = async () => {
   try {
     const response = await ClassList()
-    console.log(response);
-    
     if (response.code === 0) {
       classData.value = response.data
       // 获取到数据,将第一个选项的值作为默认选中值
@@ -225,8 +230,20 @@ const notOpen = () => {
 
 onMounted(() => {
   fetchCtTypes()
+  // 初始化平台标题
+  updatePlatformTitle()
+  // storage事件监听器,监听其他标签页对localStorage的修改
+  window.addEventListener('storage', (e) => {
+    if (e.key === 'tenantName') {
+      updatePlatformTitle()
+    }
+  })
 })
-
+// 全局:更新租户名称
+window.updateTenantName = (newName) => {
+  localStorage.setItem('tenantName', newName)
+  updatePlatformTitle()
+}
 </script>
 
 <style scoped lang="scss">