index.ts
4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import type { DeviceActiveType, DeviceAttributeItemType, DeviceItemType, DeviceProfileItemType, OrganizationItemType, ProductsDetailWithThingsModelType, RpcCommandType, SendValue, ThingsModel, ThingsModelItemType } from './model'
import { CommandWayEnum } from '@/enums/commandEnum'
import type { DeviceTypeEnum } from '@/enums/datasource'
import { FunctionTypeEnum } from '@/enums/datasource'
import { isShareMode } from '@/utils/env'
import { defHttp } from '@/utils/http'
enum Api {
GET_DEVICE_PROFILE = '/device_profile/me/list',
GET_ORG = '/organization/me/list',
GET_DEVICE_LIST = '/device/list',
GET_DEVICE_ATTRIBUTES = '/device/attributes/',
GET_DEVICE_BY_DEVICE_PROFILED_IDS = '/device/getListByDeviceProfileIds',
GET_THINGS_MODEL_SERVICES = '/things_model/get_services/',
RPC_COMMAND = '/rpc/',
GET_DEVICE_ACTIVE = 'plugins/telemetry/DEVICE/',
RPC_ONEWAY = '/rpc/oneway',
RPC_TWOWAY = '/rpc/twoway',
GEN_MODBUS_COMMAND = '/js/modbus',
GET_DEVICE_DETAIL = '/device/', // 获取设备详情
GET_LIST_BY_CONFIGURATION_ID = '/configuration/center/getListByConfigurationId',
GET_PRODUCTS_DETAIL_WITH_THINGS_MODEL = '/things_model/batch/get_tsl',
}
export interface GenModbusCommandType {
crc: string
deviceCode: string
method: string
registerAddress: number
registerNumber?: number
registerValues?: number[]
}
export const getDeviceProfile = (deviceType?: DeviceTypeEnum) => {
return defHttp.get<DeviceProfileItemType[]>({
url: Api.GET_DEVICE_PROFILE,
params: { deviceType },
})
}
export const getOrganization = (organizationId?: string) => {
return defHttp.get<OrganizationItemType[]>({
url: Api.GET_ORG,
params: { organizationId },
})
}
export const getDevice = ({ deviceProfileId, deviceType, organizationId }: { deviceType?: DeviceTypeEnum; deviceProfileId?: string; organizationId?: string }) => {
return defHttp.get<DeviceItemType[]>({
url: Api.GET_DEVICE_LIST,
params: { deviceProfileId, deviceType, organizationId },
})
}
export const getDeviceAttributes = (deviceProfileId: string) => {
return defHttp.get<ThingsModelItemType[]>({
url: `${Api.GET_DEVICE_ATTRIBUTES}${deviceProfileId}`,
})
}
export const getListByDeviceProfileIds = ({ deviceProfileIds, organizationId }: Recordable) => {
return defHttp.post<DeviceItemType[]>({
url: `${Api.GET_DEVICE_BY_DEVICE_PROFILED_IDS}?organizationId=${organizationId}`,
data: deviceProfileIds,
})
}
export const getThingsModelServices = (deviceProfileId: string) => {
return defHttp.get<ThingsModel>({
url: `${Api.GET_THINGS_MODEL_SERVICES}${deviceProfileId}`,
})
}
export const doCommandDelivery = ({ way, deviceId, command }: { way: CommandWayEnum; deviceId: string; command: RpcCommandType }) => {
return defHttp.post<Record<'rpcId', string>>({
url: `${Api.RPC_COMMAND}/${way}/${deviceId}`,
data: command,
},
{
joinPrefix: false,
},
)
}
export const getDeviceActive = (deviceId: string) => {
return defHttp.get<DeviceAttributeItemType[]>({
url: `${Api.GET_DEVICE_ACTIVE}/${deviceId}/values/attributes?keys=active`,
}, { joinPrefix: false })
}
// 命令下发
export const sendRpcOneway = (param: SendValue | any, deviceId?: string, way?: string) => {
return defHttp.post({
url: `${way !== CommandWayEnum.TWO_WAY ? Api.RPC_ONEWAY : Api.RPC_TWOWAY}/${deviceId}`,
data: param,
},
{
joinPrefix: false,
})
}
/**
* @description 生成modbus指令
* @param data
* @returns {string}
*/
export const genModbusCommand = (data: GenModbusCommandType) => {
return defHttp.post<string>({
url: Api.GEN_MODBUS_COMMAND,
data,
})
}
// 获取设备状态,在线 or 离线时间 entityId:设备id
export const getDeviceActiveTime = (entityId: string) => {
return defHttp.get<DeviceActiveType[]>(
{
url: `/plugins/telemetry/DEVICE/${entityId}/values/attributes?keys=active`,
},
{
joinPrefix: false,
},
)
}
// 获取设备详情
export const getDeviceInfo = (deviceId: string) => {
return defHttp.get<DeviceItemType>(
{
url: isShareMode() ? `${Api.GET_DEVICE_DETAIL}public/${deviceId}` : `${Api.GET_DEVICE_DETAIL}${deviceId}`,
},
)
}
export const getListByConfigurationId = (configurationId: string) => {
return defHttp.post({
url: `${Api.GET_LIST_BY_CONFIGURATION_ID}?configurationId=${configurationId}`,
})
}
export const getProductsDetailWithThingsModel = ({ deviceProfileIds, functionTypeEnum }: { deviceProfileIds: string[]; functionTypeEnum?: FunctionTypeEnum | 'all' }) => {
return defHttp.post<ProductsDetailWithThingsModelType[]>({
url: Api.GET_PRODUCTS_DETAIL_WITH_THINGS_MODEL,
data: {
deviceProfileIds,
functionTypeEnum: functionTypeEnum || FunctionTypeEnum.PROPERTIES,
},
})
}