This commit is contained in:
Baobhan Sith
2025-04-26 20:51:31 +08:00
parent 70749a2112
commit 2544bc9646
9 changed files with 126 additions and 35 deletions
+13 -2
View File
@@ -44,6 +44,7 @@ interface SettingsState {
fileManagerRowSizeMultiplier?: string; // NEW: 文件管理器行大小乘数 (e.g., '1.0')
fileManagerColWidths?: string; // NEW: 文件管理器列宽 JSON 字符串 (e.g., '{"name": 300, "size": 100}')
commandInputSyncTarget?: 'quickCommands' | 'commandHistory' | 'none'; // NEW: 命令输入同步目标
timezone?: string; // NEW: 时区设置 (e.g., 'Asia/Shanghai', 'UTC')
// Add other general settings keys here as needed
[key: string]: string | undefined; // Allow other string settings
}
@@ -206,6 +207,10 @@ export const useSettingsStore = defineStore('settings', () => {
if (settings.value.commandInputSyncTarget === undefined) {
settings.value.commandInputSyncTarget = 'none'; // 默认不同步
}
// NEW: Timezone default
if (settings.value.timezone === undefined) {
settings.value.timezone = 'UTC'; // 默认 UTC
}
// --- 语言设置 ---
const langFromSettings = settings.value.language;
@@ -282,7 +287,8 @@ export const useSettingsStore = defineStore('settings', () => {
'sidebarPaneWidths', // +++ 添加侧边栏宽度对象键 +++
'fileManagerRowSizeMultiplier', // +++ 添加文件管理器行大小键 +++
'fileManagerColWidths', // +++ 添加文件管理器列宽键 +++
'commandInputSyncTarget' // +++ 添加命令输入同步目标键 +++
'commandInputSyncTarget', // +++ 添加命令输入同步目标键 +++
'timezone' // NEW: 添加时区键
];
if (!allowedKeys.includes(key)) {
console.error(`[SettingsStore] 尝试更新不允许的设置键: ${key}`);
@@ -323,7 +329,8 @@ export const useSettingsStore = defineStore('settings', () => {
'sidebarPaneWidths', // +++ 添加侧边栏宽度对象键 +++
'fileManagerRowSizeMultiplier', // +++ 添加文件管理器行大小键 +++
'fileManagerColWidths', // +++ 添加文件管理器列宽键 +++
'commandInputSyncTarget' // +++ 添加命令输入同步目标键 +++
'commandInputSyncTarget', // +++ 添加命令输入同步目标键 +++
'timezone' // NEW: 添加时区键
];
const filteredUpdates: Partial<SettingsState> = {};
let languageUpdate: string | undefined = undefined; // Use string type
@@ -547,6 +554,9 @@ export const useSettingsStore = defineStore('settings', () => {
return 'none'; // Default to 'none' if invalid or not set
});
// NEW: Getter for timezone setting
const timezone = computed(() => settings.value.timezone || 'UTC'); // Fallback to UTC
// --- CAPTCHA Getters (Public Only) ---
const isCaptchaEnabled = computed(() => captchaSettings.value?.enabled ?? false);
const captchaProvider = computed(() => captchaSettings.value?.provider ?? 'none');
@@ -584,5 +594,6 @@ export const useSettingsStore = defineStore('settings', () => {
updateSidebarPaneWidth, // +++ 暴露更新特定面板宽度的 action +++
updateFileManagerLayoutSettings, // +++ 暴露更新文件管理器布局的 action +++
commandInputSyncTarget, // +++ 暴露命令输入同步目标 getter +++
timezone, // NEW: 暴露时区 getter
};
});
+59 -1
View File
@@ -483,6 +483,31 @@
</div>
</form>
</div>
<hr class="border-border/50"> <!-- NEW: Separator -->
<!-- Timezone Setting -->
<div class="settings-section-content">
<h3 class="text-base font-semibold text-foreground mb-3">{{ t('settings.timezone.title', '时区设置') }}</h3>
<form @submit.prevent="handleUpdateTimezone" class="space-y-4">
<div>
<label for="timezoneSelect" class="block text-sm font-medium text-text-secondary mb-1">{{ t('settings.timezone.selectLabel', '选择时区') }}</label>
<select id="timezoneSelect" v-model="selectedTimezone"
class="w-full px-3 py-2 border border-border rounded-md shadow-sm bg-background text-foreground focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary appearance-none bg-no-repeat bg-right pr-8"
style="background-image: url('data:image/svg+xml,%3csvg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 16 16\'%3e%3cpath fill=\'none\' stroke=\'%236c757d\' stroke-linecap=\'round\' stroke-linejoin=\'round\' stroke-width=\'2\' d=\'M2 5l6 6 6-6\'/%3e%3c/svg%3e'); background-position: right 0.75rem center; background-size: 16px 12px;">
<option v-for="tz in commonTimezones" :key="tz" :value="tz">
{{ tz }}
</option>
</select>
<small class="block mt-1 text-xs text-text-secondary">{{ t('settings.timezone.description', '通知中的时间戳将根据此时区进行格式化。') }}</small>
</div>
<div class="flex items-center justify-between">
<button type="submit" :disabled="timezoneLoading"
class="px-4 py-2 bg-button text-button-text rounded-md shadow-sm hover:bg-button-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed transition duration-150 ease-in-out text-sm font-medium">
{{ timezoneLoading ? $t('common.saving') : t('common.save') }}
</button>
<p v-if="timezoneMessage" :class="['text-sm', timezoneSuccess ? 'text-success' : 'text-error']">{{ timezoneMessage }}</p>
</div>
</form>
</div>
</div>
</div>
</div>
@@ -591,7 +616,10 @@ const workspaceSidebarPersistentSuccess = ref(false); // 新增
const commandInputSyncLoading = ref(false); // NEW
const commandInputSyncMessage = ref(''); // NEW
const commandInputSyncSuccess = ref(false); // NEW
const selectedTimezone = ref('UTC'); // 本地状态,用于时区 v-model
const timezoneLoading = ref(false);
const timezoneMessage = ref('');
const timezoneSuccess = ref(false);
// CAPTCHA Form State
const captchaForm = reactive<UpdateCaptchaSettingsDto>({ // Use reactive for the form object
enabled: false,
@@ -605,6 +633,17 @@ const captchaLoading = ref(false);
const captchaMessage = ref('');
const captchaSuccess = ref(false);
// 提供一些常用的时区供选择
const commonTimezones = ref([
'UTC',
'Etc/GMT+12', 'Pacific/Midway', 'Pacific/Honolulu', 'America/Anchorage',
'America/Los_Angeles', 'America/Denver', 'America/Chicago', 'America/New_York',
'America/Caracas', 'America/Halifax', 'America/Sao_Paulo', 'Atlantic/Azores',
'Europe/London', 'Europe/Paris', 'Europe/Berlin', 'Europe/Moscow',
'Asia/Dubai', 'Asia/Karachi', 'Asia/Dhaka', 'Asia/Bangkok',
'Asia/Shanghai', 'Asia/Tokyo', 'Australia/Sydney', 'Pacific/Auckland',
'Etc/GMT-14'
]);
// --- Watcher to sync local form state with store state ---
watch(settings, (newSettings, oldSettings) => {
@@ -625,6 +664,7 @@ watch(settings, (newSettings, oldSettings) => {
statusMonitorIntervalLocal.value = statusMonitorIntervalSecondsNumber.value; // 同步状态监控间隔
workspaceSidebarPersistentEnabled.value = workspaceSidebarPersistentBoolean.value; // 新增:同步侧边栏固定设置
commandInputSyncTargetLocal.value = commandInputSyncTarget.value; // NEW: Sync command input sync target
selectedTimezone.value = newSettings.timezone || 'UTC'; // 同步时区设置
}, { deep: true, immediate: true }); // immediate: true to run on initial load
@@ -795,6 +835,24 @@ const handleUpdateCommandInputSyncTarget = async () => {
}
};
// --- Timezone setting method ---
const handleUpdateTimezone = async () => {
timezoneLoading.value = true;
timezoneMessage.value = '';
timezoneSuccess.value = false;
try {
await settingsStore.updateSetting('timezone', selectedTimezone.value);
timezoneMessage.value = t('settings.timezone.success.saved', '时区设置已保存'); // 需要添加翻译
timezoneSuccess.value = true;
} catch (error: any) {
console.error('更新时区设置失败:', error);
timezoneMessage.value = error.message || t('settings.timezone.error.saveFailed', '保存时区设置失败'); // 需要添加翻译
timezoneSuccess.value = false;
} finally {
timezoneLoading.value = false;
}
};
// --- 外观设置 ---
const openStyleCustomizer = () => {
appearanceStore.toggleStyleCustomizer(true);