feat: 粗细滑块、移动端两行工具栏、二维码底部定位、字号修复及README更新

This commit is contained in:
2026-05-15 15:06:02 +08:00
parent 8789a76ecc
commit 315f568138
5 changed files with 172 additions and 50 deletions

View File

@@ -3,7 +3,7 @@
/* ========== 悬浮按钮 ========== */ /* ========== 悬浮按钮 ========== */
#qr-btn { #qr-btn {
position: fixed; position: fixed;
bottom: 100px; bottom: 20px;
left: 20px; left: 20px;
width: 44px; width: 44px;
height: 44px; height: 44px;

View File

@@ -188,39 +188,144 @@ html, body {
z-index: 10000; z-index: 10000;
} }
/* 移动端:允许横向滚动 */ /* 移动端:两行整洁布局 @ 375px 友好 */
@media (max-width: 768px) { @media (max-width: 768px) {
.editor-toolbar { .editor-toolbar {
justify-content: flex-start; justify-content: center;
overflow-x: auto; overflow: visible;
-webkit-overflow-scrolling: touch; padding: 6px 10px;
scrollbar-width: none; height: auto;
padding: 8px; box-shadow: 0 1px 6px rgba(0,0,0,0.06);
}
.editor-toolbar::-webkit-scrollbar {
display: none;
} }
.toolbar-group { .toolbar-group {
gap: 2px; gap: 6px;
flex-shrink: 0; flex-wrap: wrap;
width: 100%;
justify-content: center; justify-content: center;
align-items: center;
width: 100%;
padding: 4px 0;
}
/* 分隔线在折叠布局中隐藏 */
.toolbar-divider {
display: none;
} }
.toolbar-btn { .toolbar-btn {
width: 32px; width: 30px;
height: 32px; height: 30px;
font-size: 14px; font-size: 14px;
min-width: 0;
border-radius: 6px;
background: #f5f5f5;
border-color: #e0e0e0;
}
.toolbar-btn:active {
background: #e0e0e0;
transform: scale(0.95);
}
.toolbar-btn.active {
background: #4a90e2;
color: #fff;
border-color: #4a90e2;
}
.toolbar-btn.italic {
font-weight: normal;
font-style: italic;
font-family: 'Times New Roman', serif;
font-size: 17px;
} }
.toolbar-label { .toolbar-label {
font-size: 12px; font-size: 11px;
gap: 3px;
padding: 2px 6px;
background: #f8f8f8;
border-radius: 6px;
border: 1px solid #eee;
} }
.toolbar-label span:first-child { .toolbar-label span:first-child {
display: inline; display: inline;
color: #888;
}
.toolbar-label input[type="color"] {
width: 24px;
height: 24px;
padding: 1px;
border-radius: 4px;
border: 1px solid #ddd;
cursor: pointer;
}
.toolbar-label select {
max-width: 70px;
font-size: 11px;
padding: 2px 4px;
border-radius: 4px;
border: 1px solid #ddd;
background: #fff;
}
.toolbar-label select option {
font-size: 12px;
}
.weight-slider {
width: 56px;
accent-color: #4a90e2;
}
#weightValue {
min-width: 20px;
text-align: center;
font-size: 11px;
font-weight: bold;
color: #333;
} }
.roller-picker { .roller-picker {
min-width: 50px; min-width: 44px;
height: 32px; height: 28px;
padding: 2px 4px; padding: 1px 4px;
border-radius: 6px;
border: 1px solid #ddd;
background: #fff;
}
.roller-value {
font-size: 13px;
min-width: 20px;
font-weight: bold;
}
.roller-arrow {
font-size: 8px;
padding: 1px 3px;
}
/* 背景图工具栏仅两项,保持单行 */
.bg-tools {
flex-wrap: nowrap;
}
/* ===== 顶部工具栏 移动端优化 ===== */
.toolbar {
padding: 6px 8px;
gap: 2px;
}
.btn {
min-width: 44px;
height: 28px;
padding: 0 5px;
font-size: 11px;
border-radius: 4px;
}
.btn-primary {
min-width: 60px;
height: 28px;
padding: 0 8px;
font-size: 12px;
}
.toolbar-btn-icon {
width: 22px;
height: 22px;
font-size: 11px;
}
.toolbar-action-group {
gap: 1px;
}
.toolbar-divider-v {
height: 16px;
margin: 0 1px;
} }
} }
@@ -323,6 +428,14 @@ html, body {
margin: 0; margin: 0;
} }
.weight-slider {
width: 80px;
height: 32px;
cursor: pointer;
accent-color: #4a90e2;
margin: 0;
}
/* 旋转度数显示固定宽度 */ /* 旋转度数显示固定宽度 */
#rotateValue { #rotateValue {
display: inline-block; display: inline-block;

View File

@@ -30,7 +30,12 @@
<div class="toolbar-group text-tools" id="textTools"> <div class="toolbar-group text-tools" id="textTools">
<button class="toolbar-btn" id="lockBtn" title="锁定位置">🔒</button> <button class="toolbar-btn" id="lockBtn" title="锁定位置">🔒</button>
<div class="toolbar-divider"></div> <div class="toolbar-divider"></div>
<button class="toolbar-btn" id="boldBtn" title="加粗">B</button> <label class="toolbar-label">
<span>粗细</span>
<input type="range" id="weightSlider" min="400" max="900" step="100" value="700" class="weight-slider">
<span id="weightValue">700</span>
</label>
<div class="toolbar-divider"></div>
<button class="toolbar-btn italic" id="italicBtn" title="斜体">I</button> <button class="toolbar-btn italic" id="italicBtn" title="斜体">I</button>
<div class="toolbar-divider"></div> <div class="toolbar-divider"></div>
<label class="toolbar-label"> <label class="toolbar-label">

View File

@@ -7,7 +7,7 @@ var INPUTS_CONFIG = {
"label": "企业", "label": "企业",
"left": 100, "left": 100,
"top": 218.4, "top": 218.4,
"fontWeight": "bold", "fontWeight": 700,
"placeholder": "请输入" "placeholder": "请输入"
}, },
{ {
@@ -15,15 +15,15 @@ var INPUTS_CONFIG = {
"label": "嘉宾", "label": "嘉宾",
"left": 100, "left": 100,
"top": 261.4, "top": 261.4,
"fontWeight": "bold", "fontWeight": 700,
"placeholder": "请输入" "placeholder": "请输入"
}, },
{ {
"id": "input3", "id": "input3",
"label": "编号", "label": "编号",
"left": 100, "left": 100,
"top": 308.1, "top": 306.4,
"fontWeight": "bold", "fontWeight": 700,
"placeholder": "请输入" "placeholder": "请输入"
} }
] ]

View File

@@ -28,7 +28,8 @@
const bgScaleValue = document.getElementById('bgScaleValue'); const bgScaleValue = document.getElementById('bgScaleValue');
const bgOpacitySlider = document.getElementById('bgOpacitySlider'); const bgOpacitySlider = document.getElementById('bgOpacitySlider');
const bgOpacityValue = document.getElementById('bgOpacityValue'); const bgOpacityValue = document.getElementById('bgOpacityValue');
const boldBtn = document.getElementById('boldBtn'); const weightSlider = document.getElementById('weightSlider');
const weightValue = document.getElementById('weightValue');
const italicBtn = document.getElementById('italicBtn'); const italicBtn = document.getElementById('italicBtn');
const lockBtn = document.getElementById('lockBtn'); const lockBtn = document.getElementById('lockBtn');
const colorPicker = document.getElementById('colorPicker'); const colorPicker = document.getElementById('colorPicker');
@@ -1899,10 +1900,7 @@
const fontFamily = style.fontFamily.replace(/['"]/g, ''); const fontFamily = style.fontFamily.replace(/['"]/g, '');
const fontSize = parseInt(style.fontSize); const fontSize = parseInt(style.fontSize);
// 更新加粗按钮状态 // 更新颜色选择器
boldBtn.classList.toggle('active', fontWeight === 'bold' || fontWeight === '700' || parseInt(fontWeight) >= 700);
// 更新斜体按钮状态
italicBtn.classList.toggle('active', fontStyle === 'italic'); italicBtn.classList.toggle('active', fontStyle === 'italic');
// 更新颜色选择器 // 更新颜色选择器
@@ -1925,6 +1923,19 @@
fontPicker.value = fontPicker.options[0].value; fontPicker.value = fontPicker.options[0].value;
} }
// 更新字重滑动条(兼容关键字 bold/normal 和数值)
var numericWeight = parseInt(style.fontWeight);
if (!isNaN(numericWeight)) {
weightSlider.value = numericWeight;
weightValue.textContent = numericWeight;
} else if (fontWeight === 'bold') {
weightSlider.value = 700;
weightValue.textContent = '700';
} else {
weightSlider.value = 400;
weightValue.textContent = '400';
}
// 更新锁定按钮状态 // 更新锁定按钮状态
lockBtn.classList.toggle('active', element.classList.contains('locked')); lockBtn.classList.toggle('active', element.classList.contains('locked'));
@@ -2370,22 +2381,15 @@
// 初始化文本编辑器工具栏 // 初始化文本编辑器工具栏
function initTextEditorToolbar() { function initTextEditorToolbar() {
// 加粗按钮 // 字重滑动条
boldBtn.addEventListener('click', () => { weightSlider.addEventListener('input', function() {
const targetInput = editingInput || selectedInput; var target = editingInput || selectedInput;
if (!targetInput) return; if (!target) return;
const selection = window.getSelection(); var val = parseInt(this.value);
if (selection.rangeCount > 0 && !selection.isCollapsed) { target.style.fontWeight = val;
document.execCommand('bold', false, null); weightValue.textContent = val;
} else { });
const isBold = boldBtn.classList.contains('active'); weightSlider.addEventListener('change', function() {
if (isBold) {
targetInput.style.fontWeight = 'normal';
} else {
targetInput.style.fontWeight = 'bold';
}
boldBtn.classList.toggle('active');
}
saveState(); saveState();
}); });
@@ -3669,11 +3673,11 @@
lineHeight = lineHeight * scale; lineHeight = lineHeight * scale;
} }
// 处理字体粗细 - 统一转换为标准格式 // 处理字体粗细 - 直接使用原始数值(canvas 支持 1~1000 的数值权重)
let fontWeight = style.fontWeight; var fontWeight = style.fontWeight;
// 数值转换为关键字 // 仅将 CSS 关键字映射为对应数值
if (fontWeight === '400' || fontWeight === 'normal') fontWeight = 'normal'; if (fontWeight === 'normal') fontWeight = '400';
else if (fontWeight === '700' || fontWeight === 'bold') fontWeight = 'bold'; else if (fontWeight === 'bold') fontWeight = '700';
// 获取斜体样式 // 获取斜体样式
let fontStyle = style.fontStyle; let fontStyle = style.fontStyle;