// 与 AlarmReviewScopeService.resolveOperations 的报警读取菜单保持一致。 const alarmMenuComponents = new Set([ 'subSystem/alarm/common/remind', 'subSystem/alarm/common/list', 'subSystem/alarm/common/analysis', 'subSystem/alarm/common/alarmGIS', 'subSystem/waterSupply/alarm/alarmGIS' ]) // EquipmentTypeEnum 的四个设备大类根节点。 const rootNames = { 1: '供水设备', 2: '排水设备', 3: '燃气设备', 4: '窨井设备' } export function warningAlarmScopes(routes = []) { const scopes = new Map() function visit(menus) { for (const menu of menus) { if (menu.status !== undefined && String(menu.status) !== '0') continue if (alarmMenuComponents.has(menu.component)) { let query = menu.query || {} try { if (typeof query === 'string') query = JSON.parse(query) } catch { query = {} } const rootTypeId = Number(query?.rootTypeId) if (Object.hasOwn(rootNames, rootTypeId)) { const warningCode = query.warning_code || query.warningCode || undefined const value = JSON.stringify([rootTypeId, warningCode || '']) scopes.set(value, { value, rootTypeId, warningCode, label: rootNames[rootTypeId] + (warningCode ? `(${warningCode})` : '') }) } } if (menu.children) visit(menu.children) } } visit(routes) const result = [...scopes.values()] // 同一大类已有不限定报警编码的菜单时,仅展示这一完整范围。 return result.filter(scope => !scope.warningCode || !result.some(other => other.rootTypeId === scope.rootTypeId && !other.warningCode )).sort((a, b) => a.rootTypeId - b.rootTypeId) } export function warningAlarmQuery(scope, filters = {}) { if (!scope || !Object.hasOwn(rootNames, scope.rootTypeId)) { throw new Error('请选择已授权的设备大类') } return { rootTypeId: scope.rootTypeId, pageNum: filters.pageNum || 1, pageSize: filters.pageSize || 10, deviceCode: filters.deviceCode?.trim() || undefined, // 菜单限定编码始终优先,不能被输入框覆盖。 warningCode: scope.warningCode || filters.warningCode?.trim() || undefined, alarmStatus: filters.alarmStatus === '' ? undefined : filters.alarmStatus } }