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