update
This commit is contained in:
@@ -26,6 +26,16 @@ interface PublicCaptchaConfig {
|
||||
recaptchaSiteKey?: string;
|
||||
}
|
||||
|
||||
// Backend's full CAPTCHA Settings Interface (as returned by /settings/captcha)
|
||||
interface FullCaptchaSettings {
|
||||
enabled: boolean;
|
||||
provider: 'hcaptcha' | 'recaptcha' | 'none';
|
||||
hcaptchaSiteKey?: string;
|
||||
hcaptchaSecretKey?: string; // We won't use this in authStore
|
||||
recaptchaSiteKey?: string;
|
||||
recaptchaSecretKey?: string; // We won't use this in authStore
|
||||
}
|
||||
|
||||
// Auth Store State 接口
|
||||
interface AuthState {
|
||||
isAuthenticated: boolean;
|
||||
@@ -281,19 +291,29 @@ export const useAuthStore = defineStore('auth', {
|
||||
}
|
||||
},
|
||||
|
||||
// NEW: 获取公共 CAPTCHA 配置
|
||||
// NEW: 获取公共 CAPTCHA 配置 (修改为从 /settings/captcha 获取)
|
||||
async fetchCaptchaConfig() {
|
||||
// Avoid refetching if already loaded
|
||||
if (this.publicCaptchaConfig !== null) return;
|
||||
|
||||
// Don't set isLoading for this, it should be quick background fetch
|
||||
try {
|
||||
console.log('[AuthStore] Fetching public CAPTCHA config...');
|
||||
const response = await apiClient.get<PublicCaptchaConfig>('/auth/captcha/config');
|
||||
this.publicCaptchaConfig = response.data;
|
||||
console.log('[AuthStore] Public CAPTCHA config loaded:', this.publicCaptchaConfig);
|
||||
console.log('[AuthStore] Fetching CAPTCHA config from /settings/captcha...');
|
||||
// 修改 API 端点
|
||||
const response = await apiClient.get<FullCaptchaSettings>('/settings/captcha');
|
||||
const fullConfig = response.data;
|
||||
|
||||
// 从完整配置中提取公共部分
|
||||
this.publicCaptchaConfig = {
|
||||
enabled: fullConfig.enabled,
|
||||
provider: fullConfig.provider,
|
||||
hcaptchaSiteKey: fullConfig.hcaptchaSiteKey,
|
||||
recaptchaSiteKey: fullConfig.recaptchaSiteKey,
|
||||
};
|
||||
|
||||
console.log('[AuthStore] Public CAPTCHA config derived from /settings/captcha:', this.publicCaptchaConfig);
|
||||
} catch (error: any) {
|
||||
console.error('获取公共 CAPTCHA 配置失败:', error.response?.data?.message || error.message);
|
||||
console.error('获取 CAPTCHA 配置失败 (from /settings/captcha):', error.response?.data?.message || error.message);
|
||||
// Set a default disabled config on error to prevent blocking login UI
|
||||
this.publicCaptchaConfig = {
|
||||
enabled: false,
|
||||
|
||||
@@ -3,6 +3,7 @@ import apiClient from '../utils/apiClient'; // 使用统一的 apiClient
|
||||
import { ref, computed } from 'vue'; // 移除 watch
|
||||
import i18n, { setLocale, defaultLng } from '../i18n'; // Import i18n instance and setLocale
|
||||
import type { PaneName } from './layout.store'; // +++ Import PaneName type +++
|
||||
import { useAuthStore } from './auth.store'; // <--- 导入 authStore
|
||||
// Import CAPTCHA types from backend (adjust path if needed, assuming types are mirrored or shared)
|
||||
// For now, let's assume they are available via a shared types definition or manually defined here
|
||||
// Assuming manual definition for now if no shared types exist:
|
||||
@@ -49,6 +50,8 @@ interface SettingsState {
|
||||
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
const authStore = useAuthStore(); // <--- 实例化 authStore
|
||||
|
||||
// --- State ---
|
||||
const settings = ref<Partial<SettingsState>>({}); // 通用设置状态
|
||||
const parsedSidebarPaneWidths = ref<Record<string, string>>({}); // NEW: 解析后的侧边栏宽度对象
|
||||
@@ -428,6 +431,12 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
}
|
||||
console.log('[SettingsStore] CAPTCHA 设置更新成功。');
|
||||
|
||||
// --- 新增:强制 authStore 重新获取配置 ---
|
||||
console.log('[SettingsStore] Triggering authStore to refetch CAPTCHA config...');
|
||||
authStore.publicCaptchaConfig = null; // 重置 authStore 的状态以允许重新获取
|
||||
await authStore.fetchCaptchaConfig(); // 让 authStore 立即获取最新的配置
|
||||
// -----------------------------------------
|
||||
|
||||
} catch (err: any) {
|
||||
console.error('更新 CAPTCHA 设置失败:', err);
|
||||
error.value = err.response?.data?.message || err.message || '更新 CAPTCHA 设置失败';
|
||||
|
||||
Reference in New Issue
Block a user