修复国家检测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

@@ -115,9 +115,15 @@
<h2 class="font-bold text-slate-800 dark:text-white">{{ $t('workbenchesSetup.workbenches') }}</h2>
</div>
<div class="flex items-center gap-4 text-sm">
<div class="text-slate-500">{{ $t('workbenchesSetup.network') }}: <span class="text-blue-600 font-bold">{{
locale
== 'zh' ? countryData : countryDataEN }}</span></div>
<div class="flex items-center gap-2 text-slate-500">
<span>{{ $t('workbenchesSetup.network') }}:</span>
<span class="text-blue-600 font-bold">{{ locale == 'zh' ? countryData : countryDataEN }}</span>
<button @click="refreshCountry" :disabled="isRefreshingCountry"
class="ml-1 p-1 rounded-md hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:title="$t('workbenchesSetup.refreshCountry') || '刷新国家'">
<span class="material-icons-round text-slate-500 text-base" :class="{ 'animate-spin': isRefreshingCountry }">refresh</span>
</button>
</div>
<div class="flex items-center gap-2">
<span class="text-slate-500">指定国家:</span>
<select v-model="country_info"
@@ -301,15 +307,18 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import { getCountryName } from '@/utils/countryUtil'
import { tkaccountuseinfo, getExpiredTime } from '@/api/account'
import { useI18n } from 'vue-i18n'
const { locale } = useI18n()
import { useCountryStore } from '@/stores/countryStore'
const { t, locale } = useI18n()
const countryStore = useCountryStore()
//导入python交互方法
const { fetchDataConfig, fetchDataCount, loginBackStage, loginTikTok, backStageloginStatus, backStageloginStatusCopy, getTkLoginStatus } = usePythonBridge();
//ip国家
let countryData = ref('');
//英文国家
let countryDataEN = ref('');
//ip国家 - 使用共享 store
const countryData = computed(() => countryStore.countryData);
const countryDataEN = computed(() => countryStore.countryDataEN);
const isRefreshingCountry = computed(() => countryStore.isLoading);
let country_info = ref('全部');
let country_Lst = ref();
//获取主播数量的定时器
@@ -403,7 +412,9 @@ onMounted(async () => {
tkaccountuse(tkData.value[0].account, 0)
tkaccountuse(tkData.value[1].account, 1)
getIpInfo()
// 使用共享 store 初始化国家信息
countryStore.initCountryInfo(t)
setTimeout(() => {
// Check if user exists before calling getExpiredTime
if (getUser()?.tenantId) {
@@ -420,27 +431,26 @@ onMounted(async () => {
}, 1000 * 20)
})
const getIpInfo = async () => {
// 刷新国家信息 - 使用共享 store
const refreshCountry = async () => {
await countryStore.refreshCountry(t);
// 刷新成功后获取国家列表
if (countryStore.countryData) {
fetchCountryList(countryStore.countryData);
}
};
// 获取国家列表
const fetchCountryList = async (countryName) => {
try {
const response = await fetch('https://ipapi.co/json/');
if (!response.ok) {
throw new Error('请求失败');
}
const data = await response.json();
console.log('IP信息:', data.country);
countryDataEN.value = data.country_name
countryData.value = getCountryName(data.country);
const url = `https://datasave.api.yolozs.com/api/save_data/country_info?countryName=${countryData.value}`;
const url = `https://datasave.api.yolozs.com/api/save_data/country_info?countryName=${countryName}`;
const res = await fetch(url);
const countryres = await res.json();
country_Lst.value = countryres.data
if (countryres.data) {
country_Lst.value = countryres.data;
}
} catch (error) {
console.error('请求出错:', error);
// Optional: Re-enable if needed, but alert can be annoying
// ElMessageBox.prompt('请输入将要获取国家的中文名', '获取国家失败', { ... })
console.error('获取国家列表失败:', error);
}
};
@@ -586,12 +596,12 @@ const loginTK = (index) => {
if (index == 0) {
isLogin.value[1] = true;
statusTimer = setInterval(() => {
getloginStatus();
getloginStatus(tkData.value[index].account);
}, 2000)
} else if (index == 1) {
isLogin.value[0] = true;
statusTimerCopy = setInterval(() => {
getloginStatusCopy();
getloginStatus(tkData.value[index].account);
}, 2000)
}
}
@@ -617,32 +627,47 @@ const checkTkLoginStatus = () => {
});
}
function getloginStatus() {
backStageloginStatus().then((res) => {
const data = JSON.parse(res);
tkData.value[data.index].code = data.code
function getloginStatus(account) {
backStageloginStatus(account).then((res) => {
console.log("登录状态", res)
if (data.code == 1) {
if (!res) return;
const data = res;
// 根据 account 找到对应的 index
const index = tkData.value.findIndex(item => item.account === account);
if (index === -1) return;
// 兼容新旧接口返回格式
// 新格式: { status, account, loginStatus, message }
// 旧格式: { code, index, message }
const isSuccess = data.message === "登录成功"
tkData.value[index].code = isSuccess ? 1 : 0;
if (isSuccess) {
clearInterval(statusTimer);
clearInterval(statusTimerCopy);
statusTimer = null;
statusTimerCopy = null;
submitting.value = false
isLogin.value[0] = false;
isLogin.value[1] = false;
}
})
}
function getloginStatusCopy() {
backStageloginStatusCopy().then((res) => {
const data = JSON.parse(res);
tkData.value[data.index].code = data.code
// function getloginStatusCopy() {
// backStageloginStatusCopy().then((res) => {
// const data = JSON.parse(res);
// tkData.value[data.index].code = data.code
if (data.code == 1) {
clearInterval(statusTimer);
statusTimer = null;
submitting.value = false
isLogin.value[0] = false;
}
})
}
// if (data.code == 1) {
// clearInterval(statusTimer);
// statusTimer = null;
// submitting.value = false
// isLogin.value[0] = false;
// }
// })
// }
function tkaccountuse(id, index) {