refactor: Optimize the logic for adding charts to the dashboard

This commit is contained in:
wangjiahao
2025-09-02 22:48:23 +08:00
parent aaaa0c6c6e
commit e9d3f20089
2 changed files with 7 additions and 9 deletions
@@ -395,7 +395,7 @@ watch(
</div>
</el-popover>
</div>
<div v-if="message?.record?.chart && !isAssistant">
<div v-if="message?.record?.chart && isCompletePage">
<el-tooltip effect="dark" :content="t('chat.add_to_dashboard')" placement="top">
<el-button class="tool-btn" text @click="addToDashboard">
<el-icon size="16">
@@ -20,7 +20,6 @@ const optInit = (viewInfo: any) => {
resourceDialogShow.value = true
state.viewInfo = viewInfo
}
const curOptDashboardId = ref(null)
const state = reactive({
dashboardList: [] as SQTreeNode[],
viewInfo: null,
@@ -127,20 +126,19 @@ const saveResourcePrepare = () => {
const saveResource = (params: any, commonParams: any) => {
saveDashboardResourceTarget(params, commonParams, (res: any) => {
const messageTips = t('dashboard.add_success')
curOptDashboardId.value = res?.id
openMessageLoading(messageTips, 'success', callbackExportSuc)
openMessageLoading(messageTips, 'success', res?.id, callbackExportSuc)
resetForm()
})
}
const callbackExportSuc = () => {
const callbackExportSuc = (curOptDashboardIdValue: any) => {
// do open dashboard
const url = `#/canvas?resourceId=${curOptDashboardId.value}`
const url = `#/canvas?resourceId=${curOptDashboardIdValue}`
window.open(url, '_self')
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
const openMessageLoading = (text: string, type = 'success', cb: Function) => {
const openMessageLoading = (text: string, type = 'success', dvId: any, cb: Function) => {
// success error loading
const customClass = `sq-message-${type || 'success'} sq-message-export`
ElMessage({
@@ -161,7 +159,7 @@ const openMessageLoading = (text: string, type = 'success', cb: Function) => {
size: 'small',
class: 'btn-text',
onClick: () => {
cb()
cb(dvId)
},
},
t('dashboard.open_dashboard')
@@ -169,7 +167,7 @@ const openMessageLoading = (text: string, type = 'success', cb: Function) => {
]),
type,
showClose: true,
duration: 0,
duration: 2000,
customClass,
})
}