data-page重构评审后两项修补:①自定义页面护栏回填——重构砍掉的旧版最佳实践恰是手写页最需要的底线(骨架三件套/用户数据必转义优先textContent、innerHTML先过esc/SQL参数化+查error字段+加载错误态/大表LIMIT超2000行服务端报error),模板自带这层保护、AI自由发挥的custom.html没有,SKILL.md补为硬要求5-8并把检查清单扩成四项联动;②dashboard count模式去重复卡——metric为count时与固定「总条数」卡同值,只渲两张且省一条冗余COUNT(*) SQL,metric查询按isCount短路为null(渲染分支同守卫);另评审确认:模板/config/base.css三层职责切分成立,类覆盖无悬空,kanban-card改名接线一致,config缺失静默回退DEFAULT属可接受降级
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
/* ── 设计变量 ─────────────────────────────────────────── */
|
||||
:root {
|
||||
--bg: #f5f5f7; --surface: #fff; --border: #e8e8ed; --text: #1d1d1f;
|
||||
--text-2: #6e6e73; --accent: #0071e3; --accent-h: #0077ed; --danger: #d70015;
|
||||
--accent-2: #5ac8fa; --accent-3: #af52de;
|
||||
--ok: #34c759; --warn: #ff9f0a; --bad: #ff3b30;
|
||||
--r: 12px; --r-sm: 8px;
|
||||
--shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
--shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
|
||||
}
|
||||
|
||||
/* ── 基础 ─────────────────────────────────────────────── */
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
html, body { margin: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
|
||||
background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
padding: 16px; padding-bottom: calc(72px + env(safe-area-inset-bottom));
|
||||
}
|
||||
.container { max-width: 1200px; margin: 0 auto; }
|
||||
h1 { font-size: 20px; margin: 4px 0 20px; letter-spacing: -0.02em; }
|
||||
|
||||
/* ── 卡片 ─────────────────────────────────────────────── */
|
||||
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
|
||||
.card-pad { padding: 18px; margin-bottom: 16px; overflow: hidden; }
|
||||
.card h2 { font-size: 14px; font-weight: 600; margin: 0 0 14px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
|
||||
/* ── 按钮 ─────────────────────────────────────────────── */
|
||||
.btn { appearance: none; border: none; background: var(--accent); color: #fff; font: inherit; font-weight: 500;
|
||||
padding: 7px 14px; border-radius: 999px; cursor: pointer; transition: background .15s, transform .05s; }
|
||||
.btn:hover { background: var(--accent-h); }
|
||||
.btn:active { transform: scale(0.97); }
|
||||
|
||||
/* ── 搜索框 ───────────────────────────────────────────── */
|
||||
.search { width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: var(--r-sm);
|
||||
padding: 8px 12px; font: inherit; outline: none; transition: border-color .15s, background .15s; }
|
||||
.search:focus { border-color: var(--accent); background: var(--surface); }
|
||||
|
||||
/* ── 状态提示 ─────────────────────────────────────────── */
|
||||
.msg { text-align: center; padding: 56px 20px; color: var(--text-2); }
|
||||
.msg.err { color: var(--danger); }
|
||||
|
||||
/* ── 状态 pill ────────────────────────────────────────── */
|
||||
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px;
|
||||
font-size: 12px; background: var(--bg); color: var(--text-2); }
|
||||
.pill.ok { color: var(--ok); background: rgba(52,199,89,.12); }
|
||||
.pill.ship { color: #0a84ff; background: rgba(90,200,250,.18); }
|
||||
.pill.pay { color: var(--warn); background: rgba(255,159,10,.15); }
|
||||
.pill.refund { color: var(--bad); background: rgba(255,59,48,.12); }
|
||||
|
||||
/* ── 表格 ─────────────────────────────────────────────── */
|
||||
.tw { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { padding: 10px 18px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
||||
th { color: var(--text-2); font-weight: 500; font-size: 13px; cursor: pointer; user-select: none; }
|
||||
th:hover { color: var(--text); }
|
||||
th .ar { font-size: 10px; margin-left: 4px; opacity: .7; }
|
||||
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
td.ed { cursor: text; }
|
||||
td.ed:hover { background: rgba(0,113,227,0.04); }
|
||||
tr:last-child td { border-bottom: none; }
|
||||
.col-ac { width: 40px; }
|
||||
.del { appearance: none; background: none; border: none; color: var(--text-2); cursor: pointer;
|
||||
font-size: 18px; line-height: 1; padding: 2px 8px; border-radius: 6px; }
|
||||
.del:hover { color: var(--danger); background: rgba(215,0,21,0.08); }
|
||||
|
||||
/* ── 分页 ─────────────────────────────────────────────── */
|
||||
.pager { display: flex; align-items: center; justify-content: center; gap: 14px;
|
||||
padding: 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
|
||||
.pager button { appearance: none; border: 1px solid var(--border); background: var(--surface); font: inherit;
|
||||
padding: 5px 12px; border-radius: 999px; cursor: pointer; }
|
||||
.pager button:disabled { opacity: .4; cursor: default; }
|
||||
|
||||
/* ── 对话框表单 ───────────────────────────────────────── */
|
||||
dialog { border: none; border-radius: var(--r); padding: 0; box-shadow: var(--shadow-lg);
|
||||
width: min(420px, calc(100vw - 32px)); }
|
||||
dialog::backdrop { background: rgba(0,0,0,0.35); }
|
||||
.form { padding: 22px; }
|
||||
.form h3 { margin: 0 0 18px; font-size: 16px; }
|
||||
.fld { margin-bottom: 14px; }
|
||||
.fld label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
|
||||
.fld input, .fld select { width: 100%; border: 1px solid var(--border); border-radius: var(--r-sm);
|
||||
padding: 8px 10px; font: inherit; outline: none; transition: border-color .15s;
|
||||
background: var(--surface); color: var(--text); }
|
||||
.fld input:focus, .fld select:focus { border-color: var(--accent); }
|
||||
.acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
|
||||
.acts button { font: inherit; padding: 8px 16px; border-radius: 999px; cursor: pointer;
|
||||
border: 1px solid var(--border); background: var(--surface); color: var(--text); }
|
||||
.acts .pri { background: var(--accent); color: #fff; border-color: var(--accent); }
|
||||
.acts .pri:hover { background: var(--accent-h); }
|
||||
|
||||
/* ── 统计卡片 ─────────────────────────────────────────── */
|
||||
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
|
||||
.stat { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; }
|
||||
.stat .lbl { color: var(--text-2); font-size: 12px; margin-bottom: 4px; }
|
||||
.stat .val { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* ── 横向条 ───────────────────────────────────────────── */
|
||||
.bars { display: flex; flex-direction: column; gap: 10px; }
|
||||
.bar-row { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 12px; align-items: center; }
|
||||
.bar-row .k { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.bar-row .bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
|
||||
.bar-row .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s ease; }
|
||||
.bar-row:nth-child(3n+2) .bar > i { background: var(--accent-2); }
|
||||
.bar-row:nth-child(3n) .bar > i { background: var(--accent-3); }
|
||||
.bar-row .v { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 40px; text-align: right; }
|
||||
|
||||
/* ── 表格滚动容器 ─────────────────────────────────────── */
|
||||
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
|
||||
|
||||
/* ── 看板 ─────────────────────────────────────────────── */
|
||||
.board-outer { overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
|
||||
.board { display: flex; gap: 12px; width: fit-content; margin: 0 auto; }
|
||||
.col { flex: 0 0 260px; scroll-snap-align: start; background: var(--surface); border-radius: var(--r);
|
||||
box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: calc(100vh - 140px); }
|
||||
.col-hd { display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }
|
||||
.col-hd .n { color: var(--text-2); font-weight: 400; font-size: 12px;
|
||||
background: var(--bg); padding: 1px 8px; border-radius: 999px; }
|
||||
.col-bd { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
|
||||
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
|
||||
display: flex; flex-direction: column; gap: 8px; transition: box-shadow .15s; }
|
||||
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
|
||||
.kanban-card .t { font-size: 13px; font-weight: 500; line-height: 1.4; }
|
||||
.kanban-card .meta { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.kanban-card .meta span { font-size: 11px; color: var(--text-2); background: var(--bg); padding: 2px 7px; border-radius: 999px; }
|
||||
.kanban-card .mv { display: flex; gap: 6px; margin-top: 2px; }
|
||||
.kanban-card .mv button { appearance: none; border: 1px solid var(--border); background: var(--surface);
|
||||
color: var(--text-2); cursor: pointer; font: inherit; font-size: 12px; padding: 3px 9px;
|
||||
border-radius: 6px; transition: all .15s; }
|
||||
.kanban-card .mv button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
|
||||
.kanban-card .mv button:disabled { opacity: .3; cursor: default; }
|
||||
.col-bd .empty { text-align: center; color: var(--text-2); padding: 20px 8px; font-size: 12px; }
|
||||
|
||||
/* ── 返回应用 FAB ─────────────────────────────────────── */
|
||||
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff;
|
||||
border: none; box-shadow: 0 4px 12px rgba(0,113,227,0.3); cursor: pointer; z-index: 100;
|
||||
display: flex; align-items: center; justify-content: center; }
|
||||
.fab:hover { filter: brightness(1.08); }
|
||||
.fab:active { transform: scale(0.94); }
|
||||
|
||||
/* ── 响应式 ───────────────────────────────────────────── */
|
||||
@media (max-width: 480px) {
|
||||
body { padding: 8px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
|
||||
h1 { font-size: 18px; margin-bottom: 14px; }
|
||||
.stat .val { font-size: 20px; }
|
||||
th, td { padding: 8px 12px; font-size: 13px; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// 统计看板配置 —— 按你的表结构修改
|
||||
window.PAGE_CONFIG = {
|
||||
table: 'items',
|
||||
pk: 'id',
|
||||
title: '数据看板',
|
||||
groupBy: 'category', // 分组维度
|
||||
// 指标定义:count = 计数(默认);sum = 对某列求和
|
||||
metric: { type: 'count' },
|
||||
// metric: { type: 'sum', column: 'amount', label: '总金额' },
|
||||
detailColumns: ['name', 'category', 'qty'], // 明细表展示的列
|
||||
detailLimit: 20,
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
// 分列看板配置 —— 按你的表结构修改
|
||||
window.PAGE_CONFIG = {
|
||||
table: 'tasks',
|
||||
pk: 'id',
|
||||
title: '任务看板',
|
||||
groupField: 'status', // 用来分列的字段
|
||||
groups: ['待办', '进行中', '已完成'], // 列的显示顺序
|
||||
titleField: 'title', // 卡片主标题字段
|
||||
metaFields: ['assignee', 'due'], // 卡片上显示的次要信息
|
||||
};
|
||||
@@ -4,68 +4,20 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>数据看板</title>
|
||||
<link rel="stylesheet" href="./base.css">
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f5f5f7; --surface: #fff; --border: #e8e8ed; --text: #1d1d1f;
|
||||
--text-2: #6e6e73; --accent: #0071e3; --accent-2: #5ac8fa; --accent-3: #af52de;
|
||||
--r: 12px; --shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
}
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
html, body { margin: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
|
||||
background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
}
|
||||
.container { max-width: 1080px; margin: 0 auto; }
|
||||
h1 { font-size: 20px; margin: 4px 0 20px; letter-spacing: -0.02em; }
|
||||
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
|
||||
.stat { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; }
|
||||
.stat .lbl { color: var(--text-2); font-size: 12px; margin-bottom: 4px; }
|
||||
.stat .val { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
|
||||
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; overflow: hidden; }
|
||||
.card h2 { font-size: 14px; font-weight: 600; margin: 0 0 14px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
/* 表格可能横向溢出:滚动容器用负 margin 贴到卡片边缘,不撞破圆角 */
|
||||
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
|
||||
.bars { display: flex; flex-direction: column; gap: 10px; }
|
||||
.bar-row { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 12px; align-items: center; }
|
||||
.bar-row .k { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.bar-row .bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
|
||||
.bar-row .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s ease; }
|
||||
.bar-row:nth-child(3n+2) .bar > i { background: var(--accent-2); }
|
||||
.bar-row:nth-child(3n) .bar > i { background: var(--accent-3); }
|
||||
.bar-row .v { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-2); min-width: 40px; text-align: right; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
||||
th, td { padding: 8px 0; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
||||
th { color: var(--text-2); font-weight: 500; font-size: 12px; }
|
||||
tr:last-child td { border-bottom: none; }
|
||||
.msg { text-align: center; padding: 40px 20px; color: var(--text-2); }
|
||||
.msg.err { color: #d70015; }
|
||||
@media (max-width: 480px) {
|
||||
body { padding: 8px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
|
||||
h1 { font-size: 18px; margin-bottom: 14px; }
|
||||
.stat .val { font-size: 20px; }
|
||||
}
|
||||
/* 返回应用 FAB:固定右下、零版面占用;图标用内联 SVG 不用 ⌂ 字符(WebView 字体不保证) */
|
||||
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff;
|
||||
border: none; box-shadow: 0 4px 12px rgba(0,113,227,0.3); cursor: pointer; z-index: 100;
|
||||
display: flex; align-items: center; justify-content: center; }
|
||||
.fab:hover { filter: brightness(1.08); }
|
||||
.fab:active { transform: scale(0.94); }
|
||||
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
|
||||
.container { max-width: 1080px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 id="title">数据看板</h1>
|
||||
<div class="stats" id="stats"></div>
|
||||
<div class="card" id="chartCard">
|
||||
<div class="card card-pad">
|
||||
<h2 id="chartTitle">分布</h2>
|
||||
<div class="bars" id="bars"></div>
|
||||
</div>
|
||||
<div class="card" id="tableCard">
|
||||
<div class="card card-pad">
|
||||
<h2>明细</h2>
|
||||
<div class="table-scroll" id="table"></div>
|
||||
</div>
|
||||
@@ -75,17 +27,19 @@ body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 10.5 12 3l9 7.5"/><path d="M5 9.5V21h14V9.5"/></svg>
|
||||
</button>
|
||||
|
||||
<script src="./config-dashboard.js"></script>
|
||||
<script>
|
||||
const CONFIG = {
|
||||
table: 'items',
|
||||
pk: 'id',
|
||||
title: '数据看板',
|
||||
groupBy: 'category', // 分组维度(柱状图用)
|
||||
sumColumn: 'qty', // 求和的数值列
|
||||
sumLabel: '总量',
|
||||
detailColumns: ['name', 'category', 'qty'], // 明细表展示的列
|
||||
const DEFAULT = {
|
||||
table: 'items', pk: 'id', title: '数据看板',
|
||||
groupBy: 'category',
|
||||
metric: { type: 'count' },
|
||||
detailColumns: ['name', 'category', 'qty'],
|
||||
detailLimit: 20,
|
||||
};
|
||||
const CONFIG = Object.assign({}, DEFAULT, window.PAGE_CONFIG || {});
|
||||
if (window.PAGE_CONFIG && window.PAGE_CONFIG.metric) {
|
||||
CONFIG.metric = Object.assign({}, DEFAULT.metric, window.PAGE_CONFIG.metric);
|
||||
}
|
||||
|
||||
const API = `/api/db/${location.pathname.split('/').filter(Boolean)[1]}/query`;
|
||||
const esc = s => String(s ?? '').replace(/[&<>"']/g, c =>
|
||||
@@ -104,20 +58,24 @@ async function q(sql, params = []) {
|
||||
|
||||
async function init() {
|
||||
document.getElementById('title').textContent = CONFIG.title;
|
||||
const isCount = CONFIG.metric.type !== 'sum';
|
||||
const expr = isCount ? 'COUNT(*)' : `SUM(${CONFIG.metric.column})`;
|
||||
const metricLabel = isCount ? '总条数' : (CONFIG.metric.label || `合计 ${CONFIG.metric.column}`);
|
||||
|
||||
try {
|
||||
const [cnt, sum, group, detail] = await Promise.all([
|
||||
const [cnt, metric, group, detail] = await Promise.all([
|
||||
q(`SELECT COUNT(*) AS v FROM ${CONFIG.table}`),
|
||||
q(`SELECT SUM(${CONFIG.sumColumn}) AS v FROM ${CONFIG.table}`),
|
||||
q(`SELECT ${CONFIG.groupBy} AS k, SUM(${CONFIG.sumColumn}) AS v
|
||||
isCount ? null : q(`SELECT ${expr} AS v FROM ${CONFIG.table}`),
|
||||
q(`SELECT ${CONFIG.groupBy} AS k, ${expr} AS v
|
||||
FROM ${CONFIG.table} GROUP BY ${CONFIG.groupBy} ORDER BY v DESC LIMIT 20`),
|
||||
q(`SELECT * FROM ${CONFIG.table} LIMIT ${CONFIG.detailLimit}`),
|
||||
]);
|
||||
|
||||
document.getElementById('stats').innerHTML = `
|
||||
<div class="stat"><div class="lbl">总条数</div><div class="val">${cnt[0]?.v ?? 0}</div></div>
|
||||
<div class="stat"><div class="lbl">${esc(CONFIG.sumLabel)}</div><div class="val">${sum[0]?.v ?? 0}</div></div>
|
||||
<div class="stat"><div class="lbl">分组数</div><div class="val">${group.length}</div></div>
|
||||
`;
|
||||
// count 模式下 metric 就是总条数,不重复渲染第三张卡(也省一条同值 SQL);sum 模式才三张
|
||||
const statsCards = [`<div class="stat"><div class="lbl">总条数</div><div class="val">${cnt[0]?.v ?? 0}</div></div>`];
|
||||
if (!isCount) statsCards.push(`<div class="stat"><div class="lbl">${esc(metricLabel)}</div><div class="val">${metric[0]?.v ?? 0}</div></div>`);
|
||||
statsCards.push(`<div class="stat"><div class="lbl">分组数</div><div class="val">${group.length}</div></div>`);
|
||||
document.getElementById('stats').innerHTML = statsCards.join('');
|
||||
|
||||
document.getElementById('chartTitle').textContent = `按 ${CONFIG.groupBy} 分布`;
|
||||
const max = Math.max(...group.map(g => g.v || 0), 1);
|
||||
@@ -140,9 +98,7 @@ async function init() {
|
||||
document.getElementById('table').innerHTML = '';
|
||||
}
|
||||
}
|
||||
// 返回应用=回到发起本页的对话:主界面深链 /?s=<会话id>(数据页的 task_id 就是会话 id,
|
||||
// engine 里 1:1),前端启动时消费一次打开该会话。刻意不用 history.back():多页数据应用里
|
||||
// back 退的是上一张数据页——那是「上一页」语义,归顶部「返回导航」管。
|
||||
|
||||
function backToApp() {
|
||||
const id = location.pathname.split('/').filter(Boolean)[1];
|
||||
location.href = id ? '/?s=' + encodeURIComponent(id) : '/';
|
||||
|
||||
@@ -4,57 +4,9 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>看板</title>
|
||||
<link rel="stylesheet" href="./base.css">
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f5f5f7; --surface: #fff; --border: #e8e8ed; --text: #1d1d1f;
|
||||
--text-2: #6e6e73; --accent: #0071e3; --r: 12px; --shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
}
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
html, body { margin: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
|
||||
background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
}
|
||||
h1 { font-size: 20px; margin: 4px 0 20px; letter-spacing: -0.02em; }
|
||||
.container { max-width: 1400px; margin: 0 auto; }
|
||||
/* 外层滚、内层居中:board 用 fit-content+auto margin——列少居中、列多靠边滚动;
|
||||
若在滚动容器上直接 justify-content:center,溢出时首列会被裁掉(滚动起点落在中间)。 */
|
||||
.board-outer { overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; }
|
||||
.board { display: flex; gap: 12px; width: fit-content; margin: 0 auto; }
|
||||
.col { flex: 0 0 260px; scroll-snap-align: start; background: var(--surface); border-radius: var(--r);
|
||||
box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: calc(100vh - 140px); }
|
||||
.col-hd { display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }
|
||||
.col-hd .n { color: var(--text-2); font-weight: 400; font-size: 12px;
|
||||
background: var(--bg); padding: 1px 8px; border-radius: 999px; }
|
||||
.col-bd { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
|
||||
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
|
||||
display: flex; flex-direction: column; gap: 8px; transition: box-shadow .15s, transform .05s; }
|
||||
.card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
|
||||
.card .t { font-size: 13px; font-weight: 500; line-height: 1.4; }
|
||||
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.card .meta span { font-size: 11px; color: var(--text-2); background: var(--bg); padding: 2px 7px; border-radius: 999px; }
|
||||
.card .mv { display: flex; gap: 6px; margin-top: 2px; }
|
||||
.card .mv button { appearance: none; border: 1px solid var(--border); background: var(--surface);
|
||||
color: var(--text-2); cursor: pointer; font: inherit; font-size: 12px; padding: 3px 9px;
|
||||
border-radius: 6px; transition: all .15s; }
|
||||
.card .mv button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
|
||||
.card .mv button:disabled { opacity: .3; cursor: default; }
|
||||
.col-bd .empty { text-align: center; color: var(--text-2); padding: 20px 8px; font-size: 12px; }
|
||||
.msg { text-align: center; padding: 40px 20px; color: var(--text-2); }
|
||||
.msg.err { color: #d70015; }
|
||||
@media (max-width: 480px) { body { padding: 8px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); } h1 { font-size: 18px; margin-bottom: 14px; } }
|
||||
/* 返回应用 FAB:固定右下、零版面占用(看板列高按视口算,footer 会直接吃掉一截);
|
||||
图标用内联 SVG 不用 ⌂ 字符(WebView 字体不保证有该码位) */
|
||||
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff;
|
||||
border: none; box-shadow: 0 4px 12px rgba(0,113,227,0.3); cursor: pointer; z-index: 100;
|
||||
display: flex; align-items: center; justify-content: center; }
|
||||
.fab:hover { filter: brightness(1.08); }
|
||||
.fab:active { transform: scale(0.94); }
|
||||
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
|
||||
.container { max-width: 1400px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -67,16 +19,16 @@ body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 10.5 12 3l9 7.5"/><path d="M5 9.5V21h14V9.5"/></svg>
|
||||
</button>
|
||||
|
||||
<script src="./config-kanban.js"></script>
|
||||
<script>
|
||||
const CONFIG = {
|
||||
table: 'tasks',
|
||||
pk: 'id',
|
||||
title: '任务看板',
|
||||
groupField: 'status', // 用来分列的字段
|
||||
groups: ['待办', '进行中', '已完成'], // 列的顺序
|
||||
titleField: 'title', // 卡片主标题字段
|
||||
metaFields: ['assignee', 'due'], // 卡片上显示的次要字段
|
||||
const DEFAULT = {
|
||||
table: 'tasks', pk: 'id', title: '任务看板',
|
||||
groupField: 'status',
|
||||
groups: ['待办', '进行中', '已完成'],
|
||||
titleField: 'title',
|
||||
metaFields: ['assignee', 'due'],
|
||||
};
|
||||
const CONFIG = Object.assign({}, DEFAULT, window.PAGE_CONFIG || {});
|
||||
|
||||
const API = `/api/db/${location.pathname.split('/').filter(Boolean)[1]}/query`;
|
||||
const esc = s => String(s ?? '').replace(/[&<>"']/g, c =>
|
||||
@@ -124,7 +76,7 @@ function card(r, gi) {
|
||||
const meta = CONFIG.metaFields
|
||||
.filter(f => r[f] != null && r[f] !== '')
|
||||
.map(f => `<span>${esc(r[f])}</span>`).join('');
|
||||
return `<div class="card" data-pk="${esc(r[CONFIG.pk])}">
|
||||
return `<div class="kanban-card" data-pk="${esc(r[CONFIG.pk])}">
|
||||
<div class="t">${esc(r[CONFIG.titleField] ?? '(无标题)')}</div>
|
||||
${meta ? `<div class="meta">${meta}</div>` : ''}
|
||||
<div class="mv">
|
||||
@@ -135,7 +87,7 @@ function card(r, gi) {
|
||||
}
|
||||
|
||||
function bind() {
|
||||
document.querySelectorAll('.card').forEach(cardEl => {
|
||||
document.querySelectorAll('.kanban-card').forEach(cardEl => {
|
||||
const pk = cardEl.dataset.pk;
|
||||
cardEl.querySelectorAll('.mv button').forEach(btn => {
|
||||
btn.onclick = async () => {
|
||||
@@ -160,9 +112,6 @@ function bind() {
|
||||
});
|
||||
}
|
||||
|
||||
// 返回应用=回到发起本页的对话:主界面深链 /?s=<会话id>(数据页的 task_id 就是会话 id,
|
||||
// engine 里 1:1),前端启动时消费一次打开该会话。刻意不用 history.back():多页数据应用里
|
||||
// back 退的是上一张数据页——那是「上一页」语义,归顶部「返回导航」管。
|
||||
function backToApp() {
|
||||
const id = location.pathname.split('/').filter(Boolean)[1];
|
||||
location.href = id ? '/?s=' + encodeURIComponent(id) : '/';
|
||||
|
||||
@@ -4,82 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>数据表格</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #f5f5f7; --surface: #fff; --border: #e8e8ed; --text: #1d1d1f;
|
||||
--text-2: #6e6e73; --accent: #0071e3; --accent-h: #0077ed; --danger: #d70015;
|
||||
--r: 12px; --r-sm: 8px;
|
||||
--shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
--shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
|
||||
}
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
html, body { margin: 0; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
|
||||
background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
}
|
||||
.container { max-width: 1200px; margin: 0 auto; }
|
||||
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
|
||||
.hd { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
|
||||
.hd h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
|
||||
.btn { appearance: none; border: none; background: var(--accent); color: #fff; font: inherit; font-weight: 500;
|
||||
padding: 7px 14px; border-radius: 999px; cursor: pointer; transition: background .15s, transform .05s; }
|
||||
.btn:hover { background: var(--accent-h); }
|
||||
.btn:active { transform: scale(0.97); }
|
||||
.tb { padding: 10px 18px; border-bottom: 1px solid var(--border); }
|
||||
.search { width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: var(--r-sm);
|
||||
padding: 8px 12px; font: inherit; outline: none; transition: border-color .15s, background .15s; }
|
||||
.search:focus { border-color: var(--accent); background: var(--surface); }
|
||||
.tw { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { padding: 10px 18px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
||||
th { color: var(--text-2); font-weight: 500; font-size: 13px; cursor: pointer; user-select: none; }
|
||||
th:hover { color: var(--text); }
|
||||
th .ar { font-size: 10px; margin-left: 4px; opacity: .7; }
|
||||
td.ed { cursor: text; }
|
||||
td.ed:hover { background: rgba(0,113,227,0.04); }
|
||||
tr:last-child td { border-bottom: none; }
|
||||
.col-ac { width: 40px; }
|
||||
.del { appearance: none; background: none; border: none; color: var(--text-2); cursor: pointer;
|
||||
font-size: 18px; line-height: 1; padding: 2px 8px; border-radius: 6px; }
|
||||
.del:hover { color: var(--danger); background: rgba(215,0,21,0.08); }
|
||||
.msg { text-align: center; padding: 56px 20px; color: var(--text-2); }
|
||||
.msg.err { color: var(--danger); }
|
||||
.pager { display: flex; align-items: center; justify-content: center; gap: 14px;
|
||||
padding: 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
|
||||
.pager button { appearance: none; border: 1px solid var(--border); background: var(--surface); font: inherit;
|
||||
padding: 5px 12px; border-radius: 999px; cursor: pointer; }
|
||||
.pager button:disabled { opacity: .4; cursor: default; }
|
||||
dialog { border: none; border-radius: var(--r); padding: 0; box-shadow: var(--shadow-lg);
|
||||
width: min(420px, calc(100vw - 32px)); }
|
||||
dialog::backdrop { background: rgba(0,0,0,0.35); }
|
||||
.form { padding: 22px; }
|
||||
.form h3 { margin: 0 0 18px; font-size: 16px; }
|
||||
.fld { margin-bottom: 14px; }
|
||||
.fld label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
|
||||
.fld input { width: 100%; border: 1px solid var(--border); border-radius: var(--r-sm);
|
||||
padding: 8px 10px; font: inherit; outline: none; transition: border-color .15s; }
|
||||
.fld input:focus { border-color: var(--accent); }
|
||||
.acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
|
||||
.acts button { font: inherit; padding: 8px 16px; border-radius: 999px; cursor: pointer;
|
||||
border: 1px solid var(--border); background: var(--surface); color: var(--text); }
|
||||
.acts .pri { background: var(--accent); color: #fff; border-color: var(--accent); }
|
||||
.acts .pri:hover { background: var(--accent-h); }
|
||||
@media (max-width: 480px) {
|
||||
body { padding: 8px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); } th, td { padding: 8px 12px; font-size: 13px; }
|
||||
}
|
||||
/* 返回应用 FAB:固定右下、零版面占用(桌面优先方针下 footer 会吃掉长表/看板的垂直空间)。
|
||||
图标用内联 SVG 不用 ⌂ 字符——WebView 字体不保证有该码位,缺字即变豆腐块。 */
|
||||
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
|
||||
width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff;
|
||||
border: none; box-shadow: 0 4px 12px rgba(0,113,227,0.3); cursor: pointer; z-index: 100;
|
||||
display: flex; align-items: center; justify-content: center; }
|
||||
.fab:hover { filter: brightness(1.08); }
|
||||
.fab:active { transform: scale(0.94); }
|
||||
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
|
||||
</style>
|
||||
<link rel="stylesheet" href="./base.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@@ -110,14 +35,20 @@ body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 10.5 12 3l9 7.5"/><path d="M5 9.5V21h14V9.5"/></svg>
|
||||
</button>
|
||||
|
||||
<style>
|
||||
/* 表格页面特有样式 */
|
||||
.hd { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
|
||||
.hd h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
|
||||
.tb { padding: 10px 18px; border-bottom: 1px solid var(--border); }
|
||||
</style>
|
||||
|
||||
<script src="./config-table.js"></script>
|
||||
<script>
|
||||
const CONFIG = {
|
||||
table: 'items', // ← 修改为你的表名
|
||||
pk: 'id', // ← 修改为主键列名
|
||||
title: '数据表格', // ← 修改为页面标题
|
||||
pageSize: 10,
|
||||
editable: true,
|
||||
const DEFAULT = {
|
||||
table: 'items', pk: 'id', title: '数据表格', pageSize: 10, editable: true,
|
||||
labels: {}, numCols: [], options: {}, pills: {},
|
||||
};
|
||||
const CONFIG = Object.assign({}, DEFAULT, window.PAGE_CONFIG || {});
|
||||
|
||||
const API = `/api/db/${location.pathname.split('/').filter(Boolean)[1]}/query`;
|
||||
const S = { cols: [], rows: [], sortKey: null, sortDir: 'asc', kw: '', page: 1, loading: true, err: null };
|
||||
@@ -164,6 +95,12 @@ function view() {
|
||||
return r;
|
||||
}
|
||||
|
||||
function fmt(c, v) {
|
||||
const pm = CONFIG.pills[c];
|
||||
if (pm && v != null && pm[v]) return `<span class="pill ${pm[v]}">${esc(v)}</span>`;
|
||||
return esc(v);
|
||||
}
|
||||
|
||||
function render() {
|
||||
const root = document.getElementById('root');
|
||||
if (S.loading) return void (root.innerHTML = '<div class="msg">加载中…</div>');
|
||||
@@ -178,8 +115,10 @@ function render() {
|
||||
|
||||
let h = '<div class="tw"><table><thead><tr>';
|
||||
for (const c of S.cols) {
|
||||
const isNum = CONFIG.numCols.includes(c);
|
||||
const lb = CONFIG.labels[c] || c;
|
||||
const ar = S.sortKey === c ? (S.sortDir === 'asc' ? '↑' : '↓') : '';
|
||||
h += `<th data-c="${esc(c)}">${esc(c)}<span class="ar">${ar}</span></th>`;
|
||||
h += `<th data-c="${esc(c)}"${isNum ? ' class="num"' : ''}>${esc(lb)}<span class="ar">${ar}</span></th>`;
|
||||
}
|
||||
if (CONFIG.editable) h += '<th class="col-ac"></th>';
|
||||
h += '</tr></thead><tbody>';
|
||||
@@ -187,8 +126,10 @@ function render() {
|
||||
for (const r of cur) {
|
||||
h += `<tr data-pk="${esc(r[CONFIG.pk])}">`;
|
||||
for (const c of S.cols) {
|
||||
const ed = CONFIG.editable && c !== CONFIG.pk ? ' class="ed"' : '';
|
||||
h += `<td${ed} data-c="${esc(c)}">${esc(r[c])}</td>`;
|
||||
const cls = [];
|
||||
if (CONFIG.editable && c !== CONFIG.pk) cls.push('ed');
|
||||
if (CONFIG.numCols.includes(c)) cls.push('num');
|
||||
h += `<td${cls.length ? ` class="${cls.join(' ')}"` : ''} data-c="${esc(c)}">${fmt(c, r[c])}</td>`;
|
||||
}
|
||||
if (CONFIG.editable) h += '<td class="col-ac"><button class="del" title="删除">×</button></td>';
|
||||
h += '</tr>';
|
||||
@@ -224,9 +165,14 @@ function edit(td) {
|
||||
if (td.classList.contains('editing')) return;
|
||||
const tr = td.closest('tr'), col = td.dataset.c, pk = tr.dataset.pk, orig = td.textContent;
|
||||
td.classList.add('editing');
|
||||
td.innerHTML = `<input value="${esc(orig)}" style="width:100%;border:1px solid var(--accent);border-radius:4px;padding:2px 6px;font:inherit;outline:none">`;
|
||||
const opt = CONFIG.options[col];
|
||||
const style = 'width:100%;border:1px solid var(--accent);border-radius:4px;padding:2px 6px;font:inherit;outline:none;background:var(--surface)';
|
||||
const ctl = opt
|
||||
? `<select style="${style}">${opt.map(o => `<option${o === orig ? ' selected' : ''}>${esc(o)}</option>`).join('')}</select>`
|
||||
: `<input value="${esc(orig)}" type="${CONFIG.numCols.includes(col) ? 'number' : 'text'}" style="${style}">`;
|
||||
td.innerHTML = ctl;
|
||||
const inp = td.firstChild;
|
||||
inp.focus(); inp.select();
|
||||
inp.focus(); if (inp.select) inp.select();
|
||||
let done = false;
|
||||
const finish = async (save) => {
|
||||
if (done) return; done = true;
|
||||
@@ -235,7 +181,7 @@ function edit(td) {
|
||||
try {
|
||||
await q(`UPDATE ${CONFIG.table} SET ${col} = ? WHERE ${CONFIG.pk} = ?`, [v, pk]);
|
||||
const r = S.rows.find(x => String(x[CONFIG.pk]) === String(pk));
|
||||
if (r) r[col] = v;
|
||||
if (r) r[col] = CONFIG.numCols.includes(col) ? Number(v) : v;
|
||||
render();
|
||||
} catch (e) { alert('保存失败:' + e.message); render(); }
|
||||
};
|
||||
@@ -262,7 +208,14 @@ document.getElementById('title').textContent = CONFIG.title;
|
||||
document.getElementById('addBtn').onclick = () => {
|
||||
const dlg = document.getElementById('dlg'), flds = document.getElementById('fields');
|
||||
const cols = S.cols.filter(c => c !== CONFIG.pk);
|
||||
flds.innerHTML = cols.map(c => `<div class="fld"><label>${esc(c)}</label><input name="${esc(c)}" autocomplete="off"></div>`).join('');
|
||||
flds.innerHTML = cols.map(c => {
|
||||
const lb = CONFIG.labels[c] || c;
|
||||
const opt = CONFIG.options[c];
|
||||
const ctl = opt
|
||||
? `<select name="${esc(c)}">${opt.map(o => `<option>${esc(o)}</option>`).join('')}</select>`
|
||||
: `<input name="${esc(c)}" type="${CONFIG.numCols.includes(c) ? 'number' : 'text'}" autocomplete="off">`;
|
||||
return `<div class="fld"><label>${esc(lb)}</label>${ctl}</div>`;
|
||||
}).join('');
|
||||
dlg.showModal();
|
||||
};
|
||||
|
||||
@@ -271,7 +224,10 @@ document.getElementById('dlgForm').onsubmit = async e => {
|
||||
e.preventDefault();
|
||||
const form = e.target;
|
||||
const cols = S.cols.filter(c => c !== CONFIG.pk);
|
||||
const vals = cols.map(c => form.elements[c].value);
|
||||
const vals = cols.map(c => {
|
||||
const v = form.elements[c].value;
|
||||
return CONFIG.numCols.includes(c) && v !== '' ? Number(v) : v;
|
||||
});
|
||||
try {
|
||||
await q(`INSERT INTO ${CONFIG.table} (${cols.join(',')}) VALUES (${cols.map(() => '?').join(',')})`, vals);
|
||||
document.getElementById('dlg').close();
|
||||
@@ -279,9 +235,6 @@ document.getElementById('dlgForm').onsubmit = async e => {
|
||||
} catch (e) { alert('新增失败:' + e.message); }
|
||||
};
|
||||
|
||||
// 返回应用=回到发起本页的对话:主界面深链 /?s=<会话id>(数据页的 task_id 就是会话 id,
|
||||
// engine 里 1:1),前端启动时消费一次打开该会话。刻意不用 history.back():多页数据应用里
|
||||
// back 退的是上一张数据页——那是「上一页」语义,归顶部「返回导航」管。
|
||||
function backToApp() {
|
||||
const id = location.pathname.split('/').filter(Boolean)[1];
|
||||
location.href = id ? '/?s=' + encodeURIComponent(id) : '/';
|
||||
|
||||
Reference in New Issue
Block a user