From a986d2fef66ba96d5e7ecf0d2747afde6c8f693c Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Mon, 28 Oct 2024 20:05:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E4=BB=AA=E8=A1=A8=E6=9D=BF=E3=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B1=8F):=20=E5=AF=8C=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E8=A1=A8=E6=A0=BC=E6=8B=96=E5=8A=A8=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E9=87=8D=E6=9E=84#12467=20#12688?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rich-text/DeRichTextView.vue | 78 +- .../rich-text/DeRichTextViewFrame.vue | 751 ++++++++++++++++++ .../custom-component/user-view/Component.vue | 5 +- 3 files changed, 814 insertions(+), 20 deletions(-) create mode 100644 core/core-frontend/src/custom-component/rich-text/DeRichTextViewFrame.vue diff --git a/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue b/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue index a01c0715cd..87f3df1122 100644 --- a/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue +++ b/core/core-frontend/src/custom-component/rich-text/DeRichTextView.vue @@ -132,6 +132,7 @@ const canEdit = ref(false) // 初始化配置 const tinymceId = 'tinymce-view-' + element.value.id + '-' + suffixId.value const myValue = ref('') +const cellDragStart = ref(0) const systemFontFamily = appearanceStore.fontList.map(item => item.name) const curFontFamily = () => { @@ -172,23 +173,70 @@ const init = ref({ icons: 'vertical-content', vertical_align: element.value.propValue.verticalAlign, setup: function (editor) { - // 在表格调整大小开始时 - editor.on('ObjectResizeStart', function (e) { - const { target, width, height } = e - if (target.nodeName === 'TABLE') { - // 将宽高根据缩放比例调整 - // e.width = width / props.scale - // e.height = height / props.scale - } + let cloneHandle = null // 用于存储克隆的手柄 + let originalHandle = null // 用于存储原始手柄 + editor.on('init', () => { + const doc = editor.getDoc() + // 监测 mouseup、mousedown 和 mousemove 事件 + // 1.单元格问题 因为缩放问题 导致拖拽的坐标系有偏差,此处隐藏原有拖拽定位bar,并根据 + // 缩放比例动态调整时间定位bar的位置,这会代理鼠标移速和bar移速不同步问题,不过bar定位是准确的 + // 可以解决因为缩放导致tinymce 内部坐标系出错问题 + doc.addEventListener('mousedown', event => { + nextTick(() => { + originalHandle = event.target.closest('.ephox-snooker-resizer-bar-dragging') + if (originalHandle) { + // 克隆原始手柄 + cloneHandle = originalHandle.cloneNode(true) + cloneHandle.style.zIndex = 9999 // 提升克隆手柄的层级 + originalHandle.style.display = 'none' // 隐藏原始手柄 + // 将克隆手柄添加到原手柄的父元素中 + const parentDiv = originalHandle.parentNode // 获取原手柄的父元素 + cloneHandle.style.width = `${parentDiv.offsetWidth}px` + parentDiv.appendChild(cloneHandle) // 将克隆手柄添加到父元素中 + } + }) + }) + + // 监听 mousemove 事件以更新克隆手柄位置 + doc.addEventListener('mousemove', event => { + if (cloneHandle) { + // // 计算鼠标移动的距离 + if (cloneHandle.offsetHeight > cloneHandle.offsetWidth) { + // 计算鼠标移动的距离 + const offsetX = event.movementX * props.scale // 使用缩放比例进行调整 + cloneHandle.style.left = `${cloneHandle.offsetLeft + offsetX}px` // 更新克隆手柄的位置 + } else { + // 计算鼠标移动的距离 + const offsetY = event.movementY * props.scale // 使用缩放比例进行调整 + cloneHandle.style.top = `${cloneHandle.offsetTop + offsetY}px` // 更新克隆手柄的位置 + } + } + }) + + // 监听 mouseup 事件以结束调整 + doc.addEventListener('mouseup', event => { + if (cloneHandle) { + // 显示原始手柄并移除克隆手柄 + originalHandle.style.display = '' + if (cloneHandle) { + originalHandle.parentNode.removeChild(cloneHandle) // 获取原手柄的父元素 + } + cloneHandle = null + originalHandle = null + } + }) }) // 在表格调整大小结束时 + // 解决移动表格corner点位resize时因为缩放导致的坐标系放大问题,进而导致移动错位问题 editor.on('ObjectResized', function (e) { - const { target, width, height } = e - if (target.nodeName === 'TABLE') { + const { target, width, height, origin } = e + if (target.nodeName === 'TABLE' && origin.indexOf('corner') > -1) { // 将最终调整的宽高根据缩放比例重设 - // target.style.width = `${width * props.scale}px` - // target.style.height = `${height scaleFactor}px` + target.style.width = `${width}px` + target.style.height = `${height}px` + } else if (target.nodeName === 'TABLE' && origin.indexOf('bar-col') > -1) { + // do nothing } }) } @@ -634,12 +682,6 @@ defineExpose({ width: 0px !important; height: 0px !important; } - ::v-deep(p) { - zoom: var(--de-canvas-scale); - } - ::v-deep(td span) { - zoom: var(--de-canvas-scale); - } } :deep(.ol) { diff --git a/core/core-frontend/src/custom-component/rich-text/DeRichTextViewFrame.vue b/core/core-frontend/src/custom-component/rich-text/DeRichTextViewFrame.vue new file mode 100644 index 0000000000..aefea08bf7 --- /dev/null +++ b/core/core-frontend/src/custom-component/rich-text/DeRichTextViewFrame.vue @@ -0,0 +1,751 @@ + + + + + + {{ init.outer_placeholder }} + + + + + + + + + diff --git a/core/core-frontend/src/custom-component/user-view/Component.vue b/core/core-frontend/src/custom-component/user-view/Component.vue index 1dab9cf588..6034d08caf 100644 --- a/core/core-frontend/src/custom-component/user-view/Component.vue +++ b/core/core-frontend/src/custom-component/user-view/Component.vue @@ -1,5 +1,5 @@