warningAlarmScope.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // 与 AlarmReviewScopeService.resolveOperations 的报警读取菜单保持一致。
  2. const alarmMenuComponents = new Set([
  3. 'subSystem/alarm/common/remind',
  4. 'subSystem/alarm/common/list',
  5. 'subSystem/alarm/common/analysis',
  6. 'subSystem/alarm/common/alarmGIS',
  7. 'subSystem/waterSupply/alarm/alarmGIS'
  8. ])
  9. // EquipmentTypeEnum 的四个设备大类根节点。
  10. const rootNames = { 1: '供水设备', 2: '排水设备', 3: '燃气设备', 4: '窨井设备' }
  11. export function warningAlarmScopes(routes = []) {
  12. const scopes = new Map()
  13. function visit(menus) {
  14. for (const menu of menus) {
  15. if (menu.status !== undefined && String(menu.status) !== '0') continue
  16. if (alarmMenuComponents.has(menu.component)) {
  17. let query = menu.query || {}
  18. try {
  19. if (typeof query === 'string') query = JSON.parse(query)
  20. } catch {
  21. query = {}
  22. }
  23. const rootTypeId = Number(query?.rootTypeId)
  24. if (Object.hasOwn(rootNames, rootTypeId)) {
  25. const warningCode = query.warning_code || query.warningCode || undefined
  26. const value = JSON.stringify([rootTypeId, warningCode || ''])
  27. scopes.set(value, {
  28. value, rootTypeId, warningCode,
  29. label: rootNames[rootTypeId] + (warningCode ? `(${warningCode})` : '')
  30. })
  31. }
  32. }
  33. if (menu.children) visit(menu.children)
  34. }
  35. }
  36. visit(routes)
  37. const result = [...scopes.values()]
  38. // 同一大类已有不限定报警编码的菜单时,仅展示这一完整范围。
  39. return result.filter(scope => !scope.warningCode || !result.some(other =>
  40. other.rootTypeId === scope.rootTypeId && !other.warningCode
  41. )).sort((a, b) => a.rootTypeId - b.rootTypeId)
  42. }
  43. export function warningAlarmQuery(scope, filters = {}) {
  44. if (!scope || !Object.hasOwn(rootNames, scope.rootTypeId)) {
  45. throw new Error('请选择已授权的设备大类')
  46. }
  47. return {
  48. rootTypeId: scope.rootTypeId,
  49. pageNum: filters.pageNum || 1,
  50. pageSize: filters.pageSize || 10,
  51. deviceCode: filters.deviceCode?.trim() || undefined,
  52. // 菜单限定编码始终优先,不能被输入框覆盖。
  53. warningCode: scope.warningCode || filters.warningCode?.trim() || undefined,
  54. alarmStatus: filters.alarmStatus === '' ? undefined : filters.alarmStatus
  55. }
  56. }