问题 - 79 个组件的 844 个颜色属性里,只有 2 个(0.2%)引用令牌, 788 个(93.4%)硬编码 hex - 后果:改令牌组件不跟着变、主题定制器对组件无效、For Agents 页写的 「所有色值必须取自 au-* 变量」形同虚设 - 这是本项目第五次「声称≠实现」,且动摇了设计系统的根本 两层令牌化(此前只改了从未被加载的文件,走了弯路) - 组件样式表 frameworks/*.css:915 处 / 78 文件 - 演示页内嵌 <style>(实际生效的样式层):287 处 / 51 文件 - 内嵌样式层是决定性的:演示页只 link colors_and_type.css + 自己的 CSS, 而多数页面把关键样式写在 <style> 块里 —— 只改 CSS 文件不生效 安全策略 - 只替换颜色属性值位置的 hex(color/background*/border*/outline*/fill/stroke) - 跳过 rgba()/渐变/url() 复合值;不动 SVG 属性与 JS 数据(色板数组) - 歧义色值按属性语义消解(#FFFFFF 作 color→text-inverse,作 background→card-bg) - 幂等,可重复运行 补齐令牌语义(71 → 74) - --au-color-text-tertiary #595959(规范未定义、实现补齐,7.00:1) - --au-color-text-disabled #BFBFBF(规范定义于组件1/2.txt;WCAG 1.4.3 豁免) - --au-color-border-strong #F0F0F0(规范未定义、实现补齐) - 同步 legacy 别名;修复 colors_and_type.css 一处重复注释起始行 修复 - Countdown 首帧空白:setInterval(render, 1000) 首次执行要等 1 秒, 期间容器为空。改为定义函数后立即执行一次再挂 interval 验证(本轮核心验收) - 逐组件验证「改令牌 → 元素是否跟着变」:79/79 全部响应 - 过程中修正两处测量方法缺陷(初测 40/79 是误报): ① 选择器 .demo * 在无 .demo 容器的页面抓不到元素 ② 探针令牌选错 —— Breadcrumb 用 text-tertiary 而只改了 text-body - CSS 结构完整:158 个文件括号平衡、var(--*) 引用全部有定义 - 回归保持 100%:961 断言 / 0 失败 / 79 页全通过,三次连跑一致
197 lines
7.7 KiB
HTML
197 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Aurora Admin · Cascader (H5)</title>
|
||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css">
|
||
<link rel="stylesheet" href="./Cascader.css">
|
||
<style>
|
||
.demo { padding: 24px; background: var(--au-color-page-bg); font-family: var(--font-family); }
|
||
h1 { font-size: 20px; margin: 0 0 4px; color: var(--au-color-text-title); }
|
||
.sub { color: var(--au-color-text-secondary); margin: 0 0 24px; font-size: 12px; }
|
||
.demo-block { background: var(--au-color-card-bg); border-radius: 8px; padding: 24px; margin-bottom: 20px; }
|
||
.demo-block > .hint { color: var(--au-color-text-secondary); font-size: 12px; margin: 0 0 12px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="demo">
|
||
<h1>Aurora Admin · Cascader 组件(纯 H5)</h1>
|
||
<p class="sub">对齐 Cascader 规范:多级下拉、搜索、路径显示、多选</p>
|
||
|
||
<div class="demo-block">
|
||
<p class="hint">单选 + 搜索</p>
|
||
<div class="aa-cascader" data-cascader data-multiple="false"></div>
|
||
</div>
|
||
|
||
<div class="demo-block">
|
||
<p class="hint">多选</p>
|
||
<div class="aa-cascader" data-cascader data-multiple="true"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
const OPTIONS = [
|
||
{ value: 'zj', label: '浙江', children: [
|
||
{ value: 'hz', label: '杭州', children: [ { value: 'xh', label: '西湖区' }, { value: 'bj', label: '滨江区' } ] },
|
||
{ value: 'wz', label: '温州', children: [ { value: 'lc', label: '鹿城区' } ] }
|
||
] },
|
||
{ value: 'js', label: '江苏', children: [
|
||
{ value: 'nj', label: '南京', children: [ { value: 'xk', label: '玄武区' } ] }
|
||
] }
|
||
];
|
||
|
||
function pathLabels(values) {
|
||
let nodes = OPTIONS, labels = [];
|
||
for (const v of values) {
|
||
const n = nodes.find(x => x.value === v);
|
||
if (!n) break;
|
||
labels.push(n.label); nodes = n.children || [];
|
||
}
|
||
return labels;
|
||
}
|
||
function findNode(values) {
|
||
let nodes = OPTIONS, node = null;
|
||
for (const v of values) {
|
||
node = nodes.find(x => x.value === v);
|
||
if (!node) return null;
|
||
nodes = node.children || [];
|
||
}
|
||
return node;
|
||
}
|
||
function flatten() {
|
||
const out = [];
|
||
(function walk(list, acc) {
|
||
list.forEach(n => {
|
||
const p = [...acc, n.value];
|
||
if (n.children && n.children.length) walk(n.children, p);
|
||
else out.push(p);
|
||
});
|
||
})(OPTIONS, []);
|
||
return out;
|
||
}
|
||
|
||
function initCascader(root) {
|
||
const multiple = root.dataset.multiple === 'true';
|
||
let open = false;
|
||
let activePath = [];
|
||
let query = '';
|
||
// single: value = 数组路径或 null ; multiple: value = 路径数组的数组
|
||
let value = multiple ? [] : null;
|
||
|
||
const trigger = document.createElement('div');
|
||
trigger.className = 'aa-cascader-trigger'; trigger.setAttribute('role','button'); trigger.setAttribute('tabindex','0'); trigger.setAttribute('aria-haspopup','listbox'); trigger.setAttribute('aria-expanded','false');
|
||
|
||
function renderTrigger() {
|
||
if (multiple) {
|
||
if (!value.length) { trigger.innerHTML = '<span class="placeholder">请选择</span><span class="caret">▾</span>'; }
|
||
else {
|
||
trigger.innerHTML = '<span class="aa-cascader-tags">' +
|
||
value.map(p => `<span class="aa-cascader-tag">${pathLabels(p).join(' / ')}</span>`).join('') +
|
||
'</span><span class="caret">▾</span>';
|
||
}
|
||
} else {
|
||
trigger.innerHTML = (value ? `<span>${pathLabels(value).join(' / ')}</span>` : '<span class="placeholder">请选择</span>') + '<span class="caret">▾</span>';
|
||
}
|
||
trigger.classList.toggle('is-open', open);
|
||
}
|
||
|
||
function renderPanel() {
|
||
let panel = root.querySelector('.aa-cascader-panel');
|
||
if (!panel) { panel = document.createElement('div'); panel.className = 'aa-cascader-panel'; root.appendChild(panel); }
|
||
if (query) {
|
||
const results = flatten().filter(p => pathLabels(p).join('/').includes(query));
|
||
panel.innerHTML = `<div class="aa-cascader-results">` +
|
||
(results.length ? results.map(p => `<div class="aa-cascader-result" data-path='${JSON.stringify(p)}'>${pathLabels(p).join(' / ')}</div>`).join('') : '<div class="aa-cascader-empty">无匹配结果</div>') +
|
||
`</div>`;
|
||
panel.querySelectorAll('.aa-cascader-result').forEach(r => {
|
||
r.addEventListener('click', () => {
|
||
const p = JSON.parse(r.dataset.path);
|
||
if (multiple) {
|
||
const s = value.map(x => JSON.stringify(x));
|
||
const k = JSON.stringify(p);
|
||
if (s.includes(k)) value = value.filter(x => JSON.stringify(x) !== k);
|
||
else value = [...value, p];
|
||
renderTrigger();
|
||
} else { value = p; open = false; renderTrigger(); renderPanel(); }
|
||
});
|
||
});
|
||
return;
|
||
}
|
||
// 列视图
|
||
let html = '';
|
||
let levelNodes = OPTIONS, path = [];
|
||
for (let lv = 0; lv <= activePath.length; lv++) {
|
||
const col = levelNodes;
|
||
html += '<div class="aa-cascader-col">';
|
||
col.forEach(n => {
|
||
const isActive = activePath[lv] === n.value;
|
||
const hasChild = n.children && n.children.length;
|
||
let box = '';
|
||
if (multiple && !hasChild) {
|
||
const sel = value.some(p => JSON.stringify(p) === JSON.stringify([...path, n.value].slice(0, [...path, n.value].length)));
|
||
const checked = value.some(p => JSON.stringify(p) === JSON.stringify([...path, n.value]));
|
||
box = `<span class="box">${checked ? '✓' : ''}</span>`;
|
||
}
|
||
html += `<div class="aa-cascader-opt ${isActive ? 'is-active' : ''}" data-lv="${lv}" data-val="${n.value}">${box}<span>${n.label}</span>${hasChild ? '<span class="arrow">›</span>' : ''}</div>`;
|
||
});
|
||
html += '</div>';
|
||
if (lv < activePath.length) {
|
||
const next = levelNodes.find(x => x.value === activePath[lv]);
|
||
path = [...path, activePath[lv]];
|
||
levelNodes = next.children || [];
|
||
} else break;
|
||
}
|
||
panel.innerHTML = html;
|
||
panel.querySelectorAll('.aa-cascader-opt').forEach(opt => {
|
||
opt.addEventListener('click', () => {
|
||
const lv = +opt.dataset.lv, val = opt.dataset.val;
|
||
const node = findNode([...activePath.slice(0, lv), val]);
|
||
const full = [...activePath.slice(0, lv), val];
|
||
if (node && node.children && node.children.length) {
|
||
activePath = full; renderPanel();
|
||
} else {
|
||
if (multiple) {
|
||
const k = JSON.stringify(full);
|
||
value = value.some(p => JSON.stringify(p) === k) ? value.filter(p => JSON.stringify(p) !== k) : [...value, full];
|
||
renderTrigger();
|
||
} else { value = full; open = false; renderTrigger(); renderPanel(); }
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
trigger.addEventListener('click', (e) => {
|
||
e.stopPropagation();
|
||
open = !open; renderTrigger(); renderPanel();
|
||
});
|
||
root.appendChild(trigger);
|
||
|
||
root.addEventListener('click', (e) => {
|
||
const q = e.target.closest('.aa-cascader-search input');
|
||
if (q) return;
|
||
});
|
||
// 搜索框(filterable)
|
||
const search = document.createElement('div');
|
||
search.className = 'aa-cascader-search';
|
||
search.style.display = 'none';
|
||
search.innerHTML = '<input placeholder="搜索"><div class="aa-cascader-results"></div>';
|
||
search.querySelector('input').addEventListener('input', (e) => { query = e.target.value; renderPanel(); });
|
||
root.appendChild(search);
|
||
|
||
trigger.addEventListener('click', () => {
|
||
search.style.display = open ? 'block' : 'none';
|
||
if (open) search.querySelector('input').focus();
|
||
});
|
||
|
||
document.addEventListener('click', (e) => {
|
||
if (!root.contains(e.target)) { open = false; query = ''; renderTrigger(); renderPanel(); search.style.display = 'none'; }
|
||
});
|
||
|
||
renderTrigger();
|
||
}
|
||
document.querySelectorAll('[data-cascader]').forEach(initCascader);
|
||
</script>
|
||
</body>
|
||
</html>
|