From 00d2831df72f1e3e8c0d1c2ef7d7ce3bd03c5a31 Mon Sep 17 00:00:00 2001 From: IchliebedichZhu <54796446@qq.com> Date: Sat, 30 Mar 2024 13:04:39 +0000 Subject: [PATCH] fix: add group bug --- src/components/modules/panel/wrap/CompListWrap.vue | 2 +- src/store/design/widget/actions/group.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/modules/panel/wrap/CompListWrap.vue b/src/components/modules/panel/wrap/CompListWrap.vue index dc37318..f9e8112 100644 --- a/src/components/modules/panel/wrap/CompListWrap.vue +++ b/src/components/modules/panel/wrap/CompListWrap.vue @@ -225,7 +225,7 @@ const selectItem = async (item: TGetCompListResult) => { group.text && (group.text = decodeURIComponent(group.text)) group.left = pW / 2 - group.fontSize * (group.text.length / 2) group.top = pH / 2 - group.fontSize / 2 - widgetStore.addGroup(group) + widgetStore.addWidget(group) // store.dispatch('addWidget', group) } } diff --git a/src/store/design/widget/actions/group.ts b/src/store/design/widget/actions/group.ts index 5c13d0c..151a5fe 100644 --- a/src/store/design/widget/actions/group.ts +++ b/src/store/design/widget/actions/group.ts @@ -12,16 +12,15 @@ import { customAlphabet } from 'nanoid/non-secure' const nanoid = customAlphabet('1234567890abcdef', 12) -export function addGroup(store: TWidgetStore, group: TdWidgetData[] | TdWidgetData) { +export function addGroup(store: TWidgetStore, group: TdWidgetData[]) { const historyStore = useHistoryStore() const canvasStore = useCanvasStore() let parent: TdWidgetData | null = null - const tmpGroup: TdWidgetData[] = !Array.isArray(group) ? [group] : group - tmpGroup.forEach((item) => { + group.forEach((item) => { item.uuid = nanoid() // 重设id item.type === 'w-group' && (parent = item) // 找出父组件 }) - tmpGroup.forEach((item) => { + group.forEach((item) => { !item.isContainer && parent && (item.parent = parent.uuid) // 重设父id item.text && (item.text = decodeURIComponent(item.text)) store.dWidgets.push(item)