Commit b7ce85893fc3301218bdda96ac36f277bdb5b19c

Authored by fengtao
1 parent 45457a24

fix:DEFECT-434 修复场景联动编辑,属性无法选择其他,更换后端获取设备接口和属性接口

... ... @@ -17,9 +17,10 @@ enum ScreenManagerApi {
17 17 SCREEN_UPDATE_URL = '/sceneLinkage/update',
18 18 SCREEN_ORGANIZATION_URL = '/organization/me/list',
19 19 SCREEN_CHANGE_STATUS = '/convert/update/scene',
20   - SCREEN_GET_BY_DEPTID = '/sceneLinkage/device/',
21   - GET_ATTRBUTELIST = '/deviceProfile/devices/keys/timeseries',
  20 + SCREEN_GET_BY_DEPTID = '/sceneLinkage/device',
  21 + GET_ATTRBUTELIST = '/device/keys',
22 22 ALARM_PROFILE = '/alarm/profile/',
  23 + MASTER_GET_DEVICE = '/device/list/master',
23 24 }
24 25
25 26 /**
... ... @@ -55,6 +56,16 @@ export const screenLinkPageAddApi = (params: ScreenAddModel, isUpdate: boolean)
55 56 };
56 57
57 58 /**
  59 + * 获取主设备列表(exclude子设备)
  60 + * @param params organizationId
  61 + */
  62 +export const byOganizationIdGetMasterDevice = (params) => {
  63 + return defHttp.get({
  64 + url: ScreenManagerApi.MASTER_GET_DEVICE + '/' + params,
  65 + });
  66 +};
  67 +
  68 +/**
58 69 * 删除场景联动
59 70 * @param params pageSize page name
60 71 */
... ... @@ -99,13 +110,8 @@ export const getOrganizationAlarmConfig = (params: { organizationId }) => {
99 110 /**
100 111 * 获取设备属性列表
101 112 */
102   -export const getAttribute = () => {
103   - return defHttp.get(
104   - {
105   - url: ScreenManagerApi.GET_ATTRBUTELIST,
106   - },
107   - {
108   - joinPrefix: false,
109   - }
110   - );
  113 +export const getAttribute = (orgId, deviceIds) => {
  114 + return defHttp.get({
  115 + url: ScreenManagerApi.GET_ATTRBUTELIST + '/' + orgId + '?' + deviceIds,
  116 + });
111 117 };
... ...
... ... @@ -21,6 +21,7 @@
21 21 class="mt-4"
22 22 title="触发器"
23 23 :index="index"
  24 + :provideOrgid="provideOrgid"
24 25 :ref="skipUnwrap.triggerItemRefs"
25 26 @delete="deleteTriggerOrCondition"
26 27 />
... ... @@ -42,6 +43,7 @@
42 43 class="mt-4"
43 44 title="执行条件"
44 45 :index="index"
  46 + :provideOrgid="provideOrgid"
45 47 :ref="skipUnwrap.conditionItemRefs"
46 48 @delete="deleteTriggerOrCondition"
47 49 />
... ... @@ -94,8 +96,10 @@
94 96 import { useMessage } from '/@/hooks/web/useMessage';
95 97 import {
96 98 screenLinkPageAddApi,
97   - screenLinkPageByDeptIdGetDevice,
  99 + // screenLinkPageByDeptIdGetDevice,
98 100 getOrganizationAlarmConfig,
  101 + byOganizationIdGetMasterDevice,
  102 + getAttribute,
99 103 } from '/@/api/ruleengine/ruleengineApi';
100 104 import TriggerOrCondition from './cpns/Trigger-Condition.vue';
101 105 import Action from './cpns/Action.vue';
... ... @@ -104,6 +108,7 @@
104 108
105 109 const emit = defineEmits(['register', 'success']);
106 110
  111 + const provideOrgid = ref('');
107 112 const { createMessage } = useMessage();
108 113 const triggerData = ref([]);
109 114 const conditionData = ref([]);
... ... @@ -120,6 +125,7 @@
120 125 let getConditionFormValue = ref([]);
121 126 let getActionFormValue = ref([]);
122 127 const editEntryIdData = ref([]);
  128 + let editAttrIdData = [];
123 129 const editAlarmConfigData = ref([]);
124 130 const isUpdate = ref(false);
125 131 const id = ref(undefined);
... ... @@ -151,21 +157,25 @@
151 157 await setFieldsValue(data.record);
152 158 id.value = recordId;
153 159 tenantId.value = recordTenantId;
  160 + provideOrgid.value = organizationId;
154 161 // 获取当前组织下的设备列表
155   - const options = await screenLinkPageByDeptIdGetDevice({
156   - organizationId,
157   - });
  162 + const options = await byOganizationIdGetMasterDevice(organizationId);
158 163 // 获取当前组织下的告警配置
159 164 const alarmConfig = await getOrganizationAlarmConfig({ organizationId });
  165 + // 获取当前组织下的属性列表
  166 + const attrList = await getAttribute(
  167 + organizationId,
  168 + triggers.map((m) => m.entityId).join(',')
  169 + );
160 170
161 171 // 生成回显时对应得组件数量
162 172 triggerData.value = [...new Array(triggers.length).keys()];
163 173 conditionData.value = [...new Array(doConditions.length).keys()];
164 174 actionData.value = [...new Array(doActions.length).keys()];
165 175 // 回显设备列表
166   - editEntryIdData.value = options.items.map((item) => {
  176 + editEntryIdData.value = options.map((item) => {
167 177 return {
168   - value: item.tbDeviceId,
  178 + value: item.id,
169 179 label: item.name,
170 180 };
171 181 });
... ... @@ -176,11 +186,15 @@
176 186 };
177 187 });
178 188 deviceList.value = editEntryIdData.value;
  189 + //回显属性列表
  190 + editAttrIdData = attrList;
179 191 nextTick(() => {
180 192 setEditFields(skipUnwrap.triggerItemRefs, editEntryIdData);
181 193 setEditFields(skipUnwrap.conditionItemRefs, editEntryIdData);
182 194 setEditFields(skipUnwrap.actionItemRefs, editEntryIdData);
183 195 setEditAlarmConfig(skipUnwrap.actionItemRefs, editAlarmConfigData);
  196 + setEditAttr(skipUnwrap.triggerItemRefs, editAttrIdData);
  197 + setEditAttr(skipUnwrap.conditionItemRefs, editAttrIdData);
184 198 });
185 199
186 200 const map = {
... ... @@ -198,12 +212,15 @@
198 212 unref(skipUnwrap.triggerItemRefs)[index].isUpdate = true;
199 213 unref(skipUnwrap.triggerItemRefs)[index].alarmScheduleRef.scheduleData =
200 214 trigger.triggerCondition.schedule;
  215 + const getAttrKeyOption = trigger?.triggerCondition?.condition?.condition.map(
  216 + (m) => m.key.key
  217 + );
201 218 unref(skipUnwrap.triggerItemRefs)[index].setFieldsFormValueFun({
202 219 triggered: trigger?.triggerCondition?.condition?.spec?.type,
203 220 device: trigger?.entityType,
204 221 triggerType: trigger?.triggerType,
205 222 type1: trigger?.triggerCondition?.condition?.condition[0]?.key?.type,
206   - type2: trigger?.triggerCondition?.condition?.condition[0]?.key?.key,
  223 + type2: getAttrKeyOption,
207 224 operationType: trigger?.triggerCondition?.condition?.condition[0]?.valueType,
208 225 detail: trigger?.triggerCondition?.alarmDetails,
209 226 entityId: trigger?.entityId,
... ... @@ -270,12 +287,15 @@
270 287 unref(skipUnwrap.conditionItemRefs)[index].isUpdate = true;
271 288 unref(skipUnwrap.conditionItemRefs)[index].alarmScheduleRef.scheduleData =
272 289 condition.triggerCondition.schedule;
  290 + const getAttrKeyOption = condition?.triggerCondition?.condition?.condition.map(
  291 + (m) => m.key.key
  292 + );
273 293 unref(skipUnwrap.conditionItemRefs)[index].setFieldsFormValueFun({
274 294 triggered: condition?.triggerCondition?.condition?.spec?.type,
275 295 device: condition?.entityType,
276 296 triggerType: condition?.triggerType,
277 297 type1: condition?.triggerCondition?.condition?.condition[0]?.key?.type,
278   - type2: condition?.triggerCondition?.condition?.condition[0]?.key?.key,
  298 + type2: getAttrKeyOption,
279 299 operationType: condition?.triggerCondition?.condition?.condition[0]?.valueType,
280 300 detail: condition?.triggerCondition?.alarmDetails,
281 301 entityId: condition?.entityId,
... ... @@ -471,17 +491,26 @@
471 491 item.updateEditFieldAlarmConfig(alarmConfigList);
472 492 });
473 493 };
  494 + //设置设备属性的options
  495 + const setEditAttr = (linkAge, attrList) => {
  496 + unref(linkAge).map((item) => {
  497 + item.updateFieldAttr(attrList);
  498 + });
  499 + };
  500 +
474 501 // 监听组织变化更新设备列表
475 502 const deviceList = ref([]);
476 503 const alarmConfigList = ref([]);
  504 + let watchAttrList = [];
477 505 watch(organizationId, async (newValue: string) => {
478 506 if (!newValue) return;
479   - const { items } = await screenLinkPageByDeptIdGetDevice({ organizationId: newValue });
480   - deviceList.value = items.map((item) => ({ label: item.name, value: item.tbDeviceId }));
  507 + provideOrgid.value = newValue;
  508 + const items = await byOganizationIdGetMasterDevice(newValue);
  509 + deviceList.value = items.map((item) => ({ label: item.name, value: item.id }));
  510 + watchAttrList = await getAttribute(newValue, null);
481 511 setFields(skipUnwrap.triggerItemRefs, true);
482 512 setFields(skipUnwrap.conditionItemRefs, true);
483 513 setFields(skipUnwrap.actionItemRefs, true);
484   -
485 514 const data = await getOrganizationAlarmConfig({ organizationId: newValue });
486 515 alarmConfigList.value = data.map((item) => ({ label: item.name, value: item.id }));
487 516 setAlarmConfig(skipUnwrap.actionItemRefs, true);
... ... @@ -492,6 +521,7 @@
492 521 unref(linkAge).map((item) => {
493 522 isOrganizationChange && item.resetFieldsValueFunc();
494 523 item.updateFieldDeviceId(deviceList);
  524 + item.updateFieldAttr(watchAttrList);
495 525 });
496 526 }
497 527 function setAlarmConfig(linkAge, isOrganizationChange = false) {
... ... @@ -602,3 +632,10 @@
602 632 });
603 633 };
604 634 </script>
  635 +
  636 +<style lang="less" scoped>
  637 + ///统一下拉选择框宽度,否则超出默认宽度会造成页面样式错乱
  638 + :deep(.ant-select-selector) {
  639 + max-width: 14.2rem;
  640 + }
  641 +</style>
... ...
... ... @@ -257,7 +257,7 @@ export const trigger_condition_schema: FormSchema[] = [
257 257 {
258 258 field: 'type2',
259 259 label: '',
260   - component: 'AutoComplete',
  260 + component: 'Select',
261 261 componentProps: {
262 262 placeholder: '请选择属性',
263 263 },
... ...
... ... @@ -69,7 +69,7 @@
69 69 import AlarmSchedule from './AlarmSchedule.vue';
70 70 import { useModal } from '/@/components/Modal';
71 71
72   - defineProps({
  72 + const props = defineProps({
73 73 title: {
74 74 type: String,
75 75 required: true,
... ... @@ -78,6 +78,10 @@
78 78 type: Number,
79 79 required: true,
80 80 },
  81 + provideOrgid: {
  82 + type: String,
  83 + default: '',
  84 + },
81 85 });
82 86 const emit = defineEmits(['delete']);
83 87 const isUpdate = ref(false);
... ... @@ -101,19 +105,35 @@
101 105 options: deviceList,
102 106 onChange(e) {
103 107 if (e) {
104   - updateFieldAttributeFunc();
  108 + updateFieldAttributeFunc(e);
105 109 }
106 110 },
107 111 },
108 112 });
109 113 };
  114 + const updateFieldAttr = (attrList: any[]) => {
  115 + const attrMapList = attrList?.map((m) => {
  116 + return {
  117 + label: m,
  118 + value: m,
  119 + };
  120 + });
  121 + updateSchema({
  122 + field: 'type2',
  123 + componentProps: {
  124 + placeholder: '请选择属性',
  125 + options: attrMapList,
  126 + },
  127 + });
  128 + };
110 129 const resetFieldsValueFunc = () => resetFields();
111 130 // 回显数据函数
112 131 const setFieldsFormValueFun = (fieldsValue) => {
113 132 setFieldsValue(fieldsValue);
114 133 };
115   - const updateFieldAttributeFunc = async () => {
116   - const data = await getAttribute();
  134 + const updateFieldAttributeFunc = async (e) => {
  135 + const joinDeviceIds = e.join(',');
  136 + const data = await getAttribute(props.provideOrgid, joinDeviceIds);
117 137 const options = data.map((m) => {
118 138 return {
119 139 label: m,
... ... @@ -178,6 +198,7 @@
178 198 defineExpose({
179 199 getFieldsValueFunc,
180 200 updateFieldDeviceId,
  201 + updateFieldAttr,
181 202 resetFieldsValueFunc,
182 203 setFieldsFormValueFun,
183 204 childGetFieldsValue,
... ...