1
|
|
-import { ref, unref } from 'vue';
|
|
1
|
+import { ref } from 'vue';
|
2
|
2
|
import { BasicColumn, FormSchema } from '/@/components/Table';
|
3
|
|
-import {
|
4
|
|
- byOrganizationIdGetMasterDevice,
|
5
|
|
- screenLinkOrganizationGetApi,
|
6
|
|
- getAttribute,
|
7
|
|
-} from '/@/api/ruleengine/ruleengineApi';
|
8
|
|
-import { scheduleOptions } from './formatData';
|
|
3
|
+import { screenLinkOrganizationGetApi } from '/@/api/ruleengine/ruleengineApi';
|
9
|
4
|
import { copyTransFun } from '/@/utils/fnUtils';
|
10
|
|
-import { numberAndNonegativeRule } from '/@/utils/rules';
|
11
|
|
-import { findDictItemByCode } from '/@/api/system/dict';
|
12
|
|
-import { queryDeviceProfileBy } from '/@/api/device/deviceManager';
|
13
|
|
-import { getModelServices } from '/@/api/device/modelOfMatter';
|
14
|
|
-import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
|
15
|
|
-import useCommonFun from '../hooks/useCommonFun';
|
16
|
|
-import { DeviceProfileModel } from '/@/api/device/model/deviceModel';
|
17
|
|
-import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
|
18
|
5
|
import { useComponentRegister } from '/@/components/Form';
|
19
|
6
|
import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect';
|
20
|
|
-import { isArray } from '/@/utils/is';
|
21
|
|
-import { ReadAndWriteEnum } from '/@/enums/toolEnum';
|
22
|
7
|
|
23
|
8
|
useComponentRegister('OrgTreeSelect', OrgTreeSelect);
|
24
|
9
|
|
25
|
|
-const { useByProductGetAttribute } = useCommonFun();
|
26
|
10
|
export type TOption = {
|
27
|
11
|
label: string;
|
28
|
12
|
value: string;
|
29
|
13
|
};
|
30
|
14
|
|
31
|
|
-export enum CommandTypeEnum {
|
32
|
|
- CUSTOM = 0,
|
33
|
|
- SERVICE = 1,
|
34
|
|
- ATTRIBUTE = 2,
|
35
|
|
-}
|
36
|
|
-
|
37
|
15
|
/**
|
38
|
16
|
* 所使用的枚举值
|
39
|
17
|
*/
|
...
|
...
|
@@ -174,733 +152,3 @@ export const searchFormSchema: FormSchema[] = [ |
174
|
152
|
colProps: { span: 6 },
|
175
|
153
|
},
|
176
|
154
|
]; |
177
|
|
-// 持续时间
|
178
|
|
-const isTimeDuration = (type) => {
|
179
|
|
- return type === 'DURATION';
|
180
|
|
-};
|
181
|
|
-const isReplace = (type) => {
|
182
|
|
- return type === 'REPEATING';
|
183
|
|
-};
|
184
|
|
-// 部分
|
185
|
|
-const isPart = (type: string) => {
|
186
|
|
- return type === 'PART';
|
187
|
|
-};
|
188
|
|
-//新增代码2022-11-23
|
189
|
|
-const isPartOrAll = (type: string) => {
|
190
|
|
- return type === 'ALL' || type === 'PART';
|
191
|
|
-};
|
192
|
|
-const isService = (type: string) => {
|
193
|
|
- return Number(type) === 1;
|
194
|
|
-};
|
195
|
|
-const isDefine = (type: string) => {
|
196
|
|
- return Number(type) === 0;
|
197
|
|
-};
|
198
|
|
-//新增代码2022-11-23
|
199
|
|
-
|
200
|
|
-export const trigger_condition_schema: FormSchema[] = [
|
201
|
|
- {
|
202
|
|
- field: 'triggered',
|
203
|
|
- label: '',
|
204
|
|
- component: 'Select',
|
205
|
|
- defaultValue: 'SIMPLE',
|
206
|
|
- componentProps: {
|
207
|
|
- placeholder: '请选择触发类型',
|
208
|
|
- options: [
|
209
|
|
- { label: '简单', value: 'SIMPLE' },
|
210
|
|
- { label: '持续时长', value: 'DURATION' },
|
211
|
|
- { label: '重复次数', value: 'REPEATING' },
|
212
|
|
- ],
|
213
|
|
- },
|
214
|
|
- colProps: { span: 6 },
|
215
|
|
- },
|
216
|
|
- {
|
217
|
|
- field: 'deviceType',
|
218
|
|
- label: '',
|
219
|
|
- component: 'ApiSelect',
|
220
|
|
- colProps: { span: 6 },
|
221
|
|
- defaultValue: 'SENSOR',
|
222
|
|
- componentProps: ({ formActionType }) => {
|
223
|
|
- const { setFieldsValue } = formActionType;
|
224
|
|
- return {
|
225
|
|
- api: findDictItemByCode,
|
226
|
|
- params: {
|
227
|
|
- dictCode: 'device_type',
|
228
|
|
- },
|
229
|
|
- placeholder: '请选择类型',
|
230
|
|
- labelField: 'itemText',
|
231
|
|
- valueField: 'itemValue',
|
232
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
233
|
|
- onChange(e) {
|
234
|
|
- if (e) {
|
235
|
|
- setFieldsValue({ deviceProfileId: '' });
|
236
|
|
- }
|
237
|
|
- },
|
238
|
|
- };
|
239
|
|
- },
|
240
|
|
- },
|
241
|
|
- {
|
242
|
|
- field: 'deviceProfileId',
|
243
|
|
- label: '',
|
244
|
|
- component: 'ApiSelect',
|
245
|
|
- colProps: { span: 6 },
|
246
|
|
- componentProps: ({ formActionType, formModel }) => {
|
247
|
|
- const { updateSchema, setFieldsValue } = formActionType;
|
248
|
|
- const deviceType = formModel['deviceType'];
|
249
|
|
-
|
250
|
|
- return {
|
251
|
|
- api: queryDeviceProfileBy,
|
252
|
|
- params: {
|
253
|
|
- deviceType,
|
254
|
|
- },
|
255
|
|
- showSearch: true,
|
256
|
|
- placeholder: '请选择产品',
|
257
|
|
- labelField: 'name',
|
258
|
|
- valueField: 'id',
|
259
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
260
|
|
- onChange: async (e) => {
|
261
|
|
- if (e) {
|
262
|
|
- setFieldsValue({ type2: '', entityId: [] });
|
263
|
|
- const res = await getAttribute(e);
|
264
|
|
- const options = ref<TOption[]>([]);
|
265
|
|
- useByProductGetAttribute(res, updateSchema, options);
|
266
|
|
- }
|
267
|
|
- },
|
268
|
|
- filterOption: (inputValue: string, option: Record<'label' | 'value', string>) => {
|
269
|
|
- let { label, value } = option;
|
270
|
|
- label = label.toLowerCase();
|
271
|
|
- value = value.toLowerCase();
|
272
|
|
- inputValue = inputValue.toLowerCase();
|
273
|
|
- return label.includes(inputValue) || value.includes(inputValue);
|
274
|
|
- },
|
275
|
|
- };
|
276
|
|
- },
|
277
|
|
- },
|
278
|
|
- {
|
279
|
|
- field: 'device',
|
280
|
|
- label: '',
|
281
|
|
- component: 'Select',
|
282
|
|
- componentProps: {
|
283
|
|
- placeholder: '请选择设备',
|
284
|
|
- options: [
|
285
|
|
- { label: '全部', value: 'ALL' },
|
286
|
|
- { label: '部分', value: 'PART' },
|
287
|
|
- ],
|
288
|
|
- },
|
289
|
|
- colProps: { span: 6 },
|
290
|
|
- },
|
291
|
|
-
|
292
|
|
- {
|
293
|
|
- field: 'entityId',
|
294
|
|
- label: '',
|
295
|
|
- component: 'ApiSelect',
|
296
|
|
- componentProps: ({ formModel }) => {
|
297
|
|
- const deviceProfileId = formModel['deviceProfileId'];
|
298
|
|
- return {
|
299
|
|
- mode: 'multiple',
|
300
|
|
- api: async () => {
|
301
|
|
- if (unref(organizationId)) {
|
302
|
|
- try {
|
303
|
|
- const data = await byOrganizationIdGetMasterDevice({
|
304
|
|
- organizationId: unref(organizationId),
|
305
|
|
- deviceProfileId,
|
306
|
|
- });
|
307
|
|
- if (data)
|
308
|
|
- return data.map((item) => ({
|
309
|
|
- ...item,
|
310
|
|
- label: item.alias || item.name,
|
311
|
|
- value: item.tbDeviceId,
|
312
|
|
- }));
|
313
|
|
- } catch (error) {}
|
314
|
|
- }
|
315
|
|
- return [];
|
316
|
|
- },
|
317
|
|
- placeholder: '请选择设备',
|
318
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
319
|
|
- filterOption: (inputValue: string, option: Record<'label' | 'value', string>) => {
|
320
|
|
- let { label, value } = option;
|
321
|
|
- label = label.toLowerCase();
|
322
|
|
- value = value.toLowerCase();
|
323
|
|
- inputValue = inputValue.toLowerCase();
|
324
|
|
- return label.includes(inputValue) || value.includes(inputValue);
|
325
|
|
- },
|
326
|
|
- };
|
327
|
|
- },
|
328
|
|
- ifShow: ({ values }) => isPart(values.device),
|
329
|
|
- colProps: { span: 6 },
|
330
|
|
- },
|
331
|
|
-
|
332
|
|
- {
|
333
|
|
- field: 'time',
|
334
|
|
- label: '',
|
335
|
|
- component: 'Input',
|
336
|
|
- ifShow: ({ values }) => isTimeDuration(values.triggered),
|
337
|
|
- colProps: { span: 6 },
|
338
|
|
- slot: 'time',
|
339
|
|
- rules: numberAndNonegativeRule,
|
340
|
|
- },
|
341
|
|
- {
|
342
|
|
- field: 'timeUnit',
|
343
|
|
- label: '',
|
344
|
|
- component: 'Select',
|
345
|
|
- defaultValue: 'SECONDS',
|
346
|
|
- ifShow: ({ values }) => isTimeDuration(values.triggered),
|
347
|
|
- show: false,
|
348
|
|
- },
|
349
|
|
- {
|
350
|
|
- field: 'replaceValue',
|
351
|
|
- label: '',
|
352
|
|
- component: 'Input',
|
353
|
|
- componentProps: {
|
354
|
|
- placeholder: '事件计数值',
|
355
|
|
- },
|
356
|
|
- ifShow: ({ values }) => isReplace(values.triggered),
|
357
|
|
- colProps: { span: 6 },
|
358
|
|
- rules: numberAndNonegativeRule,
|
359
|
|
- },
|
360
|
|
- {
|
361
|
|
- field: 'triggerType',
|
362
|
|
- label: '',
|
363
|
|
- component: 'Select',
|
364
|
|
- componentProps: {
|
365
|
|
- placeholder: '设备触发',
|
366
|
|
- options: [
|
367
|
|
- { label: '设备触发', value: 'DEVICE_TRIGGER' },
|
368
|
|
- // { label: '定时触发', value: 'SCHEDULE_TRIGGER' },
|
369
|
|
- // { label: '场景触发', value: 'SCENE_TRIGGER' },
|
370
|
|
- // { label: '手动触发', value: 'HAND_ACT' },
|
371
|
|
- ],
|
372
|
|
- },
|
373
|
|
- colProps: { span: 6 },
|
374
|
|
- },
|
375
|
|
-
|
376
|
|
- {
|
377
|
|
- field: 'type1',
|
378
|
|
- label: '',
|
379
|
|
- component: 'Select',
|
380
|
|
- componentProps: {
|
381
|
|
- placeholder: '属性触发方式',
|
382
|
|
- options: [{ label: '属性触发', value: 'TIME_SERIES' }],
|
383
|
|
- },
|
384
|
|
- ifShow: ({ values }) => isDevice(values.triggerType),
|
385
|
|
- colProps: { span: 6 },
|
386
|
|
- },
|
387
|
|
- {
|
388
|
|
- field: 'type2',
|
389
|
|
- label: '',
|
390
|
|
- component: 'Select',
|
391
|
|
- componentProps: {
|
392
|
|
- placeholder: '请选择属性',
|
393
|
|
- },
|
394
|
|
- ifShow: ({ values }) => isDevice(values.triggerType),
|
395
|
|
- colProps: { span: 6 },
|
396
|
|
- // rules: numberAndEngLishRule,
|
397
|
|
- },
|
398
|
|
- {
|
399
|
|
- field: 'operationType',
|
400
|
|
- label: '',
|
401
|
|
- component: 'Select',
|
402
|
|
- slot: 'operationType',
|
403
|
|
- colProps: { span: 6 },
|
404
|
|
- },
|
405
|
|
- // {
|
406
|
|
- // field: 'detail',
|
407
|
|
- // label: '',
|
408
|
|
- // component: 'InputTextArea',
|
409
|
|
- // componentProps: {
|
410
|
|
- // placeholder: '请输入详情',
|
411
|
|
- // },
|
412
|
|
- // colProps: {
|
413
|
|
- // span: 13,
|
414
|
|
- // },
|
415
|
|
- // },
|
416
|
|
-];
|
417
|
|
-// !!!----------------------------------------------------^_^------------------------------------------------------------!!!
|
418
|
|
-enum ActionEnum {
|
419
|
|
- DEVICE_OUT = 'DEVICE_OUT',
|
420
|
|
- ALARM_OUT = 'MSG_NOTIFY',
|
421
|
|
-}
|
422
|
|
-const isDeviceOut = (type: string) => type === ActionEnum.DEVICE_OUT;
|
423
|
|
-const isAlarmOut = (type: string) => type === ActionEnum.ALARM_OUT;
|
424
|
|
-
|
425
|
|
-export const actionSchema: FormSchema[] = [
|
426
|
|
- {
|
427
|
|
- field: 'outTarget',
|
428
|
|
- label: '',
|
429
|
|
- component: 'Select',
|
430
|
|
- required: true,
|
431
|
|
- componentProps: {
|
432
|
|
- placeholder: '请选择执行动作',
|
433
|
|
- },
|
434
|
|
- slot: 'outTarget',
|
435
|
|
- colProps: { span: 6 },
|
436
|
|
- },
|
437
|
|
- {
|
438
|
|
- field: 'deviceType',
|
439
|
|
- label: '',
|
440
|
|
- component: 'ApiSelect',
|
441
|
|
- colProps: { span: 6 },
|
442
|
|
- defaultValue: 'SENSOR',
|
443
|
|
- componentProps: ({ formActionType }) => {
|
444
|
|
- const { setFieldsValue } = formActionType;
|
445
|
|
- return {
|
446
|
|
- api: findDictItemByCode,
|
447
|
|
- params: {
|
448
|
|
- dictCode: 'device_type',
|
449
|
|
- },
|
450
|
|
- placeholder: '请选择类型',
|
451
|
|
- labelField: 'itemText',
|
452
|
|
- valueField: 'itemValue',
|
453
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
454
|
|
- onChange(e) {
|
455
|
|
- if (e) {
|
456
|
|
- setFieldsValue({ deviceProfileId: '' });
|
457
|
|
- }
|
458
|
|
- },
|
459
|
|
- };
|
460
|
|
- },
|
461
|
|
- ifShow: ({ values }) => isDeviceOut(values.outTarget),
|
462
|
|
- },
|
463
|
|
- {
|
464
|
|
- field: 'transportType',
|
465
|
|
- label: '',
|
466
|
|
- component: 'Input',
|
467
|
|
- show: false,
|
468
|
|
- },
|
469
|
|
- {
|
470
|
|
- field: 'deviceProfileId',
|
471
|
|
- label: '',
|
472
|
|
- component: 'ApiSelect',
|
473
|
|
- colProps: { span: 6 },
|
474
|
|
- componentProps: ({ formActionType, formModel }) => {
|
475
|
|
- const { setFieldsValue } = formActionType;
|
476
|
|
- const deviceType = formModel['deviceType'];
|
477
|
|
- return {
|
478
|
|
- api: queryDeviceProfileBy,
|
479
|
|
- params: {
|
480
|
|
- deviceType,
|
481
|
|
- },
|
482
|
|
- placeholder: '请选择产品',
|
483
|
|
- labelField: 'name',
|
484
|
|
- valueField: 'id',
|
485
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
486
|
|
- onChange: (_value: string, options = {} as DeviceProfileModel) => {
|
487
|
|
- const oldType = formModel['transportType'];
|
488
|
|
-
|
489
|
|
- const updateFlag =
|
490
|
|
- oldType === TransportTypeEnum.TCP || options.transportType === TransportTypeEnum.TCP;
|
491
|
|
-
|
492
|
|
- setFieldsValue({
|
493
|
|
- thingsModelId: '',
|
494
|
|
- deviceId: [],
|
495
|
|
- transportType: options.transportType,
|
496
|
|
- ...(updateFlag ? { doContext: null } : {}),
|
497
|
|
- });
|
498
|
|
- },
|
499
|
|
- onOptionsChange(options: DeviceProfileModel[]) {
|
500
|
|
- const deviceProfileId = formModel['deviceProfileId'];
|
501
|
|
- if (deviceProfileId) {
|
502
|
|
- const index = options.findIndex(
|
503
|
|
- (item) => (item as Recordable).value === deviceProfileId
|
504
|
|
- );
|
505
|
|
-
|
506
|
|
- ~index && setFieldsValue({ transportType: options[index].transportType });
|
507
|
|
- }
|
508
|
|
- },
|
509
|
|
- };
|
510
|
|
- },
|
511
|
|
- ifShow: ({ values }) => isDeviceOut(values.outTarget),
|
512
|
|
- },
|
513
|
|
- {
|
514
|
|
- field: 'device',
|
515
|
|
- label: '',
|
516
|
|
- component: 'Select',
|
517
|
|
- componentProps: ({ formActionType }) => {
|
518
|
|
- const { setFieldsValue } = formActionType;
|
519
|
|
- return {
|
520
|
|
- placeholder: '请选择设备',
|
521
|
|
- options: [
|
522
|
|
- { label: '全部', value: 'ALL' },
|
523
|
|
- { label: '部分', value: 'PART' },
|
524
|
|
- ],
|
525
|
|
- onChange: () => {
|
526
|
|
- setFieldsValue({ deviceId: [], thingsModelId: null });
|
527
|
|
- },
|
528
|
|
- };
|
529
|
|
- },
|
530
|
|
- ifShow: ({ values }) => isDeviceOut(values.outTarget) && values['deviceProfileId'],
|
531
|
|
- colProps: { span: 6 },
|
532
|
|
- },
|
533
|
|
- {
|
534
|
|
- field: 'deviceId',
|
535
|
|
- label: '',
|
536
|
|
- component: 'ApiSelect',
|
537
|
|
- componentProps: ({ formModel }) => {
|
538
|
|
- const deviceProfileId = formModel['deviceProfileId'];
|
539
|
|
- return {
|
540
|
|
- mode: 'multiple',
|
541
|
|
- api: async () => {
|
542
|
|
- if (unref(organizationId)) {
|
543
|
|
- try {
|
544
|
|
- const data = await byOrganizationIdGetMasterDevice({
|
545
|
|
- organizationId: unref(organizationId),
|
546
|
|
- deviceProfileId,
|
547
|
|
- });
|
548
|
|
- if (data)
|
549
|
|
- return data.map((item) => ({
|
550
|
|
- ...item,
|
551
|
|
- label: item.alias || item.name,
|
552
|
|
- value: item.tbDeviceId,
|
553
|
|
- }));
|
554
|
|
- } catch (error) {}
|
555
|
|
- }
|
556
|
|
- return [];
|
557
|
|
- },
|
558
|
|
- placeholder: '请选择设备',
|
559
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
560
|
|
- };
|
561
|
|
- },
|
562
|
|
- ifShow: ({ values }) => isPart(values.device) && isDeviceOut(values.outTarget),
|
563
|
|
- colProps: { span: 6 },
|
564
|
|
- },
|
565
|
|
- //新增代码2022-11-23
|
566
|
|
- {
|
567
|
|
- field: 'commandType',
|
568
|
|
- label: '',
|
569
|
|
- required: true,
|
570
|
|
- component: 'ApiSelect',
|
571
|
|
- colProps: {
|
572
|
|
- span: 6,
|
573
|
|
- },
|
574
|
|
- defaultValue: '0',
|
575
|
|
- componentProps: ({ formActionType }) => {
|
576
|
|
- const { setFieldsValue } = formActionType;
|
577
|
|
- return {
|
578
|
|
- placeholder: '请选择类型',
|
579
|
|
- api: async (parmas: Recordable) => {
|
580
|
|
- try {
|
581
|
|
- const record = await findDictItemByCode(parmas);
|
582
|
|
- return record.filter(
|
583
|
|
- (item) =>
|
584
|
|
- item.itemValue !== CommandTypeEnum.ATTRIBUTE.toString() || item.itemText != '属性'
|
585
|
|
- );
|
586
|
|
- } catch (error) {
|
587
|
|
- return [];
|
588
|
|
- }
|
589
|
|
- },
|
590
|
|
- labelField: 'itemText',
|
591
|
|
- valueField: 'itemValue',
|
592
|
|
- params: {
|
593
|
|
- dictCode: 'custom_define',
|
594
|
|
- },
|
595
|
|
- numberToString: true,
|
596
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
597
|
|
- onChange: () => {
|
598
|
|
- setFieldsValue({ doContext: null, thingsModelId: null });
|
599
|
|
- },
|
600
|
|
- };
|
601
|
|
- },
|
602
|
|
- ifShow: ({ values }) => isDeviceOut(values.outTarget) && isPartOrAll(values.device),
|
603
|
|
- },
|
604
|
|
- //新增代码2022-11-23
|
605
|
|
- {
|
606
|
|
- field: 'callType',
|
607
|
|
- label: '',
|
608
|
|
- required: true,
|
609
|
|
- component: 'ApiSelect',
|
610
|
|
- colProps: {
|
611
|
|
- span: 6,
|
612
|
|
- },
|
613
|
|
- defaultValue: 'SYNC',
|
614
|
|
- componentProps: {
|
615
|
|
- placeholder: '请选择类型',
|
616
|
|
- api: findDictItemByCode,
|
617
|
|
- params: {
|
618
|
|
- dictCode: 'call_mode',
|
619
|
|
- },
|
620
|
|
- labelField: 'itemText',
|
621
|
|
- valueField: 'itemValue',
|
622
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
623
|
|
- },
|
624
|
|
- ifShow: ({ values }) =>
|
625
|
|
- isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.commandType),
|
626
|
|
- },
|
627
|
|
- {
|
628
|
|
- field: 'serviceIdentifier',
|
629
|
|
- label: '',
|
630
|
|
- component: 'Input',
|
631
|
|
- show: false,
|
632
|
|
- },
|
633
|
|
- {
|
634
|
|
- field: 'thingsModelKeys',
|
635
|
|
- label: '',
|
636
|
|
- show: false,
|
637
|
|
- component: 'Select',
|
638
|
|
- componentProps: {
|
639
|
|
- mode: 'multiple',
|
640
|
|
- },
|
641
|
|
- },
|
642
|
|
- {
|
643
|
|
- field: 'thingsModelId',
|
644
|
|
- label: '',
|
645
|
|
- required: true,
|
646
|
|
- component: 'ApiSelect',
|
647
|
|
- colProps: {
|
648
|
|
- span: 6,
|
649
|
|
- },
|
650
|
|
- componentProps: ({ formModel, formActionType }) => {
|
651
|
|
- const { updateSchema, setFieldsValue } = formActionType;
|
652
|
|
- const deviceProfileId = Reflect.get(formModel, 'deviceProfileId');
|
653
|
|
- const thingsModelId = Reflect.get(formModel, 'thingsModelId');
|
654
|
|
- const transportType = Reflect.get(formModel, 'transportType');
|
655
|
|
- return {
|
656
|
|
- placeholder: '请选择服务',
|
657
|
|
- api: async (params: Recordable) => {
|
658
|
|
- try {
|
659
|
|
- if (!Reflect.get(params, 'deviceProfileId')) return [];
|
660
|
|
- const record =
|
661
|
|
- (await getModelServices(params as Record<'deviceProfileId', string>)) || [];
|
662
|
|
- const selected = record.find((item) => item.id === thingsModelId);
|
663
|
|
- selected &&
|
664
|
|
- updateSchema({
|
665
|
|
- field: 'serviceInputValue',
|
666
|
|
- componentProps: {
|
667
|
|
- inputData: selected?.functionJson.inputData,
|
668
|
|
- },
|
669
|
|
- });
|
670
|
|
- selected &&
|
671
|
|
- setFieldsValue({
|
672
|
|
- callType: selected.callType,
|
673
|
|
- serviceIdentifier: selected?.identifier,
|
674
|
|
- thingsModelKeys: isArray(selected?.functionJson?.inputData)
|
675
|
|
- ? selected?.functionJson?.inputData
|
676
|
|
- .filter((item) => item.accessMode === ReadAndWriteEnum.READ_AND_WRITE)
|
677
|
|
- .map((item) => item.identifier)
|
678
|
|
- : [],
|
679
|
|
- });
|
680
|
|
- return record;
|
681
|
|
- } catch (error) {
|
682
|
|
- console.error(error);
|
683
|
|
- return [];
|
684
|
|
- }
|
685
|
|
- },
|
686
|
|
- params: {
|
687
|
|
- deviceProfileId,
|
688
|
|
- },
|
689
|
|
- labelField: 'functionName',
|
690
|
|
- valueField: 'id',
|
691
|
|
- getPopupContainer: (triggerNode) => triggerNode.parentNode,
|
692
|
|
- onChange: (_, options: ModelOfMatterParams) => {
|
693
|
|
- if (options) {
|
694
|
|
- // setFieldsValue({ doContext: { ...options.functionJson, callType: options.callType } });
|
695
|
|
- // if ( )
|
696
|
|
- const record = {
|
697
|
|
- callType: options.callType,
|
698
|
|
- serviceIdentifier: options.identifier,
|
699
|
|
- thingsModelKeys: isArray(options?.functionJson?.inputData)
|
700
|
|
- ? options?.functionJson?.inputData
|
701
|
|
- .filter((item) => item.accessMode === ReadAndWriteEnum.READ_AND_WRITE)
|
702
|
|
- .map((item) => item.identifier)
|
703
|
|
- : [],
|
704
|
|
- };
|
705
|
|
- transportType === TransportTypeEnum.TCP
|
706
|
|
- ? Object.assign(record, {
|
707
|
|
- tcpServiceCommand: options.functionJson?.inputData?.[0]?.serviceCommand,
|
708
|
|
- })
|
709
|
|
- : updateSchema({
|
710
|
|
- field: 'serviceInputValue',
|
711
|
|
- componentProps: {
|
712
|
|
- inputData: options.functionJson.inputData,
|
713
|
|
- },
|
714
|
|
- });
|
715
|
|
-
|
716
|
|
- setFieldsValue(record);
|
717
|
|
- } else {
|
718
|
|
- setFieldsValue({ serviceIdentifier: null });
|
719
|
|
- }
|
720
|
|
- },
|
721
|
|
- };
|
722
|
|
- },
|
723
|
|
- ifShow: ({ values }) => isDeviceOut(values.outTarget) && isService(values.commandType),
|
724
|
|
- },
|
725
|
|
- //新增代码2022-11-23
|
726
|
|
- {
|
727
|
|
- field: 'alarm_config',
|
728
|
|
- label: '',
|
729
|
|
- component: 'Input',
|
730
|
|
- componentProps: {
|
731
|
|
- placeholder: '请选择告警配置',
|
732
|
|
- },
|
733
|
|
- slot: 'alarmConfigSlot',
|
734
|
|
- ifShow: ({ values }) => values.outTarget === 'MSG_NOTIFY',
|
735
|
|
- colProps: { span: 6 },
|
736
|
|
- },
|
737
|
|
- //新增代码2022-11-23
|
738
|
|
- {
|
739
|
|
- field: 'doContext',
|
740
|
|
- component: 'Input',
|
741
|
|
- label: '',
|
742
|
|
- slot: 'doContext',
|
743
|
|
- show: ({ values }) => {
|
744
|
|
- return (
|
745
|
|
- isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.commandType)
|
746
|
|
- );
|
747
|
|
- },
|
748
|
|
- colProps: {
|
749
|
|
- span: 24,
|
750
|
|
- },
|
751
|
|
- },
|
752
|
|
- //新增代码2022-11-23
|
753
|
|
- {
|
754
|
|
- field: 'alarm_level',
|
755
|
|
- component: 'Select',
|
756
|
|
- label: '',
|
757
|
|
- show: ({ values }) => isAlarmOut(values.outTarget),
|
758
|
|
- // dynamicRules: (params) => {
|
759
|
|
- // const { outTarget } = params.values;
|
760
|
|
- // return [
|
761
|
|
- // {
|
762
|
|
- // required: outTarget == 'MSG_NOTIFY' ? true : false,
|
763
|
|
- // validator: (_, value) => {
|
764
|
|
- // if (!value) return Promise.reject('请选择告警配置');
|
765
|
|
- // Promise.resolve();
|
766
|
|
- // },
|
767
|
|
- // },
|
768
|
|
- // ];
|
769
|
|
- // },
|
770
|
|
- componentProps: {
|
771
|
|
- placeholder: '请选择告警等级',
|
772
|
|
- options: [
|
773
|
|
- {
|
774
|
|
- label: '紧急',
|
775
|
|
- value: 'CRITICAL',
|
776
|
|
- },
|
777
|
|
- {
|
778
|
|
- label: '重要',
|
779
|
|
- value: 'MAJOR',
|
780
|
|
- },
|
781
|
|
- {
|
782
|
|
- label: '次要',
|
783
|
|
- value: 'MINOR',
|
784
|
|
- },
|
785
|
|
- {
|
786
|
|
- label: '警告',
|
787
|
|
- value: 'WARNING',
|
788
|
|
- },
|
789
|
|
- {
|
790
|
|
- label: '不确定',
|
791
|
|
- value: 'INDETERMINATE',
|
792
|
|
- },
|
793
|
|
- ],
|
794
|
|
- },
|
795
|
|
- colProps: {
|
796
|
|
- span: 6,
|
797
|
|
- },
|
798
|
|
- },
|
799
|
|
- {
|
800
|
|
- field: 'clear_alarm',
|
801
|
|
- component: 'Checkbox',
|
802
|
|
- label: '',
|
803
|
|
- show: ({ values }) => isAlarmOut(values.outTarget),
|
804
|
|
- colProps: {
|
805
|
|
- span: 8,
|
806
|
|
- },
|
807
|
|
- slot: 'clearAlarm',
|
808
|
|
- },
|
809
|
|
- {
|
810
|
|
- field: 'tcpServiceCommand',
|
811
|
|
- component: 'Input',
|
812
|
|
- label: '服务命令',
|
813
|
|
- colProps: { span: 24 },
|
814
|
|
- dynamicDisabled: true,
|
815
|
|
- show: ({ values }) =>
|
816
|
|
- values['thingsModelId'] && values['transportType'] === TransportTypeEnum.TCP,
|
817
|
|
- },
|
818
|
|
- {
|
819
|
|
- field: 'serviceInputValue',
|
820
|
|
- component: 'ObjectModelValidateForm',
|
821
|
|
- label: '',
|
822
|
|
- changeEvent: 'update:value',
|
823
|
|
- valueField: 'value',
|
824
|
|
- show: ({ values }) =>
|
825
|
|
- values['thingsModelId'] && values['transportType'] !== TransportTypeEnum.TCP,
|
826
|
|
- colProps: {
|
827
|
|
- span: 24,
|
828
|
|
- },
|
829
|
|
- componentProps: {},
|
830
|
|
- },
|
831
|
|
-];
|
832
|
|
-
|
833
|
|
-export const alarmScheduleSchemas: FormSchema[] = [
|
834
|
|
- {
|
835
|
|
- field: 'schedule',
|
836
|
|
- label: '',
|
837
|
|
- component: 'Select',
|
838
|
|
- componentProps({ formActionType }) {
|
839
|
|
- const { resetFields } = formActionType;
|
840
|
|
- return {
|
841
|
|
- options: scheduleOptions,
|
842
|
|
- allowClear: false,
|
843
|
|
- onChange() {
|
844
|
|
- resetFields();
|
845
|
|
- },
|
846
|
|
- };
|
847
|
|
- },
|
848
|
|
- },
|
849
|
|
- {
|
850
|
|
- field: 'timezone',
|
851
|
|
- label: '时区',
|
852
|
|
- component: 'Select',
|
853
|
|
- defaultValue: 'Asia/Shanghai',
|
854
|
|
- componentProps: {
|
855
|
|
- options: [
|
856
|
|
- {
|
857
|
|
- label: 'Asia/Shanghai',
|
858
|
|
- value: 'Asia/Shanghai',
|
859
|
|
- },
|
860
|
|
- ],
|
861
|
|
- allowClear: false,
|
862
|
|
- },
|
863
|
|
- ifShow: ({ values }) => values.schedule !== 'ANY_TIME',
|
864
|
|
- },
|
865
|
|
- {
|
866
|
|
- field: 'daysOfWeek',
|
867
|
|
- label: '天',
|
868
|
|
- component: 'CheckboxGroup',
|
869
|
|
- rules: [
|
870
|
|
- {
|
871
|
|
- message: '请至少选择一天',
|
872
|
|
- required: true,
|
873
|
|
- },
|
874
|
|
- ],
|
875
|
|
- componentProps: {
|
876
|
|
- options: [
|
877
|
|
- { label: '星期一', value: 1 },
|
878
|
|
- { label: '星期二', value: 2 },
|
879
|
|
- { label: '星期三', value: 3 },
|
880
|
|
- { label: '星期四', value: 4 },
|
881
|
|
- { label: '星期五', value: 5 },
|
882
|
|
- { label: '星期六', value: 6 },
|
883
|
|
- { label: '星期日', value: 7 },
|
884
|
|
- ],
|
885
|
|
- },
|
886
|
|
- colProps: {
|
887
|
|
- span: 24,
|
888
|
|
- },
|
889
|
|
- ifShow: ({ values }) => values.schedule === 'SPECIFIC_TIME',
|
890
|
|
- },
|
891
|
|
- {
|
892
|
|
- field: 'time',
|
893
|
|
- label: '时间',
|
894
|
|
- labelWidth: 40,
|
895
|
|
- component: 'RangePicker',
|
896
|
|
- ifShow: ({ values }) => values.schedule === 'SPECIFIC_TIME',
|
897
|
|
- slot: 'timing',
|
898
|
|
- },
|
899
|
|
- {
|
900
|
|
- field: 'day',
|
901
|
|
- label: '天',
|
902
|
|
- component: 'CheckboxGroup',
|
903
|
|
- slot: 'customEnable',
|
904
|
|
- ifShow: ({ values }) => values.schedule === 'CUSTOM',
|
905
|
|
- },
|
906
|
|
-]; |
...
|
...
|
|