#
Junjie
2024-07-03 acebf48e2e139f6f298cfbba829cc3c29db3c891
zy-asrs-admin/src/views/IndexView.vue
@@ -13,6 +13,7 @@
  RedoOutlined,
  UserOutlined,
  TranslationOutlined,
  ApartmentOutlined,
} from "@ant-design/icons-vue";
import { formatMessage } from '@/utils/localeUtils.js';
@@ -25,6 +26,7 @@
let currentCache = ref(null);
let isRouterAlive = ref(true);
const menuCache = ref([]);
const hostList = ref([]);
const components = {
  ...Icons,
@@ -71,8 +73,6 @@
    }
  })
  console.log(tmpList);
  if (tmp == 0) {
    router.push({
      path: '/'
@@ -106,6 +106,14 @@
  }
}
function closeAllTabs() {
  routerCache.value = [];
  routerCacheList.value = [];
  router.push({
    path: '/'
  })
}
function switchTabs(item) {
  router.push({
    path: item.key
@@ -119,6 +127,41 @@
  globalState.locale = locale;
  localStorage.setItem('locale', locale)
  reloadTabs()
}
getHostList()
function getHostList() {
  post('/api/show/host.action', {}).then((resp) => {
    let result = resp.data;
    let data = result.data;
    let hostId = data.hostId;
    if (data.root) {
      post('/api/host/list', {}).then((resp) => {
        let result = resp.data;
        let data = result.data;
        hostList.value = data;
        data.forEach((item) => {
          if (item.id == hostId) {
            globalState.currentHost = item;
          }
        })
      })
    }
  })
}
const switchHost = (item) => {
  globalState.currentHost = item;
  postForm('/api/root/change/host/auth', {
    hostId: item.id
  }).then((resp) => {
    let result = resp.data;
    if (result.code == 200) {
      window.location.reload();
    } else {
      message.error(formatMessage('common.fail', '加载失败'));
    }
  })
}
</script>
@@ -159,6 +202,20 @@
            <MenuFoldOutlined v-else class="trigger" @click="() => (collapsed = !collapsed)" />
          </div>
          <div class="header-top-right">
            <div class="trigger" v-if="globalState.currentHost">
              <a-dropdown>
                <div>
                  <ApartmentOutlined />
                  {{ globalState.currentHost?.name }}
                </div>
                <template #overlay>
                  <a-menu>
                    <a-menu-item v-for="(item, index) in hostList" :key="index" @click="switchHost(item)"
                      :class="globalState.currentHost?.id == item.id ? 'active' : ''">{{ item.name }}</a-menu-item>
                  </a-menu>
                </template>
              </a-dropdown>
            </div>
            <div class="trigger">
              <a-dropdown>
                <TranslationOutlined />