27 lines
944 B
TypeScript
27 lines
944 B
TypeScript
import { computed } from 'vue'
|
|
|
|
import { listProxies } from '@/api/proxies'
|
|
import { useAsync } from '@/composables/useAsync'
|
|
import type { ProxyInfo } from '@/types/api'
|
|
|
|
/** 代理出口地区短文案:未探测=检测中、失败=未知 */
|
|
export function proxyGeoLabel(p: ProxyInfo): string {
|
|
if (!p.geoAt) return '检测中'
|
|
if (!p.country) return '未知'
|
|
return p.city ? `${p.country}·${p.city}` : p.country
|
|
}
|
|
|
|
/** 出站代理下拉数据源(租户导入 / 修改表单共用):
|
|
* 选项 label 为「名称 · 出口地区」,首项为直连哨兵 null。 */
|
|
export function useProxyOptions() {
|
|
const proxies = useAsync(listProxies)
|
|
const options = computed(() => [
|
|
{ label: '直连(不使用代理)', value: null as number | null },
|
|
...(proxies.data.value?.items ?? []).map((p) => ({
|
|
label: `${p.name} · ${proxyGeoLabel(p)}`,
|
|
value: p.id as number | null,
|
|
})),
|
|
])
|
|
return { proxies, options }
|
|
}
|