This commit is contained in:
Baobhan Sith
2025-04-20 21:53:17 +08:00
parent 7b00a111dd
commit b862e85ea5
7 changed files with 174 additions and 27 deletions
+13
View File
@@ -643,6 +643,19 @@
"saveFailed": "Failed to save Docker settings.",
"invalidInterval": "Refresh interval must be a positive integer."
}
},
"statusMonitor": {
"title": "Status Monitor Settings",
"refreshIntervalLabel": "Status Refresh Interval (seconds):",
"refreshIntervalHint": "How often to fetch server CPU, memory, disk, etc. status (minimum 1).",
"saveButton": "Save Status Monitor Settings",
"success": {
"saved": "Status monitor settings saved successfully."
},
"error": {
"saveFailed": "Failed to save status monitor settings.",
"invalidInterval": "Refresh interval must be a positive integer."
}
}
},
"common": {
+13
View File
@@ -643,6 +643,19 @@
"saveFailed": "保存 Docker 设置失败。",
"invalidInterval": "刷新间隔必须是正整数。"
}
},
"statusMonitor": {
"title": "状态监控设置",
"refreshIntervalLabel": "状态刷新间隔 (秒):",
"refreshIntervalHint": "获取服务器 CPU、内存、磁盘等状态的频率(最小为 1)。",
"saveButton": "保存状态监控设置",
"success": {
"saved": "状态监控设置已成功保存。"
},
"error": {
"saveFailed": "保存状态监控设置失败。",
"invalidInterval": "刷新间隔必须是正整数。"
}
}
},
"common": {
+16 -3
View File
@@ -16,6 +16,7 @@ interface SettingsState {
autoCopyOnSelect?: string; // 'true' or 'false' - 终端选中自动复制
dockerStatusIntervalSeconds?: string; // NEW: Docker 状态刷新间隔 (秒)
dockerDefaultExpand?: string; // NEW: Docker 默认展开详情 'true' or 'false'
statusMonitorIntervalSeconds?: string; // NEW: 状态监控轮询间隔 (秒)
// Add other general settings keys here as needed
[key: string]: string | undefined; // Allow other string settings
}
@@ -74,7 +75,10 @@ export const useSettingsStore = defineStore('settings', () => {
if (settings.value.dockerDefaultExpand === undefined) {
settings.value.dockerDefaultExpand = 'false'; // 默认不展开
}
// NEW: Status Monitor interval default
if (settings.value.statusMonitorIntervalSeconds === undefined) {
settings.value.statusMonitorIntervalSeconds = '3'; // 默认 3 秒
}
// --- 语言设置 ---
const langFromSettings = settings.value.language;
@@ -124,7 +128,8 @@ export const useSettingsStore = defineStore('settings', () => {
const allowedKeys: Array<keyof SettingsState> = [
'language', 'ipWhitelist', 'maxLoginAttempts', 'loginBanDuration',
'showPopupFileEditor', 'shareFileEditorTabs', 'ipWhitelistEnabled',
'autoCopyOnSelect', 'dockerStatusIntervalSeconds', 'dockerDefaultExpand' // +++ 添加 Docker 设置键 +++
'autoCopyOnSelect', 'dockerStatusIntervalSeconds', 'dockerDefaultExpand',
'statusMonitorIntervalSeconds' // +++ 添加状态监控间隔键 +++
];
if (!allowedKeys.includes(key)) {
console.error(`[SettingsStore] 尝试更新不允许的设置键: ${key}`);
@@ -157,7 +162,8 @@ export const useSettingsStore = defineStore('settings', () => {
const allowedKeys: Array<keyof SettingsState> = [
'language', 'ipWhitelist', 'maxLoginAttempts', 'loginBanDuration',
'showPopupFileEditor', 'shareFileEditorTabs', 'ipWhitelistEnabled',
'autoCopyOnSelect', 'dockerStatusIntervalSeconds', 'dockerDefaultExpand' // +++ 添加 Docker 设置键 +++
'autoCopyOnSelect', 'dockerStatusIntervalSeconds', 'dockerDefaultExpand',
'statusMonitorIntervalSeconds' // +++ 添加状态监控间隔键 +++
];
const filteredUpdates: Partial<SettingsState> = {};
let languageUpdate: 'en' | 'zh' | undefined = undefined;
@@ -224,6 +230,12 @@ export const useSettingsStore = defineStore('settings', () => {
return settings.value.dockerDefaultExpand === 'true';
});
// NEW: Getter for Status Monitor interval, returning number
const statusMonitorIntervalSecondsNumber = computed(() => {
const val = parseInt(settings.value.statusMonitorIntervalSeconds || '3', 10);
return isNaN(val) || val <= 0 ? 3 : val; // Fallback to 3 if invalid
});
return {
settings, // 只包含通用设置
isLoading,
@@ -234,6 +246,7 @@ export const useSettingsStore = defineStore('settings', () => {
ipWhitelistEnabled, // 暴露 IP 白名单启用状态
autoCopyOnSelectBoolean,
dockerDefaultExpandBoolean, // +++ 暴露 Docker 默认展开 getter +++
statusMonitorIntervalSecondsNumber, // +++ 暴露状态监控间隔 getter +++
// 移除外观相关的 getters 和 actions
loadInitialSettings,
updateSetting,
+42 -1
View File
@@ -156,6 +156,21 @@
</div>
<!-- END: Docker Settings Section -->
<!-- NEW: Status Monitor Settings Section -->
<div class="settings-section">
<h2>{{ t('settings.statusMonitor.title') }}</h2>
<form @submit.prevent="handleUpdateStatusMonitorInterval">
<div class="form-group">
<label for="statusMonitorInterval">{{ t('settings.statusMonitor.refreshIntervalLabel') }}</label>
<input type="number" id="statusMonitorInterval" v-model.number="statusMonitorIntervalLocal" min="1" step="1" required>
<small>{{ t('settings.statusMonitor.refreshIntervalHint') }}</small>
</div>
<button type="submit" :disabled="statusMonitorLoading">{{ statusMonitorLoading ? $t('common.saving') : t('settings.statusMonitor.saveButton') }}</button>
<p v-if="statusMonitorMessage" :class="{ 'success-message': statusMonitorSuccess, 'error-message': !statusMonitorSuccess }">{{ statusMonitorMessage }}</p>
</form>
</div>
<!-- END: Status Monitor Settings Section -->
<div class="settings-section">
<h2>{{ $t('settings.ipWhitelist.title') }}</h2>
<p>{{ $t('settings.ipWhitelist.description') }}</p>
@@ -252,7 +267,7 @@ const { t } = useI18n();
// --- Reactive state from store ---
// 使用 storeToRefs 获取响应式 getter,包括 language
const { settings, isLoading: settingsLoading, error: settingsError, showPopupFileEditorBoolean, shareFileEditorTabsBoolean, autoCopyOnSelectBoolean, dockerDefaultExpandBoolean, language: storeLanguage } = storeToRefs(settingsStore); // +++ 添加 dockerDefaultExpandBoolean 和 language getter +++
const { settings, isLoading: settingsLoading, error: settingsError, showPopupFileEditorBoolean, shareFileEditorTabsBoolean, autoCopyOnSelectBoolean, dockerDefaultExpandBoolean, statusMonitorIntervalSecondsNumber, language: storeLanguage } = storeToRefs(settingsStore); // +++ 添加 statusMonitorIntervalSecondsNumber getter +++
// --- Local state for forms ---
const ipWhitelistInput = ref('');
@@ -290,6 +305,10 @@ const dockerExpandDefault = ref(false); // 本地状态,用于 Docker 默认
const dockerSettingsLoading = ref(false);
const dockerSettingsMessage = ref('');
const dockerSettingsSuccess = ref(false);
const statusMonitorIntervalLocal = ref(3); // 本地状态,用于状态监控间隔 v-model
const statusMonitorLoading = ref(false);
const statusMonitorMessage = ref('');
const statusMonitorSuccess = ref(false);
// --- Watcher to sync local form state with store state ---
@@ -308,6 +327,7 @@ watch(settings, (newSettings, oldSettings) => {
autoCopyEnabled.value = autoCopyOnSelectBoolean.value; // 同步选中即复制状态
dockerInterval.value = parseInt(newSettings.dockerStatusIntervalSeconds || '2', 10); // 同步 Docker 间隔
dockerExpandDefault.value = dockerDefaultExpandBoolean.value; // 同步 Docker 默认展开状态
statusMonitorIntervalLocal.value = statusMonitorIntervalSecondsNumber.value; // 同步状态监控间隔
}, { deep: true, immediate: true }); // immediate: true to run on initial load
@@ -398,6 +418,27 @@ const handleUpdateDockerSettings = async () => {
}
};
// --- Status Monitor interval setting method ---
const handleUpdateStatusMonitorInterval = async () => {
statusMonitorLoading.value = true;
statusMonitorMessage.value = '';
statusMonitorSuccess.value = false;
try {
const intervalValue = statusMonitorIntervalLocal.value;
if (isNaN(intervalValue) || intervalValue < 1 || !Number.isInteger(intervalValue)) {
throw new Error(t('settings.statusMonitor.error.invalidInterval')); // 需要添加翻译
}
await settingsStore.updateSetting('statusMonitorIntervalSeconds', String(intervalValue)); // 保存为字符串
statusMonitorMessage.value = t('settings.statusMonitor.success.saved'); // 需要添加翻译
statusMonitorSuccess.value = true;
} catch (error: any) {
console.error('更新状态监控间隔失败:', error);
statusMonitorMessage.value = error.message || t('settings.statusMonitor.error.saveFailed'); // 需要添加翻译
statusMonitorSuccess.value = false;
} finally {
statusMonitorLoading.value = false;
}
};
// --- 外观设置 ---
const openStyleCustomizer = () => {