From c9f12c3864f6e7bcffcedee7c177d99de4343505 Mon Sep 17 00:00:00 2001 From: Zhukj <3262118957> Date: Mon, 20 Apr 2026 10:39:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=9B=BE=E9=BB=98=E8=AE=A4=E5=8A=A0=E8=BD=BD3=E4=B8=AA?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E4=BD=8D=E7=BD=AE=E6=96=87=E6=9C=AC=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/script.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/js/script.js b/js/script.js index 35fb212..89949c5 100644 --- a/js/script.js +++ b/js/script.js @@ -237,11 +237,56 @@ bgOpacitySlider.value = 100; bgOpacityValue.textContent = '100%'; updateBgImage(); + + // 创建初始文本输入框 + createInitialTextInputs(); }; img.src = e.target.result; }; reader.readAsDataURL(file); } + + // 创建初始文本输入框 + function createInitialTextInputs() { + const container = imageContainer; + const containerWidth = container.clientWidth; + const containerHeight = container.clientHeight; + + // 定义3个输入框的位置(像素值) + const inputs = [ + { left: 98, top: 232.945, text: '参会企业:' }, + { left: 98, top: 275.555, text: '姓名:' }, + { left: 98, top: 317.548, text: '编号:' } + ]; + + inputs.forEach((input, index) => { + const textEl = document.createElement('div'); + textEl.className = 'text-input'; + textEl.contentEditable = 'false'; + textEl.textContent = input.text; + + // 将像素位置转换为百分比 + const leftPercent = (input.left / containerWidth * 100); + const topPercent = (input.top / containerHeight * 100); + textEl.style.left = leftPercent + '%'; + textEl.style.top = topPercent + '%'; + + // 删除按钮 + const deleteBtn = document.createElement('button'); + deleteBtn.className = 'text-delete-btn'; + deleteBtn.innerHTML = '×'; + deleteBtn.addEventListener('click', (e) => { + e.stopPropagation(); + textEl.remove(); + }); + textEl.appendChild(deleteBtn); + + const inputLayer = container.querySelector('.preview-input-layer'); + inputLayer.appendChild(textEl); + + initInput(textEl); + }); + } // 添加文本输入框 function addTextInput() {