alarmReviewModel.js 1.5 KB

1234567891011121314151617181920212223242526
  1. // 报警值及阈值来自事件快照,不使用设备当前阈值重算历史事件。
  2. const present = value => value !== null && value !== undefined && value !== ''
  3. export const hasActualValue = row => present(row?.actualValue)
  4. export const valueText = (value, unit = '') => present(value) ? `${value}${unit ? ` ${unit}` : ''}` : '—'
  5. export function thresholdText(row = {}) {
  6. const unit = row.warningUnit || ''
  7. if (present(row.minValue) && present(row.maxValue)) return `${row.minValue} ~ ${valueText(row.maxValue, unit)}`
  8. if (present(row.minValue)) return `下限 ${valueText(row.minValue, unit)}`
  9. if (present(row.maxValue)) return `上限 ${valueText(row.maxValue, unit)}`
  10. return '—'
  11. }
  12. // 报警内容由后端生成,页面不再按指标名称或阈值重新拼接。
  13. export function alarmDescription(row = {}) {
  14. return present(row.alarmContent) ? row.alarmContent : ''
  15. }
  16. export function imageAttachments(value, baseUrl = '') {
  17. return String(value || '').split(',').map(path => path.trim()).filter(Boolean).flatMap(path => {
  18. // 历史附件也只允许 HTTP(S) 或站内资源,拒绝脚本 URL 和协议相对路径。
  19. if (!/^https?:\/\//i.test(path) && !/^\/(?!\/)/.test(path)) return []
  20. const pathname = path.split(/[?#]/)[0]
  21. if (!/\.(jpe?g|png|gif|webp|bmp|avif)$/i.test(pathname)) return []
  22. const url = path.startsWith('/') ? `${baseUrl}${path}` : path
  23. const name = pathname.split('/').pop() || '图片'
  24. return [{ url, name }]
  25. })
  26. }