mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-05-24 17:50:29 +08:00
feat(payment): 实现动态国家货币配置加载功能
- 移除硬编码国家货币映射,改为从API动态加载 - 添加 /api/payment/countries 接口获取支持的国家/货币列表 - 实现国家列表缓存机制(1小时有效期) - 在支付页面添加国家选择下拉框动态渲染 - 添加网络请求失败时的备用数据方案 - 保留批量模式状态不被重置的注释说明
This commit is contained in:
@@ -1061,7 +1061,7 @@ function resetButtons() {
|
||||
elements.cancelBtn.disabled = true;
|
||||
currentTask = null;
|
||||
currentBatch = null;
|
||||
isBatchMode = false;
|
||||
// 注意:不重置 isBatchMode,因为用户可能想继续使用批量模式
|
||||
// 重置完成标志
|
||||
taskCompleted = false;
|
||||
batchCompleted = false;
|
||||
|
||||
@@ -2,20 +2,53 @@
|
||||
* 支付页面 JavaScript
|
||||
*/
|
||||
|
||||
const COUNTRY_CURRENCY_MAP = {
|
||||
SG: 'SGD', US: 'USD', TR: 'TRY', JP: 'JPY',
|
||||
HK: 'HKD', GB: 'GBP', EU: 'EUR', AU: 'AUD',
|
||||
CA: 'CAD', IN: 'INR', BR: 'BRL', MX: 'MXN',
|
||||
};
|
||||
|
||||
let selectedPlan = 'plus';
|
||||
let generatedLink = '';
|
||||
let countryCurrencyMap = {}; // 动态从接口加载
|
||||
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadAccounts();
|
||||
loadCountries();
|
||||
});
|
||||
|
||||
// 加载国家/货币列表
|
||||
async function loadCountries() {
|
||||
const sel = document.getElementById('country-select');
|
||||
try {
|
||||
const resp = await fetch('/api/payment/countries');
|
||||
const data = await resp.json();
|
||||
const countries = data.countries || [];
|
||||
|
||||
// 重建映射表
|
||||
countryCurrencyMap = {};
|
||||
countries.forEach(c => {
|
||||
countryCurrencyMap[c.country_code] = c.currency;
|
||||
});
|
||||
|
||||
// 记住当前选中值
|
||||
const current = sel.value;
|
||||
|
||||
// 渲染选项
|
||||
sel.innerHTML = countries.map(c =>
|
||||
`<option value="${c.country_code}">${c.country_name} (${c.currency})</option>`
|
||||
).join('');
|
||||
|
||||
// 恢复选中或默认 SG
|
||||
sel.value = current && countryCurrencyMap[current] ? current : 'SG';
|
||||
onCountryChange();
|
||||
|
||||
if (!data.success) {
|
||||
console.warn('国家列表使用内置 fallback:', data.error);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载国家列表失败:', e);
|
||||
sel.innerHTML = '<option value="SG">Singapore (SGD)</option>';
|
||||
countryCurrencyMap = { SG: 'SGD' };
|
||||
onCountryChange();
|
||||
}
|
||||
}
|
||||
|
||||
// 加载账号列表
|
||||
async function loadAccounts() {
|
||||
try {
|
||||
@@ -37,7 +70,7 @@ async function loadAccounts() {
|
||||
// 国家切换
|
||||
function onCountryChange() {
|
||||
const country = document.getElementById('country-select').value;
|
||||
const currency = COUNTRY_CURRENCY_MAP[country] || 'USD';
|
||||
const currency = countryCurrencyMap[country] || '';
|
||||
document.getElementById('currency-display').value = currency;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user