@@ -13,7 +13,8 @@ import { useI18n } from 'vue-i18n'
1313
1414const { t } = useI18n ()
1515const dashboardStore = dashboardStoreWithOut ()
16- const { componentData, canvasViewInfo, fullscreenFlag } = storeToRefs (dashboardStore )
16+ const { componentData, canvasViewInfo, fullscreenFlag, baseMatrixCount } =
17+ storeToRefs (dashboardStore )
1718
1819const dataInitState = ref (true )
1920const state = reactive ({
@@ -23,8 +24,26 @@ const state = reactive({
2324})
2425
2526const dashboardEditorInnerRef = ref (null )
26- const addComponent = (componentType : string , viewInfo ? : any ) => {
27+ const addComponents = (componentType : string , views ? : any ) => {
2728 const component = cloneDeep (findNewComponentFromList (componentType ))
29+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
30+ component .x = findPositionX (component .sizeX )
31+ if (views ) {
32+ views .forEach ((view : any , index : number ) => {
33+ const target = cloneDeep (view )
34+ delete target .chart .sourceType
35+ if (index > 0 ) {
36+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
37+ component .x = ((component .x + component ?.sizeX - 1 ) % baseMatrixCount .value .x ) + 1
38+ }
39+ addComponent (component , target )
40+ })
41+ } else {
42+ addComponent (component )
43+ }
44+ }
45+ const addComponent = (componentSource : any , viewInfo ? : any ) => {
46+ const component = cloneDeep (componentSource )
2847 if (component && dashboardEditorInnerRef .value ) {
2948 component .id = guid ()
3049 // add view
@@ -34,9 +53,7 @@ const addComponent = (componentType: string, viewInfo?: any) => {
3453 dashboardStore .addCanvasViewInfo (viewInfo )
3554 } else if (component .component === ' SQTab' ) {
3655 const subTabName = guid (' tab' )
37- // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
3856 component .propValue [0 ].name = subTabName
39- // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
4057 component .propValue [0 ].title = t (' dashboard.new_tab' )
4158 component .activeTabName = subTabName
4259 }
@@ -85,12 +102,20 @@ const baseParams = computed(() => {
85102 pid: state .routerPid ,
86103 }
87104})
105+ const findPositionX = (width : number ) => {
106+ // @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
107+ return dashboardEditorInnerRef .value .findPositionX (width )
108+ }
88109 </script >
89110
90111<template >
91112 <div class =" editor-content" :class =" { 'editor-content-fullscreen': fullscreenFlag }" >
92113 <div class =" editor-main" >
93- <Toolbar :base-params =" baseParams" @add-component =" addComponent" ></Toolbar >
114+ <Toolbar
115+ :base-params =" baseParams"
116+ :find-position-x =" findPositionX"
117+ @add-components =" addComponents"
118+ ></Toolbar >
94119 <DashboardEditor
95120 v-if =" dataInitState"
96121 ref =" dashboardEditorInnerRef"
0 commit comments