From cc16cd08b62e279ce8fac7b4eafa347bfa6dd131 Mon Sep 17 00:00:00 2001 From: pnoker Date: Sat, 2 May 2026 14:12:17 +0800 Subject: [PATCH] refactor(api): extract gateway base paths to src/config/constant/api.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every api/*.ts module was hardcoding the same three prefixes ('api/v3/auth', 'api/v3/data', 'api/v3/manager'). Pull them into API_AUTH_BASE / API_DATA_BASE / API_MANAGER_BASE so the prefix lives in one place — aligns with the other static-constant files under src/config/constant/ and makes it trivial to retarget the gateway mount point or add a new service base. All 17 api files (including dashboard.ts, which used to declare local DATA_BASE/MANAGER_BASE) now import from the shared module. --- src/api/api.ts | 11 ++++++----- src/api/attribute.ts | 7 +++++-- src/api/dashboard.ts | 21 +++++++++------------ src/api/device.ts | 28 +++++++++++++++------------- src/api/dictionary.ts | 10 ++++++---- src/api/driver.ts | 9 +++++---- src/api/info.ts | 19 +++++++++++-------- src/api/menu.ts | 13 +++++++------ src/api/point.ts | 29 +++++++++++++++-------------- src/api/profile.ts | 15 ++++++++------- src/api/resource.ts | 13 +++++++------ src/api/role.ts | 11 ++++++----- src/api/roleResourceBind.ts | 9 +++++---- src/api/roleUserBind.ts | 9 +++++---- src/api/rule.ts | 3 ++- src/api/token.ts | 9 +++++---- src/api/user.ts | 13 +++++++------ src/config/constant/api.ts | 29 +++++++++++++++++++++++++++++ 18 files changed, 153 insertions(+), 105 deletions(-) create mode 100644 src/config/constant/api.ts diff --git a/src/api/api.ts b/src/api/api.ts index a501409c4..aee9b5a7b 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -15,13 +15,14 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const addApi = (api: any) => httpPost('api/v3/auth/api/add', api); +export const addApi = (api: any) => httpPost(`${API_AUTH_BASE}/api/add`, api); -export const deleteApi = (id: string) => httpPost(`api/v3/auth/api/delete/${id}`); +export const deleteApi = (id: string) => httpPost(`${API_AUTH_BASE}/api/delete/${id}`); -export const updateApi = (api: any) => httpPost('api/v3/auth/api/update', api); +export const updateApi = (api: any) => httpPost(`${API_AUTH_BASE}/api/update`, api); -export const getApiById = (id: string) => httpGet(`api/v3/auth/api/id/${id}`); +export const getApiById = (id: string) => httpGet(`${API_AUTH_BASE}/api/id/${id}`); -export const getApiList = (query: any) => httpPost('api/v3/auth/api/list', query); +export const getApiList = (query: any) => httpPost(`${API_AUTH_BASE}/api/list`, query); diff --git a/src/api/attribute.ts b/src/api/attribute.ts index 15a92fe8d..53a28b62c 100644 --- a/src/api/attribute.ts +++ b/src/api/attribute.ts @@ -15,7 +15,10 @@ */ import { httpGet } from '@/api/common'; +import { API_MANAGER_BASE } from '@/config/constant/api'; -export const getDriverAttributeByDriverId = (id: string) => httpGet(`api/v3/manager/driver_attribute/driver_id/${id}`); +export const getDriverAttributeByDriverId = (id: string) => + httpGet(`${API_MANAGER_BASE}/driver_attribute/driver_id/${id}`); -export const getPointAttributeByDriverId = (id: string) => httpGet(`api/v3/manager/point_attribute/driver_id/${id}`); +export const getPointAttributeByDriverId = (id: string) => + httpGet(`${API_MANAGER_BASE}/point_attribute/driver_id/${id}`); diff --git a/src/api/dashboard.ts b/src/api/dashboard.ts index b74de4f35..a24000a1d 100644 --- a/src/api/dashboard.ts +++ b/src/api/dashboard.ts @@ -15,26 +15,23 @@ */ import { httpGet } from '@/api/common'; +import { API_DATA_BASE, API_MANAGER_BASE } from '@/config/constant/api'; -// Matches backend dc3-center-data /dashboard endpoints. -const DATA_BASE = 'api/v3/data/dashboard'; -const MANAGER_BASE = 'api/v3/manager/dashboard'; - -export const statsToday = () => httpGet(`${DATA_BASE}/stats/today`); +export const statsToday = () => httpGet(`${API_DATA_BASE}/dashboard/stats/today`); export const statsTimeseries = (params: { granularity?: 'hour' | 'day'; rangeHours?: number } = {}) => - httpGet(`${DATA_BASE}/stats/timeseries`, { params }); + httpGet(`${API_DATA_BASE}/dashboard/stats/timeseries`, { params }); export const statsTop = ( params: { dimension?: 'device' | 'point' | 'driver'; rangeHours?: number; limit?: number } = {} -) => httpGet(`${DATA_BASE}/top`, { params }); +) => httpGet(`${API_DATA_BASE}/dashboard/top`, { params }); -export const streamLatest = (size = 20) => httpGet(`${DATA_BASE}/stream`, { params: { size } }); +export const streamLatest = (size = 20) => httpGet(`${API_DATA_BASE}/dashboard/stream`, { params: { size } }); -export const alertStats = () => httpGet(`${DATA_BASE}/alert/stats`); +export const alertStats = () => httpGet(`${API_DATA_BASE}/dashboard/alert/stats`); -export const alertLatest = (size = 10) => httpGet(`${DATA_BASE}/alert/latest`, { params: { size } }); +export const alertLatest = (size = 10) => httpGet(`${API_DATA_BASE}/dashboard/alert/latest`, { params: { size } }); -export const driverStats = () => httpGet(`${MANAGER_BASE}/driver/stats`); +export const driverStats = () => httpGet(`${API_MANAGER_BASE}/dashboard/driver/stats`); -export const deviceStats = (topN = 10) => httpGet(`${MANAGER_BASE}/device/stats`, { params: { topN } }); +export const deviceStats = (topN = 10) => httpGet(`${API_MANAGER_BASE}/dashboard/device/stats`, { params: { topN } }); diff --git a/src/api/device.ts b/src/api/device.ts index 7267b8b3d..43d41cc15 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -15,36 +15,38 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_DATA_BASE, API_MANAGER_BASE } from '@/config/constant/api'; -export const addDevice = (device: any) => httpPost('api/v3/manager/device/add', device); +export const addDevice = (device: any) => httpPost(`${API_MANAGER_BASE}/device/add`, device); -export const deleteDevice = (id: string) => httpPost(`api/v3/manager/device/delete/${id}`); +export const deleteDevice = (id: string) => httpPost(`${API_MANAGER_BASE}/device/delete/${id}`); -export const updateDevice = (device: any) => httpPost('api/v3/manager/device/update', device); +export const updateDevice = (device: any) => httpPost(`${API_MANAGER_BASE}/device/update`, device); -export const getDeviceById = (id: string) => httpGet(`api/v3/manager/device/id/${id}`); +export const getDeviceById = (id: string) => httpGet(`${API_MANAGER_BASE}/device/id/${id}`); -export const getDeviceByIds = (deviceIds: any) => httpPost('api/v3/manager/device/ids', deviceIds); +export const getDeviceByIds = (deviceIds: any) => httpPost(`${API_MANAGER_BASE}/device/ids`, deviceIds); -export const getDeviceByDriverId = (driverId: string) => httpGet(`api/v3/manager/device/driver_id/${driverId}`); +export const getDeviceByDriverId = (driverId: string) => httpGet(`${API_MANAGER_BASE}/device/driver_id/${driverId}`); -export const getDeviceByProfileId = (profileId: string) => httpGet(`api/v3/manager/device/profile_id/${profileId}`); +export const getDeviceByProfileId = (profileId: string) => + httpGet(`${API_MANAGER_BASE}/device/profile_id/${profileId}`); -export const getDeviceList = (device: any) => httpPost('api/v3/manager/device/list', device); +export const getDeviceList = (device: any) => httpPost(`${API_MANAGER_BASE}/device/list`, device); -export const getDeviceStatus = (device: any) => httpPost('api/v3/data/device/status/device', device); +export const getDeviceStatus = (device: any) => httpPost(`${API_DATA_BASE}/device/status/device`, device); export const getDeviceStatusByDriverId = (driverId: string) => - httpGet(`api/v3/data/device/status/device/driver_id/${driverId}`); + httpGet(`${API_DATA_BASE}/device/status/device/driver_id/${driverId}`); export const getDeviceStatusByProfileId = (profileId: string) => - httpGet(`api/v3/data/device/status/device/profile_id/${profileId}`); + httpGet(`${API_DATA_BASE}/device/status/device/profile_id/${profileId}`); export const importDeviceTemplate = (device: any) => - httpPost('api/v3/manager/device/export/import_template', device, { responseType: 'blob' }); + httpPost(`${API_MANAGER_BASE}/device/export/import_template`, device, { responseType: 'blob' }); export const importDevice = (device: any) => - httpPost('api/v3/manager/device/import', device, { + httpPost(`${API_MANAGER_BASE}/device/import`, device, { timeout: 0, headers: { 'Content-Type': 'multipart/form-data' }, }); diff --git a/src/api/dictionary.ts b/src/api/dictionary.ts index 7870c972d..9932ab00a 100644 --- a/src/api/dictionary.ts +++ b/src/api/dictionary.ts @@ -15,11 +15,13 @@ */ import { httpPost } from '@/api/common'; +import { API_MANAGER_BASE } from '@/config/constant/api'; -export const getDriverDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/driver', dictionary); +export const getDriverDictionary = (dictionary: any) => httpPost(`${API_MANAGER_BASE}/dictionary/driver`, dictionary); -export const getDeviceDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/device', dictionary); +export const getDeviceDictionary = (dictionary: any) => httpPost(`${API_MANAGER_BASE}/dictionary/device`, dictionary); -export const getProfileDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/profile', dictionary); +export const getProfileDictionary = (dictionary: any) => httpPost(`${API_MANAGER_BASE}/dictionary/profile`, dictionary); -export const getPointDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/device_point', dictionary); +export const getPointDictionary = (dictionary: any) => + httpPost(`${API_MANAGER_BASE}/dictionary/device_point`, dictionary); diff --git a/src/api/driver.ts b/src/api/driver.ts index 05da8561f..7764058c5 100644 --- a/src/api/driver.ts +++ b/src/api/driver.ts @@ -15,11 +15,12 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_DATA_BASE, API_MANAGER_BASE } from '@/config/constant/api'; -export const getDriverById = (id: string) => httpGet(`api/v3/manager/driver/id/${id}`); +export const getDriverById = (id: string) => httpGet(`${API_MANAGER_BASE}/driver/id/${id}`); -export const getDriverByIds = (driverIds: any) => httpPost('api/v3/manager/driver/ids', driverIds); +export const getDriverByIds = (driverIds: any) => httpPost(`${API_MANAGER_BASE}/driver/ids`, driverIds); -export const getDriverList = (driver: any) => httpPost('api/v3/manager/driver/list', driver); +export const getDriverList = (driver: any) => httpPost(`${API_MANAGER_BASE}/driver/list`, driver); -export const getDriverStatus = (driver: any) => httpPost('api/v3/data/driver/status/driver', driver); +export const getDriverStatus = (driver: any) => httpPost(`${API_DATA_BASE}/driver/status/driver`, driver); diff --git a/src/api/info.ts b/src/api/info.ts index 34d1bb9ce..faeed296f 100644 --- a/src/api/info.ts +++ b/src/api/info.ts @@ -15,24 +15,27 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_MANAGER_BASE } from '@/config/constant/api'; -export const addDriverInfo = (driverInfo: any) => httpPost('api/v3/manager/driver_attribute_config/add', driverInfo); +export const addDriverInfo = (driverInfo: any) => + httpPost(`${API_MANAGER_BASE}/driver_attribute_config/add`, driverInfo); export const updateDriverInfo = (driverInfo: any) => - httpPost('api/v3/manager/driver_attribute_config/update', driverInfo); + httpPost(`${API_MANAGER_BASE}/driver_attribute_config/update`, driverInfo); export const getDriverInfoByDeviceIdAndAttributeId = (deviceId: string, attributeId: string) => - httpGet(`api/v3/manager/driver_attribute_config/device_id/${deviceId}/attribute_id/${attributeId}`); + httpGet(`${API_MANAGER_BASE}/driver_attribute_config/device_id/${deviceId}/attribute_id/${attributeId}`); export const getDriverInfoByDeviceId = (deviceId: string) => - httpGet(`api/v3/manager/driver_attribute_config/device_id/${deviceId}`); + httpGet(`${API_MANAGER_BASE}/driver_attribute_config/device_id/${deviceId}`); -export const addPointInfo = (pointInfo: any) => httpPost('api/v3/manager/point_attribute_config/add', pointInfo); +export const addPointInfo = (pointInfo: any) => httpPost(`${API_MANAGER_BASE}/point_attribute_config/add`, pointInfo); -export const updatePointInfo = (pointInfo: any) => httpPost('api/v3/manager/point_attribute_config/update', pointInfo); +export const updatePointInfo = (pointInfo: any) => + httpPost(`${API_MANAGER_BASE}/point_attribute_config/update`, pointInfo); export const getPointInfoByDeviceIdAndPointId = (deviceId: string, pointId: string) => - httpGet(`api/v3/manager/point_attribute_config/device_id/${deviceId}/point_id/${pointId}`); + httpGet(`${API_MANAGER_BASE}/point_attribute_config/device_id/${deviceId}/point_id/${pointId}`); export const getPointInfoByDeviceId = (deviceId: string) => - httpGet(`api/v3/manager/point_attribute_config/device_id/${deviceId}`); + httpGet(`${API_MANAGER_BASE}/point_attribute_config/device_id/${deviceId}`); diff --git a/src/api/menu.ts b/src/api/menu.ts index dbbcf8447..a14cc45b9 100644 --- a/src/api/menu.ts +++ b/src/api/menu.ts @@ -15,15 +15,16 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const addMenu = (menu: any) => httpPost('api/v3/auth/menu/add', menu); +export const addMenu = (menu: any) => httpPost(`${API_AUTH_BASE}/menu/add`, menu); -export const deleteMenu = (id: string) => httpPost(`api/v3/auth/menu/delete/${id}`); +export const deleteMenu = (id: string) => httpPost(`${API_AUTH_BASE}/menu/delete/${id}`); -export const updateMenu = (menu: any) => httpPost('api/v3/auth/menu/update', menu); +export const updateMenu = (menu: any) => httpPost(`${API_AUTH_BASE}/menu/update`, menu); -export const getMenuById = (id: string) => httpGet(`api/v3/auth/menu/id/${id}`); +export const getMenuById = (id: string) => httpGet(`${API_AUTH_BASE}/menu/id/${id}`); -export const getMenuList = (query: any) => httpPost('api/v3/auth/menu/list', query); +export const getMenuList = (query: any) => httpPost(`${API_AUTH_BASE}/menu/list`, query); -export const getMenuTree = (query: any = {}) => httpPost('api/v3/auth/menu/tree', query); +export const getMenuTree = (query: any = {}) => httpPost(`${API_AUTH_BASE}/menu/tree`, query); diff --git a/src/api/point.ts b/src/api/point.ts index 02a908e96..dd6ffd989 100644 --- a/src/api/point.ts +++ b/src/api/point.ts @@ -15,36 +15,37 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_DATA_BASE, API_MANAGER_BASE } from '@/config/constant/api'; -export const pointAddApi = (point: any) => httpPost('api/v3/manager/point/add', point); +export const pointAddApi = (point: any) => httpPost(`${API_MANAGER_BASE}/point/add`, point); -export const pointDeleteApi = (id: string) => httpPost(`api/v3/manager/point/delete/${id}`); +export const pointDeleteApi = (id: string) => httpPost(`${API_MANAGER_BASE}/point/delete/${id}`); -export const getPointUpdate = (point: any) => httpPost('api/v3/manager/point/update', point); +export const getPointUpdate = (point: any) => httpPost(`${API_MANAGER_BASE}/point/update`, point); -export const getPointById = (id: string) => httpGet(`api/v3/manager/point/id/${id}`); +export const getPointById = (id: string) => httpGet(`${API_MANAGER_BASE}/point/id/${id}`); -export const getPointByIds = (pointIds: any) => httpPost('api/v3/manager/point/ids', pointIds); +export const getPointByIds = (pointIds: any) => httpPost(`${API_MANAGER_BASE}/point/ids`, pointIds); -export const getPointList = (point: any) => httpPost('api/v3/manager/point/list', point); +export const getPointList = (point: any) => httpPost(`${API_MANAGER_BASE}/point/list`, point); -export const getPointUnit = (pointIds: any) => httpPost('api/v3/manager/point/unit', pointIds); +export const getPointUnit = (pointIds: any) => httpPost(`${API_MANAGER_BASE}/point/unit`, pointIds); -export const getPointByProfileId = (profileId: string) => httpGet(`api/v3/manager/point/profile_id/${profileId}`); +export const getPointByProfileId = (profileId: string) => httpGet(`${API_MANAGER_BASE}/point/profile_id/${profileId}`); -export const getPointByDeviceId = (deviceId: string) => httpGet(`api/v3/manager/point/device_id/${deviceId}`); +export const getPointByDeviceId = (deviceId: string) => httpGet(`${API_MANAGER_BASE}/point/device_id/${deviceId}`); -export const getPointValueLatest = (pointValue: any) => httpPost('api/v3/data/point_value/latest', pointValue); +export const getPointValueLatest = (pointValue: any) => httpPost(`${API_DATA_BASE}/point_value/latest`, pointValue); -export const getPointValueList = (pointValue: any) => httpPost('api/v3/data/point_value/list', pointValue); +export const getPointValueList = (pointValue: any) => httpPost(`${API_DATA_BASE}/point_value/list`, pointValue); export const getPointValueHistory = (deviceId: number, pointId: number, count: number = 100) => - httpGet(`api/v3/data/point_value/history/device_id/${deviceId}/point_id/${pointId}`, { + httpGet(`${API_DATA_BASE}/point_value/history/device_id/${deviceId}/point_id/${pointId}`, { params: { count }, }); export const readPointValue = (pointValueReadVO: any) => - httpPost('api/v3/data/point_value_command/read', pointValueReadVO); + httpPost(`${API_DATA_BASE}/point_value_command/read`, pointValueReadVO); export const writePointValue = (pointValueWriteVO: any) => - httpPost('api/v3/data/point_value_command/write', pointValueWriteVO); + httpPost(`${API_DATA_BASE}/point_value_command/write`, pointValueWriteVO); diff --git a/src/api/profile.ts b/src/api/profile.ts index 25f60401c..3d851c6f8 100644 --- a/src/api/profile.ts +++ b/src/api/profile.ts @@ -15,17 +15,18 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_MANAGER_BASE } from '@/config/constant/api'; -export const addProfile = (profile: any) => httpPost('api/v3/manager/profile/add', profile); +export const addProfile = (profile: any) => httpPost(`${API_MANAGER_BASE}/profile/add`, profile); -export const deleteProfile = (id: string) => httpPost(`api/v3/manager/profile/delete/${id}`); +export const deleteProfile = (id: string) => httpPost(`${API_MANAGER_BASE}/profile/delete/${id}`); -export const updateProfile = (profile: any) => httpPost('api/v3/manager/profile/update', profile); +export const updateProfile = (profile: any) => httpPost(`${API_MANAGER_BASE}/profile/update`, profile); -export const getProfileById = (id: string) => httpGet(`api/v3/manager/profile/id/${id}`); +export const getProfileById = (id: string) => httpGet(`${API_MANAGER_BASE}/profile/id/${id}`); -export const getProfileByIds = (profileIds: any) => httpPost('api/v3/manager/profile/ids', profileIds); +export const getProfileByIds = (profileIds: any) => httpPost(`${API_MANAGER_BASE}/profile/ids`, profileIds); -export const getProfileByDeviceId = (deviceId: string) => httpGet(`api/v3/manager/profile/device_id/${deviceId}`); +export const getProfileByDeviceId = (deviceId: string) => httpGet(`${API_MANAGER_BASE}/profile/device_id/${deviceId}`); -export const getProfileList = (profile: any) => httpPost('api/v3/manager/profile/list', profile); +export const getProfileList = (profile: any) => httpPost(`${API_MANAGER_BASE}/profile/list`, profile); diff --git a/src/api/resource.ts b/src/api/resource.ts index 31dcc9725..9fae257b8 100644 --- a/src/api/resource.ts +++ b/src/api/resource.ts @@ -15,15 +15,16 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const addResource = (resource: any) => httpPost('api/v3/auth/resource/add', resource); +export const addResource = (resource: any) => httpPost(`${API_AUTH_BASE}/resource/add`, resource); -export const deleteResource = (id: string) => httpPost(`api/v3/auth/resource/delete/${id}`); +export const deleteResource = (id: string) => httpPost(`${API_AUTH_BASE}/resource/delete/${id}`); -export const updateResource = (resource: any) => httpPost('api/v3/auth/resource/update', resource); +export const updateResource = (resource: any) => httpPost(`${API_AUTH_BASE}/resource/update`, resource); -export const getResourceById = (id: string) => httpGet(`api/v3/auth/resource/id/${id}`); +export const getResourceById = (id: string) => httpGet(`${API_AUTH_BASE}/resource/id/${id}`); -export const getResourceList = (query: any) => httpPost('api/v3/auth/resource/list', query); +export const getResourceList = (query: any) => httpPost(`${API_AUTH_BASE}/resource/list`, query); -export const getResourceTree = (query: any = {}) => httpPost('api/v3/auth/resource/tree', query); +export const getResourceTree = (query: any = {}) => httpPost(`${API_AUTH_BASE}/resource/tree`, query); diff --git a/src/api/role.ts b/src/api/role.ts index c60a932a2..fe7a98c54 100644 --- a/src/api/role.ts +++ b/src/api/role.ts @@ -15,13 +15,14 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const addRole = (role: any) => httpPost('api/v3/auth/role/add', role); +export const addRole = (role: any) => httpPost(`${API_AUTH_BASE}/role/add`, role); -export const deleteRole = (id: string) => httpPost(`api/v3/auth/role/delete/${id}`); +export const deleteRole = (id: string) => httpPost(`${API_AUTH_BASE}/role/delete/${id}`); -export const updateRole = (role: any) => httpPost('api/v3/auth/role/update', role); +export const updateRole = (role: any) => httpPost(`${API_AUTH_BASE}/role/update`, role); -export const getRoleById = (id: string) => httpGet(`api/v3/auth/role/id/${id}`); +export const getRoleById = (id: string) => httpGet(`${API_AUTH_BASE}/role/id/${id}`); -export const getRoleList = (query: any) => httpPost('api/v3/auth/role/list', query); +export const getRoleList = (query: any) => httpPost(`${API_AUTH_BASE}/role/list`, query); diff --git a/src/api/roleResourceBind.ts b/src/api/roleResourceBind.ts index 352cda07e..f0d90cc8f 100644 --- a/src/api/roleResourceBind.ts +++ b/src/api/roleResourceBind.ts @@ -15,12 +15,13 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const bindRoleResource = (body: any) => httpPost('api/v3/auth/role-resource/add', body); +export const bindRoleResource = (body: any) => httpPost(`${API_AUTH_BASE}/role-resource/add`, body); -export const unbindRoleResource = (id: string) => httpPost(`api/v3/auth/role-resource/delete/${id}`); +export const unbindRoleResource = (id: string) => httpPost(`${API_AUTH_BASE}/role-resource/delete/${id}`); -export const getRoleResourceList = (query: any) => httpPost('api/v3/auth/role-resource/list', query); +export const getRoleResourceList = (query: any) => httpPost(`${API_AUTH_BASE}/role-resource/list`, query); export const listResourceByRoleId = (roleId: string) => - httpGet(`api/v3/auth/role-resource/list-resource-by-role/${roleId}`); + httpGet(`${API_AUTH_BASE}/role-resource/list-resource-by-role/${roleId}`); diff --git a/src/api/roleUserBind.ts b/src/api/roleUserBind.ts index 16aa520a2..258b019cf 100644 --- a/src/api/roleUserBind.ts +++ b/src/api/roleUserBind.ts @@ -15,15 +15,16 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const bindRoleUser = (body: any) => httpPost('api/v3/auth/role-user/add', body); +export const bindRoleUser = (body: any) => httpPost(`${API_AUTH_BASE}/role-user/add`, body); -export const unbindRoleUser = (id: string) => httpPost(`api/v3/auth/role-user/delete/${id}`); +export const unbindRoleUser = (id: string) => httpPost(`${API_AUTH_BASE}/role-user/delete/${id}`); -export const getRoleUserList = (query: any) => httpPost('api/v3/auth/role-user/list', query); +export const getRoleUserList = (query: any) => httpPost(`${API_AUTH_BASE}/role-user/list`, query); export const listRoleByUserId = (userId: string, tenantId?: string | number) => { // Only append numeric tenantId; string tenant names would cause Long type-mismatch on the backend. const query = typeof tenantId === 'number' ? `?tenantId=${tenantId}` : ''; - return httpGet(`api/v3/auth/role-user/list-role-by-user/${userId}${query}`); + return httpGet(`${API_AUTH_BASE}/role-user/list-role-by-user/${userId}${query}`); }; diff --git a/src/api/rule.ts b/src/api/rule.ts index bc76e2343..e52edb937 100644 --- a/src/api/rule.ts +++ b/src/api/rule.ts @@ -15,5 +15,6 @@ */ import { httpPost } from '@/api/common'; +import { API_MANAGER_BASE } from '@/config/constant/api'; -export const getFlowsList = (flowsQuery: any) => httpPost('api/v3/manager/ruleengine/flowsList', flowsQuery); +export const getFlowsList = (flowsQuery: any) => httpPost(`${API_MANAGER_BASE}/ruleengine/flowsList`, flowsQuery); diff --git a/src/api/token.ts b/src/api/token.ts index 5c47e4b49..baccac5a7 100644 --- a/src/api/token.ts +++ b/src/api/token.ts @@ -15,12 +15,13 @@ */ import { httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; import type { Login } from '@/config/entity'; -export const generateSalt = (login: Login) => httpPost('api/v3/auth/token/salt', login); +export const generateSalt = (login: Login) => httpPost(`${API_AUTH_BASE}/token/salt`, login); -export const generateToken = (login: Login) => httpPost('api/v3/auth/token/generate', login); +export const generateToken = (login: Login) => httpPost(`${API_AUTH_BASE}/token/generate`, login); -export const cancelToken = (login: Login) => httpPost('api/v3/auth/token/cancel', login); +export const cancelToken = (login: Login) => httpPost(`${API_AUTH_BASE}/token/cancel`, login); -export const checkTokenValid = (login: Login) => httpPost('api/v3/auth/token/check', login); +export const checkTokenValid = (login: Login) => httpPost(`${API_AUTH_BASE}/token/check`, login); diff --git a/src/api/user.ts b/src/api/user.ts index 3ad05c30a..b9ab06767 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -15,15 +15,16 @@ */ import { httpGet, httpPost } from '@/api/common'; +import { API_AUTH_BASE } from '@/config/constant/api'; -export const addUser = (user: any) => httpPost('api/v3/auth/user-profile/add', user); +export const addUser = (user: any) => httpPost(`${API_AUTH_BASE}/user-profile/add`, user); -export const deleteUser = (id: string) => httpPost(`api/v3/auth/user-profile/delete/${id}`); +export const deleteUser = (id: string) => httpPost(`${API_AUTH_BASE}/user-profile/delete/${id}`); -export const updateUser = (user: any) => httpPost('api/v3/auth/user-profile/update', user); +export const updateUser = (user: any) => httpPost(`${API_AUTH_BASE}/user-profile/update`, user); -export const getUserById = (id: string) => httpGet(`api/v3/auth/user-profile/id/${id}`); +export const getUserById = (id: string) => httpGet(`${API_AUTH_BASE}/user-profile/id/${id}`); -export const getUserByName = (name: string) => httpGet(`api/v3/auth/user-profile/name/${name}`); +export const getUserByName = (name: string) => httpGet(`${API_AUTH_BASE}/user-profile/name/${name}`); -export const getUserList = (query: any) => httpPost('api/v3/auth/user-profile/list', query); +export const getUserList = (query: any) => httpPost(`${API_AUTH_BASE}/user-profile/list`, query); diff --git a/src/config/constant/api.ts b/src/config/constant/api.ts new file mode 100644 index 000000000..749967206 --- /dev/null +++ b/src/config/constant/api.ts @@ -0,0 +1,29 @@ +/* + * Copyright 2016-present the IoT DC3 original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Gateway-prefixed base paths for every `src/api/*.ts` module. + * The gateway (dc3-gateway) strips the `/api/v3` prefix and routes the + * remainder to the matching center service (auth / data / manager). + * + * Keep these in sync with: + * - dc3-gateway/src/main/resources/application-*.yml (StripPrefix=2) + * - dc3-common-constant/.../service/{Auth,Data,Manager}Constant.java + * (SERVICE_NAME + URL_PREFIX fragments) + */ +export const API_AUTH_BASE = 'api/v3/auth'; +export const API_DATA_BASE = 'api/v3/data'; +export const API_MANAGER_BASE = 'api/v3/manager';