From 27d745460e6d4e77dc55874544a6d5da90047741 Mon Sep 17 00:00:00 2001 From: ulleo Date: Tue, 29 Jul 2025 15:02:29 +0800 Subject: [PATCH 1/4] feat: modify template --- backend/template.yaml | 1 + frontend/src/views/chat/index.vue | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/template.yaml b/backend/template.yaml index 13f902df..e7bad6bc 100644 --- a/backend/template.yaml +++ b/backend/template.yaml @@ -7,6 +7,7 @@ template: 根据表结构和问题生成符合{engine}数据库引擎规范的sql语句,以及sql中所用到的表名(不要包含schema和database,用数组返回)。 你必须遵守以下规则: - 生成的SQL必须符合{engine}的规范。 + - 提问中如果有涉及数据源名称或数据源描述的内容,则忽略数据源的信息,直接根据剩余内容生成SQL - 根据表结构生成SQL语句,需给每个表名生成一个别名(不要加AS)。 - SQL查询中不能使用星号(*),必须明确指定字段名. - SQL查询的字段名不要自动翻译,别名必须为英文。 diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue index e35d811f..8993c3b8 100644 --- a/frontend/src/views/chat/index.vue +++ b/frontend/src/views/chat/index.vue @@ -485,7 +485,6 @@ function onChatCreatedQuick(chat: ChatInfo) { chatList.value.unshift(chat) currentChatId.value = chat.id currentChat.value = chat - console.log(chat) onChatCreated(chat) } From 66cbfd22ba736c16b120e4122608e6e377a0e17e Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 29 Jul 2025 15:12:11 +0800 Subject: [PATCH 2/4] refactor: support sq add view to dashboard --- frontend/src/views/chat/chat-block/ChartBlock.vue | 3 ++- .../views/chat/component/DisplayChartBlock.vue | 15 ++++++++++++++- .../views/dashboard/common/AddViewDashboard.vue | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/chat/chat-block/ChartBlock.vue b/frontend/src/views/chat/chat-block/ChartBlock.vue index 96da119a..6c428806 100644 --- a/frontend/src/views/chat/chat-block/ChartBlock.vue +++ b/frontend/src/views/chat/chat-block/ChartBlock.vue @@ -189,8 +189,9 @@ function showSql() { } function addToDashboard() { + const viewInfo = chartRef.value?.getViewInfo() // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment - addViewRef.value?.optInit() + addViewRef.value?.optInit(viewInfo) } function copy() { diff --git a/frontend/src/views/chat/component/DisplayChartBlock.vue b/frontend/src/views/chat/component/DisplayChartBlock.vue index 2b639b57..3bc27994 100644 --- a/frontend/src/views/chat/component/DisplayChartBlock.vue +++ b/frontend/src/views/chat/component/DisplayChartBlock.vue @@ -54,9 +54,22 @@ function onTypeChange() { chartRef.value?.renderChart() }) } - +function getViewInfo() { + return { + chart: { + columns: chartObject.value?.columns, + type: props.chartType, + xAxis: xAxis.value, + yAxis: yAxis.value, + series: series.value, + title: chartObject.value.title, + }, + data: { data: props.data }, + } +} defineExpose({ onTypeChange, + getViewInfo, }) diff --git a/frontend/src/views/dashboard/common/AddViewDashboard.vue b/frontend/src/views/dashboard/common/AddViewDashboard.vue index 3bba8b96..975850c9 100644 --- a/frontend/src/views/dashboard/common/AddViewDashboard.vue +++ b/frontend/src/views/dashboard/common/AddViewDashboard.vue @@ -86,6 +86,8 @@ const saveResourcePrepare = () => { component['id'] = newComponentId component['y'] = bottomPosition + 1 canvasDataResult.push(component) + // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment + state.viewInfo.chart['id'] = newComponentId canvasViewInfoPreview[newComponentId] = state.viewInfo const commonParams = { componentData: canvasDataResult, From e6839b8ce4b95873c6dc3648004df2ababdcf60b Mon Sep 17 00:00:00 2001 From: ulleo Date: Tue, 29 Jul 2025 15:16:12 +0800 Subject: [PATCH 3/4] feat: modify template --- backend/template.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/template.yaml b/backend/template.yaml index e7bad6bc..05618089 100644 --- a/backend/template.yaml +++ b/backend/template.yaml @@ -12,10 +12,14 @@ template: - SQL查询中不能使用星号(*),必须明确指定字段名. - SQL查询的字段名不要自动翻译,别名必须为英文。 - 计算占比,百分比类型字段,保留两位小数,以%结尾。 - - 生成SQL时,必须避免关键字冲突: + - 生成SQL时,必须避免关键字冲突。 - 如数据库引擎是 PostgreSQL、Oracle,则在schema、表名、字段名、别名外层加双引号; - 如数据库引擎是 MySQL,则在表名、字段名、别名外层加反引号; - 如数据库引擎是 Microsoft SQL Server,则在schema、表名、字段名、别名外层加方括号。 + - 以PostgreSQL为例,查询Schema为TEST表TABLE下所有数据,则生成的SQL为: + SELECT * FROM "TEST"."TABLE" + - 注意在表名外双引号的位置,千万不要生成为: + SELECT * FROM "TEST.TABLE" - 如果生成SQL的字段内有时间格式的字段(重要): - 若提问中没有指定查询顺序,则默认按时间升序排序 - 若提问是时间,且没有指定具体格式,则格式化为yyyy-MM-dd HH:mm:ss的格式 From ab11a20e2ecb3b9003ee9d2079b6daf1070bf301 Mon Sep 17 00:00:00 2001 From: ulleo Date: Tue, 29 Jul 2025 15:49:17 +0800 Subject: [PATCH 4/4] feat: bar column label position --- frontend/src/views/chat/component/charts/Bar.ts | 6 ++++++ frontend/src/views/chat/component/charts/Column.ts | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/chat/component/charts/Bar.ts b/frontend/src/views/chat/component/charts/Bar.ts index f54fece9..d78c8e38 100644 --- a/frontend/src/views/chat/component/charts/Bar.ts +++ b/frontend/src/views/chat/component/charts/Bar.ts @@ -113,6 +113,12 @@ export class Bar extends BaseG2Chart { } return `${value}${_data.isPercent ? '%' : ''}` }, + position: (data: any) => { + if (data[y[0].value] < 0) { + return 'left' + } + return 'right' + }, transform: [ { type: 'contrastReverse' }, { type: 'exceedAdjust' }, diff --git a/frontend/src/views/chat/component/charts/Column.ts b/frontend/src/views/chat/component/charts/Column.ts index ad437abb..0159f81d 100644 --- a/frontend/src/views/chat/component/charts/Column.ts +++ b/frontend/src/views/chat/component/charts/Column.ts @@ -102,7 +102,12 @@ export class Column extends BaseG2Chart { } return `${value}${_data.isPercent ? '%' : ''}` }, - position: 'top', + position: (data: any) => { + if (data[y[0].value] < 0) { + return 'bottom' + } + return 'top' + }, transform: [ { type: 'contrastReverse' }, { type: 'exceedAdjust' },