home.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import request from '@/utils/request'
  2. import { normalizeRootTypeId } from '@/utils/homeScope'
  3. /**
  4. * 供水 / 排水 / 燃气 / 窨井四个子系统共用的首页接口。
  5. *
  6. * 数据范围由菜单 sys_menu.query 下发的 rootTypeId 决定(与系统既有约定一致):
  7. * 1-供水设备 2-排水设备 3-燃气设备 4-窨井设备
  8. * 前端从 useRoute().query.rootTypeId 读取后显式传给每个接口;请求拦截器不会自动附加,
  9. * 后端 HomeController 会再次校验该用户是否拥有对应 rootTypeId 的首页菜单。
  10. *
  11. * 这里做最后一道防线:缺失或非法的 rootTypeId 直接报错,绝不退化成某个默认子系统。
  12. */
  13. const BASE = '/api/home'
  14. function withScope(params) {
  15. const rootTypeId = normalizeRootTypeId(params?.rootTypeId)
  16. if (!rootTypeId) {
  17. throw new Error('首页数据范围缺失:请检查 sys_menu.query.rootTypeId(1供水 / 2排水 / 3燃气 / 4窨井)')
  18. }
  19. return { ...params, rootTypeId }
  20. }
  21. /** 设备清单(首页顶部健康度带、片区点阵) */
  22. export function getHomeDevices(rootTypeId) {
  23. return request({ url: `${BASE}/devices`, method: 'get', params: withScope({ rootTypeId }) })
  24. }
  25. /** 待办工单(orderStatus 支持逗号分隔多值) */
  26. export function getHomeWorkOrders(params) {
  27. return request({ url: `${BASE}/work-orders`, method: 'get', params: withScope(params) })
  28. }
  29. /** 报警清单(AlarmQuery:rootTypeId / pageNum / pageSize / startTime ...) */
  30. export function getHomeAlarms(params) {
  31. return request({ url: `${BASE}/alarms`, method: 'get', params: withScope(params) })
  32. }
  33. /** 设备 GIS 点位 */
  34. export function getHomeGisPoints(rootTypeId) {
  35. return request({ url: `${BASE}/gis/points`, method: 'get', params: withScope({ rootTypeId }) })
  36. }
  37. /** 管网 GeoJSON(FeatureCollection,LineString 起终点坐标);rootTypeId=4 不区分管网类型,返回全部管线 */
  38. export function getHomePipeLines(rootTypeId) {
  39. return request({ url: `${BASE}/gis/pipe-lines`, method: 'get', params: withScope({ rootTypeId }) })
  40. }
  41. /** 设备详情弹窗 */
  42. export function getHomeEquipmentDetail(equipmentId, rootTypeId) {
  43. return request({
  44. url: `${BASE}/equipment/${encodeURIComponent(equipmentId)}/detail`,
  45. method: 'get',
  46. params: withScope({ rootTypeId })
  47. })
  48. }