Commit bb028e900fa67c8c7caa6583efc2e3733d514ccf

Authored by ww
1 parent e95e5596

perf: data component create component add deviceType field

... ... @@ -3,9 +3,10 @@ import { HistoryData } from './model';
3 3 import { defHttp } from '/@/utils/http/axios';
4 4
5 5 // 获取设备配置
6   -export const getDeviceProfile = () => {
  6 +export const getDeviceProfile = (deviceType?: string) => {
7 7 return defHttp.get<DeviceProfileModel[]>({
8 8 url: '/device_profile/me/list',
  9 + params: { deviceType },
9 10 });
10 11 };
11 12
... ...
... ... @@ -7,6 +7,7 @@ import {
7 7 DeviceAttributeParams,
8 8 DeviceAttributeRecord,
9 9 GetDataBoardParams,
  10 + GetMeetTheConditionsDeviceParams,
10 11 MasterDeviceList,
11 12 SendCommandParams,
12 13 UpdateDataBoardLayoutParams,
... ... @@ -39,9 +40,10 @@ enum SendCommand {
39 40 }
40 41
41 42 enum DeviceUrl {
42   - GET_DEVICE = '/device/list/master',
  43 + GET_DEVICE_MASTER = '/device/list/master',
43 44 GET_SLAVE_DEVICE = '/device/list/slave',
44 45 GET_DEVICE_ATTRIBUTE = '/device/attributes',
  46 + GET_DEVICE = '/device/list',
45 47 }
46 48
47 49 /**
... ... @@ -168,12 +170,24 @@ export const getShareBoardComponentInfo = (params: { boardId: string; tenantId:
168 170 */
169 171 export const getAllDeviceByOrg = (organizationId: string, deviceProfileId?: string) => {
170 172 return defHttp.get<MasterDeviceList[]>({
171   - url: `${DeviceUrl.GET_DEVICE}/${organizationId}`,
  173 + url: `${DeviceUrl.GET_DEVICE_MASTER}/${organizationId}`,
172 174 params: { deviceProfileId },
173 175 });
174 176 };
175 177
176 178 /**
  179 + * @description 获取满足条件的设备
  180 + * @param params
  181 + * @returns
  182 + */
  183 +export const getMeetTheConditionsDevice = (params: GetMeetTheConditionsDeviceParams) => {
  184 + return defHttp.get({
  185 + url: DeviceUrl.GET_DEVICE,
  186 + params,
  187 + });
  188 +};
  189 +
  190 +/**
177 191 * @description 获取网关子设备
178 192 * @param params
179 193 * @returns
... ...
... ... @@ -162,3 +162,10 @@ export interface SendCommandParams {
162 162 deviceId: string;
163 163 value: any;
164 164 }
  165 +
  166 +export interface GetMeetTheConditionsDeviceParams {
  167 + deviceLabel?: string;
  168 + deviceType?: string;
  169 + organizationId?: string;
  170 + deviceProfileId?: string;
  171 +}
... ...
1   -import { getAllDeviceByOrg, getDeviceAttributes, getGatewaySlaveDevice } from '/@/api/dataBoard';
  1 +import { getDeviceAttributes, getMeetTheConditionsDevice } from '/@/api/dataBoard';
2 2 import { getOrganizationList } from '/@/api/system/system';
3 3 import { FormSchema } from '/@/components/Form';
4 4 import { copyTransFun } from '/@/utils/fnUtils';
... ... @@ -6,6 +6,8 @@ import { DeviceAttributeParams, MasterDeviceList } from '/@/api/dataBoard/model'
6 6 import { FrontComponent } from '../../const/const';
7 7 import { getDeviceProfile } from '/@/api/alarm/position';
8 8 import { getModelServices } from '/@/api/device/modelOfMatter';
  9 +import { findDictItemByCode } from '/@/api/system/dict';
  10 +import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
9 11
10 12 export enum BasicConfigField {
11 13 NAME = 'name',
... ... @@ -31,10 +33,11 @@ const getDeviceService = async (deviceProfileId: string) => {
31 33
32 34 export enum DataSourceField {
33 35 IS_GATEWAY_DEVICE = 'gatewayDevice',
  36 + DEVICE_TYPE = 'deviceType',
34 37 TRANSPORT_TYPE = 'transportType',
35 38 ORIGINATION_ID = 'organizationId',
36 39 DEVICE_ID = 'deviceId',
37   - SLAVE_DEVICE_ID = 'slaveDeviceId',
  40 + // SLAVE_DEVICE_ID = 'slaveDeviceId',
38 41 DEVICE_PROFILE_ID = 'deviceProfileId',
39 42 ATTRIBUTE = 'attribute',
40 43 ATTRIBUTE_RENAME = 'attributeRename',
... ... @@ -107,6 +110,34 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
107 110 show: false,
108 111 },
109 112 {
  113 + field: DataSourceField.DEVICE_TYPE,
  114 + component: 'ApiSelect',
  115 + label: '设备类型',
  116 + colProps: { span: 8 },
  117 + defaultValue: DeviceTypeEnum.SENSOR,
  118 + componentProps: ({ formActionType }) => {
  119 + const { setFieldsValue } = formActionType;
  120 + return {
  121 + api: findDictItemByCode,
  122 + params: {
  123 + dictCode: 'device_type',
  124 + },
  125 + valueField: 'itemValue',
  126 + labelField: 'itemText',
  127 + placeholder: '请选择设备类型',
  128 + onChange: (value: DeviceTypeEnum) => {
  129 + setFieldsValue({
  130 + [DataSourceField.IS_GATEWAY_DEVICE]: value === DeviceTypeEnum.GATEWAY,
  131 + [DataSourceField.DEVICE_PROFILE_ID]: null,
  132 + [DataSourceField.DEVICE_ID]: null,
  133 + [DataSourceField.ATTRIBUTE]: null,
  134 + [DataSourceField.TRANSPORT_TYPE]: null,
  135 + });
  136 + },
  137 + };
  138 + },
  139 + },
  140 + {
110 141 field: DataSourceField.DEVICE_PROFILE_ID,
111 142 component: 'ApiSelect',
112 143 label: '产品',
... ... @@ -115,9 +146,11 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
115 146 componentProps: ({ formActionType, formModel }) => {
116 147 const { setFieldsValue } = formActionType;
117 148 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
  149 + const deviceType = formModel[DataSourceField.DEVICE_TYPE];
118 150 return {
119 151 api: async () => {
120   - const list = await getDeviceProfile();
  152 + if (!deviceType) return [];
  153 + const list = await getDeviceProfile(deviceType);
121 154 if (deviceProfileId) {
122 155 const record = list.find((item) => item.id === deviceProfileId);
123 156 setFieldsValue({ [DataSourceField.TRANSPORT_TYPE]: record?.transportType });
... ... @@ -126,14 +159,12 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
126 159 },
127 160 labelField: 'name',
128 161 valueField: 'id',
129   - onChange: (_, option: Record<'transportType', string>) => {
130   - console.log(option);
  162 + placeholder: '请选择产品',
  163 + onChange: (_, option = {} as Record<'transportType', string>) => {
131 164 setFieldsValue({
132 165 [DataSourceField.DEVICE_ID]: null,
133 166 [DataSourceField.ATTRIBUTE]: null,
134   - [DataSourceField.SLAVE_DEVICE_ID]: null,
135   - [DataSourceField.IS_GATEWAY_DEVICE]: false,
136   - [DataSourceField.TRANSPORT_TYPE]: option.transportType,
  167 + [DataSourceField.TRANSPORT_TYPE]: option[DataSourceField.TRANSPORT_TYPE],
137 168 });
138 169 },
139 170 };
... ... @@ -157,9 +188,6 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
157 188 onChange() {
158 189 setFieldsValue({
159 190 [DataSourceField.DEVICE_ID]: null,
160   - [DataSourceField.ATTRIBUTE]: null,
161   - [DataSourceField.SLAVE_DEVICE_ID]: null,
162   - [DataSourceField.IS_GATEWAY_DEVICE]: false,
163 191 });
164 192 },
165 193 getPopupContainer: () => document.body,
... ... @@ -182,12 +210,17 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
182 210 const { setFieldsValue } = formActionType;
183 211 const organizationId = formModel[DataSourceField.ORIGINATION_ID];
184 212 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
  213 + const deviceType = formModel[DataSourceField.DEVICE_TYPE];
185 214
186 215 return {
187 216 api: async () => {
188 217 if (organizationId) {
189 218 try {
190   - const data = await getAllDeviceByOrg(organizationId, deviceProfileId);
  219 + const data = await getMeetTheConditionsDevice({
  220 + organizationId,
  221 + deviceProfileId,
  222 + deviceType,
  223 + });
191 224 if (data)
192 225 return data.map((item) => ({
193 226 ...item,
... ... @@ -202,9 +235,6 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
202 235
203 236 onChange(_value, record: MasterDeviceList) {
204 237 setFieldsValue({
205   - [DataSourceField.ATTRIBUTE]: null,
206   - [DataSourceField.IS_GATEWAY_DEVICE]: record?.deviceType === 'GATEWAY',
207   - [DataSourceField.SLAVE_DEVICE_ID]: null,
208 238 [DataSourceField.DEVICE_NAME]: record?.label,
209 239 });
210 240 },
... ... @@ -214,58 +244,6 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
214 244 },
215 245 },
216 246 {
217   - field: DataSourceField.SLAVE_DEVICE_ID,
218   - label: '网关子设备',
219   - component: 'ApiSelect',
220   - colProps: { span: 8 },
221   - rules: [{ required: true, message: '网关子设备为必填项' }],
222   - show: false,
223   - ifShow({ model }) {
224   - const transportType = model[DataSourceField.TRANSPORT_TYPE];
225   - return (
226   - !(isControlComponent(frontId as FrontComponent) && isTcpProfile(transportType)) &&
227   - model[DataSourceField.IS_GATEWAY_DEVICE]
228   - );
229   - },
230   - dynamicRules({ model }) {
231   - return [
232   - { required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' },
233   - ];
234   - },
235   - componentProps({ formModel, formActionType }) {
236   - const { setFieldsValue } = formActionType;
237   - const organizationId = formModel[DataSourceField.ORIGINATION_ID];
238   - const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
239   - const deviceId = formModel[DataSourceField.DEVICE_ID];
240   -
241   - return {
242   - api: async () => {
243   - if (organizationId && isGatewayDevice) {
244   - try {
245   - const data = await getGatewaySlaveDevice({ organizationId, masterId: deviceId });
246   - if (data)
247   - return data.map((item) => ({
248   - ...item,
249   - label: item.name,
250   - value: item.id,
251   - deviceType: item.deviceType,
252   - }));
253   - } catch (error) {}
254   - }
255   - return [];
256   - },
257   - onChange(_value, record: MasterDeviceList) {
258   - setFieldsValue({
259   - [DataSourceField.ATTRIBUTE]: null,
260   - [DataSourceField.DEVICE_NAME]: record?.label,
261   - });
262   - },
263   - placeholder: '请选择网关子设备',
264   - getPopupContainer: () => document.body,
265   - };
266   - },
267   - },
268   - {
269 247 field: DataSourceField.ATTRIBUTE,
270 248 component: 'ApiSelect',
271 249 label: '属性',
... ...