This commit is contained in:
2025-09-10 07:52:32 +08:00
parent 295288edb4
commit aec6a426ed
2 changed files with 74 additions and 40 deletions

View File

@@ -46,20 +46,21 @@ document.addEventListener('DOMContentLoaded', function() {
// 修改全局偏移量输入框事件监听 // 修改全局偏移量输入框事件监听
const globalStopDistanceInput = document.getElementById('global-stop-distance'); // 删除以下全局停止距离相关代码
// const globalStopDistanceInput = document.getElementById('global-stop-distance');
// 初始化全局偏移量(从localStorage加载或使用默认值) //
const savedGlobalStopDistance = localStorage.getItem('globalStopDistance'); // // 初始化全局偏移量(从localStorage加载或使用默认值)
if (savedGlobalStopDistance) { // const savedGlobalStopDistance = localStorage.getItem('globalStopDistance');
globalStopDistanceInput.value = savedGlobalStopDistance; // if (savedGlobalStopDistance) {
} // globalStopDistanceInput.value = savedGlobalStopDistance;
// }
// 全局偏移量变更事件 - 保存到localStorage无需选中箭头 //
globalStopDistanceInput.addEventListener('input', function() { // // 全局偏移量变更事件 - 保存到localStorage无需选中箭头
const globalValue = this.value; // globalStopDistanceInput.addEventListener('input', function() {
localStorage.setItem('globalStopDistance', globalValue); // const globalValue = this.value;
console.log(`[全局设置] 箭头停止距离: ${globalValue}px`); // localStorage.setItem('globalStopDistance', globalValue);
}); // console.log(`[全局设置] 箭头停止距离: ${globalValue}px`);
// });
@@ -69,8 +70,8 @@ document.addEventListener('DOMContentLoaded', function() {
const arrowHeight = ARROW_HEIGHT; const arrowHeight = ARROW_HEIGHT;
const centerOffsetX = arrowWidth / 2; const centerOffsetX = arrowWidth / 2;
const centerOffsetY = arrowHeight / 2; const centerOffsetY = arrowHeight / 2;
// 使用全局偏移量替换单个箭头的stopDistance // 使用当前箭头的停止距离默认为50
const stopDistance = parseInt(document.getElementById('global-stop-distance').value) || STOP_DISTANCE; const stopDistance = parseInt(arrow.dataset.stopDistance) || 50;
const rect = arrow.getBoundingClientRect(); const rect = arrow.getBoundingClientRect();
const containerRect = backgroundContainer.getBoundingClientRect(); const containerRect = backgroundContainer.getBoundingClientRect();
@@ -233,19 +234,48 @@ document.addEventListener('DOMContentLoaded', function() {
container.style.top = (y - centerOffsetY) + 'px'; container.style.top = (y - centerOffsetY) + 'px';
} }
// 双击编辑文字 // 双击编辑文字和停止距离
container.addEventListener('dblclick', (e) => { container.addEventListener('dblclick', (e) => {
e.stopPropagation(); e.stopPropagation();
const currentText = container.dataset.text || ''; const currentText = container.dataset.text || '';
// 使用layui layer.prompt替换原生prompt const currentStopDistance = container.dataset.stopDistance || '50';
layer.prompt({
title: '请输入文字', // 创建自定义弹窗内容使用layui表单样式
value: currentText, const content = `
formType: 3, // 文本输入框类型 <div style="padding: 20px;">
area: ['300px', 'auto'] // 定义弹窗宽度 <div class="layui-form-item">
}, function(value, index, elem){ <label class="layui-form-label">文字内容:</label>
if (value !== null) { <div class="layui-input-block">
if (value.trim() === '') { <input type="text" id="arrowText" value="${currentText}" class="layui-input" style="width: 100%;">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">停止距离 (px):</label>
<div class="layui-input-block">
<input type="number" id="arrowStopDistance" value="${currentStopDistance}" min="0" max="200" class="layui-input" style="width: 100%;">
</div>
</div>
</div>
`;
// 使用layer.open创建自定义弹窗增加宽度并应用layui样式
layer.open({
type: 1,
title: '编辑箭头属性',
area: ['500px', 'auto'], // 增加宽度到500px
content: content,
btn: ['确定', '取消'],
skin: 'layui-layer-molv', // 使用layui默认皮肤
success: function(layero) {
// 初始化layui表单样式
layui.form.render(null, 'arrowForm');
},
yes: function(index, layero) {
const textValue = layero.find('#arrowText').val().trim();
const stopDistanceValue = layero.find('#arrowStopDistance').val();
// 保存文字内容
if (textValue === '') {
container.querySelector('.arrow-text')?.remove(); container.querySelector('.arrow-text')?.remove();
delete container.dataset.text; delete container.dataset.text;
} else { } else {
@@ -255,12 +285,18 @@ document.addEventListener('DOMContentLoaded', function() {
textElement.className = 'arrow-text'; textElement.className = 'arrow-text';
container.appendChild(textElement); container.appendChild(textElement);
} }
textElement.textContent = value; textElement.textContent = textValue;
container.dataset.text = value; container.dataset.text = textValue;
}
// 保存停止距离
if (!isNaN(stopDistanceValue) && stopDistanceValue >= 0) {
container.dataset.stopDistance = stopDistanceValue;
}
saveAllElements(); saveAllElements();
layer.close(index);
} }
}
layer.close(index); // 关闭弹窗
}); });
}); });
@@ -339,7 +375,10 @@ document.addEventListener('DOMContentLoaded', function() {
localStorage.removeItem('centerPoint'); localStorage.removeItem('centerPoint');
} }
// 保存箭头(移除stopDistance属性) // 删除全局停止距离的保存
localStorage.removeItem('globalStopDistance');
// 保存箭头(添加stopDistance属性)
document.querySelectorAll('.arrow-container').forEach(arrow => { document.querySelectorAll('.arrow-container').forEach(arrow => {
elements.push({ elements.push({
type: 'arrow', type: 'arrow',
@@ -347,8 +386,8 @@ document.addEventListener('DOMContentLoaded', function() {
left: arrow.style.left, left: arrow.style.left,
top: arrow.style.top, top: arrow.style.top,
text: arrow.dataset.text || '', text: arrow.dataset.text || '',
referencePoint: arrow.dataset.referencePoint || 'top-left' referencePoint: arrow.dataset.referencePoint || 'top-left',
// 删除stopDistance属性 stopDistance: arrow.dataset.stopDistance || '50' // 添加停止距离保存
}); });
}); });

View File

@@ -23,12 +23,7 @@
<div class="image-btn" data-image="images/5.png" style="background-image: url('images/5.png');"></div> <div class="image-btn" data-image="images/5.png" style="background-image: url('images/5.png');"></div>
<div class="image-btn" data-image="images/6.png" style="background-image: url('images/6.png');"></div> <div class="image-btn" data-image="images/6.png" style="background-image: url('images/6.png');"></div>
</div> </div>
<!-- 添加偏移量控制区域 --> <!-- 删除全局停止距离输入框 -->
<div class="offset-control" style="margin-top: 15px; padding: 10px; border: 1px solid #eee; border-radius: 4px;">
<label for="global-stop-distance" style="display: block; margin-bottom: 5px;">箭头停止距离 (px):</label>
<input type="number" id="global-stop-distance" min="0" max="100" value="20" style="width: 100%; padding: 8px;">
<p style="font-size: 12px; color: #666; margin: 5px 0 0 0;">* 全局设置,所有箭头生效</p>
</div>
<button class="save-btn" id="markCenterBtn" style="margin-top: 10px;">标记中心点</button> <button class="save-btn" id="markCenterBtn" style="margin-top: 10px;">标记中心点</button>
<button class="save-btn" id="startAnimationBtn" style="margin-top: 10px;">开始</button> <button class="save-btn" id="startAnimationBtn" style="margin-top: 10px;">开始</button>
<button class="save-btn" id="resetBtn" style="margin-top: 10px;">重置</button> <button class="save-btn" id="resetBtn" style="margin-top: 10px;">重置</button>