Commit 0b21afc0a28f3336bd424f318397c63dc6f8f16f

Authored by xp.Huang
2 parents 593d18a5 11cc50c1

Merge branch 'fix/DEFECT-1302' into 'main_dev'

fix: DEFECT-1302修复组件复制功能,复制的组件布局信息为初始化布局信息

See merge request yunteng/thingskit-front!632
@@ -12,10 +12,11 @@ @@ -12,10 +12,11 @@
12 import { addDataComponent, deleteDataComponent } from '/@/api/dataBoard'; 12 import { addDataComponent, deleteDataComponent } from '/@/api/dataBoard';
13 import { useBoardId } from '../../hooks/useBoardId'; 13 import { useBoardId } from '../../hooks/useBoardId';
14 import { unref, toRaw } from 'vue'; 14 import { unref, toRaw } from 'vue';
15 - import { ApiDataBoardDataType } from '../../types'; 15 + import { ApiDataBoardDataType, ComponentLayoutType } from '../../types';
16 import { useCalcNewWidgetPosition } from '../../hooks/useCalcNewWidgetPosition'; 16 import { useCalcNewWidgetPosition } from '../../hooks/useCalcNewWidgetPosition';
17 import { Layout } from 'vue3-grid-layout'; 17 import { Layout } from 'vue3-grid-layout';
18 import { DataComponentRecord } from '/@/api/dataBoard/model'; 18 import { DataComponentRecord } from '/@/api/dataBoard/model';
  19 + import { computed } from 'vue';
19 20
20 const props = defineProps<{ 21 const props = defineProps<{
21 sourceInfo: WidgetDataType; 22 sourceInfo: WidgetDataType;
@@ -72,11 +73,16 @@ @@ -72,11 +73,16 @@
72 } catch (error) {} 73 } catch (error) {}
73 } 74 }
74 75
  76 + const getLayout = computed(() => {
  77 + const { sourceInfo } = props;
  78 + const { id, w, h, x, y } = sourceInfo;
  79 + return { id, w, h, x, y } as ComponentLayoutType;
  80 + });
  81 +
75 async function handleCopy() { 82 async function handleCopy() {
76 const id = props.sourceInfo.id; 83 const id = props.sourceInfo.id;
77 const copyRecord = props.rawDataSource.componentData.find((item) => item.id === id); 84 const copyRecord = props.rawDataSource.componentData.find((item) => item.id === id);
78 - const copyLayout = props.rawDataSource.componentLayout.find((item) => item.id === id);  
79 - 85 + const copyLayout = unref(getLayout);
80 const raw = toRaw(copyRecord) as unknown as DataComponentRecord; 86 const raw = toRaw(copyRecord) as unknown as DataComponentRecord;
81 87
82 const layout = useCalcNewWidgetPosition( 88 const layout = useCalcNewWidgetPosition(
@@ -104,9 +104,10 @@ export const useDataSource = (propsRef: ComputedRef<Recordable>) => { @@ -104,9 +104,10 @@ export const useDataSource = (propsRef: ComputedRef<Recordable>) => {
104 */ 104 */
105 const setLayoutInfo = async () => { 105 const setLayoutInfo = async () => {
106 try { 106 try {
  107 + const layout = getLayoutInfo();
107 await updateDataBoardLayout({ 108 await updateDataBoardLayout({
108 boardId: unref(getBoardId), 109 boardId: unref(getBoardId),
109 - layout: getLayoutInfo(), 110 + layout,
110 }); 111 });
111 } catch (error) {} 112 } catch (error) {}
112 }; 113 };