Files
orion-visor/orion-ops-ui/src/views/asset/host/index.vue

92 lines
2.4 KiB
Vue
Raw Normal View History

2023-09-11 16:33:57 +08:00
<template>
<div class="layout-container">
2023-09-28 01:30:25 +08:00
<!-- 列表-表格 -->
<host-table v-if="renderTable"
ref="table"
2023-09-14 16:18:41 +08:00
@openAdd="() => modal.openAdd()"
2023-09-20 10:40:59 +08:00
@openUpdate="(e) => modal.openUpdate(e)"
@openUpdateConfig="(e) => config.open(e)" />
2023-09-28 01:30:25 +08:00
<!-- 列表-卡片 -->
<host-card-list v-else
2023-10-05 00:50:15 +08:00
ref="card"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)"
@openUpdateConfig="(e) => config.open(e)" />
2023-09-11 16:33:57 +08:00
<!-- 添加修改模态框 -->
<host-form-modal ref="modal"
2023-10-07 18:08:31 +08:00
@added="modalAddCallback"
@updated="modalUpdateCallback" />
2023-09-20 10:40:59 +08:00
<!-- 配置面板 -->
<host-config-drawer ref="config" />
2023-09-11 16:33:57 +08:00
</div>
</template>
<script lang="ts">
export default {
name: 'assetHost'
};
</script>
<script lang="ts" setup>
import HostTable from './components/host-table.vue';
2023-09-28 01:30:25 +08:00
import HostCardList from '@/views/asset/host/components/host-card-list.vue';
2023-09-11 16:33:57 +08:00
import HostFormModal from './components/host-form-modal.vue';
2023-09-20 10:40:59 +08:00
import HostConfigDrawer from '@/views/asset/host/components/host-config-drawer.vue';
2023-10-07 18:08:31 +08:00
import { getTagList } from '@/api/meta/tag';
import { Message } from '@arco-design/web-vue';
2023-09-11 16:33:57 +08:00
2023-10-08 01:05:52 +08:00
import { computed, onUnmounted, ref } from 'vue';
import { useAppStore, useCacheStore } from '@/store';
2023-09-11 16:33:57 +08:00
const table = ref();
2023-09-28 01:30:25 +08:00
const card = ref();
2023-09-11 16:33:57 +08:00
const modal = ref();
2023-09-20 10:40:59 +08:00
const config = ref();
2023-09-28 01:30:25 +08:00
const appStore = useAppStore();
2023-10-07 18:08:31 +08:00
const cacheStore = useCacheStore();
2023-09-28 01:30:25 +08:00
2023-10-07 18:55:24 +08:00
const renderTable = computed(() => appStore.hostView === 'table');
2023-09-11 16:33:57 +08:00
2023-10-07 18:08:31 +08:00
// 添加回调
const modalAddCallback = () => {
if (renderTable.value) {
table.value.addedCallback();
} else {
card.value.addedCallback();
}
};
// 修改回调
const modalUpdateCallback = () => {
if (renderTable.value) {
table.value.updatedCallback();
} else {
card.value.updatedCallback();
}
};
// 加载 tags
const loadTags = async () => {
try {
const { data } = await getTagList('HOST');
// 设置到缓存
2023-10-07 22:17:01 +08:00
cacheStore.set('hostTags', data);
2023-10-07 18:08:31 +08:00
} catch {
Message.error('tag加载失败');
}
};
loadTags();
2023-09-14 16:18:41 +08:00
// 卸载时清除 tags cache
onUnmounted(() => {
2023-10-07 22:17:01 +08:00
cacheStore.set('hostTags', []);
2023-09-22 11:50:56 +08:00
cacheStore.set('hostKeys', []);
cacheStore.set('hostIdentities', []);
2023-09-14 16:18:41 +08:00
});
2023-09-11 16:33:57 +08:00
</script>
<style lang="less" scoped>
</style>