/*! * cy-sidebar.js · 模式感知常驻侧栏(共享组件) * ──────────────────────────────────────────────────────────────── * 用途:为独立可售模块(IC / CRS / CFSI …)提供统一的常驻左侧栏, * 一处升级、全模块生效(CLAUDE.md §2 共享 JS 杠杆点)。 * * 双模式(见 IC 设计文档 §5.1): * - 平台模式(window.CY_PLATFORM === true,由 data/cy-config.js 置位): * 渲染完整 9 分组平台导航;每个 navJumpTo 项渲染前校验 * window.CY_PAGES[target] 存在,不存在则跳过 → 死链物理隔离。 * - 独立模式(默认 · fail-safe):只渲染 品牌 + 模块名 + CTA(约演示/联系顾问), * 零跨模块链接。 * * 用法: *
← 挂载点 * CYSidebar.render({ mount: '#cy-sidebar-mount', activeKey: 'insurance', * moduleName: '保额计算器', moduleEn: 'Insurance Calculator' }); * * 依赖:navJumpTo / navAssetTab / CY_PAGES(均来自 cy-renderer.js)。 * 新增于 2026-07-11 · IC v5.0 app-shell 化 Phase 1 */ (function () { 'use strict'; // ============== 平台 9 分组导航数据(对齐 Dashboard v2.4)============== // route: 走 navJumpTo(route),渲染前校验 CY_PAGES[route] 存在 // asset: 走 navAssetTab(asset) // href: 直接跳转(PlanningOverview 等平台内页) // 无动作项:静态展示(评测总览/家族画像库等占位) var NAV_GROUPS = [ { key: 'overview', icon: '◉', label: '总览', en: 'Overview', items: [ { key: 'dashboard', icon: '◉', label: '我的看板', route: 'dashboard' } ]}, { key: 'clients', icon: '👥', label: '客户管理', en: 'Clients', items: [ { key: 'clientlist', icon: '⌂', label: '客户列表', route: 'clientlist', badge: '528' }, { key: 'clientprofile', icon: '◔', label: '客户 360 画像', route: 'clientprofile' }, { key: 'newclient', icon: '+', label: '新增客户', route: 'newclient' } ]}, { key: 'cfas', icon: '🎯', label: '测评系统', en: 'Assessment Hub', items: [ { icon: '▦', label: '评测总览' }, { key: 'cfsi', icon: '◆', label: 'CFSI 家族传承', route: 'cfsi', badge: 'Quick Scan' }, { key: 'cfpi', icon: '◇', label: 'CFPI 家族保障', route: 'cfpi' }, { key: 'insurance', icon: '🛡', label: '保额计算器', route: 'insurance' }, { key: 'crs', icon: '🌐', label: 'CRS 合规自查器', route: 'crs' }, { icon: '◈', label: 'CFHI 家族健康', dev: true, badge: '开发中' }, { icon: '⚏', label: '家族画像库' } ]}, { key: 'assets', icon: '💼', label: '资产配置', en: 'Assets', items: [ { icon: '⊞', label: '持仓总览', asset: 'holdings' }, { icon: '▤', label: '资产检视台', asset: 'inspector' }, { icon: '⛨', label: '保单检视台', asset: 'policy' }, { icon: '⌗', label: '标签工作台', asset: 'tags' }, { icon: '⇌', label: 'KYC-KYP 匹配', asset: 'match' }, { icon: '▥', label: '产品池', asset: 'catalog' } ]}, { key: 'simulators', icon: '🔮', label: '推演工具', en: 'Simulators', items: [ { key: 'letssee', icon: '📊', label: "Let's See 推演", route: 'letssee' }, { key: 'whatif', icon: '⇄', label: 'What If 场景', route: 'whatif' } ]}, { key: 'reports', icon: '📄', label: '报告中心', en: 'Reports', items: [ { icon: '▤', label: '报告模板库' }, { icon: '📄', label: '我的报告' }, { icon: '🎨', label: '主题切换' } ]}, { key: 'settings', icon: '⚙️', label: '设置', en: 'Settings', items: [ { icon: '⌥', label: '个人资料' }, { icon: '⚙', label: '系统设置' } ]} ]; function esc(s) { return String(s == null ? '' : s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } // 单个 nav-item 的 HTML(含 target 校验:route 不在 CY_PAGES 则不接 onclick 也不显示) function renderItem(it, activeKey) { // route 项:校验 CY_PAGES 存在,否则整项跳过(死链物理隔离) if (it.route) { var ok = window.CY_PAGES && window.CY_PAGES[it.route]; if (!ok) return ''; // 兄弟模块未随附 → 不渲染,杜绝死链 } var cls = 'nav-item' + (it.dev ? ' dev' : '') + (it.key && it.key === activeKey ? ' active' : ''); var onclick = ''; if (it.route && !it.dev) onclick = ' onclick="navJumpTo(\'' + it.route + '\')" style="cursor:pointer"'; else if (it.asset) onclick = ' onclick="navAssetTab(\'' + it.asset + '\')" style="cursor:pointer"'; else if (it.href) onclick = ' onclick="window.location.href=\'' + esc(it.href) + '\'" style="cursor:pointer"'; var badge = it.badge ? '' + esc(it.badge) + '' : ''; return '
' + esc(it.icon) + '' + esc(it.label) + '' + badge + '
'; } function renderPlatformNav(activeKey) { return NAV_GROUPS.map(function (g) { var itemsHtml = g.items.map(function (it) { return renderItem(it, activeKey); }).join(''); if (!itemsHtml.trim()) return ''; // 整组被过滤空则不显示 var open = g.items.some(function (it) { return it.key === activeKey; }) ? ' open' : ''; var en = g.en ? '' + esc(g.en) + '' : ''; var visCount = g.items.filter(function (it) { return !it.route || (window.CY_PAGES && window.CY_PAGES[it.route]); }).length; return ''; }).join(''); } // 独立模式:品牌 + 模块名 + CTA function renderStandalone(opts) { return '
' + '
' + '
🛡
' + '
' + esc(opts.moduleName || '保额计算器') + '' + esc(opts.moduleEn || 'Insurance Calculator') + '' + '
' + '
' + '
' + '📅 预约演示' + '💬 联系顾问' + '
' + '
Benchmark Wealth · 独立部署版
' + '
'; } function brandBlock() { var rects = ''; for (var a = 0; a < 360; a += 30) { rects += ''; } var svg = '' + '' + '' + rects + ''; return '
' + svg + '
' + '
Benchmark WealthFamily Wealth Platform
'; } // ============== 注入 CSS(含 IC 缺失变量 fallback)============== var CSS = [ '.cy-app{display:grid;grid-template-columns:240px 1fr;min-height:100vh}', '.cy-app>.cy-main{min-width:0}', // 防子元素撑破 // z-index:200 · 盖住主区 band 的 box-shadow:100vmax 全宽出血(否则色条向左溢出到侧栏);isolation 建独立层叠上下文,稳态压过 .container z-index '.sidebar{background:linear-gradient(180deg,#2C2218 0%,#0A0806 100%);border-right:1px solid rgba(201,168,76,0.15);display:flex;flex-direction:column;position:sticky;top:0;height:100vh;overflow-y:auto;z-index:200;isolation:isolate}', '.sidebar::-webkit-scrollbar{width:4px}.sidebar::-webkit-scrollbar-thumb{background:rgba(201,168,76,0.25);border-radius:3px}', '.sidebar .brand{padding:18px 20px 16px;border-bottom:1px solid rgba(201,168,76,0.2);display:flex;align-items:center;gap:10px}', '.sidebar .brand-mark{width:36px;height:36px;flex-shrink:0;display:flex;align-items:center;justify-content:center}', '.sidebar .brand-mark svg{width:100%;height:100%;display:block}', '.sidebar .brand-text{font-family:"Fraunces","Noto Serif SC",Georgia,serif!important;font-size:15px;font-weight:600;line-height:1.25;color:rgba(245,237,216,0.92);min-width:0;flex:1}', '.sidebar .brand-text .accent{display:block;font-family:"Fraunces","Noto Serif SC",Georgia,serif;font-size:8.5px;color:#D97757;text-transform:uppercase;letter-spacing:.8px;font-weight:700;margin-top:5px;white-space:nowrap}', '.sidebar .nav-section{border-top:1px solid rgba(255,255,255,0.06)}.sidebar .nav-section:first-of-type{border-top:none}', '.sidebar .nav-section-header{padding:14px 16px;display:flex;align-items:center;gap:10px;cursor:pointer;user-select:none;transition:background .15s}', '.sidebar .nav-section-header:hover{background:rgba(201,168,76,0.1)}', '.sidebar .sec-icon{width:18px;text-align:center;font-size:13px;color:rgba(201,168,76,0.7);flex-shrink:0}', '.sidebar .sec-label{flex:1;font-size:12px;color:rgba(245,237,216,0.85);font-weight:600;letter-spacing:.4px}', '.sidebar .sec-label .en{display:block;font-size:9.5px;color:rgba(245,237,216,0.35);text-transform:uppercase;letter-spacing:1.4px;font-weight:500;margin-top:1px}', '.sidebar .sec-count{font-size:10px;color:rgba(245,237,216,0.35);font-family:var(--font-mono);background:rgba(255,255,255,0.07);padding:1px 6px;border-radius:8px;margin-right:4px}', '.sidebar .caret{font-size:9px;color:rgba(245,237,216,0.3);transition:transform .2s}', '.sidebar .nav-section.open .caret{transform:rotate(90deg);color:var(--gold-3,#C9A84C)}', '.sidebar .nav-section.open .nav-section-header{background:rgba(201,168,76,0.12)}', '.sidebar .nav-section.open .sec-label{color:var(--gold-3,#C9A84C)}', '.sidebar .nav-section-body{max-height:0;overflow:hidden;transition:max-height .25s ease-out}', '.sidebar .nav-section.open .nav-section-body{max-height:600px;padding-bottom:8px}', '.sidebar .nav-item{padding:9px 18px 9px 44px;display:flex;align-items:center;gap:10px;color:rgba(245,237,216,0.55);font-size:12.5px;cursor:default;border-left:2px solid transparent;transition:all .15s;position:relative}', '.sidebar .nav-item:hover{background:rgba(201,168,76,0.1);color:rgba(245,237,216,0.9)}', '.sidebar .nav-item.active{background:rgba(201,168,76,0.16);color:#E8D5A0;border-left-color:var(--gold-3,#C9A84C);font-weight:500}', '.sidebar .nav-item .icon{width:16px;text-align:center;font-size:12px;flex-shrink:0;color:rgba(245,237,216,0.3)}', '.sidebar .nav-item.active .icon{color:var(--gold-3,#C9A84C)}', '.sidebar .nav-item .label{flex:1}', '.sidebar .nav-item .badge{font-size:10px;background:var(--gold,#9B7C3A);color:#fff;border-radius:10px;padding:1px 7px;font-family:var(--font-mono);font-weight:500}', '.sidebar .nav-item.dev{opacity:.4;cursor:not-allowed}.sidebar .nav-item.dev:hover{background:transparent;color:rgba(245,237,216,0.55)}', '.sidebar .nav-item.dev .badge{background:transparent;color:rgba(201,168,76,0.6);border:1px solid rgba(201,168,76,0.25);font-size:9px;padding:0 6px}', // 独立模式样式 '.cy-sb-standalone{display:flex;flex-direction:column;flex:1;padding:24px 20px;gap:20px}', '.cy-sb-module{display:flex;align-items:center;gap:12px;padding-bottom:18px;border-bottom:1px solid rgba(201,168,76,0.15)}', '.cy-sb-module-icon{font-size:26px}', '.cy-sb-module-name{font-family:var(--font-serif);font-size:16px;font-weight:600;color:rgba(245,237,216,0.95);line-height:1.3}', '.cy-sb-module-en{display:block;font-size:10px;color:var(--gold,#9B7C3A);font-style:italic;letter-spacing:.5px;margin-top:2px}', '.cy-sb-cta-wrap{display:flex;flex-direction:column;gap:10px;margin-top:8px}', '.cy-sb-cta{display:block;text-align:center;padding:11px 14px;border-radius:8px;font-size:13px;font-weight:600;text-decoration:none;transition:all .15s;border:1px solid rgba(201,168,76,0.3);color:rgba(245,237,216,0.85)}', '.cy-sb-cta:hover{background:rgba(201,168,76,0.12)}', '.cy-sb-cta.primary{background:linear-gradient(135deg,var(--gold-3,#C9A84C),var(--gold,#9B7C3A));color:#fff;border:none}', '.cy-sb-cta.primary:hover{filter:brightness(1.08)}', '.cy-sb-foot{margin-top:auto;font-size:10px;color:rgba(245,237,216,0.3);text-align:center;letter-spacing:.3px}', // 窄屏降级:侧栏置顶单栏 '@media(max-width:1000px){.cy-app{grid-template-columns:1fr}.sidebar{position:relative;height:auto;flex-direction:row;flex-wrap:wrap;overflow:visible}}' ].join('\n'); function injectCSS() { if (document.getElementById('cy-sidebar-css')) return; var st = document.createElement('style'); st.id = 'cy-sidebar-css'; st.textContent = CSS; document.head.appendChild(st); } // 折叠切换(避免与页面既有 toggleSection 命名冲突,用独立名) window.cySidebarToggle = function (headerEl) { var sec = headerEl && headerEl.closest ? headerEl.closest('.nav-section') : null; if (sec) sec.classList.toggle('open'); }; // ============== 主入口 ============== var CYSidebar = { render: function (opts) { opts = opts || {}; injectCSS(); var mount = typeof opts.mount === 'string' ? document.querySelector(opts.mount) : opts.mount; if (!mount) { console.warn('[cy-sidebar] 挂载点未找到:', opts.mount); return; } var isPlatform = !!window.CY_PLATFORM; var inner = isPlatform ? (brandBlock() + renderPlatformNav(opts.activeKey)) : (brandBlock() + renderStandalone(opts)); mount.className = 'sidebar'; mount.innerHTML = inner; console.log('[cy-sidebar] 渲染完成 · 模式=' + (isPlatform ? 'platform' : 'standalone') + ' · active=' + (opts.activeKey || '-')); } }; window.CYSidebar = CYSidebar; })();