From 3b9fb714e5407346c4981f26933e633f0f157e24 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 2 Jul 2026 20:22:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(editor):=20=E8=A7=A3=E8=80=A6=20Floati?= =?UTF-8?q?ngBox=20=E7=9A=84=20uiService=20=E4=BE=9D=E8=B5=96=E5=B9=B6?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20props=20=E4=BC=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FloatingBox 不再强制依赖 uiService - frameworkWidth 默认回退到视窗宽度 - 新增 initialStyle prop 支持外部设置初始样式 - 各调用方显式传入 frameworkWidth 以保留右边界收敛行为 --- .../editor/src/components/CodeBlockEditor.vue | 2 + .../editor/src/components/FloatingBox.vue | 15 +++-- .../editor/src/fields/DataSourceFields.vue | 3 + .../editor/src/fields/DataSourceMocks.vue | 2 + .../editor/src/layouts/sidebar/Sidebar.vue | 2 + .../data-source/DataSourceConfigPanel.vue | 2 + .../layouts/workspace/viewer/NodeListMenu.vue | 5 +- .../tests/unit/components/FloatingBox.spec.ts | 63 ++++++++++++++++++- .../workspace/viewer/NodeListMenu.spec.ts | 6 +- 9 files changed, 91 insertions(+), 9 deletions(-) diff --git a/packages/editor/src/components/CodeBlockEditor.vue b/packages/editor/src/components/CodeBlockEditor.vue index f3f936ee..b69940d4 100644 --- a/packages/editor/src/components/CodeBlockEditor.vue +++ b/packages/editor/src/components/CodeBlockEditor.vue @@ -6,6 +6,7 @@ v-model:height="codeBlockEditorHeight" :body-style="{ padding: '0 16px' }" :title="content.name ? `${disabled ? '查看' : '编辑'}${content.name}` : '新增代码'" + :framework-width="frameworkWidth" :position="boxPosition" :before-close="beforeClose" > @@ -207,6 +208,7 @@ const closedHandler = () => { const parentFloating = inject>('parentFloating', ref(null)); const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(uiService, parentFloating); +const frameworkWidth = computed(() => uiService.get('frameworkRect')?.width || 0); watch(boxVisible, (visible) => { nextTick(() => { diff --git a/packages/editor/src/components/FloatingBox.vue b/packages/editor/src/components/FloatingBox.vue index 2fdf00b4..da0cbbc3 100644 --- a/packages/editor/src/components/FloatingBox.vue +++ b/packages/editor/src/components/FloatingBox.vue @@ -30,7 +30,6 @@ import VanillaMoveable from 'moveable'; import { TMagicButton, useZIndex } from '@tmagic/design'; import MIcon from '@editor/components/Icon.vue'; -import { useServices } from '@editor/hooks/use-services'; interface Position { left: number; @@ -46,11 +45,17 @@ const props = withDefaults( position?: Position; title?: string; bodyStyle?: CSSProperties; + /** 浮窗初始样式,会与内部计算样式合并,外部传入优先 */ + initialStyle?: CSSProperties; + /** 用于约束浮窗 left 的容器宽度,传入时按宽度收敛 left,避免超出右边界;默认取视窗宽度 */ + frameworkWidth?: number; beforeClose?: (_done: (_cancel?: boolean) => void) => void; }>(), { title: '', position: () => ({ left: 0, top: 0 }), + initialStyle: () => ({}), + frameworkWidth: 0, }, ); @@ -73,12 +78,11 @@ const bodyHeight = computed(() => { return 'auto'; }); -const { uiService } = useServices(); -const frameworkWidth = computed(() => uiService.get('frameworkRect').width || 0); const style = computed(() => { let { left } = props.position; - if (width.value) { - left = left + width.value > frameworkWidth.value ? frameworkWidth.value - width.value : left; + const frameworkWidth = props.frameworkWidth || globalThis.window?.innerWidth || 0; + if (width.value && frameworkWidth) { + left = left + width.value > frameworkWidth ? frameworkWidth - width.value : left; } return { @@ -86,6 +90,7 @@ const style = computed(() => { top: `${props.position.top}px`, width: width.value ? `${width.value}px` : 'auto', height: height.value ? `${height.value}px` : 'auto', + ...props.initialStyle, }; }); diff --git a/packages/editor/src/fields/DataSourceFields.vue b/packages/editor/src/fields/DataSourceFields.vue index c5e64cb2..e904e45e 100644 --- a/packages/editor/src/fields/DataSourceFields.vue +++ b/packages/editor/src/fields/DataSourceFields.vue @@ -13,6 +13,7 @@ v-model:width="width" v-model:height="editorHeight" :title="fieldTitle" + :framework-width="frameworkWidth" :position="boxPosition" >