Skip to content

Commit a4dd431

Browse files
authored
Pr@main@refactor dashboard (#103)
* refactor: Optimize the logic for adding charts to the dashboard * refactor: Support adding the modified chart with retained type to the dashboard * refactor: Optimize dashboard name storage, enter key automatically saves * refactor: Optimize the method of adding components so that they can be arranged in sequence
1 parent aaaa0c6 commit a4dd431

File tree

5 files changed

+70
-11
lines changed

5 files changed

+70
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function addToDashboard() {
216216
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
217217
const chartBaseInfo = JSON.parse(props.message?.record?.chart)
218218
recordeInfo['chart'] = {
219-
type: chartBaseInfo.type,
219+
type: currentChartType.value,
220220
title: chartBaseInfo.title,
221221
columns: chartBaseInfo.columns,
222222
xAxis: chartBaseInfo.axis?.x ? [chartBaseInfo.axis.x] : [],
@@ -395,7 +395,7 @@ watch(
395395
</div>
396396
</el-popover>
397397
</div>
398-
<div v-if="message?.record?.chart && !isAssistant">
398+
<div v-if="message?.record?.chart && isCompletePage">
399399
<el-tooltip effect="dark" :content="t('chat.add_to_dashboard')" placement="top">
400400
<el-button class="tool-btn" text @click="addToDashboard">
401401
<el-icon size="16">

frontend/src/views/dashboard/canvas/CanvasCore.vue

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,8 @@ const forceComputed = () => {
10631063
}
10641064
10651065
function addItemBox(item: CanvasItem) {
1066+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
1067+
item.x = findPositionX(item)
10661068
canvasComponentData.value.push(item)
10671069
forceComputed()
10681070
nextTick(() => {
@@ -1166,6 +1168,49 @@ function tabMoveInCheckSQ() {
11661168
}
11671169
}
11681170
1171+
/**
1172+
* Find position box
1173+
*/
1174+
function findPositionX(item: CanvasItem) {
1175+
const width = item.sizeX
1176+
let resultX = 1
1177+
let checkPointYIndex = -1 // -1 means not occupying any Y-direction canvas
1178+
// Component width
1179+
let pb = positionBox.value
1180+
if (width <= 0) return
1181+
// Find the highest position index of the component. Component rule: the latest y is 1.
1182+
canvasComponentData.value.forEach((component) => {
1183+
const componentYIndex = component.y + component.sizeY - 2
1184+
if (checkPointYIndex < componentYIndex) {
1185+
checkPointYIndex = componentYIndex
1186+
}
1187+
})
1188+
// Start checking from index i in the X direction;
1189+
const pbX = pb[checkPointYIndex]
1190+
// Get the last column array in the X direction
1191+
if (checkPointYIndex < 0 || !pbX) {
1192+
return 1
1193+
} else {
1194+
// The width to check is the component width. The end index of the check is checkEndIndex = i + width - 1;
1195+
// The exit condition for the check is when the end index checkEndIndex is out of bounds (exceeds the end index of pbX).
1196+
for (let i = 0, checkEndIndex = width - 1; checkEndIndex < pbX.length; i++, checkEndIndex++) {
1197+
let adaptorCount = 0
1198+
// Locate the occupied position in the last column
1199+
for (let k = 0; k < width; k++) {
1200+
// pbX[i + k].el === false indicates that the current matrix point is not occupied. When the width of consecutive unoccupied matrix points equals the component width, the starting point i is available.
1201+
if (!pbX[i + k].el) {
1202+
adaptorCount++
1203+
}
1204+
}
1205+
if (adaptorCount === width) {
1206+
resultX = i + 1
1207+
break
1208+
}
1209+
}
1210+
return resultX
1211+
}
1212+
}
1213+
11691214
useEmitt({
11701215
name: `editor-delete-${props.canvasId}`,
11711216
callback: removeItemById,

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const optInit = (viewInfo: any) => {
2020
resourceDialogShow.value = true
2121
state.viewInfo = viewInfo
2222
}
23-
const curOptDashboardId = ref(null)
2423
const state = reactive({
2524
dashboardList: [] as SQTreeNode[],
2625
viewInfo: null,
@@ -127,20 +126,19 @@ const saveResourcePrepare = () => {
127126
const saveResource = (params: any, commonParams: any) => {
128127
saveDashboardResourceTarget(params, commonParams, (res: any) => {
129128
const messageTips = t('dashboard.add_success')
130-
curOptDashboardId.value = res?.id
131-
openMessageLoading(messageTips, 'success', callbackExportSuc)
129+
openMessageLoading(messageTips, 'success', res?.id, callbackExportSuc)
132130
resetForm()
133131
})
134132
}
135133
136-
const callbackExportSuc = () => {
134+
const callbackExportSuc = (curOptDashboardIdValue: any) => {
137135
// do open dashboard
138-
const url = `#/canvas?resourceId=${curOptDashboardId.value}`
136+
const url = `#/canvas?resourceId=${curOptDashboardIdValue}`
139137
window.open(url, '_self')
140138
}
141139
142140
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
143-
const openMessageLoading = (text: string, type = 'success', cb: Function) => {
141+
const openMessageLoading = (text: string, type = 'success', dvId: any, cb: Function) => {
144142
// success error loading
145143
const customClass = `sq-message-${type || 'success'} sq-message-export`
146144
ElMessage({
@@ -161,15 +159,15 @@ const openMessageLoading = (text: string, type = 'success', cb: Function) => {
161159
size: 'small',
162160
class: 'btn-text',
163161
onClick: () => {
164-
cb()
162+
cb(dvId)
165163
},
166164
},
167165
t('dashboard.open_dashboard')
168166
),
169167
]),
170168
type,
171169
showClose: true,
172-
duration: 0,
170+
duration: 2000,
173171
customClass,
174172
})
175173
}

frontend/src/views/dashboard/editor/Toolbar.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ const editCanvasName = () => {
9191
nameInput.value?.focus()
9292
})
9393
}
94+
const handleEnterEditCanvasName = (event: Event) => {
95+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
96+
event.target?.blur()
97+
}
9498
const closeEditCanvasName = () => {
9599
nameEdit.value = false
96100
if (!inputName.value || !inputName.value.trim()) {
@@ -240,6 +244,7 @@ const previewInner = () => {
240244
<input
241245
ref="nameInput"
242246
v-model="inputName"
247+
@keydown.enter="handleEnterEditCanvasName"
243248
@change="onDvNameChange"
244249
@blur="closeEditCanvasName"
245250
/>

frontend/src/views/dashboard/editor/index.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,23 @@ const addComponent = (componentType: string, viewInfo?: any) => {
4040
component.propValue[0].title = t('dashboard.new_tab')
4141
component.activeTabName = subTabName
4242
}
43-
component.y = 100
43+
component.y = maxYComponentCount() + 10
4444
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
4545
dashboardEditorInnerRef.value.addItemToBox(component)
4646
}
4747
}
4848
49+
const maxYComponentCount = () => {
50+
if (componentData.value.length === 0) {
51+
return 1
52+
} else {
53+
return componentData.value
54+
.filter((item) => item['y'])
55+
.map((item) => item['y'] + item['sizeY']) // Calculate the y+sizeY of each element
56+
.reduce((max, current) => Math.max(max, current), 0)
57+
}
58+
}
59+
4960
onMounted(() => {
5061
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
5162
state.opt = router.currentRoute.value.query.opt

0 commit comments

Comments
 (0)