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