/**
* 企业级页面渲染模块。
* 负责企业总览、企业指标分析、项目图表和项目清单弹窗,数据来源主要是 core 模块按企业派生的项目样本。
*/
function renderEnterpriseView() {
const enterprise = getEnterprise(state.enterpriseName);
const stats = getStats(enterprise);
const projects = generateProjects(enterprise, state.dimension);
const indicators = buildEnterpriseIndicatorItems(getWarningIndicators(), projects, stats);
// 新开工维度下部分企业没有项目,单独展示空态,避免图表按空数组渲染出异常坐标。
if (!stats.projectCount) {
app.innerHTML = `
当前企业在「${dimLabel()}」维度暂无数据。
`;
return;
}
app.innerHTML = `
${miniMetric("项目数量", stats.projectCount, "个", `${enterprise.name} 当前${dimLabel()}项目数量`, "enterprise-project-list")}
${miniMetric("上线率", fmtPercent(stats.onlineRate), "", "项目已建档并进入系统", "enterprise-offline-list")}
${miniMetric("使用率", fmtPercent(stats.usageRate), "", "连续三天无更新视未使用")}
${miniMetric("准确率", fmtPercent(stats.accuracyRate), "", "数据准确情况")}
${renderFocusIndicators(indicators.slice(0, 8), 0, { highlightHigh: false })}
${renderTrendChart({
online: enterprise.trend.online,
usage: enterprise.trend.usage,
accuracy: enterprise.trend.accuracy
}, 1840, 112)}
${renderProjectRateChart(projects, { height: 210 })}
企业层用于回答:本单位哪些项目未上线、哪些项目上线后未使用指标、哪些项目数据连续未更新。
${renderEnterpriseIndicatorAnalysis(indicators)}
`;
}
/**
* 企业页顶部小指标卡。
* action 不为空时会写入 data-action,事件代理据此打开项目清单或未上线项目清单弹窗。
*/
function miniMetric(label, value, unit, desc, action = "") {
return `
${label}
${value}${unit}
${desc}
`;
}
/**
* 企业项目风险表。
* 每行带 data-project,点击后切换到项目明细页;表格主要用于从企业层快速定位异常项目。
*/
function renderProjectTable(projectRiskList) {
return `
| 项目名称 |
是否上线 |
使用率 |
准确率 |
预警项 |
最近更新 |
风险 |
${projectRiskList.map(({ project }) => `
| ${project.name} |
${project.created ? '已上线' : '未上线'} |
${fmtPercent(project.usageRate)} |
${fmtPercent(project.accuracyRate)} |
${project.warningCount} |
${project.lastUpdate} |
${riskPill(project.risk)} |
`).join("")}
`;
}
/**
* 企业项目清单弹窗。
* type=offline 时只展示未建档/未上线项目;其他情况展示当前维度下所有生成项目。
*/
function renderEnterpriseProjectListModal(type) {
const enterprise = getEnterprise(state.enterpriseName);
const projects = generateProjects(enterprise, state.dimension);
const rows = type === "offline"
? projects.filter((project) => !project.created)
: projects;
const title = type === "offline" ? "未上线项目清单" : "所有项目清单";
const emptyText = type === "offline" ? "当前企业暂无未上线项目。" : "当前企业暂无项目。";
if (!rows.length) {
return `
`;
}
return `
| 项目名称 |
是否上线 |
使用率 |
准确率 |
预警项 |
最近更新 |
责任人 |
风险 |
${rows.map((project) => `
| ${project.name} |
${project.created ? '已上线' : '未上线'} |
${fmtPercent(project.usageRate)} |
${fmtPercent(project.accuracyRate)} |
${project.warningCount} |
${project.lastUpdate} |
${project.owner} |
${riskPill(project.risk)} |
`).join("")}
`;
}