Commit 3722918a7b076c123736a5038a1e21dff4fcb1b6
Merge branch 'dev-ww' into 'main'
feat: linkedge action add service command See merge request huang/yun-teng-iot-front!402
Showing
6 changed files
with
163 additions
and
70 deletions
... | ... | @@ -10,6 +10,8 @@ enum ModelOfMatter { |
10 | 10 | TSL = '/things_model', |
11 | 11 | LIST = '/things_model/page', |
12 | 12 | RELEASE = '/things_model', |
13 | + | |
14 | + GET_MODEL_SERVICE = '/things_model/get_services', | |
13 | 15 | } |
14 | 16 | |
15 | 17 | export const getModelList = ( |
... | ... | @@ -60,3 +62,10 @@ export const releaseModel = (deviceProfileId: string) => { |
60 | 62 | url: `${ModelOfMatter.RELEASE}/${deviceProfileId}`, |
61 | 63 | }); |
62 | 64 | }; |
65 | + | |
66 | +export const getModelServices = (params: { deviceProfileId: string }) => { | |
67 | + const { deviceProfileId } = params; | |
68 | + return defHttp.get({ | |
69 | + url: `${ModelOfMatter.GET_MODEL_SERVICE}/${deviceProfileId}`, | |
70 | + }); | |
71 | +}; | ... | ... |
... | ... | @@ -112,9 +112,14 @@ export const getAttribute = (orgId, deviceIds) => { |
112 | 112 | * 获取主设备列表(exclude子设备)---执行动作 |
113 | 113 | * @param params organizationId |
114 | 114 | */ |
115 | -export const byOganizationIdGetMasterDevice = (params) => { | |
115 | +export const byOrganizationIdGetMasterDevice = (params: { | |
116 | + organizationId: string; | |
117 | + deviceProfileId?: string; | |
118 | +}) => { | |
119 | + const { organizationId, deviceProfileId } = params; | |
116 | 120 | return defHttp.get({ |
117 | - url: ScreenManagerApi.MASTER_GET_DEVICE + '/' + params, | |
121 | + url: `${ScreenManagerApi.MASTER_GET_DEVICE}/${organizationId}`, | |
122 | + params: { deviceProfileId }, | |
118 | 123 | }); |
119 | 124 | }; |
120 | 125 | //TODO-fengtao | ... | ... |
... | ... | @@ -116,9 +116,9 @@ |
116 | 116 | <script lang="ts" setup> |
117 | 117 | import { ref, watch, unref, computed, nextTick } from 'vue'; |
118 | 118 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; |
119 | - import { formSchema, organizationId } from './config/config.data.ts'; | |
119 | + import { formSchema, organizationId as organizationIdRef } from './config/config.data'; | |
120 | 120 | import { BasicForm, useForm } from '/@/components/Form'; |
121 | - import { genTriggerOrConditionData, genActionData } from './config/formatData.ts'; | |
121 | + import { genTriggerOrConditionData, genActionData } from './config/formatData'; | |
122 | 122 | import { Divider } from 'ant-design-vue'; |
123 | 123 | import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons-vue'; |
124 | 124 | import { useMessage } from '/@/hooks/web/useMessage'; |
... | ... | @@ -126,11 +126,10 @@ |
126 | 126 | screenLinkPageAddApi, |
127 | 127 | screenLinkPageByDeptIdGetDevice, |
128 | 128 | getOrganizationAlarmConfig, |
129 | - byOganizationIdGetMasterDevice, | |
130 | 129 | } from '/@/api/ruleengine/ruleengineApi'; |
131 | 130 | import TriggerOrCondition from './cpns/Trigger-Condition.vue'; |
132 | 131 | import Action from './cpns/Action.vue'; |
133 | - import { findOperation } from './config/formatData.ts'; | |
132 | + import { findOperation } from './config/formatData'; | |
134 | 133 | import { formatToDateTime } from '/@/utils/dateUtil'; |
135 | 134 | |
136 | 135 | const emit = defineEmits(['register', 'success']); |
... | ... | @@ -179,6 +178,7 @@ |
179 | 178 | doConditions, |
180 | 179 | doActions, |
181 | 180 | } = data.record; |
181 | + organizationIdRef.value = organizationId; | |
182 | 182 | // 赋值 |
183 | 183 | await setFieldsValue(data.record); |
184 | 184 | id.value = recordId; |
... | ... | @@ -186,7 +186,7 @@ |
186 | 186 | //TODO-fengtao-把组织id传给子组件 |
187 | 187 | provideOrgid.value = organizationId; |
188 | 188 | //TODO-fengtao获取当前执行动作下的设备(master那个接口) |
189 | - getMasterDeviceList.value = await byOganizationIdGetMasterDevice(organizationId); | |
189 | + // getMasterDeviceList.value = await byOrganizationIdGetMasterDevice(organizationId); | |
190 | 190 | //TODO-fengtao |
191 | 191 | // 获取当前组织下的设备列表 |
192 | 192 | const options = await screenLinkPageByDeptIdGetDevice({ |
... | ... | @@ -394,6 +394,7 @@ |
394 | 394 | const selectDeviceId = ref(''); |
395 | 395 | // 设置执行动作外层值 |
396 | 396 | unref(skipUnwrap.actionItemRefs)[index].setFieldsFormValueFun({ |
397 | + ...action, | |
397 | 398 | outTarget: action.outTarget, |
398 | 399 | device: action.entityType, |
399 | 400 | deviceId: action.deviceId, |
... | ... | @@ -451,12 +452,12 @@ |
451 | 452 | } |
452 | 453 | //fengtao-把设备id回传给子组件 |
453 | 454 | item.updateFieldAttributeFunc(selectDeviceId.value, provideOrgid.value); |
454 | - item.updateFieldDeviceId( | |
455 | - deviceList.value, | |
456 | - provideOrgid.value, | |
457 | - isUpdate.value, | |
458 | - getMasterDeviceList.value | |
459 | - ); | |
455 | + // item.updateFieldDeviceId( | |
456 | + // deviceList.value, | |
457 | + // provideOrgid.value, | |
458 | + // isUpdate.value, | |
459 | + // getMasterDeviceList.value | |
460 | + // ); | |
460 | 461 | //fengtao |
461 | 462 | // 单独设置operationType值 操作符类型 NUMERIC|String|Boolean|DATE_TIME |
462 | 463 | item.operationType = |
... | ... | @@ -533,12 +534,12 @@ |
533 | 534 | }); |
534 | 535 | |
535 | 536 | // 设置设备的options |
536 | - const setEditFields = (linkAge, deviceList) => { | |
537 | - unref(linkAge).map((item) => { | |
538 | - //TODO-fengtao | |
539 | - item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList); | |
540 | - //TODO-fengtao | |
541 | - }); | |
537 | + const setEditFields = (_linkAge, _deviceList) => { | |
538 | + // unref(linkAge).map((item) => { | |
539 | + //TODO-fengtao | |
540 | + // item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList); | |
541 | + //TODO-fengtao | |
542 | + // }); | |
542 | 543 | }; |
543 | 544 | // 设置告警配置options |
544 | 545 | const setEditAlarmConfig = (linkAge, alarmConfigList) => { |
... | ... | @@ -554,16 +555,20 @@ |
554 | 555 | //FT add 2022-10-27 |
555 | 556 | const addOrgId = ref(''); |
556 | 557 | //FT add 2022-10-27 |
557 | - watch(organizationId, async (newValue: string) => { | |
558 | + watch(organizationIdRef, async (newValue: string) => { | |
558 | 559 | if (!newValue) return; |
559 | 560 | //FT add 2022-10-27 |
560 | 561 | addOrgId.value = newValue; |
561 | 562 | //FT add 2022-10-27 |
562 | 563 | const { items = [] } = await screenLinkPageByDeptIdGetDevice({ organizationId: newValue }); |
563 | 564 | //TODO fengtao |
564 | - getMasterDeviceList.value = await byOganizationIdGetMasterDevice(newValue); | |
565 | + // getMasterDeviceList.value = await byOrganizationIdGetMasterDevice(newValue); | |
565 | 566 | //TODO fengtao |
566 | - deviceList.value = (items || []).map((item) => ({ label: item.name, value: item.tbDeviceId })); | |
567 | + deviceList.value = (items || []).map((item) => ({ | |
568 | + ...item, | |
569 | + label: item.name, | |
570 | + value: item.tbDeviceId, | |
571 | + })); | |
567 | 572 | //TODO fengtao |
568 | 573 | orgId.value = newValue; |
569 | 574 | //TODO fengtao |
... | ... | @@ -595,7 +600,7 @@ |
595 | 600 | unref(linkAge).map((item) => { |
596 | 601 | isOrganizationChange && item.resetFieldsValueFunc(); |
597 | 602 | //TODO fengtao |
598 | - item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList); | |
603 | + // item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList); | |
599 | 604 | if (isUpdate.value) { |
600 | 605 | item.updateEditFieldAlarmConfig(editAlarmConfigData); |
601 | 606 | } else { |
... | ... | @@ -661,6 +666,8 @@ |
661 | 666 | createMessage.error('请添加触发器或者执行条件'); |
662 | 667 | throw '请添加触发器或者执行条件'; |
663 | 668 | } |
669 | + | |
670 | + // return; | |
664 | 671 | //新增的代码2022-11-22 |
665 | 672 | const postAddOrEditData = { |
666 | 673 | ...basicFormValue, |
... | ... | @@ -722,7 +729,7 @@ |
722 | 729 | const handleClose = () => { |
723 | 730 | id.value = undefined; |
724 | 731 | tenantId.value = undefined; |
725 | - organizationId.value = undefined; | |
732 | + organizationIdRef.value = undefined; | |
726 | 733 | isView.value = true; |
727 | 734 | getTriggerFormValue.value = []; |
728 | 735 | getConditionFormValue.value = []; | ... | ... |
1 | -import { ref } from 'vue'; | |
1 | +import { ref, unref } from 'vue'; | |
2 | 2 | import { BasicColumn, FormSchema } from '/@/components/Table'; |
3 | -import { screenLinkOrganizationGetApi } from '/@/api/ruleengine/ruleengineApi'; | |
3 | +import { | |
4 | + byOrganizationIdGetMasterDevice, | |
5 | + screenLinkOrganizationGetApi, | |
6 | +} from '/@/api/ruleengine/ruleengineApi'; | |
4 | 7 | import { scheduleOptions } from './formatData'; |
5 | 8 | import { copyTransFun } from '/@/utils/fnUtils'; |
6 | 9 | import { numberAndNonegativeRule } from '/@/utils/rules'; |
7 | 10 | import { findDictItemByCode } from '/@/api/system/dict'; |
11 | +import { deviceProfile } from '/@/api/device/deviceManager'; | |
12 | +import { getModelServices } from '/@/api/device/modelOfMatter'; | |
13 | +import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
8 | 14 | |
9 | 15 | /** |
10 | 16 | * 所使用的枚举值 |
... | ... | @@ -167,10 +173,10 @@ const isPartOrAll = (type: string) => { |
167 | 173 | return type === 'ALL' || type === 'PART'; |
168 | 174 | }; |
169 | 175 | const isService = (type: string) => { |
170 | - return type === 'service'; | |
176 | + return Number(type) === 1; | |
171 | 177 | }; |
172 | 178 | const isDefine = (type: string) => { |
173 | - return type === 'custom_define'; | |
179 | + return Number(type) === 0; | |
174 | 180 | }; |
175 | 181 | //新增代码2022-11-23 |
176 | 182 | |
... | ... | @@ -319,95 +325,147 @@ export const actionSchema: FormSchema[] = [ |
319 | 325 | colProps: { span: 6 }, |
320 | 326 | }, |
321 | 327 | { |
328 | + field: 'deviceProfileId', | |
329 | + label: '', | |
330 | + component: 'ApiSelect', | |
331 | + colProps: { span: 6 }, | |
332 | + componentProps: ({ formActionType }) => { | |
333 | + const { setFieldsValue } = formActionType; | |
334 | + return { | |
335 | + api: deviceProfile, | |
336 | + placeholder: '请选择产品', | |
337 | + labelField: 'name', | |
338 | + valueField: 'id', | |
339 | + getPopupContainer: () => document.body, | |
340 | + onChange: () => { | |
341 | + setFieldsValue({ deviceId: [] }); | |
342 | + }, | |
343 | + }; | |
344 | + }, | |
345 | + ifShow: ({ values }) => isDeviceOut(values.outTarget), | |
346 | + }, | |
347 | + { | |
322 | 348 | field: 'device', |
323 | 349 | label: '', |
324 | 350 | component: 'Select', |
325 | - componentProps: { | |
326 | - placeholder: '请选择设备', | |
327 | - options: [ | |
328 | - { label: '全部', value: 'ALL' }, | |
329 | - { label: '部分', value: 'PART' }, | |
330 | - ], | |
351 | + componentProps: ({ formActionType }) => { | |
352 | + const { setFieldsValue } = formActionType; | |
353 | + return { | |
354 | + placeholder: '请选择设备', | |
355 | + options: [ | |
356 | + { label: '全部', value: 'ALL' }, | |
357 | + { label: '部分', value: 'PART' }, | |
358 | + ], | |
359 | + onChange: () => { | |
360 | + setFieldsValue({ deviceId: [], thingsModelId: null }); | |
361 | + }, | |
362 | + }; | |
331 | 363 | }, |
332 | - ifShow: ({ values }) => isDeviceOut(values.outTarget), | |
364 | + ifShow: ({ values }) => isDeviceOut(values.outTarget) && values['deviceProfileId'], | |
333 | 365 | colProps: { span: 6 }, |
334 | 366 | }, |
335 | 367 | { |
336 | 368 | field: 'deviceId', |
337 | 369 | label: '', |
338 | - component: 'Select', | |
339 | - componentProps: { | |
340 | - placeholder: '请选择设备', | |
341 | - mode: 'multiple', | |
370 | + component: 'ApiSelect', | |
371 | + componentProps: ({ formModel }) => { | |
372 | + const deviceProfileId = formModel['deviceProfileId']; | |
373 | + return { | |
374 | + placeholder: '请选择设备', | |
375 | + mode: 'multiple', | |
376 | + api: byOrganizationIdGetMasterDevice, | |
377 | + params: { | |
378 | + organizationId: unref(organizationId), | |
379 | + deviceProfileId, | |
380 | + }, | |
381 | + labelField: 'name', | |
382 | + valueField: 'id', | |
383 | + }; | |
342 | 384 | }, |
343 | 385 | ifShow: ({ values }) => isPart(values.device) && isDeviceOut(values.outTarget), |
344 | 386 | colProps: { span: 6 }, |
345 | 387 | }, |
346 | 388 | //新增代码2022-11-23 |
347 | 389 | { |
348 | - field: 'customDefine', | |
390 | + field: 'commandType', | |
349 | 391 | label: '', |
350 | 392 | required: true, |
351 | 393 | component: 'ApiSelect', |
352 | 394 | colProps: { |
353 | 395 | span: 6, |
354 | 396 | }, |
355 | - defaultValue: 'custom_define', | |
356 | - componentProps: { | |
357 | - placeholder: '请选择类型', | |
358 | - api: findDictItemByCode, | |
359 | - params: { | |
360 | - dictCode: 'custom_define', | |
361 | - }, | |
362 | - labelField: 'itemText', | |
363 | - valueField: 'itemValue', | |
364 | - getPopupContainer: () => document.body, | |
397 | + defaultValue: '0', | |
398 | + componentProps: ({ formActionType }) => { | |
399 | + const { setFieldsValue } = formActionType; | |
400 | + return { | |
401 | + placeholder: '请选择类型', | |
402 | + api: async () => { | |
403 | + const record = await findDictItemByCode({ | |
404 | + dictCode: 'custom_define', | |
405 | + }); | |
406 | + return record.map((item) => ({ ...item, itemValue: Number(item.itemValue) })); | |
407 | + }, | |
408 | + labelField: 'itemText', | |
409 | + valueField: 'itemValue', | |
410 | + getPopupContainer: () => document.body, | |
411 | + onChange: () => { | |
412 | + setFieldsValue({ doContext: null, thingsModelId: null }); | |
413 | + }, | |
414 | + }; | |
365 | 415 | }, |
366 | 416 | ifShow: ({ values }) => isDeviceOut(values.outTarget) && isPartOrAll(values.device), |
367 | 417 | }, |
368 | 418 | //新增代码2022-11-23 |
369 | 419 | { |
370 | - field: 'customMode', | |
420 | + field: 'callType', | |
371 | 421 | label: '', |
372 | 422 | required: true, |
373 | 423 | component: 'ApiSelect', |
374 | 424 | colProps: { |
375 | 425 | span: 6, |
376 | 426 | }, |
377 | - defaultValue: 'OneWay', | |
427 | + defaultValue: 'SYNC', | |
378 | 428 | componentProps: { |
379 | 429 | placeholder: '请选择类型', |
380 | 430 | api: findDictItemByCode, |
381 | 431 | params: { |
382 | - dictCode: 'custom_mode', | |
432 | + dictCode: 'call_mode', | |
383 | 433 | }, |
384 | 434 | labelField: 'itemText', |
385 | 435 | valueField: 'itemValue', |
386 | 436 | getPopupContainer: () => document.body, |
387 | 437 | }, |
388 | 438 | ifShow: ({ values }) => |
389 | - isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.customDefine), | |
439 | + isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.commandType), | |
390 | 440 | }, |
391 | 441 | //新增代码2022-11-23 |
392 | 442 | { |
393 | - field: 'service', | |
443 | + field: 'thingsModelId', | |
394 | 444 | label: '', |
395 | 445 | required: true, |
396 | 446 | component: 'ApiSelect', |
397 | 447 | colProps: { |
398 | 448 | span: 6, |
399 | 449 | }, |
400 | - componentProps: { | |
401 | - placeholder: '请选择服务', | |
402 | - api: findDictItemByCode, | |
403 | - params: { | |
404 | - dictCode: 'attribute_unit', | |
405 | - }, | |
406 | - labelField: 'itemText', | |
407 | - valueField: 'itemValue', | |
408 | - getPopupContainer: () => document.body, | |
450 | + componentProps: ({ formModel, formActionType }) => { | |
451 | + const { setFieldsValue } = formActionType; | |
452 | + const deviceProfileId = formModel['deviceProfileId']; | |
453 | + return { | |
454 | + placeholder: '请选择服务', | |
455 | + api: getModelServices, | |
456 | + params: { | |
457 | + deviceProfileId, | |
458 | + }, | |
459 | + labelField: 'functionName', | |
460 | + valueField: 'id', | |
461 | + getPopupContainer: () => document.body, | |
462 | + onChange: (_, options: ModelOfMatterParams) => { | |
463 | + // console.log(options); | |
464 | + setFieldsValue({ doContext: { ...options.functionJson, callType: options.callType } }); | |
465 | + }, | |
466 | + }; | |
409 | 467 | }, |
410 | - ifShow: ({ values }) => isDeviceOut(values.outTarget) && isService(values.customDefine), | |
468 | + ifShow: ({ values }) => isDeviceOut(values.outTarget) && isService(values.commandType), | |
411 | 469 | }, |
412 | 470 | //新增代码2022-11-23 |
413 | 471 | { |
... | ... | @@ -429,7 +487,7 @@ export const actionSchema: FormSchema[] = [ |
429 | 487 | slot: 'doContext', |
430 | 488 | show: ({ values }) => { |
431 | 489 | return ( |
432 | - isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.customDefine) | |
490 | + isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.commandType) | |
433 | 491 | ); |
434 | 492 | }, |
435 | 493 | colProps: { | ... | ... |
1 | 1 | import { formatToDateTime } from '/@/utils/dateUtil'; |
2 | 2 | import { Number_Operation, String_Operation, Boolean_Operation } from '/@/enums/operationEnum'; |
3 | -import { numberAndNonegativeRule } from '/@/utils/rules'; | |
4 | 3 | |
5 | 4 | // 生成触发器或执行条件JSON数据 |
6 | 5 | export const genTriggerOrConditionData = (triggerData) => { |
... | ... | @@ -77,6 +76,11 @@ export const genActionData = (actionData) => { |
77 | 76 | doContext, |
78 | 77 | device, |
79 | 78 | deviceId, |
79 | + deviceProfileId, | |
80 | + commandType, | |
81 | + callType, | |
82 | + service, | |
83 | + thingsModelId, | |
80 | 84 | } = actionData; |
81 | 85 | const clearRule = clearRules.map((item) => { |
82 | 86 | const mapPredicate = item.predicate.map((pred) => { |
... | ... | @@ -133,6 +137,11 @@ export const genActionData = (actionData) => { |
133 | 137 | outTarget, |
134 | 138 | entityType: device ?? 'ALL', |
135 | 139 | deviceId: device === 'PART' ? deviceId : null, |
140 | + deviceProfileId, | |
141 | + commandType, | |
142 | + callType, | |
143 | + service, | |
144 | + thingsModelId, | |
136 | 145 | doContext: clearRule?.length |
137 | 146 | ? { |
138 | 147 | alarmLevel: alarm_level, | ... | ... |
... | ... | @@ -246,15 +246,20 @@ |
246 | 246 | } |
247 | 247 | //ft-add-2022-11-22 |
248 | 248 | //TODO-fengtao-设备验证 |
249 | + const value = getFieldsValue(); | |
250 | + const doContext = unref(jsonInstance)?.get() || {}; | |
249 | 251 | return { |
250 | - ...getFieldsValue(), | |
251 | - doContext: unref(jsonInstance.value)?.get(), | |
252 | + ...value, | |
253 | + ...(Number(value.commandType) === 0 ? { doContext } : {}), | |
252 | 254 | clearRule, |
253 | 255 | }; |
254 | 256 | }; |
255 | 257 | |
256 | 258 | const setFieldsFormValueFun = (fieldsValue) => { |
257 | - setFieldsValue(fieldsValue); | |
259 | + setFieldsValue({ | |
260 | + ...fieldsValue, | |
261 | + ...(fieldsValue.commandType ? { commandType: String(fieldsValue.commandType) } : {}), | |
262 | + }); | |
258 | 263 | }; |
259 | 264 | //ft-add |
260 | 265 | const resetConditionForm = () => {}; | ... | ... |