From b976d5c06dcf470f4cfb04ab472b90865954fa2a Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Wed, 29 Apr 2026 20:44:43 +0800 Subject: [PATCH] feat: add column type mapping and display in DataGrid --- src/components/grid/DataGrid.vue | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/grid/DataGrid.vue b/src/components/grid/DataGrid.vue index ddf40e116..f1b0fe77e 100644 --- a/src/components/grid/DataGrid.vue +++ b/src/components/grid/DataGrid.vue @@ -37,6 +37,33 @@ const emit = defineEmits<{ }>(); const hasData = computed(() => props.result.columns.length > 0); + +const columnTypeMap = computed(() => { + const map = new Map(); + if (props.tableMeta?.columns) { + for (const col of props.tableMeta.columns) { + map.set(col.name, shortTypeName(col.data_type)); + } + } + return map; +}); + +function shortTypeName(t: string): string { + const s = t.toLowerCase(); + if (s === "character varying") return "varchar"; + if (s === "character") return "char"; + if (s === "double precision") return "double"; + if (s === "timestamp without time zone") return "timestamp"; + if (s === "timestamp with time zone") return "timestamptz"; + if (s === "time without time zone") return "time"; + if (s === "time with time zone") return "timetz"; + if (s === "boolean") return "bool"; + if (s === "integer") return "int"; + if (s === "smallint") return "int2"; + if (s === "bigint") return "int8"; + if (s === "real") return "float4"; + return t; +} const contextCell = ref<{ row: number; col: number } | null>(null); const sortCol = ref(null); const sortDir = ref<"asc" | "desc">("asc"); @@ -466,6 +493,7 @@ const sqlOneLiner = computed(() => props.sql?.replace(/\s+/g, " ").trim() || "") {{ col }} + #{{ columnTypeMap.get(col) }}