update
This commit is contained in:
@@ -32,9 +32,8 @@ export interface FileTab {
|
||||
// sessionId: string; // 暂时不加,因为 session.store 已处理独立模式
|
||||
}
|
||||
|
||||
|
||||
// 辅助函数:根据文件名获取语言 (保持不变)
|
||||
const getLanguageFromFilename = (filename: string): string => {
|
||||
// --- 辅助函数 (移到外部并导出) ---
|
||||
export const getLanguageFromFilename = (filename: string): string => {
|
||||
const extension = filename.split('.').pop()?.toLowerCase();
|
||||
switch (extension) {
|
||||
case 'js': return 'javascript';
|
||||
@@ -65,11 +64,10 @@ const getLanguageFromFilename = (filename: string): string => {
|
||||
}
|
||||
};
|
||||
|
||||
// 辅助函数:从路径获取文件名
|
||||
const getFilenameFromPath = (filePath: string): string => {
|
||||
export const getFilenameFromPath = (filePath: string): string => {
|
||||
return filePath.split('/').pop() || filePath;
|
||||
};
|
||||
|
||||
// --- End Helper Functions ---
|
||||
|
||||
export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
const { t } = useI18n();
|
||||
@@ -80,6 +78,7 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
const activeTabId = ref<string | null>(null); // 当前激活的标签页 ID
|
||||
// const editorVisibleState = ref<'visible' | 'minimized' | 'closed'>('closed'); // 移除,面板可见性由布局控制
|
||||
const popupTrigger = ref(0); // 新增:用于触发弹窗显示的信号
|
||||
const popupFileInfo = ref<{ filePath: string; sessionId: string } | null>(null); // 新增:存储弹窗文件信息
|
||||
|
||||
// --- 计算属性 ---
|
||||
const orderedTabs = computed(() => Array.from(tabs.value.values())); // 获取标签页数组,用于渲染
|
||||
@@ -100,6 +99,13 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
|
||||
// --- 核心方法 ---
|
||||
|
||||
// 修改:triggerPopup 接收文件信息并存储
|
||||
const triggerPopup = (filePath: string, sessionId: string) => {
|
||||
console.log(`[文件编辑器 Store] Triggering popup for ${filePath} in session ${sessionId}.`);
|
||||
popupFileInfo.value = { filePath, sessionId };
|
||||
popupTrigger.value++; // 增加触发器值以通知监听者
|
||||
};
|
||||
|
||||
// 获取指定会话的 SFTP 管理器 (保持不变)
|
||||
const getSftpManager = (sessionId: string | null) => {
|
||||
if (!sessionId) return null;
|
||||
@@ -151,8 +157,8 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
};
|
||||
tabs.value.set(tabId, newTab);
|
||||
setActiveTab(tabId); // 激活新标签页
|
||||
// 触发弹窗 (如果设置允许)
|
||||
popupTrigger.value++;
|
||||
// 不再在这里触发弹窗
|
||||
// popupTrigger.value++;
|
||||
|
||||
// 获取 SFTP 管理器
|
||||
const sftpManager = getSftpManager(sessionId);
|
||||
@@ -419,6 +425,7 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
activeTabId: readonly(activeTabId),
|
||||
// editorVisibleState: readonly(editorVisibleState), // 移除
|
||||
popupTrigger: readonly(popupTrigger), // 暴露触发器 (只读)
|
||||
popupFileInfo: readonly(popupFileInfo), // 暴露弹窗文件信息 (只读)
|
||||
|
||||
// 计算属性
|
||||
orderedTabs,
|
||||
@@ -432,6 +439,7 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
closeAllTabs,
|
||||
setActiveTab,
|
||||
updateFileContent, // 暴露新的更新方法
|
||||
triggerPopup, // 暴露新的触发方法
|
||||
// setEditorVisibility, // 移除
|
||||
};
|
||||
});
|
||||
|
||||
@@ -29,6 +29,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
* Should be called early in the application lifecycle (e.g., main.ts).
|
||||
*/
|
||||
async function loadInitialSettings() {
|
||||
console.log('[SettingsStore] Entering loadInitialSettings function...'); // <-- 添加更早的日志
|
||||
isLoading.value = true;
|
||||
error.value = null;
|
||||
let fetchedLang: 'en' | 'zh' | undefined;
|
||||
@@ -37,12 +38,13 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
console.log('[SettingsStore] Starting loadInitialSettings...'); // 添加日志
|
||||
const response = await axios.get<Record<string, string>>('/api/v1/settings');
|
||||
settings.value = response.data; // Store all fetched settings
|
||||
console.log('[SettingsStore] Fetched settings:', JSON.stringify(settings.value)); // 添加日志
|
||||
console.log('[SettingsStore] Fetched settings raw:', JSON.stringify(response.data)); // 打印原始响应
|
||||
console.log('[SettingsStore] Raw showPopupFileEditor from backend:', response.data.showPopupFileEditor); // <--- 添加日志:打印原始值
|
||||
|
||||
// --- 设置默认值 (如果后端未返回) ---
|
||||
// 弹窗编辑器设置
|
||||
if (settings.value.showPopupFileEditor === undefined) {
|
||||
console.log('[SettingsStore] Setting default for showPopupFileEditor: true');
|
||||
console.log('[SettingsStore] showPopupFileEditor is undefined, setting default: true'); // 修改日志
|
||||
settings.value.showPopupFileEditor = 'true'; // 默认为 true
|
||||
}
|
||||
// 共享编辑器标签页设置
|
||||
@@ -92,18 +94,20 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
* @param value The new value for the setting.
|
||||
*/
|
||||
async function updateSetting(key: keyof SettingsState, value: string) {
|
||||
const previousValue = settings.value[key];
|
||||
settings.value = { ...settings.value, [key]: value }; // Optimistic update
|
||||
// const previousValue = settings.value[key]; // No longer needed for optimistic revert
|
||||
// settings.value = { ...settings.value, [key]: value }; // Remove optimistic update
|
||||
|
||||
try {
|
||||
await axios.put('/api/v1/settings', { [key]: value });
|
||||
// Update store state *after* successful API call
|
||||
settings.value = { ...settings.value, [key]: value };
|
||||
// If updating language, also update i18n
|
||||
if (key === 'language' && (value === 'en' || value === 'zh')) {
|
||||
setLocale(value);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(`Failed to update setting '${key}':`, err);
|
||||
settings.value = { ...settings.value, [key]: previousValue }; // Revert on error
|
||||
// settings.value = { ...settings.value, [key]: previousValue }; // Remove revert logic
|
||||
throw new Error(err.response?.data?.message || err.message || `Failed to update setting '${key}'`);
|
||||
}
|
||||
}
|
||||
@@ -113,18 +117,20 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
* @param updates An object containing key-value pairs of settings to update.
|
||||
*/
|
||||
async function updateMultipleSettings(updates: Partial<SettingsState>) {
|
||||
const previousSettings = { ...settings.value };
|
||||
settings.value = { ...settings.value, ...updates }; // Optimistic update
|
||||
// const previousSettings = { ...settings.value }; // No longer needed for optimistic revert
|
||||
// settings.value = { ...settings.value, ...updates }; // Remove optimistic update
|
||||
|
||||
try {
|
||||
await axios.put('/api/v1/settings', updates);
|
||||
// Update store state *after* successful API call
|
||||
settings.value = { ...settings.value, ...updates };
|
||||
// If language is updated, apply it
|
||||
if (updates.language && (updates.language === 'en' || updates.language === 'zh')) {
|
||||
setLocale(updates.language);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error('Failed to update multiple settings:', err);
|
||||
settings.value = previousSettings; // Revert on error
|
||||
// settings.value = previousSettings; // Remove revert logic
|
||||
throw new Error(err.response?.data?.message || err.message || 'Failed to update settings');
|
||||
}
|
||||
}
|
||||
@@ -137,9 +143,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
// Getter for the popup editor setting, returning boolean
|
||||
const showPopupFileEditorBoolean = computed(() => {
|
||||
// 默认为 true,除非明确设置为 'false'
|
||||
// 默认为 true (共享),除非明确设置为 'false'
|
||||
// 默认为 true (共享),除非明确设置为 'false'
|
||||
return settings.value.shareFileEditorTabs !== 'false';
|
||||
return settings.value.showPopupFileEditor !== 'false'; // <-- 修正:检查正确的键 showPopupFileEditor
|
||||
});
|
||||
|
||||
// Getter for sharing setting, returning boolean
|
||||
|
||||
Reference in New Issue
Block a user