#
Junjie
2024-07-03 b334ee72afc23ead7f0cd5efc9a1343f7ceaae90
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';
@@ -21,10 +22,11 @@
const collapsed = ref(false);
const router = useRouter();
let routerCache = ref([]);
let routerCacheMap = ref(new Map());
let routerCacheList = ref([]);
let currentCache = ref(null);
let isRouterAlive = ref(true);
const menuCache = ref([]);
const hostList = ref([]);
const components = {
  ...Icons,
@@ -38,26 +40,36 @@
}
function menuSelect(item) {
  console.log(item.key);
  router.push({
    path: item.key
  })
  let name = item.item.name;
  currentCache.value = name;
  // console.log(routerCache.value);
  if (name != undefined && routerCache.value.indexOf(name) == -1) {
    routerCache.value.push(item.item.name)
    routerCacheMap.value.set(name, item.key)
    routerCacheList.value.push({
      key: item.key,
      languageId: item.item.languageId,
      name: item.item.name,
    })
  }
}
function closeTabs(name) {
function closeTabs(param) {
  let name = param.name;
  let tmp = []
  let tmpList = [];
  routerCache.value.forEach((item) => {
    if (item != name) {
      tmp.push(item);
    }
  })
  routerCacheList.value.forEach((item) => {
    if (item.name != name) {
      tmpList.push(item);
    }
  })
@@ -66,12 +78,17 @@
      path: '/'
    })
    routerCache.value.push('home')
    routerCacheMap.value.set('home', '/')
    routerCacheList.value.push({
      key: '/',
      languageId: 'common.home',
      name: '主页',
    })
    selectedKeys.value = ['/']
  } else {
    switchTabs(tmp[0]);
    switchTabs(tmpList[0]);
  }
  routerCache.value = tmp;
  routerCacheList.value = tmpList;
}
function reloadTabs() {
@@ -89,23 +106,62 @@
  }
}
function switchTabs(name) {
function closeAllTabs() {
  routerCache.value = [];
  routerCacheList.value = [];
  router.push({
    path: routerCacheMap.value.get(name)
    path: '/'
  })
}
function switchTabs(item) {
  router.push({
    path: item.key
  })
  currentCache.value = name;
  selectedKeys.value = [routerCacheMap.value.get(name)]
  // console.log(routerCacheMap, name, routerCacheMap.value.get(name));
  currentCache.value = item.name;
  selectedKeys.value = [item.key]
}
const switchLocale = (locale) => {
  globalState.locale = locale;
  localStorage.setItem('locale', locale)
  reloadTabs()
  console.log(locale);
}
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>
@@ -126,12 +182,12 @@
          <template #title>
            <span>
              <component :is="components[ref(item.icon).value]" />
              {{ item.name }}
              {{ formatMessage(item.languageId, item.name) }}
            </span>
          </template>
          <div v-for="(child, idx) in item.children">
            <a-menu-item v-if="child.status == 1" :key="child.route" :name="child.name">
              {{ child.name }}
            <a-menu-item v-if="child.status == 1" :key="child.route" :name="child.name" :languageId="child.languageId">
              {{ formatMessage(child.languageId, child.name) }}
            </a-menu-item>
          </div>
        </a-sub-menu>
@@ -146,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 />
@@ -177,12 +247,12 @@
      </a-layout-header>
      <a-layout-content class="content-view">
        <div class="tabs-fixed">
          <div v-for="(item, index) in routerCache" :key="index" @click="switchTabs(item)" class="tabs-item"
            :class="currentCache == item ? 'tabs-item-active' : ''">
            <div :class="currentCache == item ? '' : 'tabs-item-reload-none'" @click="reloadTabs" @click.stop>
          <div v-for="(item, index) in routerCacheList" :key="index" @click="switchTabs(item)" class="tabs-item"
            :class="currentCache == item.name ? 'tabs-item-active' : ''">
            <div :class="currentCache == item.name ? '' : 'tabs-item-reload-none'" @click="reloadTabs" @click.stop>
              <RedoOutlined />
            </div>
            <div>{{ item }}</div>
            <div>{{ formatMessage(item.languageId, item.name) }}</div>
            <div @click="closeTabs(item)" @click.stop>
              <CloseOutlined />
            </div>