|
|
@@ -1,6 +1,6 @@
|
|
|
/* ══════════════════════════════════════════════════════════════════
|
|
|
铭道 · 家族谱析图(三代分支版 · mfp-* = Mingdao Family Pedigree)
|
|
|
- v1.0 · 2026-10-10 · 数据源 window.MINGDAO_PEDIGREE(family-pedigree-data.js)
|
|
|
+ v1.1.6 · 2026-11-03 · 去草样占位;人卡方案·周期·效果 + 图外总表共用 API · 数据源 window.MINGDAO_PEDIGREE(family-pedigree-data.js)
|
|
|
用法:MingdaoFamilyPedigree.render(document.getElementById('xxx'), 'family-li-jing')
|
|
|
定位(vs 旧 family-tree.js 纵向清单版):
|
|
|
· 全图总览:三代横排分支结构 + SVG 直角连线(横滑查看 · 可全屏)
|
|
|
@@ -26,7 +26,10 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
warn:'linear-gradient(135deg,#D9534F,#9A3B34)',
|
|
|
sym: 'linear-gradient(135deg,#8A938E,#5F6E68)'
|
|
|
};
|
|
|
- var ST_C = { ok:'#2C6E49', warn:'#B0722B', sym:'#5F6E68' };
|
|
|
+ var ST_C = { ok:'#2C6E49', warn:'#946023', sym:'#5F6E68' };
|
|
|
+
|
|
|
+ var markerSeq = 0;
|
|
|
+ var detailCleanup = null;
|
|
|
|
|
|
var CSS = ''
|
|
|
+ '.mfp{background:var(--bg-card,#fff);border:1px solid var(--border,rgba(27,158,143,.14));border-radius:14px;padding:12px 12px 12px;margin-bottom:14px}'
|
|
|
@@ -39,43 +42,52 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
+ '.mfp-fs,.mfp-fold{font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.58rem;color:var(--primary,#1B9E8F);background:none;border:1px solid rgba(27,158,143,.35);border-radius:99px;padding:4px 10px;cursor:pointer;line-height:1}'
|
|
|
/* 全图画布 */
|
|
|
+ '.mfp-canvas{overflow-x:auto;-webkit-overflow-scrolling:touch}'
|
|
|
- + '.mfp-sheet{position:relative;width:100%;min-width:880px;max-width:960px;margin:0 auto;padding:8px 12px 12px;box-sizing:border-box}'
|
|
|
+ + '.mfp-sheet{position:relative;width:100%;min-width:940px;max-width:1000px;margin:0 auto;padding:8px 12px 12px;box-sizing:border-box}'
|
|
|
+ '.mfp-svg{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:0}'
|
|
|
+ '.mfp-gen{position:relative;z-index:1;display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px;align-items:start}'
|
|
|
+ + '.mfp-gen.g2{margin-top:72px}.mfp-gen.g3{margin-top:36px}'
|
|
|
+ '.mfp-gen.g1{display:flex;justify-content:center;gap:0}'
|
|
|
+ '.mfp-pair{display:flex;align-items:center;justify-content:center;gap:5px}'
|
|
|
+ '.mfp-slot{display:flex;justify-content:center}'
|
|
|
+ '.mfp-mate{color:var(--gold,#C9A84C);font-size:.62rem;flex-shrink:0;line-height:1}'
|
|
|
- /* 成员卡 */
|
|
|
+ /* 成员卡与三字段方案块(自然换行) */
|
|
|
+ + '.mfp-unit{display:flex;flex-direction:column;align-items:center;position:relative;z-index:1}'
|
|
|
+ + '.mfp-planblock{width:140px;max-width:100%;box-sizing:border-box;font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.7rem;font-weight:600;color:#8A5A20;background:rgba(255,251,244,.96);border:1.4px dashed rgba(201,134,43,.75);border-radius:8px;padding:5px 7px;line-height:1.5;white-space:normal;overflow-wrap:anywhere;box-shadow:0 2px 6px rgba(160,110,40,.12);margin-top:6px}'
|
|
|
+ + '.mfp-plan-line{white-space:normal}'
|
|
|
+ + '.mfp-pair>.mfp-unit,.mfp-brow>.mfp-unit{align-self:flex-start}'
|
|
|
+ + '.mfp-pair>.mfp-unit{width:140px;flex-shrink:0}'
|
|
|
+ + '.mfp-brow .mfp-planblock{width:158px}.mfp-brow.mini .mfp-planblock{width:140px}'
|
|
|
+ '.mfp-card{display:flex;align-items:center;gap:7px;background:var(--bg-warm,#F4F9F8);border:1px solid var(--border,rgba(27,158,143,.14));border-radius:11px;padding:7px 9px;width:132px;box-sizing:border-box;cursor:pointer;-webkit-tap-highlight-color:transparent}'
|
|
|
+ '.mfp-card:active{filter:brightness(.96)}'
|
|
|
- + '.mfp-av{width:32px;height:32px;border-radius:50%;color:#fff;display:flex;align-items:center;justify-content:center;font-family:var(--font-han,"Noto Serif SC",serif);font-weight:700;font-size:.85rem;flex-shrink:0;box-shadow:0 2px 5px rgba(0,0,0,.14)}'
|
|
|
+ + '.mfp-av{width:26px;height:26px;border-radius:50%;color:#fff;display:flex;align-items:center;justify-content:center;font-family:var(--font-han,"Noto Serif SC",serif);font-weight:700;font-size:.85rem;flex-shrink:0;box-shadow:0 2px 5px rgba(0,0,0,.14)}'
|
|
|
+ '.mfp-info{flex:1;min-width:0}'
|
|
|
+ '.mfp-nm{font-family:var(--font-han,"Noto Serif SC",serif);font-size:.76rem;font-weight:700;color:var(--ink,#22312B);white-space:nowrap}'
|
|
|
+ '.mfp-role{font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.5rem;font-weight:400;color:var(--ink-mute,#8A938E);margin-left:5px}'
|
|
|
- + '.mfp-note{font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.54rem;color:var(--ink-mute,#8A938E);margin-top:2px;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;line-height:1.45}'
|
|
|
- + '.mfp-st{display:inline-block;font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.52rem;font-weight:600;color:#fff;border-radius:99px;padding:1.5px 8px;margin-top:3px;white-space:nowrap}'
|
|
|
+ + '.mfp-note{font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.625rem;color:var(--ink-soft,#4A6660);margin-top:2px;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;line-height:1.45}'
|
|
|
+ + '.mfp-st{display:inline-block;font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.625rem;font-weight:600;color:#fff;border-radius:99px;padding:1.5px 8px;margin-top:3px;white-space:nowrap}'
|
|
|
+ '.mfp-score{flex-shrink:0;text-align:right}'
|
|
|
+ '.mfp-score b{font-family:var(--font-en,"Playfair Display",serif);font-size:1.02rem;font-weight:800;line-height:1;display:block}'
|
|
|
- + '.mfp-score i{font-style:normal;font-family:var(--font-en,"Playfair Display",serif);font-size:.42rem;letter-spacing:.12em;color:var(--ink-mute,#8A938E)}'
|
|
|
- /* 方案注记(虚线框) */
|
|
|
- + '.mfp-plan{display:inline-flex;font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.56rem;font-weight:600;color:#B0722B;background:rgba(255,251,244,.94);border:1.4px dashed rgba(201,134,43,.75);border-radius:8px;padding:4px 9px;white-space:nowrap;box-shadow:0 2px 6px rgba(160,110,40,.12)}'
|
|
|
- /* 方案一览条(v1.144:4 张注记改底部横排 · 防 G2 密集区压卡) */
|
|
|
- + '.mfp-plans{position:relative;z-index:1;display:flex;flex-wrap:wrap;gap:6px;justify-content:center;margin-top:10px}'
|
|
|
- /* 结论行 */
|
|
|
- + '.mfp-verdicts{position:relative;z-index:1;display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px;margin-top:20px}'
|
|
|
- + '.mfp-vd{background:linear-gradient(180deg,#FDFBF5,#F7F3E8);border:1px solid rgba(201,168,76,.4);border-radius:10px;padding:8px 10px;text-align:center}'
|
|
|
- + '.mfp-vd-t{font-family:var(--font-han,"Noto Serif SC",serif);font-size:.72rem;font-weight:700;color:#8A6D2F;letter-spacing:.06em}'
|
|
|
- + '.mfp-vd-s{font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.52rem;color:var(--ink-mute,#8A938E);margin-top:3px;line-height:1.5}'
|
|
|
+ + '.mfp-score i{font-style:normal;font-family:var(--font-en,"Playfair Display",serif);font-size:.5rem;letter-spacing:.08em;color:var(--ink-soft,#4A6660)}'
|
|
|
+ /* 独立治疗方案面板(画布外布局,手机无需横滑) */
|
|
|
+ + '.mfp-txpanel{margin-top:10px;padding:10px;border:1px dashed rgba(201,168,76,.7);border-radius:12px;background:var(--bg-warm,#F4F9F8);text-align:left;font-family:var(--font-body,"Noto Sans SC",sans-serif)}'
|
|
|
+ + '.mfp-txhead{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 12px;margin-bottom:10px}'
|
|
|
+ + '.mfp-txtitle{margin:0;font-family:var(--font-han,"Noto Serif SC",serif);font-size:.875rem;color:var(--primary,#1B9E8F);font-weight:700}'
|
|
|
+ + '.mfp-txhint{font-size:.75rem;color:var(--ink-soft,#4A6660);line-height:1.6}'
|
|
|
+ + '.mfp-txlist{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}'
|
|
|
+ + '.mfp-txcard{min-width:0;padding:10px 12px;border:1px solid var(--border,rgba(27,158,143,.14));border-radius:9px;background:var(--bg-card,#fff);break-inside:avoid}'
|
|
|
+ + '.mfp-txfields{display:grid;grid-template-columns:4em minmax(0,1fr);gap:5px 10px;margin:0;font-size:.75rem;line-height:1.6}'
|
|
|
+ + '.mfp-txfields dt{color:var(--ink-soft,#4A6660)}'
|
|
|
+ + '.mfp-txfields dd{margin:0;min-width:0;overflow-wrap:anywhere;color:var(--ink,#22312B)}'
|
|
|
+ + '.mfp-txname{font-weight:700}'
|
|
|
+ + '.mfp-branch .mfp-txlist{grid-template-columns:minmax(0,1fr)}'
|
|
|
+ + '@media(max-width:600px){.mfp-txlist{grid-template-columns:minmax(0,1fr)}.mfp-txpanel{padding:8px}.mfp-txcard{padding:10px}.mfp-txfields{font-size:.8125rem;gap:6px 8px}}'
|
|
|
+ + '@media print{.mfp-txpanel{margin-top:8px;padding:8px}.mfp-txhead{margin-bottom:6px}.mfp-txlist{grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}.mfp-txcard{padding:6px 8px}.mfp-txfields{font-size:11px;gap:2px 8px}}'
|
|
|
/* 分支视图 */
|
|
|
+ '.mfp-branch{max-width:400px;margin:0 auto;text-align:center}'
|
|
|
+ '.mfp-brow{display:flex;align-items:center;justify-content:center;gap:5px;margin:0}'
|
|
|
+ '.mfp-brow .mfp-card{width:158px}'
|
|
|
+ '.mfp-brow.mini .mfp-card{width:128px;padding:6px 8px}'
|
|
|
+ '.mfp-junction{width:2px;height:20px;margin:-2px auto -1px;background:rgba(27,158,143,.55);position:relative}' + '.mfp-junction::before{content:"";position:absolute;top:0;left:50%;transform:translateX(-50%);width:72px;height:2px;background:rgba(27,158,143,.55)}'
|
|
|
- + '.mfp-bplan{display:inline-block;font-family:var(--font-body,"Noto Sans SC",sans-serif);font-size:.58rem;font-weight:600;color:#B0722B;border:1.4px dashed rgba(201,134,43,.75);border-radius:99px;padding:3px 12px;margin:6px 0 2px;background:rgba(255,251,244,.94)}'
|
|
|
- + '.mfp-bout{background:linear-gradient(180deg,#FDFBF5,#F7F3E8);border:1px solid rgba(201,168,76,.4);border-radius:10px;padding:10px;margin-top:8px}'
|
|
|
- + '.mfp-bout .mfp-vd-t{font-size:.78rem}'
|
|
|
/* 详情抽屉 */
|
|
|
+ '.mfp-mask{position:fixed;inset:0;background:rgba(15,40,36,.45);z-index:9999;display:flex;align-items:flex-end;justify-content:center}'
|
|
|
+ '.mfp-dtl{width:100%;max-width:430px;background:var(--bg-card,#fff);border-radius:16px 16px 0 0;padding:16px 18px 22px;box-sizing:border-box;max-height:72vh;overflow-y:auto;animation:mfpUp .22s ease}'
|
|
|
@@ -90,6 +102,11 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
+ '.mfp-dv{color:var(--ink,#22312B);min-width:0}'
|
|
|
+ '.mfp-dv b{font-family:var(--font-en,"Playfair Display",serif);font-size:.95rem}'
|
|
|
+ '.mfp-empty{font-size:.62rem;color:var(--ink-mute,#8A938E);text-align:center;padding:18px 0}'
|
|
|
+ + '.mfp-card:focus-visible,.mfp button:focus-visible{outline:2px solid var(--primary,#127268);outline-offset:3px}'
|
|
|
+ + '.mfp-context{font-size:.6875rem;color:var(--ink-soft,#4A6660);line-height:1.6;margin-bottom:12px}'
|
|
|
+ + '.mfp:fullscreen{overflow:auto;background:var(--bg-card,#fff);padding:20px}'
|
|
|
+ + '@media(max-width:600px){.mfp-seg{margin-left:0}.mfp-seg button,.mfp-fs,.mfp-fold{font-size:.75rem;min-height:44px;padding:8px 12px}.mfp-sub{display:none}.mfp-planblock{font-size:.75rem}.mfp-brow .mfp-unit{flex:0 1 158px;min-width:0}.mfp-brow .mfp-card{width:100%;min-width:0}.mfp-branch .mfp-note{font-size:.75rem;-webkit-line-clamp:3}.mfp-branch .mfp-nm{font-size:.875rem}.mfp-brow.mini .mfp-unit{flex-basis:148px}.mfp-brow.mini .mfp-card{width:100%}.mfp-drow{font-size:.875rem}.mfp-dt span{font-size:.75rem}.mfp-dx{min-width:44px;min-height:44px;top:2px;right:4px}.mfp-dt{padding-right:30px}}'
|
|
|
+ + '@media print{.mfp-head button,.mfp-seg,.mfp-mask{display:none!important}.mfp-body{display:block!important}.mfp-canvas{overflow:visible}.mfp-sheet{width:940px;min-width:940px;max-width:none}.mfp{width:966px;break-inside:avoid;print-color-adjust:exact;-webkit-print-color-adjust:exact}.mfp-note{display:block;overflow:visible}.mfp-card{cursor:default}.mfp-gen.g2{margin-top:36px}.mfp-gen.g3{margin-top:16px}.mfp-context{margin-bottom:6px}.mfp-sheet{padding-top:4px;padding-bottom:4px}.mfp-note{font-size:10px!important}.mfp{padding:8px;margin-bottom:6px}}'
|
|
|
+ '@media (min-width:720px){.mfp-mask{align-items:center}.mfp-dtl{border-radius:16px;max-width:400px}}';
|
|
|
|
|
|
function injectCSS() {
|
|
|
@@ -102,48 +119,93 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
|
|
|
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); }
|
|
|
|
|
|
+ function planTargets(p) {
|
|
|
+ return Array.isArray(p.targets) ? p.targets : (typeof p.target === 'string' ? [p.target] : []);
|
|
|
+ }
|
|
|
+
|
|
|
+ function memberTreatment(m, fam) {
|
|
|
+ var plan = (fam.treatmentPlans || []).filter(function (p) {
|
|
|
+ return planTargets(p).indexOf(m.key) >= 0;
|
|
|
+ })[0];
|
|
|
+ var branch = (fam.branches || []).filter(function (b) {
|
|
|
+ return b.child === m.key || (plan && plan.branchKey === b.key);
|
|
|
+ })[0];
|
|
|
+ return {
|
|
|
+ show: m.statusType === 'warn' || m.statusType === 'sym' || !!plan,
|
|
|
+ name: (plan && (plan.short || plan.name)) || '待评估',
|
|
|
+ cycle: (plan && plan.cycle) || '—',
|
|
|
+ effect: (plan && plan.effect) || (branch && branch.outcome && branch.outcome.title) || '待评估'
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
function cardHtml(m, fam, mini) {
|
|
|
var c = bandColor(m.miss);
|
|
|
+ var treatment = memberTreatment(m, fam);
|
|
|
/* 称谓独占主行;角色/病史并入小字行(方案C式排版 · 防与右侧得分挤压) */
|
|
|
var meta = [m.role, m.note].filter(Boolean).join(' · ');
|
|
|
var metaHtml = meta ? '<div class="mfp-note">' + esc(meta) + '</div>' : '';
|
|
|
- return '<div class="mfp-card' + (mini ? ' mini' : '') + '" data-mfp="' + m.key + '">'
|
|
|
+ return '<div class="mfp-unit"><div class="mfp-card' + (mini ? ' mini' : '') + '" data-mfp="' + esc(m.key) + '" role="button" tabindex="0" aria-label="' + esc(m.label + ',' + m.role + ',查看详情') + '">'
|
|
|
+ '<div class="mfp-av" style="background:' + (AV[m.statusType] || AV.warn) + '">' + esc(m.label.charAt(0)) + '</div>'
|
|
|
+ '<div class="mfp-info"><div class="mfp-nm">' + esc(m.label) + '</div>'
|
|
|
+ metaHtml
|
|
|
+ '<span class="mfp-st" style="background:' + (ST_C[m.statusType] || ST_C.warn) + '">' + esc(m.status) + '</span></div>'
|
|
|
+ '<div class="mfp-score"><b style="color:' + c + '">' + fmtScore(m.miss) + '</b><i>' + esc(fam.scoreLabel || 'MISS') + '</i></div>'
|
|
|
+ + '</div>'
|
|
|
+ + (treatment.show ? '<div class="mfp-planblock">'
|
|
|
+ + '<div class="mfp-plan-line">方案:' + esc(treatment.name) + '</div>'
|
|
|
+ + '<div class="mfp-plan-line">周期:' + esc(treatment.cycle) + '</div>'
|
|
|
+ + '<div class="mfp-plan-line">效果:' + esc(treatment.effect) + '</div></div>' : '')
|
|
|
+ '</div>';
|
|
|
}
|
|
|
|
|
|
/* ---------- 详情抽屉 ---------- */
|
|
|
function openDetail(m, fam) {
|
|
|
+ var previousFocus = document.activeElement;
|
|
|
closeDetail();
|
|
|
var br = null;
|
|
|
(fam.branches || []).forEach(function (b) {
|
|
|
if (b.child === m.key || b.parents.indexOf(m.key) >= 0) br = b;
|
|
|
});
|
|
|
- var g1plan = (m.plan) ? m.plan : '';
|
|
|
+ var treatment = (fam.treatmentPlans || []).filter(function (p) {
|
|
|
+ return planTargets(p).indexOf(m.key) >= 0 || p.target === m.key;
|
|
|
+ })[0];
|
|
|
var rows = '';
|
|
|
rows += '<div class="mfp-drow"><div class="mfp-dk">综合得分</div><div class="mfp-dv"><b style="color:' + bandColor(m.miss) + '">' + fmtScore(m.miss) + '</b> ' + esc(fam.scoreLabel || 'MISS') + ' · ' + esc(fam.scoreHint || '') + '</div></div>';
|
|
|
rows += '<div class="mfp-drow"><div class="mfp-dk">状态</div><div class="mfp-dv">' + esc(m.status) + '</div></div>';
|
|
|
if (m.note) rows += '<div class="mfp-drow"><div class="mfp-dk">病史 / 症状</div><div class="mfp-dv">' + esc(m.note) + '</div></div>';
|
|
|
if (br) rows += '<div class="mfp-drow"><div class="mfp-dk">所属分支</div><div class="mfp-dv">' + esc(br.label) + '(' + esc(br.parents.map(function (k) { return memberByKey(fam, k).label; }).join(' + ')) + ' → ' + esc(memberByKey(fam, br.child).label) + ')</div></div>';
|
|
|
- var plan = g1plan || (br && br.plan) || '';
|
|
|
+ var plan = (treatment && treatment.name) || m.plan || (br && br.plan) || '';
|
|
|
if (plan) rows += '<div class="mfp-drow"><div class="mfp-dk">干预方案</div><div class="mfp-dv">' + esc(plan) + '</div></div>';
|
|
|
+ var fields = memberTreatment(m, fam);
|
|
|
+ if (fields.show) rows += '<div class="mfp-drow"><div class="mfp-dk">周期</div><div class="mfp-dv">' + esc(fields.cycle) + '</div></div>'
|
|
|
+ + '<div class="mfp-drow"><div class="mfp-dk">治疗后效果</div><div class="mfp-dv">' + esc(fields.effect) + '</div></div>';
|
|
|
if (br && br.child === m.key && br.outcome) rows += '<div class="mfp-drow"><div class="mfp-dk">干预结局</div><div class="mfp-dv"><b>' + esc(br.outcome.title) + '</b> · ' + esc(br.outcome.desc) + '</div></div>';
|
|
|
rows += '<div class="mfp-drow"><div class="mfp-dk">数据来源</div><div class="mfp-dv">' + esc(window.MINGDAO_PEDIGREE.source || '') + '</div></div>';
|
|
|
|
|
|
var mask = document.createElement('div');
|
|
|
mask.className = 'mfp-mask';
|
|
|
- mask.innerHTML = '<div class="mfp-dtl" style="position:relative"><button class="mfp-dx">✕</button>'
|
|
|
+ mask.innerHTML = '<div class="mfp-dtl" role="dialog" aria-modal="true" aria-label="成员健康详情" tabindex="-1" style="position:relative"><button type="button" class="mfp-dx" aria-label="关闭详情">✕</button>'
|
|
|
+ '<div class="mfp-dt"><b>' + esc(m.label) + '</b><span>' + esc(m.role) + '</span></div>'
|
|
|
+ rows + '</div>';
|
|
|
mask.addEventListener('click', function (e) { if (e.target === mask) closeDetail(); });
|
|
|
mask.querySelector('.mfp-dx').addEventListener('click', closeDetail);
|
|
|
document.body.appendChild(mask);
|
|
|
+ var previousOverflow = document.body.style.overflow;
|
|
|
+ document.body.style.overflow = 'hidden';
|
|
|
+ function onKey(e) {
|
|
|
+ if (e.key === 'Escape') closeDetail();
|
|
|
+ if (e.key === 'Tab') { e.preventDefault(); mask.querySelector('.mfp-dx').focus(); }
|
|
|
+ }
|
|
|
+ document.addEventListener('keydown', onKey);
|
|
|
+ detailCleanup = function () {
|
|
|
+ document.removeEventListener('keydown', onKey);
|
|
|
+ document.body.style.overflow = previousOverflow;
|
|
|
+ if (previousFocus && previousFocus.isConnected) previousFocus.focus();
|
|
|
+ };
|
|
|
+ mask.querySelector('.mfp-dx').focus();
|
|
|
}
|
|
|
function closeDetail() {
|
|
|
+ if (detailCleanup) { detailCleanup(); detailCleanup = null; }
|
|
|
var old = document.querySelector('.mfp-mask');
|
|
|
if (old) old.parentNode.removeChild(old);
|
|
|
}
|
|
|
@@ -155,6 +217,23 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
return { key: key, label: key, role: '', miss: 0, status: '', statusType: 'ok', note: '' };
|
|
|
}
|
|
|
|
|
|
+ /* APP 与独立页图外共用治疗方案总表 */
|
|
|
+ function treatmentPanelHtml(plans) {
|
|
|
+ if (!plans.length) return '';
|
|
|
+ return '<section class="mfp-txpanel" aria-label="本家族治疗方案">'
|
|
|
+ + '<div class="mfp-txhead"><h3 class="mfp-txtitle">本家族治疗方案</h3>'
|
|
|
+ + '</div>'
|
|
|
+ + '<div class="mfp-txlist">' + plans.map(function (p) {
|
|
|
+ return '<article class="mfp-txcard"><dl class="mfp-txfields">'
|
|
|
+ + '<dt>目标人</dt><dd>' + esc(p.targetLabel) + '</dd>'
|
|
|
+ + '<dt>方案名</dt><dd class="mfp-txname">' + esc(p.name) + '</dd>'
|
|
|
+ + '<dt>周期要点</dt><dd>' + esc(p.cycle) + '</dd>'
|
|
|
+ + '<dt>治疗后效果</dt><dd>' + esc(p.effect || '待评估') + '</dd>'
|
|
|
+ + '<dt>跟进人</dt><dd>' + esc(p.owner) + '</dd>'
|
|
|
+ + '</dl></article>';
|
|
|
+ }).join('') + '</div></section>';
|
|
|
+ }
|
|
|
+
|
|
|
/* ---------- 全图 ---------- */
|
|
|
function fullHtml(fam) {
|
|
|
var g1 = fam.generations[0], g2 = fam.generations[1], g3 = fam.generations[2];
|
|
|
@@ -179,21 +258,10 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
var g3Html = '<div class="mfp-gen g3">';
|
|
|
(fam.branches || []).forEach(function (b) { g3Html += '<div class="mfp-slot">' + cardHtml(memberByKey(fam, b.child), fam) + '</div>'; });
|
|
|
g3Html += '</div>';
|
|
|
- /* 结论行 */
|
|
|
- var vdHtml = '<div class="mfp-verdicts">';
|
|
|
- (fam.branches || []).forEach(function (b) {
|
|
|
- vdHtml += '<div class="mfp-vd"><div class="mfp-vd-t">' + esc(b.outcome.title) + '</div><div class="mfp-vd-s">' + esc(b.outcome.desc) + '</div></div>';
|
|
|
- });
|
|
|
- vdHtml += '</div>';
|
|
|
- /* 方案一览条(v1.144 · 原绝对定位压卡改底部横排) */
|
|
|
- var plHtml = '<div class="mfp-plans">';
|
|
|
- (fam.planNotes || []).forEach(function (n) { plHtml += '<span class="mfp-plan">' + esc(n.text) + '</span>'; });
|
|
|
- plHtml += '</div>';
|
|
|
-
|
|
|
var g1Html = '<div class="mfp-gen g1">' + pairRow(g1.members) + '</div>';
|
|
|
return '<div class="mfp-canvas"><div class="mfp-sheet">'
|
|
|
+ '<svg class="mfp-svg" xmlns="http://www.w3.org/2000/svg"></svg>'
|
|
|
- + g1Html + g2Html + g3Html + vdHtml + plHtml
|
|
|
+ + g1Html + g2Html + g3Html
|
|
|
+ '</div></div>';
|
|
|
}
|
|
|
|
|
|
@@ -209,30 +277,31 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
var el = sheet.querySelector('[data-mfp="' + key + '"]');
|
|
|
if (!el) return null;
|
|
|
var r = el.getBoundingClientRect();
|
|
|
- return { x: r.left - sr.left + r.width / 2, y: r.top - sr.top + r.height / 2,
|
|
|
+ var unitBottom = el.closest('.mfp-unit').getBoundingClientRect().bottom - sr.top;
|
|
|
+ return { unitBottom: unitBottom, x: r.left - sr.left + r.width / 2, y: r.top - sr.top + r.height / 2,
|
|
|
top: r.top - sr.top, bottom: r.bottom - sr.top,
|
|
|
left: r.left - sr.left, right: r.right - sr.left };
|
|
|
}
|
|
|
+ var markerId = 'mfp-ar-' + (++markerSeq);
|
|
|
var parts = [];
|
|
|
- function line(d, dashed) {
|
|
|
+ function line(d, dashed, arrow) {
|
|
|
parts.push('<path d="' + d + '" fill="none" stroke="rgba(27,158,143,.55)" stroke-width="1.6"'
|
|
|
- + (dashed ? ' stroke-dasharray="5 4"' : '') + ' stroke-linecap="round" marker-end="url(#mfp-ar)"/>');
|
|
|
+ + (dashed ? ' stroke-dasharray="5 4"' : '') + ' stroke-linecap="round"' + (arrow === false ? '' : ' marker-end="url(#' + markerId + ')"') + '/>');
|
|
|
}
|
|
|
/* 婚姻线(❖中线) */
|
|
|
(fam.couples || []).forEach(function (cp) {
|
|
|
var a = box(cp[0]), b = box(cp[1]);
|
|
|
if (!a || !b) return;
|
|
|
- line('M ' + (a.x) + ' ' + a.y + ' L ' + (b.x) + ' ' + b.y);
|
|
|
+ line('M ' + (a.x) + ' ' + a.y + ' L ' + (b.x) + ' ' + b.y, false, false);
|
|
|
});
|
|
|
/* G1 → G2:汇合横线 + 共同干 + 直角分支入亲生子女 */
|
|
|
var g1 = fam.generations[0].members;
|
|
|
var fa = box(g1[0].key), mo = box(g1[1].key);
|
|
|
var blood = fam.generations[1].members.filter(function (m) { return m.childOf; });
|
|
|
if (fa && mo && blood.length) {
|
|
|
- var sibY = Math.max(fa.bottom, mo.bottom) + 14;
|
|
|
- parts.push('<path d="M ' + fa.x + ' ' + fa.bottom + ' L ' + fa.x + ' ' + sibY + ' L ' + mo.x + ' ' + sibY + ' L ' + mo.x + ' ' + mo.bottom
|
|
|
- + '" fill="none" stroke="rgba(27,158,143,.55)" stroke-width="1.6" stroke-linecap="round"/>');
|
|
|
- var midX = (fa.x + mo.x) / 2, barY = sibY + 16;
|
|
|
+ var midX = (fa.x + mo.x) / 2;
|
|
|
+ var sibY = (fa.y + mo.y) / 2;
|
|
|
+ var barY = Math.max(fa.unitBottom, mo.unitBottom) + 24; // 横线留在 G1 三字段块下方
|
|
|
var xs = blood.map(function (m) { return box(m.key); }).filter(Boolean);
|
|
|
if (xs.length) {
|
|
|
var l = Math.min.apply(null, xs.map(function (b) { return b.x; }));
|
|
|
@@ -250,18 +319,11 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
var a = box(b.parents[0]), c = box(b.parents[1]), k = box(b.child);
|
|
|
if (!a || !c || !k) return;
|
|
|
var mx = (a.x + c.x) / 2, my = (a.y + c.y) / 2;
|
|
|
- var midY = my + (k.top - my) / 2;
|
|
|
+ var unitBottom = Math.max(a.unitBottom, c.unitBottom);
|
|
|
+ var midY = unitBottom + (k.top - unitBottom) / 2;
|
|
|
line('M ' + mx + ' ' + my + ' L ' + mx + ' ' + midY + ' L ' + k.x + ' ' + midY + ' L ' + k.x + ' ' + (k.top - 1));
|
|
|
});
|
|
|
- /* G3 → 结局(短虚线) */
|
|
|
- (fam.branches || []).forEach(function (b, i) {
|
|
|
- var k = box(b.child);
|
|
|
- var vd = sheet.querySelectorAll('.mfp-vd')[i];
|
|
|
- if (!k || !vd) return;
|
|
|
- var vr = vd.getBoundingClientRect();
|
|
|
- line('M ' + k.x + ' ' + k.bottom + ' L ' + k.x + ' ' + (vr.top - sr.top - 1), true);
|
|
|
- });
|
|
|
- svg.innerHTML = '<defs><marker id="mfp-ar" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="5.5" markerHeight="5.5" orient="auto-start-reverse">'
|
|
|
+ svg.innerHTML = '<defs><marker id="' + markerId + '" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="5.5" markerHeight="5.5" orient="auto-start-reverse">'
|
|
|
+ '<path d="M0 0 L8 4 L0 8 z" fill="rgba(27,158,143,.55)"/></marker></defs>' + parts.join('');
|
|
|
|
|
|
}
|
|
|
@@ -278,8 +340,6 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
+ '<div class="mfp-brow">' + b.parents.map(function (k) { return cardHtml(memberByKey(fam, k), fam); }).join('<span class="mfp-mate">❖</span>') + '</div>'
|
|
|
+ '<div class="mfp-junction"></div>'
|
|
|
+ '<div class="mfp-brow">' + cardHtml(child, fam) + '</div>'
|
|
|
- + (b.plan ? '<div><span class="mfp-bplan">' + esc(b.plan) + '</span></div>' : '')
|
|
|
- + '<div class="mfp-bout"><div class="mfp-vd-t">' + esc(b.outcome.title) + '</div><div class="mfp-vd-s">' + esc(b.outcome.desc) + '</div></div>'
|
|
|
+ '</div>';
|
|
|
}
|
|
|
|
|
|
@@ -293,7 +353,7 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
injectCSS();
|
|
|
closeDetail();
|
|
|
|
|
|
- var view = 'full';
|
|
|
+ var view = window.matchMedia('(max-width:600px)').matches && !document.body.classList.contains('export') ? 'mid' : 'full';
|
|
|
el.innerHTML = '<div class="mfp">'
|
|
|
+ '<div class="mfp-head"><span class="mfp-title">🌳 家族谱系 · 健康传承</span><span class="mfp-sub">' + esc(fam.nameEn || '') + '</span>'
|
|
|
+ '<span class="mfp-seg">'
|
|
|
@@ -301,21 +361,35 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
+ '</span>'
|
|
|
+ '<button class="mfp-fs">⛶ 全屏</button>'
|
|
|
+ '<button class="mfp-fold">▼ 收起</button></div>'
|
|
|
+ + '<div class="mfp-context">称谓以首代父母为参照;户主为长子。实线表示亲属关系;干预方案见人卡。</div>'
|
|
|
+ '<div class="mfp-body"></div></div>';
|
|
|
|
|
|
var root = el.querySelector('.mfp');
|
|
|
var body = el.querySelector('.mfp-body');
|
|
|
var seg = el.querySelector('.mfp-seg');
|
|
|
var sheet = null;
|
|
|
+ var ro = 'ResizeObserver' in window ? new ResizeObserver(function () { draw(sheet, fam); }) : null;
|
|
|
|
|
|
function paint() {
|
|
|
+ seg.querySelectorAll('button').forEach(function (b) {
|
|
|
+ var selected = b.getAttribute('data-v') === view;
|
|
|
+ b.classList.toggle('on', selected);
|
|
|
+ b.setAttribute('aria-pressed', String(selected));
|
|
|
+ });
|
|
|
if (view === 'full') body.innerHTML = fullHtml(fam);
|
|
|
else body.innerHTML = branchHtml(fam, view);
|
|
|
body.querySelectorAll('.mfp-card').forEach(function (c) {
|
|
|
- c.addEventListener('click', function () { openDetail(memberByKey(fam, c.getAttribute('data-mfp')), fam); });
|
|
|
+ function showDetail() { openDetail(memberByKey(fam, c.getAttribute('data-mfp')), fam); }
|
|
|
+ c.addEventListener('click', showDetail);
|
|
|
+ c.addEventListener('keydown', function (e) {
|
|
|
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); showDetail(); }
|
|
|
+ });
|
|
|
});
|
|
|
sheet = body.querySelector('.mfp-sheet');
|
|
|
- if (sheet) requestAnimationFrame(function () { draw(sheet, fam); });
|
|
|
+ if (sheet) {
|
|
|
+ if (ro) { ro.disconnect(); ro.observe(sheet); }
|
|
|
+ requestAnimationFrame(function () { draw(sheet, fam); });
|
|
|
+ }
|
|
|
}
|
|
|
paint();
|
|
|
|
|
|
@@ -335,7 +409,10 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
var open = body.style.display !== 'none';
|
|
|
body.style.display = open ? 'none' : '';
|
|
|
foldBtn.textContent = open ? '▶ 展开谱系图' : '▼ 收起';
|
|
|
+ foldBtn.setAttribute('aria-expanded', String(!open));
|
|
|
+ if (!open && sheet) requestAnimationFrame(function () { draw(sheet, fam); });
|
|
|
});
|
|
|
+ foldBtn.setAttribute('aria-expanded', String(!opts.collapsed));
|
|
|
if (opts.collapsed) { body.style.display = 'none'; foldBtn.textContent = '▶ 展开谱系图'; }
|
|
|
|
|
|
/* SPA 兼容:容器隐藏时坐标为 0 → IntersectionObserver 可见时首绘 + resize 重绘 */
|
|
|
@@ -347,9 +424,26 @@ window.MingdaoFamilyPedigree = (function () {
|
|
|
}
|
|
|
var rzT = null;
|
|
|
function onRz() { clearTimeout(rzT); rzT = setTimeout(function () { if (view === 'full' && sheet) draw(sheet, fam); }, 160); }
|
|
|
+ var screenView, screenDisplay;
|
|
|
+ window.addEventListener('beforeprint', function () {
|
|
|
+ screenView = view; screenDisplay = body.style.display;
|
|
|
+ body.style.display = 'block'; view = 'full'; paint(); draw(sheet, fam);
|
|
|
+ });
|
|
|
+ window.addEventListener('afterprint', function () {
|
|
|
+ if (screenView) { view = screenView; screenView = null; body.style.display = screenDisplay; paint(); }
|
|
|
+ });
|
|
|
+ if (document.fonts && document.fonts.ready) document.fonts.ready.then(onRz);
|
|
|
window.addEventListener('resize', onRz);
|
|
|
window.addEventListener('orientationchange', onRz);
|
|
|
}
|
|
|
|
|
|
- return { render: render };
|
|
|
+ function renderTreatmentPlans(el, familyId) {
|
|
|
+ if (!el) return;
|
|
|
+ injectCSS();
|
|
|
+ var data = window.MINGDAO_PEDIGREE;
|
|
|
+ var fam = data && data.families && data.families[familyId];
|
|
|
+ el.innerHTML = fam ? treatmentPanelHtml(fam.treatmentPlans || []) : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return { render: render, renderTreatmentPlans: renderTreatmentPlans };
|
|
|
})();
|