This commit is contained in:
2026-02-10 19:24:46 +08:00
parent d59e4c0bb9
commit bef5c2f437
6 changed files with 94 additions and 5 deletions

View File

@@ -126,6 +126,55 @@ export const useCountryStore = defineStore('country', () => {
await fetchCountryInfo(t, true)
}
/**
* 手动设置国家信息
* @param {string} countryName - 国家名称(中文)
* @param {Function} t - 国际化函数(可选)
*/
const setCountryManually = (countryName, t = null) => {
if (!countryName || countryName.trim() === '') {
return false
}
countryData.value = countryName.trim()
countryDataEN.value = countryName.trim()
hasInitialized.value = true
lastFetchTime.value = Date.now()
if (t) {
ElMessage.success(t('workbenchesSetup.countrySetSuccess') || t('hostsList.countrySetSuccess') || '国家设置成功')
}
return true
}
/**
* 显示编辑国家的弹窗
* @param {Function} t - 国际化函数
*/
const showEditCountryDialog = (t) => {
ElMessageBox.prompt(
t('workbenchesSetup.editCountryPrompt') || t('hostsList.editCountryPrompt') || '请输入国家名称(中文)',
t('workbenchesSetup.editCountryTitle') || t('hostsList.editCountryTitle') || '编辑国家',
{
confirmButtonText: t('workbenchesSetup.confirm') || t('hostsList.confirm') || '确定',
cancelButtonText: t('workbenchesSetup.cancel') || t('hostsList.cancel') || '取消',
inputPlaceholder: t('workbenchesSetup.countryPlaceholder') || t('hostsList.countryPlaceholder') || '例如:美国、日本、英国',
inputValue: countryData.value, // 预填充当前值
inputValidator: (value) => {
if (!value || value.trim() === '') {
return t('workbenchesSetup.countryRequired') || t('hostsList.countryRequired') || '请输入国家名称'
}
return true
}
}
).then(({ value }) => {
setCountryManually(value, t)
}).catch(() => {
// 用户取消编辑
})
}
return {
// 状态
countryData,
@@ -139,5 +188,7 @@ export const useCountryStore = defineStore('country', () => {
refreshCountry,
showCountryInputDialog,
initCountryInfo,
setCountryManually,
showEditCountryDialog,
}
})