From c9f14545fffd7c751018b020ff6e84cfb4f345fe Mon Sep 17 00:00:00 2001
From: wangjiahao <1522128093@qq.com>
Date: Tue, 29 Jul 2025 15:55:32 +0800
Subject: [PATCH] refactor: add view question
---
frontend/src/i18n/en.json | 2 +
frontend/src/i18n/zh-CN.json | 2 +
.../src/views/chat/chat-block/ChartBlock.vue | 22 ++++++++--
.../dashboard/common/AddViewDashboard.vue | 43 +++++++++++++------
4 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json
index ddbe077a..cdb426ab 100644
--- a/frontend/src/i18n/en.json
+++ b/frontend/src/i18n/en.json
@@ -36,6 +36,8 @@
"password_reset_successful": "Password reset successful"
},
"dashboard": {
+ "add_dashboard_name_tips": "Please Input Dashboard Name",
+ "existing_dashboard": "Existing Dashboard",
"add_success": "Add Success",
"no_data": "No Relevant Content Found",
"new_tab": "New Tab",
diff --git a/frontend/src/i18n/zh-CN.json b/frontend/src/i18n/zh-CN.json
index 8d5014db..3ed9c7af 100644
--- a/frontend/src/i18n/zh-CN.json
+++ b/frontend/src/i18n/zh-CN.json
@@ -39,6 +39,8 @@
"or": "或者"
},
"dashboard": {
+ "add_dashboard_name_tips": "请输入仪表板名称",
+ "existing_dashboard": "存量仪表板",
"add_success": "添加成功",
"no_data": "没找到相关内容",
"new_tab": "新建Tab",
diff --git a/frontend/src/views/chat/chat-block/ChartBlock.vue b/frontend/src/views/chat/chat-block/ChartBlock.vue
index 32de5d61..bcac8a82 100644
--- a/frontend/src/views/chat/chat-block/ChartBlock.vue
+++ b/frontend/src/views/chat/chat-block/ChartBlock.vue
@@ -192,9 +192,25 @@ function showSql() {
}
function addToDashboard() {
- const viewInfo = chartRef.value?.getViewInfo()
+ const recordeInfo = {
+ id: '1-1',
+ data: {
+ data: data.value,
+ },
+ chart: {},
+ }
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
- addViewRef.value?.optInit(viewInfo)
+ const chartBaseInfo = JSON.parse(props.message?.record?.chart)
+ recordeInfo['chart'] = {
+ type: chartBaseInfo.type,
+ title: chartBaseInfo.title,
+ columns: chartBaseInfo.columns,
+ xAxis: chartBaseInfo.axis?.x ? [chartBaseInfo.axis.x] : [],
+ yAxis: chartBaseInfo.axis?.y ? [chartBaseInfo.axis.y] : [],
+ series: chartBaseInfo.axis?.series ? [chartBaseInfo.axis.series] : [],
+ }
+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ addViewRef.value?.optInit(recordeInfo)
}
function copy() {
@@ -264,7 +280,7 @@ function copy() {
-
+
diff --git a/frontend/src/views/dashboard/common/AddViewDashboard.vue b/frontend/src/views/dashboard/common/AddViewDashboard.vue
index 975850c9..47dc7e00 100644
--- a/frontend/src/views/dashboard/common/AddViewDashboard.vue
+++ b/frontend/src/views/dashboard/common/AddViewDashboard.vue
@@ -68,6 +68,10 @@ const saveResourcePrepare = () => {
if (result) {
const component = cloneDeep(findNewComponentFromList('SQView'))
const newComponentId = guid()
+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ state.viewInfo.chart['id'] = newComponentId
+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ state.viewInfo['id'] = newComponentId
if (resourceForm.addType === 'history' && component) {
findNextComponentIndex({ id: resourceForm.dashboardId }, (result: any) => {
const {
@@ -84,10 +88,8 @@ const saveResourcePrepare = () => {
name: dashboardInfo.name,
}
component['id'] = newComponentId
- component['y'] = bottomPosition + 1
+ component['y'] = bottomPosition
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,
@@ -97,12 +99,22 @@ const saveResourcePrepare = () => {
saveResource(params, commonParams)
})
} else if (resourceForm.addType === 'new' && component) {
- const params = { opt: 'newLeaf', pid: 'root', name: resourceForm.dashboardName }
+ const params = {
+ opt: 'newLeaf',
+ pid: 'root',
+ name: resourceForm.dashboardName,
+ level: 1,
+ node_type: 'leaf',
+ type: 'dashboard',
+ }
component['id'] = newComponentId
+ const canvasViewInfo = {}
+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ canvasViewInfo[newComponentId] = state.viewInfo
const commonParams = {
componentData: [component],
canvasStyleData: {},
- canvasViewInfo: { newComponentId: state.viewInfo },
+ canvasViewInfo: canvasViewInfo,
}
saveResource(params, commonParams)
}
@@ -112,7 +124,7 @@ const saveResourcePrepare = () => {
const saveResource = (params: any, commonParams: any) => {
saveDashboardResourceTarget(params, commonParams, function () {
- const messageTips = t('common.save_success')
+ const messageTips = t('dashboard.add_success')
ElMessage({
type: 'success',
message: messageTips,
@@ -142,7 +154,7 @@ defineExpose({
-
+
- 存量仪表板
- 新建仪表板
+ {{ t('dashboard.existing_dashboard') }}
+ {{ t('dashboard.new_dashboard') }}
-
+