|
@@ -11,6 +11,7 @@ import { toWorkOrder, toWorkOrderTimeline, workOrderStateName } from './workOrde
|
|
|
import { trackOf } from './workOrderTimeline.js'
|
|
import { trackOf } from './workOrderTimeline.js'
|
|
|
import { facilityStatusTone } from './facilityStatus.js'
|
|
import { facilityStatusTone } from './facilityStatus.js'
|
|
|
import { pumpStationTypeText } from './facilityTypeDict.js'
|
|
import { pumpStationTypeText } from './facilityTypeDict.js'
|
|
|
|
|
+import { DICT_TYPES, dictLabel } from './dictLabels.js'
|
|
|
export { facilityStatusTone } from './facilityStatus.js'
|
|
export { facilityStatusTone } from './facilityStatus.js'
|
|
|
|
|
|
|
|
export const ENTITY_DETAIL_KIND = Object.freeze({
|
|
export const ENTITY_DETAIL_KIND = Object.freeze({
|
|
@@ -101,6 +102,8 @@ export function entityDetailView(detail) {
|
|
|
subtitle: current.subtitle || assetSubtitle(current.kindLabel, current.displayCode),
|
|
subtitle: current.subtitle || assetSubtitle(current.kindLabel, current.displayCode),
|
|
|
tone: current.tone || 'neutral',
|
|
tone: current.tone || 'neutral',
|
|
|
status: current.statusText || '',
|
|
status: current.statusText || '',
|
|
|
|
|
+ // 徽标的抬头:防护目标写「风险等级」,其它对象的状态不加抬头。
|
|
|
|
|
+ statusCaption: current.statusCaption || '',
|
|
|
// 等级与状态各有自己的语义色:等级沿用卡片那张四级词表,不与状态色混用。
|
|
// 等级与状态各有自己的语义色:等级沿用卡片那张四级词表,不与状态色混用。
|
|
|
levelLabel: current.levelLabel || '',
|
|
levelLabel: current.levelLabel || '',
|
|
|
levelTone: current.levelTone || '',
|
|
levelTone: current.levelTone || '',
|
|
@@ -134,7 +137,10 @@ function normalizeAsset(identity, source) {
|
|
|
const name = text(source.name || source.facilityName || source.resourceName || source.title) || (emergency ? '应急对象名称未提供' : '设施名称未提供')
|
|
const name = text(source.name || source.facilityName || source.resourceName || source.title) || (emergency ? '应急对象名称未提供' : '设施名称未提供')
|
|
|
// 状态是码值时翻成中文(设施:0 正常 / 1 异常;后端若直接给人话则原样用)。
|
|
// 状态是码值时翻成中文(设施:0 正常 / 1 异常;后端若直接给人话则原样用)。
|
|
|
const statusRaw = source.status ?? source.state ?? source.statusName ?? source.stateName
|
|
const statusRaw = source.status ?? source.state ?? source.statusName ?? source.stateName
|
|
|
- const status = (category === 'PROTECTION_TARGET' ? riskLevelText(statusRaw) : emergency ? undefinedEnumText(statusRaw) : facilityStatusText(statusRaw)) || '状态未发布'
|
|
|
|
|
|
|
+ const isRiskTarget = category === 'PROTECTION_TARGET'
|
|
|
|
|
+ const status = (isRiskTarget ? riskLevelText(statusRaw) : emergency ? undefinedEnumText(statusRaw) : facilityStatusText(statusRaw)) || '状态未发布'
|
|
|
|
|
+ // 防护目标的「状态」就是风险等级(规格 §5):抬头只留一个「风险等级」徽标,配色跟 risk_color。
|
|
|
|
|
+ const riskColorRaw = isRiskTarget ? attributes.riskColor ?? statusRaw : ''
|
|
|
const location = text(source.address || source.location || source.position)
|
|
const location = text(source.address || source.location || source.position)
|
|
|
const fields = assetFields(category, attributes)
|
|
const fields = assetFields(category, attributes)
|
|
|
const kindLabel = emergency ? '应急对象' : '设施'
|
|
const kindLabel = emergency ? '应急对象' : '设施'
|
|
@@ -144,7 +150,9 @@ function normalizeAsset(identity, source) {
|
|
|
kindLabel,
|
|
kindLabel,
|
|
|
// 抬头只拼接真实存在的业务编码;没有编码列时不留「编码未提供」。
|
|
// 抬头只拼接真实存在的业务编码;没有编码列时不留「编码未提供」。
|
|
|
subtitle: assetSubtitle(kindLabel, displayCode, hasCodeColumn),
|
|
subtitle: assetSubtitle(kindLabel, displayCode, hasCodeColumn),
|
|
|
- statusText: status, tone: emergency ? 'neutral' : facilityStatusTone(source.status), raw: source,
|
|
|
|
|
|
|
+ statusText: status, statusCaption: isRiskTarget ? '风险等级' : '',
|
|
|
|
|
+ tone: isRiskTarget ? riskTone(riskColorRaw) : emergency ? 'neutral' : facilityStatusTone(source.status),
|
|
|
|
|
+ raw: source,
|
|
|
categoryText: facilityCategoryText(category),
|
|
categoryText: facilityCategoryText(category),
|
|
|
coordinates: source.coordinates || null,
|
|
coordinates: source.coordinates || null,
|
|
|
summary: assetSummary(category, attributes, location),
|
|
summary: assetSummary(category, attributes, location),
|
|
@@ -276,7 +284,8 @@ function assetSummary(category, attributes, location) {
|
|
|
PIPE_NETWORK: ['lengthMeters', 'diameterMillimeters', 'material'],
|
|
PIPE_NETWORK: ['lengthMeters', 'diameterMillimeters', 'material'],
|
|
|
MANHOLE: ['manholeDepth', 'manholeShape', 'material', 'ownershipUnit'],
|
|
MANHOLE: ['manholeDepth', 'manholeShape', 'material', 'ownershipUnit'],
|
|
|
HAZARD: ['level', 'rectifyDeadline', 'rectifyPerson'],
|
|
HAZARD: ['level', 'rectifyDeadline', 'rectifyPerson'],
|
|
|
- PROTECTION_TARGET: ['riskLevel', 'riskScore', 'assessmentTime'],
|
|
|
|
|
|
|
+ // 风险等级由抬头徽标承担,摘要不再重复同一个词(票面「只出现一次」)。
|
|
|
|
|
+ PROTECTION_TARGET: ['riskScore', 'assessmentTime'],
|
|
|
EMERGENCY_RESOURCE: ['model', 'specification', 'maintainer'],
|
|
EMERGENCY_RESOURCE: ['model', 'specification', 'maintainer'],
|
|
|
}
|
|
}
|
|
|
const labels = { ...SUMMARY_LABELS, ...SUMMARY_LABELS_BY_CATEGORY[category] }
|
|
const labels = { ...SUMMARY_LABELS, ...SUMMARY_LABELS_BY_CATEGORY[category] }
|
|
@@ -522,14 +531,14 @@ const ASSET_FIELD_ROWS = {
|
|
|
{ label: '隐患图片', key: 'images', wide: true },
|
|
{ label: '隐患图片', key: 'images', wide: true },
|
|
|
{ label: '备注', key: 'remark', wide: true },
|
|
{ label: '备注', key: 'remark', wide: true },
|
|
|
],
|
|
],
|
|
|
|
|
+ // 风险等级与风险颜色不再进明细:已由抬头那一个「风险等级」徽标承担(规格 §5)。
|
|
|
|
|
+ // 风险因素改成键值网格,不再把一整串 JSON 打在页面上。
|
|
|
PROTECTION_TARGET: [
|
|
PROTECTION_TARGET: [
|
|
|
{ label: '关联管网', key: 'networkId' },
|
|
{ label: '关联管网', key: 'networkId' },
|
|
|
- { label: '风险等级', key: 'riskLevel' },
|
|
|
|
|
{ label: '风险分值', key: 'riskScore' },
|
|
{ label: '风险分值', key: 'riskScore' },
|
|
|
- { label: '风险颜色', key: 'riskColor' },
|
|
|
|
|
{ label: '评估模型', key: 'assessmentModel' },
|
|
{ label: '评估模型', key: 'assessmentModel' },
|
|
|
{ label: '评估时间', key: 'assessmentTime' },
|
|
{ label: '评估时间', key: 'assessmentTime' },
|
|
|
- { label: '风险因素', key: 'riskFactors', wide: true },
|
|
|
|
|
|
|
+ { label: '风险因素', key: 'riskFactors', wide: true, pairs: true },
|
|
|
{ label: '危险源', key: 'hazardSources', wide: true },
|
|
{ label: '危险源', key: 'hazardSources', wide: true },
|
|
|
{ label: '备注', key: 'remark', wide: true },
|
|
{ label: '备注', key: 'remark', wide: true },
|
|
|
],
|
|
],
|
|
@@ -547,11 +556,71 @@ function undefinedEnumText(raw) {
|
|
|
return /^[+-]?\d+(?:\.\d+)?$/.test(value) ? `未定义(原值:${value})` : '未知'
|
|
return /^[+-]?\d+(?:\.\d+)?$/.test(value) ? `未定义(原值:${value})` : '未知'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/** RiskAssessmentServiceImpl 发布 high/medium/low;历史数字码无定义,不套易积水点字典。 */
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 风险等级:业务库 risk_level 字典是唯一权威(0 重大 / 1 较大 / 2 一般 / 3 低)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 字典没取到时回**原码**,不再写「未定义(原值:N)」——那是把「字典还没到」
|
|
|
|
|
+ * 说成「后端给了个没定义的枚举」。high/medium/low 是风险评估服务的历史发布形状,
|
|
|
|
|
+ * 保留映射(它不是数字码,字典里没有对应行);已发布中文原样透传。
|
|
|
|
|
+ */
|
|
|
|
|
+const RISK_LEVEL_LEGACY_TEXT = { high: '高风险', medium: '中风险', low: '低风险' }
|
|
|
function riskLevelText(raw) {
|
|
function riskLevelText(raw) {
|
|
|
const value = text(raw)
|
|
const value = text(raw)
|
|
|
- const names = { high: '高风险', medium: '中风险', low: '低风险' }
|
|
|
|
|
- return Object.hasOwn(names, value) ? names[value] : undefinedEnumText(raw)
|
|
|
|
|
|
|
+ if (!value) return ''
|
|
|
|
|
+ return dictLabel(DICT_TYPES.riskLevel, value) || RISK_LEVEL_LEGACY_TEXT[value] || value
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 风险颜色码 → 中文(红/橙/黄/蓝);字典没取到就回原码。 */
|
|
|
|
|
+function riskColorText(raw) {
|
|
|
|
|
+ const value = text(raw)
|
|
|
|
|
+ if (!value) return ''
|
|
|
|
|
+ return dictLabel(DICT_TYPES.riskColor, value) || value
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 风险颜色码 → 语义色键(0 红 / 1 橙 / 2 黄 / 3 蓝);认不出回中性。 */
|
|
|
|
|
+const RISK_TONE_BY_CODE = { 0: 'risk-1', 1: 'risk-2', 2: 'risk-3', 3: 'risk-4' }
|
|
|
|
|
+function riskTone(value) {
|
|
|
|
|
+ return RISK_TONE_BY_CODE[text(value)] || 'neutral'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 风险因素 → 键值对(规格 §2「风险因素从字符串改为键值组结构」)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 后端既可能下发对象,也可能下发 JSON 字符串;解析失败(非法 JSON、纯文本)回 null,
|
|
|
|
|
+ * 由调用方原样展示 —— 不吞掉内容,也不假装解析成功。
|
|
|
|
|
+ */
|
|
|
|
|
+function riskFactorPairs(value) {
|
|
|
|
|
+ if (value === null || value === undefined || value === '') return null
|
|
|
|
|
+ let source = value
|
|
|
|
|
+ if (typeof source === 'string') {
|
|
|
|
|
+ try {
|
|
|
|
|
+ source = JSON.parse(source)
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Array.isArray(source)) {
|
|
|
|
|
+ const pairs = source.map((item, index) => [`${index + 1}`, text(item)]).filter(([, label]) => label)
|
|
|
|
|
+ return pairs.length ? pairs : null
|
|
|
|
|
+ }
|
|
|
|
|
+ if (source && typeof source === 'object') {
|
|
|
|
|
+ const pairs = Object.entries(source).map(([key, item]) => [key, text(item)]).filter(([, label]) => label)
|
|
|
|
|
+ return pairs.length ? pairs : null
|
|
|
|
|
+ }
|
|
|
|
|
+ return null
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 关联管网的业务引用(规格 §5):只认后端下发的 name + code。
|
|
|
|
|
+ * 只有内部 id 时不渲染 id —— 字段表据此显示「未提供」。
|
|
|
|
|
+ */
|
|
|
|
|
+function networkReference(a) {
|
|
|
|
|
+ const network = a.network
|
|
|
|
|
+ if (!network || typeof network !== 'object') return null
|
|
|
|
|
+ const code = text(network.code)
|
|
|
|
|
+ const name = text(network.name)
|
|
|
|
|
+ if (!code && !name) return null
|
|
|
|
|
+ return { label: name && code ? `${name}(${code})` : name || code, code }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 详情里按完整时间戳展示的字段。 */
|
|
/** 详情里按完整时间戳展示的字段。 */
|
|
@@ -572,7 +641,7 @@ function assetFieldValue(key, a) {
|
|
|
}
|
|
}
|
|
|
if (['networkId', 'workOrderId', 'equipmentTypeId'].includes(key)) return '未提供'
|
|
if (['networkId', 'workOrderId', 'equipmentTypeId'].includes(key)) return '未提供'
|
|
|
if (key === 'riskLevel') return riskLevelText(a[key])
|
|
if (key === 'riskLevel') return riskLevelText(a[key])
|
|
|
- if (key === 'riskColor') return undefinedEnumText(a[key])
|
|
|
|
|
|
|
+ if (key === 'riskColor') return riskColorText(a[key])
|
|
|
if (ASSET_TIMESTAMP_KEYS.has(key)) return formatEventTime(a[key])
|
|
if (ASSET_TIMESTAMP_KEYS.has(key)) return formatEventTime(a[key])
|
|
|
if (ASSET_DATE_KEYS.has(key)) return formatAssetDate(a[key])
|
|
if (ASSET_DATE_KEYS.has(key)) return formatAssetDate(a[key])
|
|
|
return a[key]
|
|
return a[key]
|
|
@@ -581,6 +650,17 @@ function assetFieldValue(key, a) {
|
|
|
function assetFields(category, a) {
|
|
function assetFields(category, a) {
|
|
|
const rows = category === 'PIPE_NETWORK' ? pipesFields(a) : ASSET_FIELD_ROWS[category] || []
|
|
const rows = category === 'PIPE_NETWORK' ? pipesFields(a) : ASSET_FIELD_ROWS[category] || []
|
|
|
return rows.map((row) => {
|
|
return rows.map((row) => {
|
|
|
|
|
+ // 关联管网:后端下发 name + code 时显示「名称(编码)」并给聚焦入口;否则如实「未提供」。
|
|
|
|
|
+ if (row.key === 'networkId' && category === 'PROTECTION_TARGET') {
|
|
|
|
|
+ const ref = networkReference(a)
|
|
|
|
|
+ if (!ref) return field(row.label, '未提供')
|
|
|
|
|
+ return field(row.label, ref.label, false, { action: ref.code ? { kind: 'focus-network', code: ref.code } : null })
|
|
|
|
|
+ }
|
|
|
|
|
+ // 风险因素:能解析成键值就出网格;非法 JSON / 纯文本原样展示。
|
|
|
|
|
+ if (row.pairs) {
|
|
|
|
|
+ const pairs = riskFactorPairs(a[row.key])
|
|
|
|
|
+ return pairs ? field(row.label, '', row.wide === true, { pairs }) : field(row.label, a[row.key], row.wide === true)
|
|
|
|
|
+ }
|
|
|
// 单位一律由 `unitOf(category, key)` 给:同一字段名在不同设施里量纲可能不同。
|
|
// 单位一律由 `unitOf(category, key)` 给:同一字段名在不同设施里量纲可能不同。
|
|
|
const raw = row.format ? row.format(a[row.key]) : withUnitText(assetFieldValue(row.key, a), unitOf(category, row.key))
|
|
const raw = row.format ? row.format(a[row.key]) : withUnitText(assetFieldValue(row.key, a), unitOf(category, row.key))
|
|
|
// always 行(如非排水管的二级分类)保留占位;其余缺值由 compactSections 剔除。
|
|
// always 行(如非排水管的二级分类)保留占位;其余缺值由 compactSections 剔除。
|
|
@@ -871,11 +951,12 @@ function timelineAttachments(records) { return (Array.isArray(records) ? records
|
|
|
*/
|
|
*/
|
|
|
function compactSections(sections) {
|
|
function compactSections(sections) {
|
|
|
return sections
|
|
return sections
|
|
|
- .map((group) => ({ ...group, fields: group.fields.filter((item) => item.always || item.value !== PLACEHOLDER) }))
|
|
|
|
|
|
|
+ // 键值网格行(风险因素)没有单值文本,但它本身有内容,不能按占位符剔掉。
|
|
|
|
|
+ .map((group) => ({ ...group, fields: group.fields.filter((item) => item.always || item.pairs || item.value !== PLACEHOLDER) }))
|
|
|
.filter((group) => group.fields.length)
|
|
.filter((group) => group.fields.length)
|
|
|
}
|
|
}
|
|
|
function section(title, fields) { return { title, fields } }
|
|
function section(title, fields) { return { title, fields } }
|
|
|
-function field(label, value, wide = false) { return { label, value: display(value), wide, always: false, note: '' } }
|
|
|
|
|
|
|
+function field(label, value, wide = false, extra = {}) { return { label, value: display(value), wide, always: false, note: '', ...extra } }
|
|
|
function display(value) { return value === null || value === undefined || String(value).trim() === '' ? PLACEHOLDER : String(value) }
|
|
function display(value) { return value === null || value === undefined || String(value).trim() === '' ? PLACEHOLDER : String(value) }
|
|
|
function text(value) { return value === null || value === undefined ? '' : String(value).trim() }
|
|
function text(value) { return value === null || value === undefined ? '' : String(value).trim() }
|
|
|
/**
|
|
/**
|