From 1baec3f1d44e4449bea572badecfe6f1f1b32e98 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 9 Jan 2025 20:48:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(editor):=20useTemplateRef=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E8=83=BD=E4=B8=8E=E5=8F=98=E9=87=8F=E5=90=8D?= =?UTF-8?q?=E4=B8=80=E6=A0=B7=EF=BC=8C=E4=B8=8D=E7=84=B6=E4=BC=9A=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E4=B8=AAwarn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/src/components/CodeBlockEditor.vue | 6 ++--- packages/editor/src/components/CodeParams.vue | 4 +-- .../editor/src/components/ContentMenu.vue | 26 +++++++++---------- .../editor/src/components/FloatingBox.vue | 18 ++++++------- packages/editor/src/components/Resizer.vue | 4 +-- packages/editor/src/components/ScrollBar.vue | 13 +++++----- .../editor/src/components/ScrollViewer.vue | 12 ++++----- packages/editor/src/components/SplitView.vue | 4 +-- .../editor/src/fields/DataSourceInput.vue | 6 ++--- .../editor/src/fields/DataSourceMethods.vue | 8 +++--- .../editor/src/hooks/use-code-block-edit.ts | 10 +++---- packages/editor/src/layouts/CodeEditor.vue | 12 ++++----- packages/editor/src/layouts/Framework.vue | 10 +++---- packages/editor/src/layouts/NavMenu.vue | 9 ++++--- .../editor/src/layouts/page-bar/PageBar.vue | 26 +++++++++---------- .../page-bar/PageBarScrollContainer.vue | 23 ++++++++-------- .../src/layouts/props-panel/FormPanel.vue | 12 ++++----- .../sidebar/code-block/CodeBlockListPanel.vue | 6 ++--- .../src/layouts/sidebar/layer/LayerMenu.vue | 4 +-- .../src/layouts/sidebar/layer/LayerPanel.vue | 9 ++++--- .../src/layouts/sidebar/layer/use-click.ts | 10 +++---- .../layouts/workspace/viewer/NodeListMenu.vue | 10 +++---- .../src/layouts/workspace/viewer/Stage.vue | 26 +++++++++---------- .../layouts/workspace/viewer/StageOverlay.vue | 4 +-- .../layouts/workspace/viewer/ViewerMenu.vue | 6 ++--- 25 files changed, 140 insertions(+), 138 deletions(-) diff --git a/packages/editor/src/components/CodeBlockEditor.vue b/packages/editor/src/components/CodeBlockEditor.vue index f57109e3e..665a06afd 100644 --- a/packages/editor/src/components/CodeBlockEditor.vue +++ b/packages/editor/src/components/CodeBlockEditor.vue @@ -104,14 +104,14 @@ const { height: codeBlockEditorHeight } = useEditorContentHeight(); const difVisible = ref(false); const { rect: windowRect } = useWindowRect(); -const magicVsEditor = useTemplateRef>('magicVsEditor'); +const magicVsEditorRef = useTemplateRef>('magicVsEditor'); const diffChange = () => { - if (!magicVsEditor.value || !formBox.value?.form) { + if (!magicVsEditorRef.value || !formBox.value?.form) { return; } - formBox.value.form.values.content = magicVsEditor.value.getEditorValue(); + formBox.value.form.values.content = magicVsEditorRef.value.getEditorValue(); difVisible.value = false; }; diff --git a/packages/editor/src/components/CodeParams.vue b/packages/editor/src/components/CodeParams.vue index ddb0552f0..2f095e8aa 100644 --- a/packages/editor/src/components/CodeParams.vue +++ b/packages/editor/src/components/CodeParams.vue @@ -32,7 +32,7 @@ const props = defineProps<{ const emit = defineEmits(['change']); -const form = useTemplateRef>('form'); +const formRef = useTemplateRef>('form'); const getFormConfig = (items: FormConfig = []) => [ { @@ -61,7 +61,7 @@ const codeParamsConfig = computed(() => */ const onParamsChangeHandler = async (v: FormValue, eventData: ContainerChangeEventData) => { try { - const value = await form.value?.submitForm(true); + const value = await formRef.value?.submitForm(true); emit('change', value, eventData); } catch (e) { error(e); diff --git a/packages/editor/src/components/ContentMenu.vue b/packages/editor/src/components/ContentMenu.vue index fb0e8726b..ee6bcb7d1 100644 --- a/packages/editor/src/components/ContentMenu.vue +++ b/packages/editor/src/components/ContentMenu.vue @@ -69,9 +69,9 @@ const emit = defineEmits<{ mouseenter: []; }>(); -const menu = useTemplateRef('menu'); -const buttons = useTemplateRef[]>('buttons'); -const subMenu = useTemplateRef('subMenu'); +const menuEl = useTemplateRef('menu'); +const buttonRefs = useTemplateRef[]>('buttons'); +const subMenuRef = useTemplateRef('subMenu'); const visible = ref(false); const subMenuData = ref<(MenuButton | MenuComponent)[]>([]); const zIndex = useZIndex(); @@ -88,13 +88,13 @@ const menuStyle = computed(() => ({ zIndex: curZIndex.value, })); -const contains = (el: HTMLElement) => menu.value?.contains(el) || subMenu.value?.contains(el); +const contains = (el: HTMLElement) => menuEl.value?.contains(el) || subMenuRef.value?.contains(el); const hide = () => { if (!visible.value) return; visible.value = false; - subMenu.value?.hide(); + subMenuRef.value?.hide(); emit('hide'); }; @@ -121,7 +121,7 @@ const outsideClickHideHandler = (e: MouseEvent) => { }; const setPosition = (e: { clientY: number; clientX: number }) => { - const menuHeight = menu.value?.clientHeight || 0; + const menuHeight = menuEl.value?.clientHeight || 0; let top = e.clientY; if (menuHeight + e.clientY > document.body.clientHeight) { @@ -158,15 +158,15 @@ const showSubMenu = (item: MenuButton | MenuComponent, index: number) => { return; } - if (menu.value) { + if (menuEl.value) { // 将子菜单放置在按钮右侧,与按钮齐平 - let y = menu.value.offsetTop; - if (buttons.value?.[index].$el) { - const rect = buttons.value?.[index].$el.getBoundingClientRect(); + let y = menuEl.value.offsetTop; + if (buttonRefs.value?.[index].$el) { + const rect = buttonRefs.value?.[index].$el.getBoundingClientRect(); y = rect.top; } - subMenu.value?.show({ - clientX: menu.value.offsetLeft + menu.value.clientWidth - 2, + subMenuRef.value?.show({ + clientX: menuEl.value.offsetLeft + menuEl.value.clientWidth - 2, clientY: y, }); } @@ -190,7 +190,7 @@ onBeforeUnmount(() => { }); defineExpose({ - menu, + menu: menuEl, menuPosition, hide, show, diff --git a/packages/editor/src/components/FloatingBox.vue b/packages/editor/src/components/FloatingBox.vue index 0ba95ef36..0afc402dc 100644 --- a/packages/editor/src/components/FloatingBox.vue +++ b/packages/editor/src/components/FloatingBox.vue @@ -1,7 +1,7 @@