shared.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. export const fallbackWarningTypes = [
  2. { label: '供水管网预警', value: 'WATER_PIPE' },
  3. { label: '排水管网预警', value: 'SEWER_PIPE' },
  4. { label: '燃气管网预警', value: 'GAS_PIPE' },
  5. { label: '窨井预警', value: 'MANHOLE' }
  6. ]
  7. export const warningLevels = [
  8. { label: '蓝色预警(IV级)', shortLabel: '蓝色', value: '1', color: '#3b82f6', tagType: 'primary' },
  9. { label: '黄色预警(III级)', shortLabel: '黄色', value: '2', color: '#eab308', tagType: 'warning' },
  10. { label: '橙色预警(II级)', shortLabel: '橙色', value: '3', color: '#f97316', tagType: 'warning' },
  11. { label: '红色预警(I级)', shortLabel: '红色', value: '4', color: '#ef4444', tagType: 'danger' }
  12. ]
  13. export const itemStatuses = [
  14. { label: '已启用', value: 'ENABLED', type: 'success' },
  15. { label: '已禁用', value: 'DISABLED', type: 'info' },
  16. { label: '已作废', value: 'INVALID', type: 'danger' }
  17. ]
  18. export const industryOptions = ['供水', '排水', '燃气', '窨井']
  19. export const defaultLinks = [
  20. { name: '监测触发', handler: '监测中心', timeLimit: 5, description: '监测数据达到预警阈值后自动触发' },
  21. { name: '研判确认', handler: '行业主管部门', timeLimit: 15, description: '核验数据并确认预警事项' },
  22. { name: '发布处置', handler: '应急处置人员', timeLimit: 30, description: '发布预警并按预案执行处置' },
  23. { name: '复核归档', handler: '预警管理人员', timeLimit: 60, description: '复核处置结果并完成归档' }
  24. ]
  25. export function optionLabel(options, value, fallback = '-') {
  26. return options.find(item => String(item.value) === String(value))?.label || value || fallback
  27. }
  28. export function statusMeta(value) {
  29. return itemStatuses.find(item => item.value === value) || { label: value || '未知', type: 'info' }
  30. }
  31. export function levelMeta(value) {
  32. return warningLevels.find(item => item.value === String(value)) || {
  33. label: value || '未配置',
  34. shortLabel: value || '-',
  35. color: '#94a3b8',
  36. tagType: 'info'
  37. }
  38. }
  39. export function parseLinkConfig(value) {
  40. if (!value) return []
  41. if (Array.isArray(value)) return value
  42. try {
  43. const parsed = JSON.parse(value)
  44. return Array.isArray(parsed) ? parsed : []
  45. } catch {
  46. return [{ name: '环节说明', handler: '-', timeLimit: null, description: value }]
  47. }
  48. }
  49. export function cloneDefaultLinks() {
  50. return defaultLinks.map(item => ({ ...item }))
  51. }
  52. export function normalizeWarningTypeDict(data = []) {
  53. const enabled = data
  54. .filter(item => item.status === undefined || String(item.status) === '0')
  55. .map(item => ({ label: item.dictLabel, value: item.dictValue }))
  56. return enabled.length ? enabled : fallbackWarningTypes
  57. }