Files
aurora-admin f1fbfc2ddb
Regression / regression (push) Canceled after 0s
feat(品牌标识): 几何 K 图标(favicon/顶栏标记/theme-color) + 并行会话成果入库
## 品牌标识(本次会话)

起因:品牌此前没有任何图形标识 —— 唯一 favicon 是内联 data-URI 里的字母「A」,
那是 v2.0.0「Aurora Admin → Kole UI」改名漏掉的一处(PC 顶栏也是「A」,
移动端站已是「K」;移动端文档站则完全没有 favicon)。

- 几何:24 网格三个互不接触的笔画(竖 + 两斜),圆头描边;
  描边 2.25 → 16px 标签页尺寸下正好 1.5px = 规范原文「描边1.5px」
- 取色分两套(刻意):favicon 硬编码品牌蓝/白(渲染在浏览器标签栏,不继承 kole-dark);
  顶栏标记走 currentColor(实测暗色下自动转 rgb(20,22,28))
- 新增 theme-color 双条(light #FFFFFF / dark #1C1F26,取 --kole-color-card-bg)
- 修 site/app.js hero 标语 KOLE ADMIN → KOLE UI(改名变形残留)
- 移动端 7 个模板补 favicon(此前计数 0)

验收:门禁 9 条全 OK(site-routing/site-routes/mobile-docs/mobile-site/isolation/
theme/nav/i18n/icons);PC 回归 1464/1464 · 移动端 807/807,各连跑 8 次一致;
两端 favicon 405 字节逐字节一致;PC 站控制台错误 1→0。

## 并行会话成果(本次一并入库)

- 图标系统:2576 图标(TDesign/Element Plus,MIT)+ 11 端注入 + 5 个构建门禁工具
  + IconPreview 预览页 + ICON-SPEC.md 冻结规格
- 移动端平台:47 组件 × 6 端 + 文档站 53 页 + 隔离门禁
- PC 组件:103 个大后台组件 / 组件11 批次
- uni-app:PC 端试点 + 移动端端实现 + 真实编译验证

## 工程

- .gitignore 补 .scratch/ 与 .zcode-preexisting-*.txt(会话中间产物,实测 9.1MB,不入库)
- CHANGELOG 补品牌标识条目
- ROADMAP 登 S8-P4(品牌标识任务包 + og:image/apple-touch-icon 未做部分)
2026-09-21 10:05:48 +08:00

149 lines
6.1 KiB
React
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { useState, useMemo, useRef } from 'react';
import './TreeTable.css';
/**
* Kole UI TreeTable(React)
* 对齐 组件7.txt TreeTable 规范:层级缩进16px/级、展开/折叠箭头、父级汇总(叶子合计)、选择父级联动子级
* columns: [{ key, title, align? }]
* data: 树形行 [{ key, children, ...字段 }]
* summaryColumn: 指定数值列,父级与表尾显示叶子求和
*/
function hasChildren(n) { return !!(n.children && n.children.length); }
function leafSum(node, key) {
if (!hasChildren(node)) return Number(node[key]) || 0;
return node.children.reduce((s, c) => s + leafSum(c, key), 0);
}
function leafKeys(data, rowKey) {
const out = [];
const walk = (nodes) => nodes.forEach(n => { if (hasChildren(n)) walk(n.children); else out.push(n[rowKey]); });
walk(data);
return out;
}
function descendantKeys(node, rowKey) { let o = []; (node.children || []).forEach(c => { o.push(c[rowKey]); o = o.concat(descendantKeys(c, rowKey)); }); return o; }
function allChildrenSelected(node, set, rowKey) { if (!hasChildren(node)) return set.has(node[rowKey]); return node.children.every(c => allChildrenSelected(c, set, rowKey)); }
export default function TreeTable({
columns = [],
data = [],
rowKey = 'key',
selectable = false,
selectedKeys = [],
defaultExpandedKeys = [],
summaryColumn = '',
summary = { label: '合计' },
onSelectionChange
}) {
const [expanded, setExpanded] = useState(() => new Set(defaultExpandedKeys));
const [selected, setSelected] = useState(() => new Set(selectedKeys));
const visibleList = useMemo(() => {
const out = [];
const walk = (nodes, depth) => nodes.forEach(n => {
out.push({ node: n, depth });
if (hasChildren(n) && expanded.has(n[rowKey])) walk(n.children, depth + 1);
});
walk(data, 0);
return out;
}, [data, expanded, rowKey]);
const totalOf = (key) => data.reduce((s, n) => s + leafSum(n, key), 0);
const allSelected = data.length > 0 && leafKeys(data, rowKey).every(k => selected.has(k));
const leaves = leafKeys(data, rowKey);
const nSel = leaves.filter(k => selected.has(k)).length;
const someSelected = nSel > 0 && nSel < leaves.length;
const toggleExpand = (key) => setExpanded(prev => { const n = new Set(prev); n.has(key) ? n.delete(key) : n.add(key); return n; });
const toggleCheck = (node) => {
const key = node[rowKey];
const willCheck = !selected.has(key);
const keys = [key, ...descendantKeys(node, rowKey)];
const next = new Set(selected);
keys.forEach(k => willCheck ? next.add(k) : next.delete(k));
const propagate = (nodes) => nodes.forEach(n => {
if (hasChildren(n)) { allChildrenSelected(n, next, rowKey) ? next.add(n[rowKey]) : next.delete(n[rowKey]); propagate(n.children); }
});
propagate(data);
setSelected(next);
onSelectionChange && onSelectionChange([...next]);
};
const toggleAll = () => {
const next = allSelected ? [] : leafKeys(data, rowKey);
setSelected(new Set(next));
onSelectionChange && onSelectionChange(next);
};
const onRowClick = (node) => { setSelected(new Set([node[rowKey]])); onSelectionChange && onSelectionChange([node[rowKey]]); };
const cellValue = (node, key) => (hasChildren(node) && key === summaryColumn ? leafSum(node, key) : node[key]);
return (
<div className="kole-tt">
<table>
<thead>
<tr>
{selectable && <th className="col-selection" style={{ width: 48 }}>
<input type="checkbox" className="tt-check" checked={allSelected}
ref={el => el && (el.indeterminate = someSelected)} onChange={toggleAll} />
</th>}
{columns.map(col => (
<th key={col.key} className={col.align === 'right' ? 'align-right' : ''}>{col.title}</th>
))}
</tr>
</thead>
<tbody>
{visibleList.map(({ node, depth }) => (
<tr key={node[rowKey]} className={selected.has(node[rowKey]) ? 'is-selected' : ''} onClick={() => onRowClick(node)}>
{selectable && (
<td className="col-selection">
<input type="checkbox" className="tt-check" checked={selected.has(node[rowKey])}
onClick={e => e.stopPropagation()} onChange={() => toggleCheck(node)} />
</td>
)}
{columns.map(col => (
<td key={col.key} className={col.align === 'right' ? 'align-right' : ''}>
{col.key === columns[0].key ? (
<div className="tree-cell" style={{ paddingLeft: depth * 16 }}>
{hasChildren(node) ? (
<span className={`tt-arrow${expanded.has(node[rowKey]) ? ' is-open' : ''}`} onClick={e => { e.stopPropagation(); toggleExpand(node[rowKey]); }}>▸</span>
) : <span className="tt-arrow-placeholder" />}
<span>{node[col.key]}</span>
{hasChildren(node) && summaryColumn && <span className="tt-summary">(汇总)</span>}
</div>
) : cellValue(node, col.key)}
</td>
))}
</tr>
))}
</tbody>
{summaryColumn && (
<tfoot>
<tr>
{selectable && <td />}
<td>{summary.label || '合计'}</td>
{columns.slice(1).map(col => (
<td key={col.key} className={col.align === 'right' ? 'align-right' : ''}>
{col.key === summaryColumn ? totalOf(col.key) : ''}
</td>
))}
</tr>
</tfoot>
)}
</table>
</div>
);
}
/*
用法示例:
import TreeTable from './TreeTable';
const columns = [
{ key: 'name', title: '部门/人员' },
{ key: 'count', title: '人数', align: 'right' },
{ key: 'budget', title: '预算(万)', align: 'right' }
];
const data = [{ key: 'tech', name: '技术中心', children: [{ key: 'fe', name: '前端组', count: 12, budget: 80 }] }];
<TreeTable columns={columns} data={data} selectable summaryColumn="budget" defaultExpandedKeys={['tech']} onSelectionChange={setSel} />
*/