mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-05 22:03:36 +08:00
🐛 fix(external-sql): 修复外部 SQL 文件保存不写回源文件
- 保存逻辑:外部 SQL 文件标签页携带 filePath,保存时写回原始磁盘文件 - 后端接口:新增 WriteSQLFile 能力,支持覆盖已有 SQL 文件并保留原文件权限 - 状态隔离:外部文件保存失败时不创建 savedQuery,避免写入 localStorage 副本 - 兼容行为:非文件标签页继续沿用原有 savedQuery 快速保存逻辑 - 文案优化:将数据库下入口改为“外部 SQL 目录”,减少与单文件打开入口的歧义 - 测试覆盖:补充前端保存分支、后端写文件边界和外部 SQL 目录文案测试 Refs #422
This commit is contained in:
@@ -6,7 +6,7 @@ import { format } from 'sql-formatter';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { TabData, ColumnDefinition } from '../types';
|
||||
import { useStore } from '../store';
|
||||
import { DBQueryWithCancel, DBQueryMulti, DBGetTables, DBGetAllColumns, DBGetDatabases, DBGetColumns, CancelQuery, GenerateQueryID } from '../../wailsjs/go/app/App';
|
||||
import { DBQueryWithCancel, DBQueryMulti, DBGetTables, DBGetAllColumns, DBGetDatabases, DBGetColumns, CancelQuery, GenerateQueryID, WriteSQLFile } from '../../wailsjs/go/app/App';
|
||||
import DataGrid, { GONAVI_ROW_KEY } from './DataGrid';
|
||||
import { getDataSourceCapabilities } from '../utils/dataSourceCapabilities';
|
||||
import { convertMongoShellToJsonCommand } from '../utils/mongodb';
|
||||
@@ -2204,7 +2204,31 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
|
||||
return saved;
|
||||
};
|
||||
|
||||
const handleQuickSave = () => {
|
||||
const handleQuickSave = async () => {
|
||||
const filePath = String(tab.filePath || '').trim();
|
||||
if (filePath) {
|
||||
const sql = getCurrentQuery();
|
||||
try {
|
||||
const res = await WriteSQLFile(filePath, sql);
|
||||
if (!res.success) {
|
||||
message.error('保存 SQL 文件失败: ' + (res.message || '未知错误'));
|
||||
return;
|
||||
}
|
||||
addTab({
|
||||
...tab,
|
||||
query: sql,
|
||||
connectionId: currentConnectionId,
|
||||
dbName: currentDb || tab.dbName || '',
|
||||
filePath,
|
||||
savedQueryId: undefined,
|
||||
});
|
||||
message.success('SQL 文件已保存!');
|
||||
} catch (error) {
|
||||
message.error('保存 SQL 文件失败: ' + (error instanceof Error ? error.message : String(error)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const existed = currentSavedQuery || null;
|
||||
const fallbackSavedId = String(tab.savedQueryId || '').trim();
|
||||
const saveId = existed?.id || fallbackSavedId || '';
|
||||
|
||||
Reference in New Issue
Block a user