fix(query): 修复查询结果表头提示与全量排序 (#164)
* fix(grid): 修复查询结果表头提示与排序 修复 MySQL 查询结果列元数据取错库名的问题,并补齐查询结果全量排序链路,避免表头提示与排序行为失效。 * fix(query): 修复结果排序重复列名报错
This commit is contained in:
1 parent
c036dd19e4
commit
3b4b6c1ff7
11 files changed
+246
-51
No files matched your search
@@ -1,10 +1,15 @@
|
||||
import { type ComputedRef } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { buildTableSelectSql, quoteTableIdentifier } from "@/lib/tableSelectSql";
|
||||
import { buildSortedQuerySql } from "@/lib/queryResultSort";
|
||||
import type { QueryTab } from "@/types/database";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
|
||||
export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>) {
|
||||
const { t } = useI18n();
|
||||
const { toast } = useToast();
|
||||
const connectionStore = useConnectionStore();
|
||||
const queryStore = useQueryStore();
|
||||
|
||||
@@ -44,13 +49,24 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
if (!tab) return;
|
||||
if (tab.mode === "data" && tab.tableMeta) {
|
||||
queryStore.updateSql(tab.id, buildTableSql(tab, { whereInput }));
|
||||
return queryStore.executeCurrentTab();
|
||||
await queryStore.executeCurrentTab();
|
||||
return;
|
||||
}
|
||||
if (tab.resultSortedSql) {
|
||||
await queryStore.executeTabSql(tab.id, tab.resultSortedSql, {
|
||||
resultBaseSql: tab.resultBaseSql ?? tab.sql,
|
||||
resultSortedSql: tab.resultSortedSql,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Results mode: re-run only the SQL that produced the current result set
|
||||
if (sql?.trim()) {
|
||||
return queryStore.executeTabSql(tab.id, sql);
|
||||
await queryStore.executeTabSql(tab.id, sql, {
|
||||
resultBaseSql: sql,
|
||||
resultSortedSql: undefined,
|
||||
});
|
||||
return;
|
||||
}
|
||||
return queryStore.executeCurrentTab();
|
||||
await queryStore.executeCurrentTab();
|
||||
}
|
||||
|
||||
async function onPaginate(offset: number, limit: number, whereInput?: string, orderBy?: string) {
|
||||
@@ -61,13 +77,48 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
await queryStore.executeCurrentTab();
|
||||
}
|
||||
|
||||
async function onSort(column: string, direction: "asc" | "desc" | null, whereInput?: string) {
|
||||
async function onSort(column: string, columnIndex: number, direction: "asc" | "desc" | null, whereInput?: string) {
|
||||
const tab = activeTab.value;
|
||||
if (!tab?.tableMeta) return;
|
||||
const orderBy = direction ? `${quoteIdent(tab, column)} ${direction.toUpperCase()}` : undefined;
|
||||
const sql = buildTableSql(tab, { orderBy, whereInput });
|
||||
queryStore.updateSql(tab.id, sql);
|
||||
await queryStore.executeCurrentTab();
|
||||
if (!tab) return;
|
||||
|
||||
if (tab.mode === "data") {
|
||||
if (!tab.tableMeta) return;
|
||||
const orderBy = direction ? `${quoteIdent(tab, column)} ${direction.toUpperCase()}` : undefined;
|
||||
const sql = buildTableSql(tab, { orderBy, whereInput });
|
||||
queryStore.updateSql(tab.id, sql);
|
||||
await queryStore.executeCurrentTab();
|
||||
return;
|
||||
}
|
||||
|
||||
const baseSql = tab.resultBaseSql ?? tab.sql;
|
||||
if (!baseSql.trim()) return;
|
||||
|
||||
if (!direction) {
|
||||
await queryStore.executeTabSql(tab.id, baseSql, {
|
||||
resultBaseSql: baseSql,
|
||||
resultSortedSql: undefined,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const config = connectionStore.getConfig(tab.connectionId);
|
||||
const built = buildSortedQuerySql(
|
||||
baseSql,
|
||||
config?.db_type,
|
||||
tab.result?.columns ?? [],
|
||||
columnIndex,
|
||||
column,
|
||||
direction,
|
||||
);
|
||||
if (!built.ok) {
|
||||
toast(t("grid.sortUnsupported"), 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
await queryStore.executeTabSql(tab.id, built.sql, {
|
||||
resultBaseSql: baseSql,
|
||||
resultSortedSql: built.sql,
|
||||
});
|
||||
}
|
||||
|
||||
return { onExecuteSql, onReloadData, onPaginate, onSort };
|
||||
|
||||
Reference in new issue
Block a user