Compare commits

..
7 Commits
Author SHA1 Message Date
hz4th_coder 79a1ca36c5 feat: 添加 keepalive 保活脚本 + cron 定时检查
- 每5分钟检查服务是否运行
- 自动杀掉占用端口的非 node 进程(如 Python http.server)
- 自动重启 node 服务
2026-07-24 17:34:02 +08:00
hz4th_coder a6c8de5820 fix: 修复表格模式无法显示的问题
1. 修复 registerFont API 调用 - @napi-rs/canvas 使用 GlobalFonts.registerFromPath 而非 registerFont
2. 确保 Express 服务端正确启动(之前误用 Python http.server 导致 POST 请求返回 501)
2026-07-24 16:17:32 +08:00
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
5 changed files with 273 additions and 51 deletions
+1
View File
@@ -673,6 +673,7 @@ function generateTable() {
theme: document.getElementById('tableTheme').value,
fontSize: parseInt(document.getElementById('tableFontSize').value) || 14,
stripeRows: document.getElementById('stripeRows').checked,
borderStyle: document.getElementById('borderStyle').value,
pixelRatio: 2
};
+61 -3
View File
@@ -81,6 +81,13 @@ C, 20, 30, 40</pre>
<option value="gold">金色</option>
<option value="coral">珊瑚</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>
</div>
@@ -123,6 +130,13 @@ C, 20, 30, 40</pre>
<option value="gold">金色</option>
<option value="coral">珊瑚</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>
</div>
@@ -137,6 +151,22 @@ C, 20, 30, 40</pre>
<label><input type="checkbox" id="stripeRows" checked onchange="updateTable()"> 斑马纹</label>
</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>
<!-- 系列配置区 -->
@@ -186,7 +216,7 @@ C, 20, 30, 40</pre>
</div>
</div>
<!-- 右侧面板:图表预览 -->
<!-- 右侧面板:图表预览 + 风格切换 -->
<div class="right-panel">
<div class="chart-container">
<div id="chartArea" class="chart-area">
@@ -196,9 +226,9 @@ C, 20, 30, 40</pre>
</div>
</div>
</div>
<!-- 风格快速切换按钮 -->
<!-- 风格快速切换按钮(放在图表右侧) -->
<div class="theme-buttons-section">
<h3>🎨 快速切换风格</h3>
<h3>🎨 风格</h3>
<div class="theme-buttons-grid" id="themeButtonsGrid">
<button class="theme-btn" data-theme="default" onclick="quickSwitchTheme('default')">
<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-name">薄荷</span>
</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>
Executable
+45
View File
@@ -0,0 +1,45 @@
#!/bash
# data-chart-tool 保活脚本
# 检查服务是否运行,如果没有则启动
PORT=16016
APP_DIR="/home/openclaw/.openclaw/workspace-hz4th_coder/works/data-chart-tool"
LOG_FILE="$APP_DIR/logs/server.log"
# 检查端口是否被占用
if ss -tlnp | grep -q ":$PORT "; then
# 检查是不是 node 进程
PID=$(ss -tlnp | grep ":$PORT " | grep -oP 'pid=\K[0-9]+' | head -1)
if [ -n "$PID" ]; then
CMD=$(ps -p "$PID" -o comm= 2>/dev/null)
if [ "$CMD" = "node" ] || [ "$CMD" = "MainThread" ]; then
# node 服务在运行,检查是否正常响应
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$PORT/api/health 2>/dev/null)
if [ "$HTTP_CODE" = "200" ]; then
echo "[$(date)] Service OK (PID=$PID, HTTP=$HTTP_CODE)"
exit 0
fi
fi
# 端口被非 node 进程占用(如 Python http.server),杀掉它
echo "[$(date)] Port $PORT occupied by $CMD (PID=$PID), killing..."
kill -9 "$PID" 2>/dev/null
sleep 1
fi
fi
# 启动 node 服务
echo "[$(date)] Starting data-chart-tool..."
cd "$APP_DIR"
nohup node server.js >> "$LOG_FILE" 2>&1 &
echo "[$(date)] Started with PID $!"
# 等待启动
sleep 2
# 验证
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$PORT/api/health 2>/dev/null)
if [ "$HTTP_CODE" = "200" ]; then
echo "[$(date)] Service started successfully (HTTP=$HTTP_CODE)"
else
echo "[$(date)] WARNING: Service may not have started correctly (HTTP=$HTTP_CODE)"
fi
+113 -28
View File
@@ -6,8 +6,10 @@ const path = require('path');
// 注册中文字体
try {
registerFont('/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', { family: 'Noto Sans CJK SC' });
registerFont('/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', { family: 'Noto Sans CJK SC', weight: 'bold' });
const { GlobalFonts } = require('@napi-rs/canvas');
GlobalFonts.registerFromPath('/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', 'Noto Sans CJK SC');
GlobalFonts.registerFromPath('/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', 'Noto Sans CJK SC');
console.log('中文字体注册成功');
} catch (e) {
console.warn('中文字体注册失败,将使用系统默认字体:', e.message);
}
@@ -570,6 +572,70 @@ const tableThemes = {
borderColor: '#80cbc4',
stripeColor: '#e0f2f1',
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 +657,8 @@ function generateTableImage(params) {
borderWidth = 1,
stripeRows = true,
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;
const tableData = parseTableData(data);
@@ -630,7 +697,7 @@ function generateTableImage(params) {
const headerHeight = fontSize * 2.5;
const rowHeight = fontSize * 2.2;
const titleHeight = title ? fontSize * 3 : 0;
const tableHeight = headerHeight + rows.length * rowHeight + borderWidth * 2;
const tableHeight = headerHeight + rows.length * rowHeight;
const finalHeight = tableHeight + titleHeight;
// 创建正式 canvas
@@ -699,34 +766,50 @@ function generateTableImage(params) {
ctx.strokeStyle = themeConfig.borderColor;
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();
ctx.moveTo(0, startY + headerHeight);
ctx.lineTo(finalWidth, startY + headerHeight);
ctx.stroke();
rows.forEach((_, rowIdx) => {
const y = startY + headerHeight + (rowIdx + 1) * rowHeight;
// 表头分隔线(横线
if (drawHeaderLine) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(finalWidth, y);
ctx.moveTo(0, startY + headerHeight);
ctx.lineTo(finalWidth, startY + headerHeight);
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;
colWidths.forEach((width, i) => {
if (i > 0) {
ctx.beginPath();
ctx.moveTo(x, startY);
ctx.lineTo(x, startY + tableHeight);
ctx.stroke();
}
x += width;
});
if (drawVertical) {
x = 0;
colWidths.forEach((width, i) => {
if (i > 0) {
ctx.beginPath();
ctx.moveTo(x, startY);
ctx.lineTo(x, startY + tableHeight);
ctx.stroke();
}
x += width;
});
}
return canvas;
}
@@ -768,7 +851,8 @@ app.get('/api/table', (req, res) => {
borderWidth: parseInt(req.query.borderWidth) || 1,
stripeRows: req.query.stripeRows !== 'false',
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) {
@@ -886,7 +970,8 @@ app.get('/api/docs', (req, res) => {
borderWidth: { type: 'number', default: 1, description: '边框宽度' },
stripeRows: { type: 'boolean', default: true, 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',
example: {
+53 -20
View File
@@ -320,9 +320,14 @@ body {
.right-panel {
position: sticky;
top: 20px;
display: flex;
gap: 16px;
align-items: flex-start;
}
.chart-container {
flex: 1;
min-width: 0;
background: var(--panel-bg);
border-radius: var(--radius);
padding: 20px;
@@ -367,6 +372,20 @@ body {
.chart-area {
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);
}
/* ===== 风格快速切换按钮区 ===== */
/* ===== 风格快速切换按钮区(右侧) ===== */
.theme-buttons-section {
margin-top: 16px;
width: 160px;
flex-shrink: 0;
background: var(--panel-bg);
border-radius: var(--radius);
padding: 16px 20px;
padding: 16px;
box-shadow: var(--shadow);
border: 1px solid var(--border);
max-height: calc(100vh - 140px);
overflow-y: auto;
}
.theme-buttons-section h3 {
font-size: 0.95rem;
font-size: 0.9rem;
margin-bottom: 12px;
color: var(--text);
display: flex;
align-items: center;
gap: 6px;
text-align: center;
}
.theme-buttons-grid {
display: flex;
flex-wrap: wrap;
gap: 10px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
}
.theme-btn {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
padding: 8px 12px;
gap: 4px;
padding: 6px 4px;
border: 2px solid var(--border);
border-radius: 10px;
border-radius: 8px;
background: white;
cursor: pointer;
transition: all 0.2s;
min-width: 72px;
}
.theme-btn:hover {
border-color: var(--primary);
transform: translateY(-2px);
transform: translateY(-1px);
box-shadow: var(--shadow);
}
.theme-btn.active {
border-color: var(--primary);
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 {
display: block;
width: 40px;
height: 28px;
border-radius: 6px;
width: 32px;
height: 20px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
}
.theme-name {
font-size: 0.75rem;
font-size: 0.7rem;
color: var(--text-light);
font-weight: 500;
}
@@ -527,3 +546,17 @@ input[type="range"]::-moz-range-thumb {
color: var(--primary);
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;
}