🔨 重构主机模块.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<host-table class="host-list"
|
||||
v-model:selected-keys="selectedKeysValue"
|
||||
:host-list="hostList"
|
||||
empty-message="当前分组内无授权主机/主机未启用 SSH 配置!" />
|
||||
empty-message="当前分组内无授权主机!" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
import type { SelectOptionData } from '@arco-design/web-vue';
|
||||
import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data';
|
||||
import type { HostQueryResponse } from '@/api/asset/host';
|
||||
import type { HostType } from '@/api/asset/host';
|
||||
import { onMounted, ref, watch, computed } from 'vue';
|
||||
import { dataColor } from '@/utils';
|
||||
import { dictKeys, NewConnectionType, newConnectionTypeKey } from './types/const';
|
||||
@@ -92,6 +93,12 @@
|
||||
import HostTable from './components/host-table.vue';
|
||||
import HostGroup from './components/host-group.vue';
|
||||
|
||||
const props = withDefaults(defineProps<Partial<{
|
||||
type: HostType;
|
||||
}>>(), {
|
||||
type: undefined,
|
||||
});
|
||||
|
||||
const emits = defineEmits(['selected']);
|
||||
|
||||
const { toRadioOptions, loadKeys } = useDictStore();
|
||||
@@ -110,10 +117,10 @@
|
||||
const emptyMessage = computed(() => {
|
||||
if (newConnectionType.value === NewConnectionType.LIST) {
|
||||
// 列表
|
||||
return '无授权主机/主机未启用 SSH 配置!';
|
||||
return '无授权主机!';
|
||||
} else if (newConnectionType.value === NewConnectionType.FAVORITE) {
|
||||
// 收藏
|
||||
return '无收藏主机/主机未启用 SSH 配置!';
|
||||
return '无收藏主机!';
|
||||
} else if (newConnectionType.value === NewConnectionType.LATEST) {
|
||||
// 最近连接
|
||||
return '暂无连接记录!';
|
||||
@@ -144,7 +151,7 @@
|
||||
setLoading(true);
|
||||
try {
|
||||
// 加载主机列表
|
||||
const { data } = await getCurrentAuthorizedHost('ssh');
|
||||
const { data } = await getCurrentAuthorizedHost(props.type);
|
||||
hosts.value = data;
|
||||
// 禁用别名
|
||||
data.hostList.forEach(s => s.alias = undefined as unknown as string);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<a-select v-model:model-value="value"
|
||||
:options="optionData"
|
||||
:loading="loading"
|
||||
:multiple="multiple"
|
||||
placeholder="请选择主机"
|
||||
allow-clear />
|
||||
</template>
|
||||
@@ -14,22 +15,30 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { SelectOptionData } from '@arco-design/web-vue';
|
||||
import type { HostType } from '@/api/asset/host';
|
||||
import { computed, onBeforeMount, ref } from 'vue';
|
||||
import { useCacheStore } from '@/store';
|
||||
import useLoading from '@/hooks/loading';
|
||||
|
||||
const props = defineProps<Partial<{
|
||||
modelValue: number;
|
||||
}>>();
|
||||
const props = withDefaults(defineProps<Partial<{
|
||||
type: HostType;
|
||||
status: string | undefined;
|
||||
modelValue: number | Array<number>;
|
||||
multiple: boolean;
|
||||
}>>(), {
|
||||
type: undefined,
|
||||
status: undefined,
|
||||
multiple: false,
|
||||
});
|
||||
|
||||
const emits = defineEmits(['update:modelValue']);
|
||||
|
||||
const { loading, setLoading } = useLoading();
|
||||
const cacheStore = useCacheStore();
|
||||
|
||||
const value = computed<number>({
|
||||
const value = computed({
|
||||
get() {
|
||||
return props.modelValue as number;
|
||||
return props.modelValue;
|
||||
},
|
||||
set(e) {
|
||||
if (e) {
|
||||
@@ -45,13 +54,14 @@
|
||||
onBeforeMount(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const hosts = await cacheStore.loadHosts();
|
||||
optionData.value = hosts.map(s => {
|
||||
return {
|
||||
label: `${s.name} - ${s.address}`,
|
||||
value: s.id,
|
||||
};
|
||||
});
|
||||
const hosts = await cacheStore.loadHosts(props.type);
|
||||
optionData.value = hosts.filter(s => !props.status || s.status === props.status)
|
||||
.map(s => {
|
||||
return {
|
||||
label: `${s.name} - ${s.address}`,
|
||||
value: s.id,
|
||||
};
|
||||
});
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user