Skip to content

Commit c9f1454

Browse files
committed
refactor: add view question
1 parent 39bedc5 commit c9f1454

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

frontend/src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"password_reset_successful": "Password reset successful"
3737
},
3838
"dashboard": {
39+
"add_dashboard_name_tips": "Please Input Dashboard Name",
40+
"existing_dashboard": "Existing Dashboard",
3941
"add_success": "Add Success",
4042
"no_data": "No Relevant Content Found",
4143
"new_tab": "New Tab",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"or": "或者"
4040
},
4141
"dashboard": {
42+
"add_dashboard_name_tips": "请输入仪表板名称",
43+
"existing_dashboard": "存量仪表板",
4244
"add_success": "添加成功",
4345
"no_data": "没找到相关内容",
4446
"new_tab": "新建Tab",

frontend/src/views/chat/chat-block/ChartBlock.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,25 @@ function showSql() {
192192
}
193193
194194
function addToDashboard() {
195-
const viewInfo = chartRef.value?.getViewInfo()
195+
const recordeInfo = {
196+
id: '1-1',
197+
data: {
198+
data: data.value,
199+
},
200+
chart: {},
201+
}
202+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
203+
const chartBaseInfo = JSON.parse(props.message?.record?.chart)
204+
recordeInfo['chart'] = {
205+
type: chartBaseInfo.type,
206+
title: chartBaseInfo.title,
207+
columns: chartBaseInfo.columns,
208+
xAxis: chartBaseInfo.axis?.x ? [chartBaseInfo.axis.x] : [],
209+
yAxis: chartBaseInfo.axis?.y ? [chartBaseInfo.axis.y] : [],
210+
series: chartBaseInfo.axis?.series ? [chartBaseInfo.axis.series] : [],
211+
}
196212
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
197-
addViewRef.value?.optInit(viewInfo)
213+
addViewRef.value?.optInit(recordeInfo)
198214
}
199215
200216
function copy() {
@@ -264,7 +280,7 @@ function copy() {
264280
</el-button>
265281
</el-tooltip>
266282
</div>
267-
<div v-if="false">
283+
<div>
268284
<!-- todo -->
269285
<el-tooltip effect="dark" :content="t('chat.add_to_dashboard')" placement="top">
270286
<el-button class="tool-btn" text @click="addToDashboard">

frontend/src/views/dashboard/common/AddViewDashboard.vue

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const saveResourcePrepare = () => {
6868
if (result) {
6969
const component = cloneDeep(findNewComponentFromList('SQView'))
7070
const newComponentId = guid()
71+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
72+
state.viewInfo.chart['id'] = newComponentId
73+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
74+
state.viewInfo['id'] = newComponentId
7175
if (resourceForm.addType === 'history' && component) {
7276
findNextComponentIndex({ id: resourceForm.dashboardId }, (result: any) => {
7377
const {
@@ -84,10 +88,8 @@ const saveResourcePrepare = () => {
8488
name: dashboardInfo.name,
8589
}
8690
component['id'] = newComponentId
87-
component['y'] = bottomPosition + 1
91+
component['y'] = bottomPosition
8892
canvasDataResult.push(component)
89-
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
90-
state.viewInfo.chart['id'] = newComponentId
9193
canvasViewInfoPreview[newComponentId] = state.viewInfo
9294
const commonParams = {
9395
componentData: canvasDataResult,
@@ -97,12 +99,22 @@ const saveResourcePrepare = () => {
9799
saveResource(params, commonParams)
98100
})
99101
} else if (resourceForm.addType === 'new' && component) {
100-
const params = { opt: 'newLeaf', pid: 'root', name: resourceForm.dashboardName }
102+
const params = {
103+
opt: 'newLeaf',
104+
pid: 'root',
105+
name: resourceForm.dashboardName,
106+
level: 1,
107+
node_type: 'leaf',
108+
type: 'dashboard',
109+
}
101110
component['id'] = newComponentId
111+
const canvasViewInfo = {}
112+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
113+
canvasViewInfo[newComponentId] = state.viewInfo
102114
const commonParams = {
103115
componentData: [component],
104116
canvasStyleData: {},
105-
canvasViewInfo: { newComponentId: state.viewInfo },
117+
canvasViewInfo: canvasViewInfo,
106118
}
107119
saveResource(params, commonParams)
108120
}
@@ -112,7 +124,7 @@ const saveResourcePrepare = () => {
112124
113125
const saveResource = (params: any, commonParams: any) => {
114126
saveDashboardResourceTarget(params, commonParams, function () {
115-
const messageTips = t('common.save_success')
127+
const messageTips = t('dashboard.add_success')
116128
ElMessage({
117129
type: 'success',
118130
message: messageTips,
@@ -142,7 +154,7 @@ defineExpose({
142154
<el-dialog
143155
v-model="resourceDialogShow"
144156
class="create-dialog"
145-
title="添加到仪表板"
157+
:title="t('chat.add_to_dashboard')"
146158
width="420px"
147159
:before-close="resetForm"
148160
append-to-body
@@ -157,33 +169,36 @@ defineExpose({
157169
:rules="resourceForm.addType === 'new' ? resourceFormRulesNew : resourceFormRulesHistory"
158170
@submit.prevent
159171
>
160-
<el-form-item label="仪表板名称" required prop="addType">
172+
<el-form-item :label="t('dashboard.dashboard_name')" required prop="addType">
161173
<el-radio-group v-model="resourceForm.addType">
162-
<el-radio value="history">存量仪表板</el-radio>
163-
<el-radio value="new">新建仪表板</el-radio>
174+
<el-radio value="history">{{ t('dashboard.existing_dashboard') }}</el-radio>
175+
<el-radio value="new">{{ t('dashboard.new_dashboard') }}</el-radio>
164176
</el-radio-group>
165177
</el-form-item>
166178
<el-form-item
167179
v-if="resourceForm.addType === 'new'"
168-
label="仪表板"
180+
:label="t('dashboard.dashboard')"
169181
required
170182
prop="dashboardName"
171183
>
172184
<el-input
173185
v-model="resourceForm.dashboardName"
174186
clearable
175-
placeholder="请输入仪表板名称"
187+
:placeholder="t('dashboard.add_dashboard_name_tips')"
176188
@keydown.stop
177189
@keyup.stop
178190
/>
179191
</el-form-item>
180192
<el-form-item
181193
v-if="resourceForm.addType === 'history'"
182-
label="仪表板"
194+
:label="t('dashboard.dashboard')"
183195
required
184196
prop="dashboardId"
185197
>
186-
<el-select v-model="resourceForm.dashboardId" placeholder="请选择仪表板">
198+
<el-select
199+
v-model="resourceForm.dashboardId"
200+
:placeholder="t('dashboard.select_dashboard')"
201+
>
187202
<el-option
188203
v-for="item in state.dashboardList"
189204
:key="item.id"

0 commit comments

Comments
 (0)