Archive the differentiated YuXinGu product docs, AI engineering system, design contract, and Go/Vue scaffold. Next execution prioritizes Cece-parity over early innovation (see .ai/product/STRATEGY.md). Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
/* 愈心谷共享壳 —— 底栏注入、高亮、二级返回 */
|
||
(function () {
|
||
var body = document.body;
|
||
if (!body) return;
|
||
|
||
var navKey = body.getAttribute('data-nav') || 'none';
|
||
var backTo = body.getAttribute('data-back') || '';
|
||
var pageTitle = body.getAttribute('data-title') || document.title || '';
|
||
var base = body.getAttribute('data-base') || '';
|
||
|
||
// 根据当前路径推断资源根:根目录页用 '',pages/ 下用 '../'
|
||
if (!base) {
|
||
base = /\/pages\//.test(location.pathname) ? '../' : '';
|
||
}
|
||
|
||
body.classList.add('app-body');
|
||
if (navKey === 'none') body.classList.add('no-nav');
|
||
|
||
function abs(path) {
|
||
if (!path) return base;
|
||
if (/^(https?:|mailto:|tel:|#)/.test(path)) return path;
|
||
return base + path.replace(/^\.\//, '');
|
||
}
|
||
|
||
// 二级顶栏
|
||
if (navKey === 'none' && (backTo || pageTitle)) {
|
||
var top = document.createElement('div');
|
||
top.className = 'app-topbar';
|
||
var backHref = abs(backTo || 'yuxingu.html');
|
||
top.innerHTML =
|
||
'<a class="back" href="' + backHref + '" aria-label="返回">←</a>' +
|
||
'<div class="title"></div>';
|
||
top.querySelector('.title').textContent = pageTitle;
|
||
body.insertBefore(top, body.firstChild);
|
||
}
|
||
|
||
// 一级底栏
|
||
if (navKey !== 'none') {
|
||
var items = [
|
||
{ key: 'home', href: 'yuxingu.html', icon: '⌂', label: '首页' },
|
||
{ key: 'know', href: 'pages/know.html', icon: '◉', label: '认识自己' },
|
||
{ key: 'scales', href: 'pages/scales.html', icon: '☰', label: '专业测评' },
|
||
{ key: 'activity', href: 'pages/activity.html', icon: '✦', label: '私域活动' },
|
||
{ key: 'health', href: 'pages/health.html', icon: '♡', label: '健康管理' },
|
||
{ key: 'mine', href: 'pages/mine.html', icon: '◍', label: '我的' }
|
||
];
|
||
var nav = document.createElement('nav');
|
||
nav.className = 'app-nav';
|
||
nav.setAttribute('aria-label', '主导航');
|
||
nav.innerHTML = items.map(function (it) {
|
||
var cls = it.key === navKey ? ' active' : '';
|
||
return (
|
||
'<a href="' + abs(it.href) + '" class="' + cls.trim() + '">' +
|
||
'<span class="ni">' + it.icon + '</span>' + it.label +
|
||
'</a>'
|
||
);
|
||
}).join('');
|
||
body.appendChild(nav);
|
||
}
|
||
})();
|