修复国家检测bug

This commit is contained in:
2026-02-09 21:04:09 +08:00
parent 658f50cc51
commit d59e4c0bb9
7 changed files with 419 additions and 71 deletions

View File

@@ -109,9 +109,14 @@
</div>
<!-- Status Info -->
<div class="bg-slate-50 px-4 py-2 rounded-xl border border-slate-100 text-sm">
<div class="bg-slate-50 px-4 py-2 rounded-xl border border-slate-100 text-sm flex items-center gap-2">
<span class="text-slate-500">{{ $t('hostsList.currentNetwork') || '当前网络' }}:</span>
<span class="ml-2 font-bold text-primary">{{ countryData }}</span>
<span class="font-bold text-primary">{{ countryData }}</span>
<button @click="refreshCountry" :disabled="isRefreshingCountry"
class="p-1 rounded-md hover:bg-slate-200 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:title="$t('hostsList.refreshCountry') || '刷新国家'">
<span class="material-icons-round text-slate-500 text-base" :class="{ 'animate-spin': isRefreshingCountry }">refresh</span>
</button>
</div>
</div>
</div>
@@ -218,6 +223,7 @@ import { getUser } from "@/utils/storage";
import { getCountryName } from "@/utils/countryUtil";
import { ElMessage, ElMessageBox, ElLoading } from "element-plus";
import { useI18n } from 'vue-i18n';
import { useCountryStore } from '@/stores/countryStore';
// Mock API calls if not present
// Ideally we should import these from api file, but for simplicity I will mock them or use empty callbacks
@@ -228,6 +234,7 @@ import { useI18n } from 'vue-i18n';
import { tkhostdata, getCountryinfo } from "@/api/account";
const { t, locale } = useI18n();
const countryStore = useCountryStore();
// Component State
const queryFormData = ref({
@@ -263,7 +270,9 @@ const streamdialogVisible = ref(false);
const streamdialogVisibletext = ref(false);
const filterdialogVisible = ref(false);
const textarea = ref("");
const countryData = ref("");
// 使用共享 store 的国家信息
const countryData = computed(() => countryStore.countryData);
const isRefreshingCountry = computed(() => countryStore.isLoading);
const userInfo = ref({});
const options = ref([]);
@@ -311,7 +320,10 @@ const timerId = ref(null);
// Lifecycle
onMounted(async () => {
userInfo.value = getUser() || { tenantId: 0, id: 0 };
getIpInfo();
// 使用共享 store 初始化国家信息
await countryStore.initCountryInfo(t);
getCountry();
getlist();
@@ -321,7 +333,7 @@ onMounted(async () => {
// savedSettings might be object already if backend returned object, or string
const data = typeof savedSettings === 'string' ? JSON.parse(savedSettings) : savedSettings;
queryFormData.value = data;
if (data.anchor_ids && data.anchor_ids.length > 0) {
streamdialogVisibletext.value = true;
textarea.value = data.anchor_ids.join("\n");
@@ -546,15 +558,9 @@ function openTikTok() {
loginTikTok();
}
// IP / Country
const getIpInfo = async () => {
try {
const response = await fetch("https://ipapi.co/json/");
if (response.ok) {
const data = await response.json();
countryData.value = getCountryName(data.country);
}
} catch {}
// 刷新国家信息 - 使用共享 store
const refreshCountry = async () => {
await countryStore.refreshCountry(t);
};
function getCountry() {