123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- import qs from 'qs';
- import { request } from '@/utils';
- import type {
- AddInterface,
- AgreementUpdate,
- DeviceGroupItem,
- DevicesList,
- DictTypeData,
- DictTypeDataParams,
- EquipmentInformationForm,
- EquipmentTypeItem,
- EquipmentUpdateForm,
- GatewayInformation,
- GatewayInterface,
- GatewayModelInfo,
- GetListItem,
- GroupingList,
- GroupingListData,
- InterfaceData,
- ListEquipmentParametersItemData,
- ListInfo,
- ListInterfaces,
- ListPhysicalInterfaces,
- ParameterVerification,
- PostProtocolPage,
- PostProtocolPageItemData,
- ProtocolBaseInfo,
- ProtocolGatewayListListItem,
- ProtocolItemData,
- ProtocolList,
- ProtocolListItem,
- ProtocolParamData,
- ProtocolParamInfo,
- ProtocolParamSearchParams,
- ProtocolReset,
- ProtocolStandardParamData,
- ProtocolStandardParamSearchParams,
- SerialNumberItemData,
- VerificationAgreement,
- VerificationEquipment,
- } from '@/types';
- /**
- * 获取认证授权服务 url
- */
- const apiUaa = (path: string, params?: unknown) => {
- const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
- return `/api-uaa${apiUrl}`;
- };
- /**
- * 获取系统服务 url
- */
- const apiSys = (path: string, params?: unknown) => {
- const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
- return `/api-sys${apiUrl}`;
- };
- /**
- * 获取业务服务 url
- */
- const apiBiz = (path: string, params?: unknown) => {
- const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
- return `/api-biz${apiUrl}`;
- };
- // ----- 认证授权服务 -----
- // 登录和注销
- export const loginUser = async () => {
- const params = {
- grant_type: 'password',
- username: 'admin1',
- password: 'admin',
- };
- await request(apiUaa('/oauth/token', params), {
- method: 'POST',
- headers: {
- Authorization: 'Basic ' + btoa('unimat:unimat'),
- },
- });
- };
- export const logoutUser = async () => {
- await request(apiUaa('/oauth/remove/token'));
- };
- export const refreshUser = async () => {
- await request(apiUaa('/oauth/token'));
- };
- // ----- 系统服务 -----
- // 字典类型表
- export const getDictTypeData = async (params: DictTypeDataParams) => {
- const data = await request<DictTypeData[]>(apiSys('/sysDictType/typeAndData/', params));
- return data;
- };
- // ----- 业务服务 -----
- // 设备组列表
- export const getPageList = async () => {
- const data = await request<DeviceGroupItem[]>(apiBiz('/deviceGroup/getList'), {
- method: 'POST',
- });
- return data;
- };
- // 设备列表
- export const deviceAdd = async (equipmentInformationForm: EquipmentInformationForm) => {
- const data = await request<number>(apiBiz('/device/add'), {
- method: 'POST',
- body: JSON.stringify(equipmentInformationForm),
- });
- return data;
- };
- export const deviceDeletion = async (id: number) => {
- await request(apiBiz(`${'/device/delete/'}${id}`), {
- method: 'POST',
- });
- };
- export const queryDevicesList = async (devicesList: DevicesList) => {
- await request(apiBiz('/device/getPageList'), {
- method: 'POST',
- body: JSON.stringify(devicesList),
- });
- };
- // 设备网关
- export const deviceGatewayUpdate = async (equipmentUpdateForm: EquipmentUpdateForm[]) => {
- await request(apiBiz('/deviceGateway/update'), {
- method: 'POST',
- body: JSON.stringify(equipmentUpdateForm),
- });
- };
- // 设备协议参数验证
- export const postParameterVerification = async (deviceId: number) => {
- const data = await request<ParameterVerification[]>(apiBiz('/protocolParamVerify/list'), {
- method: 'POST',
- body: JSON.stringify(deviceId),
- });
- return data;
- };
- // 设备参数分组
- export const equipmentParametersList = async (groupingList: GroupingList[]) => {
- await request(apiBiz('/deviceParamGroup/update/batch'), {
- method: 'POST',
- body: JSON.stringify(groupingList),
- });
- };
- export const queryEquipmentParametersList = async (deviceId: number) => {
- const data = await request<GroupingListData[]>(apiBiz('/deviceParamGroup/getList'), {
- method: 'POST',
- body: JSON.stringify({ deviceId }),
- });
- return data;
- };
- // 网关基本信息
- export const addGateway = async () => {
- await request(apiBiz('/gateway/add'));
- };
- export const validateGatewayInfo = async (registerGatewayForm: VerificationEquipment) => {
- const data = await request<GatewayInformation>(apiBiz('/gateway/validate', registerGatewayForm), {
- method: 'POST',
- });
- return data;
- };
- // 网关通讯
- export const gatewayLinkAdd = async (addInterface: AddInterface) => {
- await request(apiBiz('/gatewayLink/add'), {
- method: 'POST',
- body: JSON.stringify(addInterface),
- });
- };
- export const gatewayLinkDelete = async (id: number) => {
- await request(apiBiz(`${'/gatewayLink/delete/'}${id}`), {
- method: 'POST',
- });
- };
- export const gatewayLinkGetList = async (gatewayId: number) => {
- const data = await request<InterfaceData[]>(apiBiz(`${'/gatewayLink/getList/'}${gatewayId}`), {
- method: 'POST',
- });
- return data;
- };
- export const gatewayLinkUpdate = async (agreementUpdate: AgreementUpdate) => {
- await request(apiBiz('/gatewayLink/update'), {
- method: 'POST',
- body: JSON.stringify(agreementUpdate),
- });
- };
- // 网关型号
- export const getGatewayModelInfo = async (id: number) => {
- const data = await request<GatewayModelInfo>(apiBiz(`${'/gatewayModel/info/'}${id}`));
- return data;
- };
- export const getGatewayModelInterfaces = async (id: number) => {
- const data = await request<GatewayInterface[]>(apiBiz(`${'/gatewayModel/interfaces/'}${id}`), {
- method: 'POST',
- });
- return data;
- };
- // 网关物理接口协议
- export const obtainListPhysicalInterfaces = async (id: number) => {
- const data = await request<ListPhysicalInterfaces[]>(apiBiz(`${'/gatewayInterfaceProtocol/getProtocols/'}${id}`));
- return data;
- };
- // 网关型号物理接口
- export const obtainListInterfaces = async (id: number) => {
- const data = await request<ListInterfaces[]>(apiBiz(`${'/gatewayPhysicalInterface/getInterfaces/'}${id}`));
- return data;
- };
- // 网关接口协议
- export const gatewayLinkProtocolList = async <T>(protocolListItem: ProtocolListItem) => {
- const data = await request<T>(apiBiz('/gatewayLinkProtocol/getParamPageList'), {
- method: 'POST',
- body: JSON.stringify(protocolListItem),
- });
- return data;
- };
- export const gatewayLinkProtocolGatewayList = async (protocolGatewayListListItem: ProtocolGatewayListListItem) => {
- const data = await request<ListEquipmentParametersItemData>(
- apiBiz('/gatewayLinkProtocol/getParamPageListByGateway'),
- {
- method: 'POST',
- body: JSON.stringify(protocolGatewayListListItem),
- },
- );
- return data;
- };
- export const gatewayLinkList = async (id: number) => {
- const data = await request<VerificationAgreement[]>(apiBiz(`${'/gatewayLinkProtocol/getProtocolInfoList/'}${id}`), {
- method: 'POST',
- });
- return data;
- };
- export const gatewayLinkProtocolReset = async (protocolReset: ProtocolReset) => {
- await request(apiBiz('/gatewayLinkProtocol/reset'), {
- method: 'POST',
- body: JSON.stringify(protocolReset),
- });
- };
- export const postProtocolCandidatesList = async (protocolList: ProtocolList, gatewayId: number) => {
- const data = await request<ProtocolItemData>(apiBiz(`${'/gatewayLinkProtocol/getProtocolCandidates/'}${gatewayId}`), {
- method: 'POST',
- body: JSON.stringify(protocolList),
- });
- return data;
- };
- // 组织网关
- export const orgGatewayRegister = async (gatewayId: number) => {
- await request(apiBiz('/orgGateway/register'), {
- method: 'POST',
- body: JSON.stringify({ gatewayId }),
- });
- };
- export const orgGatewaySerialNumber = async (protocolList: ProtocolList) => {
- const data = await request<SerialNumberItemData>(apiBiz('/orgGateway/getGatewayPageList'), {
- method: 'POST',
- body: JSON.stringify(protocolList),
- });
- return data;
- };
- // 协议标准参数
- export const getProtocolStandardParamList = async (params: ProtocolStandardParamSearchParams) => {
- const data = await request<ProtocolStandardParamData>(apiBiz('/protocolStandardParam/getPageList'), {
- method: 'POST',
- body: JSON.stringify(params),
- });
- return data;
- };
- // 协议参数
- export const addProtocolParam = async (params: Partial<ProtocolParamInfo>) => {
- await request(apiBiz('/protocolParamInfo/add'), {
- method: 'POST',
- body: JSON.stringify(params),
- });
- };
- export const getProtocolParamList = async (params: ProtocolParamSearchParams) => {
- const data = await request<ProtocolParamData>(apiBiz('/protocolParamInfo/getPageList'), {
- method: 'POST',
- body: JSON.stringify(params),
- });
- return data;
- };
- export const batchDeleleProtocolParam = async (params: number[]) => {
- await request(apiBiz('/protocolParamInfo/batchDeleleByIds'), {
- method: 'POST',
- body: JSON.stringify(params),
- });
- };
- // 协议基本信息
- export const addProtocolBaseInfo = async () => {
- await request(apiBiz('/protocolBaseInfo/add'), {
- method: 'POST',
- });
- };
- export const downloadProtocolTemplate = async (fileName: string) => {
- const blob = await request<Blob>(apiBiz(`/protocolBaseInfo/downloadTemplate/${fileName}`));
- return blob;
- };
- export const uploadUserProtocol = async (protocolType: string, file: Blob) => {
- const formData = new FormData();
- formData.append('file', file);
- const data = await request<Pick<ProtocolBaseInfo, 'id' | 'protocolName' | 'protocolType'>>(
- apiBiz('/protocolBaseInfo/uploadUserTemplate/', { protocolType }),
- {
- method: 'POST',
- body: formData,
- },
- );
- return data;
- };
- export const reUploadUserProtocol = async (protocolType: string, id: number, file: Blob) => {
- const formData = new FormData();
- formData.append('file', file);
- const data = await request<Pick<ProtocolBaseInfo, 'id' | 'protocolName' | 'protocolType'>>(
- apiBiz('/protocolBaseInfo/resetConfiguration/', { protocolType, id }),
- {
- method: 'POST',
- body: formData,
- },
- );
- return data;
- };
- export const downloadUserProtocol = async (protocolType: string, protocolName: string) => {
- const blob = await request<Blob>(
- apiBiz('/protocolBaseInfo/downloadUserProtocol/', {
- protocolType,
- protocolName,
- }),
- );
- return blob;
- };
- /**
- * @deprecated
- */
- export const getUploadProtocol = async (protocolType: string, protocolName: string) => {
- const data = await request<ProtocolBaseInfo>(
- apiBiz('/protocolBaseInfo/findUploadProtocolBaseInfo/', {
- protocolType,
- protocolName,
- }),
- );
- return data;
- };
- export const getProtocolBaseInfo = async (id: number) => {
- const data = await request<ProtocolBaseInfo>(apiBiz(`/protocolBaseInfo/info/${id}`));
- return data;
- };
- export const updateProtocolBaseInfo = async (params: Partial<ProtocolBaseInfo>) => {
- await request(apiBiz('/protocolBaseInfo/update'), {
- method: 'POST',
- body: JSON.stringify(params),
- });
- };
- export const postProtocolList = async (protocolList: ProtocolList) => {
- const data = await request<ProtocolItemData>(apiBiz('/protocolBaseInfo/getPageList'), {
- method: 'POST',
- body: JSON.stringify(protocolList),
- });
- return data;
- };
- // 协议参数表
- export const postProtocolPageList = async (postProtocolPage: PostProtocolPage) => {
- const data = await request<PostProtocolPageItemData>(apiBiz('/protocolParamInfo/page/list'), {
- method: 'POST',
- body: JSON.stringify(postProtocolPage),
- });
- return data;
- };
- export const postProtocolGetList = async (getListItem: GetListItem) => {
- const data = await request<PostProtocolPageItemData>(apiBiz('/protocolParamInfo/getList'), {
- method: 'POST',
- body: JSON.stringify(getListItem),
- });
- return data;
- };
- // 全局参数
- export const groupList = async (listInfo: ListInfo) => {
- const data = await request<EquipmentTypeItem[]>(apiBiz('/deviceGlobalData/getList'), {
- method: 'POST',
- body: JSON.stringify(listInfo),
- });
- return data;
- };
|