gisMapColors.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { isActiveWorkOrderStatus } from './waterSupplyUiModel.js'
  2. export const gisPointStatusColors = {
  3. normal: '#2ecc71',
  4. alarm: '#e74c3c',
  5. warning: '#f1c40f',
  6. workOrder: '#3498db',
  7. offline: '#95a5a6'
  8. }
  9. export const gisPointStatusIcons = {
  10. normal: new URL('../assets/gis/T_MarkPoint_Green.png', import.meta.url).href,
  11. alarm: new URL('../assets/gis/T_MarkPoint_Red.png', import.meta.url).href,
  12. warning: new URL('../assets/gis/T_MarkPoint_Yellow.png', import.meta.url).href,
  13. workOrder: new URL('../assets/gis/T_MarkPoint_Blue.png', import.meta.url).href,
  14. offline: new URL('../assets/gis/T_MarkPoint_Grey.png', import.meta.url).href
  15. }
  16. /**
  17. * 设施状态语义:与监测设备共用同一套状态色(绿-正常、红-报警/异常、蓝-工单/检修、黄-预警/欠费)。
  18. * 供水设施 GIS 一张图与首页全域态势都从这里取状态,保证设施颜色只有一处定义。
  19. * 状态缺失或未维护时按“正常”处理,不臆造异常。
  20. */
  21. const facilityStatusMeta = {
  22. source: {
  23. 0: { key: 'normal', text: '正常' },
  24. 1: { key: 'alarm', text: '异常' }
  25. },
  26. plant: {
  27. 0: { key: 'normal', text: '正常' },
  28. 1: { key: 'alarm', text: '停产' }
  29. },
  30. pumpStation: {
  31. 0: { key: 'normal', text: '正常' },
  32. 1: { key: 'alarm', text: '故障停运' },
  33. 2: { key: 'workOrder', text: '检修中' }
  34. },
  35. // 管网保持现状:只构造管线,不落点位图标,因此不参与状态色映射
  36. user: {
  37. 0: { key: 'normal', text: '正常' },
  38. 1: { key: 'warning', text: '欠费' },
  39. 2: { key: 'alarm', text: '停用' }
  40. }
  41. }
  42. export function getFacilityStatusMeta(type = '', status = null) {
  43. return facilityStatusMeta[type]?.[String(status)] || { key: 'normal', text: '正常' }
  44. }
  45. /** 设施点位图标:按状态取图标,管网不落点位图标。 */
  46. export function getFacilityStatusIcon(type = '', status = null) {
  47. if (type === 'pipe') return null
  48. return getMonitoringPointIcon({ statusKey: getFacilityStatusMeta(type, status).key })
  49. }
  50. const clusterPointIcon = new URL('../assets/gis/T_MarkPoint_Colorful.png', import.meta.url).href
  51. export function getMapClusterIcon(points = []) {
  52. const icons = [...new Set((Array.isArray(points) ? points : [])
  53. .map(point => point?.iconUrl || getMonitoringPointIcon(point))
  54. .filter(Boolean))]
  55. return icons.length === 1 ? icons[0] : clusterPointIcon
  56. }
  57. export const gisPointStatusLabels = {
  58. normal: '正常',
  59. alarm: '报警',
  60. warning: '预警',
  61. workOrder: '关联工单',
  62. offline: '离线'
  63. }
  64. export const gisPointStatusTagTypes = {
  65. normal: 'success',
  66. alarm: 'danger',
  67. warning: 'warning',
  68. workOrder: 'primary',
  69. offline: 'info'
  70. }
  71. export function getMonitoringPointStatus(point = {}) {
  72. if (point.statusKey && gisPointStatusColors[point.statusKey]) return point.statusKey
  73. const relatedOrderNo = point.orderNo ?? point.relatedOrderNo ?? point.relatedWorkOrderNo ?? point.latestOrderNo
  74. const orderStatus = point.orderStatus ?? point.relatedWorkOrderStatus ?? point.latestMaintainStatus
  75. const orderIsKnownActive = orderStatus === undefined || orderStatus === null || orderStatus === '' || isActiveWorkOrderStatus(orderStatus)
  76. if (relatedOrderNo && relatedOrderNo !== '-' && orderIsKnownActive) return 'workOrder'
  77. if (Number(point.deviceAlarmStatus ?? point.alarmStatus) === 1) return 'alarm'
  78. if (Number(point.currentStatus) === 3) return 'warning'
  79. if (Number(point.onlineStatus) === 0) return 'offline'
  80. return 'normal'
  81. }
  82. export function getMonitoringPointColor(point = {}) {
  83. return gisPointStatusColors[getMonitoringPointStatus(point)] || gisPointStatusColors.normal
  84. }
  85. export function getMonitoringPointIcon(point = {}) {
  86. return gisPointStatusIcons[getMonitoringPointStatus(point)] || gisPointStatusIcons.normal
  87. }
  88. export function getMonitoringPointLabel(point = {}) {
  89. return gisPointStatusLabels[getMonitoringPointStatus(point)] || gisPointStatusLabels.normal
  90. }
  91. export function getMonitoringPointTagType(point = {}) {
  92. return gisPointStatusTagTypes[getMonitoringPointStatus(point)] || gisPointStatusTagTypes.normal
  93. }