add i18n step1
This commit is contained in:
parent
34d553a890
commit
79e3db6078
23 changed files with 2309 additions and 450 deletions
|
|
@ -1,25 +1,21 @@
|
|||
// js/global.js - 全局配置页面的逻辑
|
||||
|
||||
import { theme, activateNav } from './common.js';
|
||||
import { initializePage } from './common.js'; // 导入通用初始化函数
|
||||
import { api } from './api.js';
|
||||
import { notification } from './notifications.js';
|
||||
import { initCaddyStatus } from './caddy.js';
|
||||
import { createCustomSelect } from './ui.js';
|
||||
|
||||
const DOMElements = {
|
||||
globalForm: document.getElementById('global-caddy-form'),
|
||||
themeToggleInput: document.getElementById('theme-toggle-input'),
|
||||
logoutBtn: document.getElementById('logout-btn'),
|
||||
toastContainer: document.getElementById('toast-container'),
|
||||
dialogContainer: document.getElementById('dialog-container'),
|
||||
enableDnsChallengeCheckbox: document.getElementById('enable_dns_challenge'),
|
||||
globalTlsConfigGroup: document.getElementById('global-tls-config-group'),
|
||||
enableEchCheckbox: document.getElementById('enable_ech'),
|
||||
echConfigGroup: document.getElementById('ech-config-group'),
|
||||
};
|
||||
const submitButton = DOMElements.globalForm.querySelector('button[type="submit"]');
|
||||
// submitButton 在 pageInit 中获取, 确保DOM已加载
|
||||
let submitButton;
|
||||
|
||||
// 从表单收集数据, 构建成后端需要的JSON结构
|
||||
function getGlobalConfigFromForm() {
|
||||
const formData = new FormData(DOMElements.globalForm);
|
||||
const enableEch = DOMElements.enableEchCheckbox.checked;
|
||||
|
|
@ -49,7 +45,6 @@ function getGlobalConfigFromForm() {
|
|||
};
|
||||
}
|
||||
|
||||
// 用从API获取的数据填充表单
|
||||
function fillGlobalConfigForm(config) {
|
||||
if (!config) return;
|
||||
|
||||
|
|
@ -100,7 +95,6 @@ async function handleSaveGlobalConfig(e) {
|
|||
submitButton.querySelector('span').textContent = "保存中...";
|
||||
|
||||
try {
|
||||
// 修正: 更新API端点路径
|
||||
const result = await api.put('/global/config', configData);
|
||||
notification.toast(result.message || '全局配置已成功保存,Caddy正在重载...', 'success');
|
||||
} catch (error) {
|
||||
|
|
@ -118,23 +112,19 @@ async function handleLogout() {
|
|||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
theme.init(DOMElements.themeToggleInput);
|
||||
notification.init(DOMElements.toastContainer, DOMElements.dialogContainer);
|
||||
activateNav('global');
|
||||
initCaddyStatus();
|
||||
// 页面特有的初始化逻辑
|
||||
function pageInit() {
|
||||
// 在这里获取 submitButton, 确保 DOM 已加载
|
||||
submitButton = DOMElements.globalForm.querySelector('button[type="submit"]');
|
||||
|
||||
// 修正: 更新API端点路径
|
||||
api.get('/global/log/levels')
|
||||
.then(levels => createCustomSelect('select-log-level', Object.keys(levels)))
|
||||
.catch(err => notification.toast(`加载日志级别失败: ${err.message}`, 'error'));
|
||||
|
||||
// 修正: 更新API端点路径
|
||||
api.get('/global/tls/providers')
|
||||
.then(providers => createCustomSelect('select-tls-provider', Object.keys(providers)))
|
||||
.catch(err => notification.toast(`加载TLS提供商失败: ${err.message}`, 'error'));
|
||||
|
||||
// 修正: 更新API端点路径
|
||||
api.get('/global/config')
|
||||
.then(config => fillGlobalConfigForm(config))
|
||||
.catch(err => notification.toast(`加载全局配置失败: ${err.message}`, 'error'));
|
||||
|
|
@ -150,4 +140,5 @@ function init() {
|
|||
});
|
||||
}
|
||||
|
||||
init();
|
||||
// 使用通用初始化函数启动页面
|
||||
initializePage({ pageId: 'global', pageInit: pageInit });
|
||||
Loading…
Add table
Add a link
Reference in a new issue