Compare commits

..
5 Commits
Author SHA1 Message Date
hz4th_coder 5f9357a182 feat: 新增表格边框样式控制功能
支持10种边框样式:
- all: 全部边框(默认)
- none: 无边框
- no-outer: 无外边线
- no-horizontal: 无横线
- no-vertical: 无竖线
- no-inner: 无内部线
- no-inner-horizontal: 无内部横线
- no-inner-vertical: 无内部竖线
- outer-only: 仅外边框
- header-only: 仅表头分隔线

前端和API均已支持
2026-07-17 13:37:43 +08:00
hz4th_coder c6b930b6d6 fix: 修复表格底部多余空白
- 去掉高度计算中多余的 borderWidth * 2
- 调整边框绘制,向内偏移半个线宽
- 边框紧贴表格内容,无额外空白
2026-07-17 13:30:26 +08:00
hz4th_coder 0e1ef77054 feat: 风格切换按钮移至图表右侧
布局调整:
- 风格按钮区域移到图表展示区右侧并排显示
- 右侧面板改为 flex 横向布局
- 风格区域固定宽度 160px,每行2个按钮
- 风格区域支持独立滚动
- 小屏幕下自动回到图表下方(响应式)
2026-07-17 13:21:52 +08:00
hz4th_coder 9f4d67a65f style: 风格切换按钮改为每行两个布局
- 使用 grid 布局,固定两列
- 按钮更宽,预览色块更清晰
- 保持右侧位置,便于快速切换
2026-07-17 13:17:56 +08:00
hz4th_coder 2f85dd5b28 feat: 新增7种简约纯色表格风格
新增风格:
- slate 石板灰:专业商务
- sky 天空蓝:清爽明亮
- rose 玫瑰红:优雅大方
- amber 琥珀黄:温暖柔和
- emerald 翡翠绿:高贵典雅
- indigo 靛蓝色:沉稳内敛
- stone 石灰白:极简现代

特点:纯色表头,简洁干净,无渐变效果
2026-07-17 13:14:47 +08:00
4 changed files with 224 additions and 49 deletions
+1
View File
@@ -673,6 +673,7 @@ function generateTable() {
theme: document.getElementById('tableTheme').value, theme: document.getElementById('tableTheme').value,
fontSize: parseInt(document.getElementById('tableFontSize').value) || 14, fontSize: parseInt(document.getElementById('tableFontSize').value) || 14,
stripeRows: document.getElementById('stripeRows').checked, stripeRows: document.getElementById('stripeRows').checked,
borderStyle: document.getElementById('borderStyle').value,
pixelRatio: 2 pixelRatio: 2
}; };
+61 -3
View File
@@ -81,6 +81,13 @@ C, 20, 30, 40</pre>
<option value="gold">金色</option> <option value="gold">金色</option>
<option value="coral">珊瑚</option> <option value="coral">珊瑚</option>
<option value="mint">薄荷</option> <option value="mint">薄荷</option>
<option value="slate">石板灰</option>
<option value="sky">天空蓝</option>
<option value="rose">玫瑰红</option>
<option value="amber">琥珀黄</option>
<option value="emerald">翡翠绿</option>
<option value="indigo">靛蓝色</option>
<option value="stone">石灰白</option>
</select> </select>
</div> </div>
@@ -123,6 +130,13 @@ C, 20, 30, 40</pre>
<option value="gold">金色</option> <option value="gold">金色</option>
<option value="coral">珊瑚</option> <option value="coral">珊瑚</option>
<option value="mint">薄荷</option> <option value="mint">薄荷</option>
<option value="slate">石板灰</option>
<option value="sky">天空蓝</option>
<option value="rose">玫瑰红</option>
<option value="amber">琥珀黄</option>
<option value="emerald">翡翠绿</option>
<option value="indigo">靛蓝色</option>
<option value="stone">石灰白</option>
</select> </select>
</div> </div>
@@ -137,6 +151,22 @@ C, 20, 30, 40</pre>
<label><input type="checkbox" id="stripeRows" checked onchange="updateTable()"> 斑马纹</label> <label><input type="checkbox" id="stripeRows" checked onchange="updateTable()"> 斑马纹</label>
</div> </div>
</div> </div>
<div class="config-group">
<label>边框样式</label>
<select id="borderStyle" onchange="updateTable()">
<option value="all">全部边框</option>
<option value="none">无边框</option>
<option value="no-outer">无外边线</option>
<option value="no-horizontal">无横线</option>
<option value="no-vertical">无竖线</option>
<option value="no-inner">无内部线</option>
<option value="no-inner-horizontal">无内部横线</option>
<option value="no-inner-vertical">无内部竖线</option>
<option value="outer-only">仅外边框</option>
<option value="header-only">仅表头分隔线</option>
</select>
</div>
</div> </div>
<!-- 系列配置区 --> <!-- 系列配置区 -->
@@ -186,7 +216,7 @@ C, 20, 30, 40</pre>
</div> </div>
</div> </div>
<!-- 右侧面板:图表预览 --> <!-- 右侧面板:图表预览 + 风格切换 -->
<div class="right-panel"> <div class="right-panel">
<div class="chart-container"> <div class="chart-container">
<div id="chartArea" class="chart-area"> <div id="chartArea" class="chart-area">
@@ -196,9 +226,9 @@ C, 20, 30, 40</pre>
</div> </div>
</div> </div>
</div> </div>
<!-- 风格快速切换按钮 --> <!-- 风格快速切换按钮(放在图表右侧) -->
<div class="theme-buttons-section"> <div class="theme-buttons-section">
<h3>🎨 快速切换风格</h3> <h3>🎨 风格</h3>
<div class="theme-buttons-grid" id="themeButtonsGrid"> <div class="theme-buttons-grid" id="themeButtonsGrid">
<button class="theme-btn" data-theme="default" onclick="quickSwitchTheme('default')"> <button class="theme-btn" data-theme="default" onclick="quickSwitchTheme('default')">
<span class="theme-preview" style="background: linear-gradient(135deg, #5470c6, #91cc75)"></span> <span class="theme-preview" style="background: linear-gradient(135deg, #5470c6, #91cc75)"></span>
@@ -260,6 +290,34 @@ C, 20, 30, 40</pre>
<span class="theme-preview" style="background: linear-gradient(135deg, #00bfa5, #80cbc4)"></span> <span class="theme-preview" style="background: linear-gradient(135deg, #00bfa5, #80cbc4)"></span>
<span class="theme-name">薄荷</span> <span class="theme-name">薄荷</span>
</button> </button>
<button class="theme-btn" data-theme="slate" onclick="quickSwitchTheme('slate')">
<span class="theme-preview" style="background: #475569"></span>
<span class="theme-name">石板灰</span>
</button>
<button class="theme-btn" data-theme="sky" onclick="quickSwitchTheme('sky')">
<span class="theme-preview" style="background: #0ea5e9"></span>
<span class="theme-name">天空蓝</span>
</button>
<button class="theme-btn" data-theme="rose" onclick="quickSwitchTheme('rose')">
<span class="theme-preview" style="background: #e11d48"></span>
<span class="theme-name">玫瑰红</span>
</button>
<button class="theme-btn" data-theme="amber" onclick="quickSwitchTheme('amber')">
<span class="theme-preview" style="background: #f59e0b"></span>
<span class="theme-name">琥珀黄</span>
</button>
<button class="theme-btn" data-theme="emerald" onclick="quickSwitchTheme('emerald')">
<span class="theme-preview" style="background: #10b981"></span>
<span class="theme-name">翡翠绿</span>
</button>
<button class="theme-btn" data-theme="indigo" onclick="quickSwitchTheme('indigo')">
<span class="theme-preview" style="background: #6366f1"></span>
<span class="theme-name">靛蓝色</span>
</button>
<button class="theme-btn" data-theme="stone" onclick="quickSwitchTheme('stone')">
<span class="theme-preview" style="background: #78716c"></span>
<span class="theme-name">石灰白</span>
</button>
</div> </div>
</div> </div>
</div> </div>
+109 -26
View File
@@ -570,6 +570,70 @@ const tableThemes = {
borderColor: '#80cbc4', borderColor: '#80cbc4',
stripeColor: '#e0f2f1', stripeColor: '#e0f2f1',
titleColor: '#004d40' titleColor: '#004d40'
},
// 简约纯色风格
slate: {
bgColor: '#ffffff',
headerBg: '#475569',
headerColor: '#ffffff',
cellColor: '#334155',
borderColor: '#cbd5e1',
stripeColor: '#f8fafc',
titleColor: '#1e293b'
},
sky: {
bgColor: '#ffffff',
headerBg: '#0ea5e9',
headerColor: '#ffffff',
cellColor: '#0c4a6e',
borderColor: '#bae6fd',
stripeColor: '#f0f9ff',
titleColor: '#0c4a6e'
},
rose: {
bgColor: '#ffffff',
headerBg: '#e11d48',
headerColor: '#ffffff',
cellColor: '#881337',
borderColor: '#fecdd3',
stripeColor: '#fff1f2',
titleColor: '#881337'
},
amber: {
bgColor: '#ffffff',
headerBg: '#f59e0b',
headerColor: '#ffffff',
cellColor: '#78350f',
borderColor: '#fde68a',
stripeColor: '#fffbeb',
titleColor: '#78350f'
},
emerald: {
bgColor: '#ffffff',
headerBg: '#10b981',
headerColor: '#ffffff',
cellColor: '#064e3b',
borderColor: '#a7f3d0',
stripeColor: '#ecfdf5',
titleColor: '#064e3b'
},
indigo: {
bgColor: '#ffffff',
headerBg: '#6366f1',
headerColor: '#ffffff',
cellColor: '#312e81',
borderColor: '#c7d2fe',
stripeColor: '#eef2ff',
titleColor: '#312e81'
},
stone: {
bgColor: '#ffffff',
headerBg: '#78716c',
headerColor: '#ffffff',
cellColor: '#44403c',
borderColor: '#d6d3d1',
stripeColor: '#fafaf9',
titleColor: '#292524'
} }
}; };
@@ -591,7 +655,8 @@ function generateTableImage(params) {
borderWidth = 1, borderWidth = 1,
stripeRows = true, stripeRows = true,
pixelRatio = 2, pixelRatio = 2,
maxWidth = 1200 maxWidth = 1200,
borderStyle = 'all' // all, none, no-outer, no-horizontal, no-vertical, no-inner, no-inner-horizontal, no-inner-vertical, outer-only, header-only
} = params; } = params;
const tableData = parseTableData(data); const tableData = parseTableData(data);
@@ -630,7 +695,7 @@ function generateTableImage(params) {
const headerHeight = fontSize * 2.5; const headerHeight = fontSize * 2.5;
const rowHeight = fontSize * 2.2; const rowHeight = fontSize * 2.2;
const titleHeight = title ? fontSize * 3 : 0; const titleHeight = title ? fontSize * 3 : 0;
const tableHeight = headerHeight + rows.length * rowHeight + borderWidth * 2; const tableHeight = headerHeight + rows.length * rowHeight;
const finalHeight = tableHeight + titleHeight; const finalHeight = tableHeight + titleHeight;
// 创建正式 canvas // 创建正式 canvas
@@ -699,34 +764,50 @@ function generateTableImage(params) {
ctx.strokeStyle = themeConfig.borderColor; ctx.strokeStyle = themeConfig.borderColor;
ctx.lineWidth = borderWidth; ctx.lineWidth = borderWidth;
// 边框样式控制
const drawOuter = !['none', 'no-outer', 'no-inner', 'no-inner-horizontal', 'no-inner-vertical', 'header-only'].includes(borderStyle);
const drawHorizontal = !['none', 'no-horizontal', 'no-inner', 'no-inner-horizontal', 'outer-only', 'header-only'].includes(borderStyle);
const drawVertical = !['none', 'no-vertical', 'no-inner', 'no-inner-vertical', 'outer-only'].includes(borderStyle);
const drawHeaderLine = !['none', 'no-horizontal', 'no-inner', 'no-inner-horizontal'].includes(borderStyle);
// 外边框 // 外边框
ctx.strokeRect(0, startY, finalWidth, tableHeight); if (drawOuter) {
const offset = borderWidth / 2;
ctx.strokeRect(offset, startY + offset, finalWidth - borderWidth, tableHeight - borderWidth);
}
// 横线 // 表头分隔线(横线
ctx.beginPath(); if (drawHeaderLine) {
ctx.moveTo(0, startY + headerHeight);
ctx.lineTo(finalWidth, startY + headerHeight);
ctx.stroke();
rows.forEach((_, rowIdx) => {
const y = startY + headerHeight + (rowIdx + 1) * rowHeight;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(0, y); ctx.moveTo(0, startY + headerHeight);
ctx.lineTo(finalWidth, y); ctx.lineTo(finalWidth, startY + headerHeight);
ctx.stroke(); ctx.stroke();
}); }
// 数据行横线
if (drawHorizontal) {
rows.forEach((_, rowIdx) => {
const y = startY + headerHeight + (rowIdx + 1) * rowHeight;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(finalWidth, y);
ctx.stroke();
});
}
// 竖线 // 竖线
x = 0; if (drawVertical) {
colWidths.forEach((width, i) => { x = 0;
if (i > 0) { colWidths.forEach((width, i) => {
ctx.beginPath(); if (i > 0) {
ctx.moveTo(x, startY); ctx.beginPath();
ctx.lineTo(x, startY + tableHeight); ctx.moveTo(x, startY);
ctx.stroke(); ctx.lineTo(x, startY + tableHeight);
} ctx.stroke();
x += width; }
}); x += width;
});
}
return canvas; return canvas;
} }
@@ -768,7 +849,8 @@ app.get('/api/table', (req, res) => {
borderWidth: parseInt(req.query.borderWidth) || 1, borderWidth: parseInt(req.query.borderWidth) || 1,
stripeRows: req.query.stripeRows !== 'false', stripeRows: req.query.stripeRows !== 'false',
pixelRatio: parseInt(req.query.pixelRatio) || 2, pixelRatio: parseInt(req.query.pixelRatio) || 2,
maxWidth: parseInt(req.query.maxWidth) || 1200 maxWidth: parseInt(req.query.maxWidth) || 1200,
borderStyle: req.query.borderStyle || 'all'
}; };
if (!params.data) { if (!params.data) {
@@ -886,7 +968,8 @@ app.get('/api/docs', (req, res) => {
borderWidth: { type: 'number', default: 1, description: '边框宽度' }, borderWidth: { type: 'number', default: 1, description: '边框宽度' },
stripeRows: { type: 'boolean', default: true, description: '是否斑马纹' }, stripeRows: { type: 'boolean', default: true, description: '是否斑马纹' },
pixelRatio: { type: 'number', default: 2, description: '像素倍率(清晰度)' }, pixelRatio: { type: 'number', default: 2, description: '像素倍率(清晰度)' },
maxWidth: { type: 'number', default: 1200, description: '最大宽度(px)' } maxWidth: { type: 'number', default: 1200, description: '最大宽度(px)' },
borderStyle: { type: 'string', default: 'all', options: ['all', 'none', 'no-outer', 'no-horizontal', 'no-vertical', 'no-inner', 'no-inner-horizontal', 'no-inner-vertical', 'outer-only', 'header-only'], description: '边框样式' }
}, },
returns: 'image/png', returns: 'image/png',
example: { example: {
+53 -20
View File
@@ -320,9 +320,14 @@ body {
.right-panel { .right-panel {
position: sticky; position: sticky;
top: 20px; top: 20px;
display: flex;
gap: 16px;
align-items: flex-start;
} }
.chart-container { .chart-container {
flex: 1;
min-width: 0;
background: var(--panel-bg); background: var(--panel-bg);
border-radius: var(--radius); border-radius: var(--radius);
padding: 20px; padding: 20px;
@@ -367,6 +372,20 @@ body {
.chart-area { .chart-area {
height: 450px; height: 450px;
} }
/* 小屏幕下风格按钮回到图表下方 */
.right-panel {
flex-direction: column;
}
.theme-buttons-section {
width: 100%;
max-height: none;
}
.theme-buttons-grid {
grid-template-columns: repeat(4, 1fr);
}
} }
/* ===== 动画 ===== */ /* ===== 动画 ===== */
@@ -458,67 +477,67 @@ input[type="range"]::-moz-range-thumb {
box-shadow: 0 2px 4px rgba(0,0,0,0.2); box-shadow: 0 2px 4px rgba(0,0,0,0.2);
} }
/* ===== 风格快速切换按钮区 ===== */ /* ===== 风格快速切换按钮区(右侧) ===== */
.theme-buttons-section { .theme-buttons-section {
margin-top: 16px; width: 160px;
flex-shrink: 0;
background: var(--panel-bg); background: var(--panel-bg);
border-radius: var(--radius); border-radius: var(--radius);
padding: 16px 20px; padding: 16px;
box-shadow: var(--shadow); box-shadow: var(--shadow);
border: 1px solid var(--border); border: 1px solid var(--border);
max-height: calc(100vh - 140px);
overflow-y: auto;
} }
.theme-buttons-section h3 { .theme-buttons-section h3 {
font-size: 0.95rem; font-size: 0.9rem;
margin-bottom: 12px; margin-bottom: 12px;
color: var(--text); color: var(--text);
display: flex; text-align: center;
align-items: center;
gap: 6px;
} }
.theme-buttons-grid { .theme-buttons-grid {
display: flex; display: grid;
flex-wrap: wrap; grid-template-columns: repeat(2, 1fr);
gap: 10px; gap: 8px;
} }
.theme-btn { .theme-btn {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 6px; gap: 4px;
padding: 8px 12px; padding: 6px 4px;
border: 2px solid var(--border); border: 2px solid var(--border);
border-radius: 10px; border-radius: 8px;
background: white; background: white;
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
min-width: 72px;
} }
.theme-btn:hover { .theme-btn:hover {
border-color: var(--primary); border-color: var(--primary);
transform: translateY(-2px); transform: translateY(-1px);
box-shadow: var(--shadow); box-shadow: var(--shadow);
} }
.theme-btn.active { .theme-btn.active {
border-color: var(--primary); border-color: var(--primary);
background: rgba(79, 70, 229, 0.05); background: rgba(79, 70, 229, 0.05);
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15); box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
} }
.theme-preview { .theme-preview {
display: block; display: block;
width: 40px; width: 32px;
height: 28px; height: 20px;
border-radius: 6px; border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
} }
.theme-name { .theme-name {
font-size: 0.75rem; font-size: 0.7rem;
color: var(--text-light); color: var(--text-light);
font-weight: 500; font-weight: 500;
} }
@@ -527,3 +546,17 @@ input[type="range"]::-moz-range-thumb {
color: var(--primary); color: var(--primary);
font-weight: 600; font-weight: 600;
} }
/* 滚动条样式 */
.theme-buttons-section::-webkit-scrollbar {
width: 4px;
}
.theme-buttons-section::-webkit-scrollbar-track {
background: transparent;
}
.theme-buttons-section::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 2px;
}