2026-02-07 14:30:46 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="space-y-1.5">
|
|
|
|
|
<Select
|
|
|
|
|
:model-value="modelValue"
|
|
|
|
|
:disabled="proxyNodesStore.loading || nodeOptions.length === 0"
|
|
|
|
|
@update:model-value="(v: string) => $emit('update:modelValue', v)"
|
|
|
|
|
>
|
|
|
|
|
<SelectTrigger :class="triggerClass">
|
|
|
|
|
<SelectValue
|
|
|
|
|
:placeholder="proxyNodesStore.loading
|
2026-06-30 14:14:12 +08:00
|
|
|
? legacyT('加载节点列表中...')
|
2026-02-07 14:30:46 +08:00
|
|
|
: nodeOptions.length === 0
|
2026-06-30 14:14:12 +08:00
|
|
|
? legacyT('暂无可用节点')
|
|
|
|
|
: legacyT('选择代理节点...')"
|
2026-02-07 14:30:46 +08:00
|
|
|
/>
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
<SelectItem
|
|
|
|
|
v-for="node in nodeOptions"
|
|
|
|
|
:key="node.id"
|
|
|
|
|
:value="node.id"
|
|
|
|
|
>
|
2026-02-11 15:33:01 +08:00
|
|
|
{{ node.name }}{{ node.region ? ` · ${formatRegion(node.region, '')}` : '' }} ({{ node.ip }}:{{ node.port }})
|
2026-02-07 14:30:46 +08:00
|
|
|
</SelectItem>
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-07-16 15:21:11 +08:00
|
|
|
import { computed, onMounted } from 'vue'
|
2026-02-07 14:30:46 +08:00
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
} from '@/components/ui'
|
|
|
|
|
import { useProxyNodesStore } from '@/stores/proxy-nodes'
|
2026-06-30 14:14:12 +08:00
|
|
|
import { useI18n } from '@/i18n'
|
2026-02-11 15:33:01 +08:00
|
|
|
import { formatRegion } from '@/utils/region'
|
2026-02-07 14:30:46 +08:00
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
modelValue: string
|
|
|
|
|
triggerClass?: string
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
defineEmits<{
|
|
|
|
|
'update:modelValue': [value: string]
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const proxyNodesStore = useProxyNodesStore()
|
2026-06-30 14:14:12 +08:00
|
|
|
const { legacyT } = useI18n()
|
2026-02-07 14:30:46 +08:00
|
|
|
|
|
|
|
|
/** 在线节点 + 保留当前已选节点(可能已离线) */
|
|
|
|
|
const nodeOptions = computed(() => {
|
|
|
|
|
const online = proxyNodesStore.onlineNodes
|
|
|
|
|
if (props.modelValue) {
|
|
|
|
|
const found = online.find(n => n.id === props.modelValue)
|
|
|
|
|
if (!found) {
|
|
|
|
|
const allNode = proxyNodesStore.nodes.find(n => n.id === props.modelValue)
|
|
|
|
|
if (allNode) return [allNode, ...online]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return online
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/** 供父组件调用:启用代理时懒加载节点列表 */
|
|
|
|
|
function ensureLoaded() {
|
2026-07-16 15:21:11 +08:00
|
|
|
return proxyNodesStore.ensureLoaded()
|
2026-02-07 14:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-16 15:21:11 +08:00
|
|
|
onMounted(ensureLoaded)
|
|
|
|
|
|
2026-02-07 14:30:46 +08:00
|
|
|
defineExpose({ ensureLoaded })
|
|
|
|
|
</script>
|