Commit b7ce85893fc3301218bdda96ac36f277bdb5b19c

Authored by fengtao
1 parent 45457a24

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

@@ -17,9 +17,10 @@ enum ScreenManagerApi { @@ -17,9 +17,10 @@ enum ScreenManagerApi {
17 SCREEN_UPDATE_URL = '/sceneLinkage/update', 17 SCREEN_UPDATE_URL = '/sceneLinkage/update',
18 SCREEN_ORGANIZATION_URL = '/organization/me/list', 18 SCREEN_ORGANIZATION_URL = '/organization/me/list',
19 SCREEN_CHANGE_STATUS = '/convert/update/scene', 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 ALARM_PROFILE = '/alarm/profile/', 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,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 * @param params pageSize page name 70 * @param params pageSize page name
60 */ 71 */
@@ -99,13 +110,8 @@ export const getOrganizationAlarmConfig = (params: { organizationId }) => { @@ -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,6 +21,7 @@
21 class="mt-4" 21 class="mt-4"
22 title="触发器" 22 title="触发器"
23 :index="index" 23 :index="index"
  24 + :provideOrgid="provideOrgid"
24 :ref="skipUnwrap.triggerItemRefs" 25 :ref="skipUnwrap.triggerItemRefs"
25 @delete="deleteTriggerOrCondition" 26 @delete="deleteTriggerOrCondition"
26 /> 27 />
@@ -42,6 +43,7 @@ @@ -42,6 +43,7 @@
42 class="mt-4" 43 class="mt-4"
43 title="执行条件" 44 title="执行条件"
44 :index="index" 45 :index="index"
  46 + :provideOrgid="provideOrgid"
45 :ref="skipUnwrap.conditionItemRefs" 47 :ref="skipUnwrap.conditionItemRefs"
46 @delete="deleteTriggerOrCondition" 48 @delete="deleteTriggerOrCondition"
47 /> 49 />
@@ -94,8 +96,10 @@ @@ -94,8 +96,10 @@
94 import { useMessage } from '/@/hooks/web/useMessage'; 96 import { useMessage } from '/@/hooks/web/useMessage';
95 import { 97 import {
96 screenLinkPageAddApi, 98 screenLinkPageAddApi,
97 - screenLinkPageByDeptIdGetDevice, 99 + // screenLinkPageByDeptIdGetDevice,
98 getOrganizationAlarmConfig, 100 getOrganizationAlarmConfig,
  101 + byOganizationIdGetMasterDevice,
  102 + getAttribute,
99 } from '/@/api/ruleengine/ruleengineApi'; 103 } from '/@/api/ruleengine/ruleengineApi';
100 import TriggerOrCondition from './cpns/Trigger-Condition.vue'; 104 import TriggerOrCondition from './cpns/Trigger-Condition.vue';
101 import Action from './cpns/Action.vue'; 105 import Action from './cpns/Action.vue';
@@ -104,6 +108,7 @@ @@ -104,6 +108,7 @@
104 108
105 const emit = defineEmits(['register', 'success']); 109 const emit = defineEmits(['register', 'success']);
106 110
  111 + const provideOrgid = ref('');
107 const { createMessage } = useMessage(); 112 const { createMessage } = useMessage();
108 const triggerData = ref([]); 113 const triggerData = ref([]);
109 const conditionData = ref([]); 114 const conditionData = ref([]);
@@ -120,6 +125,7 @@ @@ -120,6 +125,7 @@
120 let getConditionFormValue = ref([]); 125 let getConditionFormValue = ref([]);
121 let getActionFormValue = ref([]); 126 let getActionFormValue = ref([]);
122 const editEntryIdData = ref([]); 127 const editEntryIdData = ref([]);
  128 + let editAttrIdData = [];
123 const editAlarmConfigData = ref([]); 129 const editAlarmConfigData = ref([]);
124 const isUpdate = ref(false); 130 const isUpdate = ref(false);
125 const id = ref(undefined); 131 const id = ref(undefined);
@@ -151,21 +157,25 @@ @@ -151,21 +157,25 @@
151 await setFieldsValue(data.record); 157 await setFieldsValue(data.record);
152 id.value = recordId; 158 id.value = recordId;
153 tenantId.value = recordTenantId; 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 const alarmConfig = await getOrganizationAlarmConfig({ organizationId }); 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 triggerData.value = [...new Array(triggers.length).keys()]; 172 triggerData.value = [...new Array(triggers.length).keys()];
163 conditionData.value = [...new Array(doConditions.length).keys()]; 173 conditionData.value = [...new Array(doConditions.length).keys()];
164 actionData.value = [...new Array(doActions.length).keys()]; 174 actionData.value = [...new Array(doActions.length).keys()];
165 // 回显设备列表 175 // 回显设备列表
166 - editEntryIdData.value = options.items.map((item) => { 176 + editEntryIdData.value = options.map((item) => {
167 return { 177 return {
168 - value: item.tbDeviceId, 178 + value: item.id,
169 label: item.name, 179 label: item.name,
170 }; 180 };
171 }); 181 });
@@ -176,11 +186,15 @@ @@ -176,11 +186,15 @@
176 }; 186 };
177 }); 187 });
178 deviceList.value = editEntryIdData.value; 188 deviceList.value = editEntryIdData.value;
  189 + //回显属性列表
  190 + editAttrIdData = attrList;
179 nextTick(() => { 191 nextTick(() => {
180 setEditFields(skipUnwrap.triggerItemRefs, editEntryIdData); 192 setEditFields(skipUnwrap.triggerItemRefs, editEntryIdData);
181 setEditFields(skipUnwrap.conditionItemRefs, editEntryIdData); 193 setEditFields(skipUnwrap.conditionItemRefs, editEntryIdData);
182 setEditFields(skipUnwrap.actionItemRefs, editEntryIdData); 194 setEditFields(skipUnwrap.actionItemRefs, editEntryIdData);
183 setEditAlarmConfig(skipUnwrap.actionItemRefs, editAlarmConfigData); 195 setEditAlarmConfig(skipUnwrap.actionItemRefs, editAlarmConfigData);
  196 + setEditAttr(skipUnwrap.triggerItemRefs, editAttrIdData);
  197 + setEditAttr(skipUnwrap.conditionItemRefs, editAttrIdData);
184 }); 198 });
185 199
186 const map = { 200 const map = {
@@ -198,12 +212,15 @@ @@ -198,12 +212,15 @@
198 unref(skipUnwrap.triggerItemRefs)[index].isUpdate = true; 212 unref(skipUnwrap.triggerItemRefs)[index].isUpdate = true;
199 unref(skipUnwrap.triggerItemRefs)[index].alarmScheduleRef.scheduleData = 213 unref(skipUnwrap.triggerItemRefs)[index].alarmScheduleRef.scheduleData =
200 trigger.triggerCondition.schedule; 214 trigger.triggerCondition.schedule;
  215 + const getAttrKeyOption = trigger?.triggerCondition?.condition?.condition.map(
  216 + (m) => m.key.key
  217 + );
201 unref(skipUnwrap.triggerItemRefs)[index].setFieldsFormValueFun({ 218 unref(skipUnwrap.triggerItemRefs)[index].setFieldsFormValueFun({
202 triggered: trigger?.triggerCondition?.condition?.spec?.type, 219 triggered: trigger?.triggerCondition?.condition?.spec?.type,
203 device: trigger?.entityType, 220 device: trigger?.entityType,
204 triggerType: trigger?.triggerType, 221 triggerType: trigger?.triggerType,
205 type1: trigger?.triggerCondition?.condition?.condition[0]?.key?.type, 222 type1: trigger?.triggerCondition?.condition?.condition[0]?.key?.type,
206 - type2: trigger?.triggerCondition?.condition?.condition[0]?.key?.key, 223 + type2: getAttrKeyOption,
207 operationType: trigger?.triggerCondition?.condition?.condition[0]?.valueType, 224 operationType: trigger?.triggerCondition?.condition?.condition[0]?.valueType,
208 detail: trigger?.triggerCondition?.alarmDetails, 225 detail: trigger?.triggerCondition?.alarmDetails,
209 entityId: trigger?.entityId, 226 entityId: trigger?.entityId,
@@ -270,12 +287,15 @@ @@ -270,12 +287,15 @@
270 unref(skipUnwrap.conditionItemRefs)[index].isUpdate = true; 287 unref(skipUnwrap.conditionItemRefs)[index].isUpdate = true;
271 unref(skipUnwrap.conditionItemRefs)[index].alarmScheduleRef.scheduleData = 288 unref(skipUnwrap.conditionItemRefs)[index].alarmScheduleRef.scheduleData =
272 condition.triggerCondition.schedule; 289 condition.triggerCondition.schedule;
  290 + const getAttrKeyOption = condition?.triggerCondition?.condition?.condition.map(
  291 + (m) => m.key.key
  292 + );
273 unref(skipUnwrap.conditionItemRefs)[index].setFieldsFormValueFun({ 293 unref(skipUnwrap.conditionItemRefs)[index].setFieldsFormValueFun({
274 triggered: condition?.triggerCondition?.condition?.spec?.type, 294 triggered: condition?.triggerCondition?.condition?.spec?.type,
275 device: condition?.entityType, 295 device: condition?.entityType,
276 triggerType: condition?.triggerType, 296 triggerType: condition?.triggerType,
277 type1: condition?.triggerCondition?.condition?.condition[0]?.key?.type, 297 type1: condition?.triggerCondition?.condition?.condition[0]?.key?.type,
278 - type2: condition?.triggerCondition?.condition?.condition[0]?.key?.key, 298 + type2: getAttrKeyOption,
279 operationType: condition?.triggerCondition?.condition?.condition[0]?.valueType, 299 operationType: condition?.triggerCondition?.condition?.condition[0]?.valueType,
280 detail: condition?.triggerCondition?.alarmDetails, 300 detail: condition?.triggerCondition?.alarmDetails,
281 entityId: condition?.entityId, 301 entityId: condition?.entityId,
@@ -471,17 +491,26 @@ @@ -471,17 +491,26 @@
471 item.updateEditFieldAlarmConfig(alarmConfigList); 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 const deviceList = ref([]); 502 const deviceList = ref([]);
476 const alarmConfigList = ref([]); 503 const alarmConfigList = ref([]);
  504 + let watchAttrList = [];
477 watch(organizationId, async (newValue: string) => { 505 watch(organizationId, async (newValue: string) => {
478 if (!newValue) return; 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 setFields(skipUnwrap.triggerItemRefs, true); 511 setFields(skipUnwrap.triggerItemRefs, true);
482 setFields(skipUnwrap.conditionItemRefs, true); 512 setFields(skipUnwrap.conditionItemRefs, true);
483 setFields(skipUnwrap.actionItemRefs, true); 513 setFields(skipUnwrap.actionItemRefs, true);
484 -  
485 const data = await getOrganizationAlarmConfig({ organizationId: newValue }); 514 const data = await getOrganizationAlarmConfig({ organizationId: newValue });
486 alarmConfigList.value = data.map((item) => ({ label: item.name, value: item.id })); 515 alarmConfigList.value = data.map((item) => ({ label: item.name, value: item.id }));
487 setAlarmConfig(skipUnwrap.actionItemRefs, true); 516 setAlarmConfig(skipUnwrap.actionItemRefs, true);
@@ -492,6 +521,7 @@ @@ -492,6 +521,7 @@
492 unref(linkAge).map((item) => { 521 unref(linkAge).map((item) => {
493 isOrganizationChange && item.resetFieldsValueFunc(); 522 isOrganizationChange && item.resetFieldsValueFunc();
494 item.updateFieldDeviceId(deviceList); 523 item.updateFieldDeviceId(deviceList);
  524 + item.updateFieldAttr(watchAttrList);
495 }); 525 });
496 } 526 }
497 function setAlarmConfig(linkAge, isOrganizationChange = false) { 527 function setAlarmConfig(linkAge, isOrganizationChange = false) {
@@ -602,3 +632,10 @@ @@ -602,3 +632,10 @@
602 }); 632 });
603 }; 633 };
604 </script> 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,7 +257,7 @@ export const trigger_condition_schema: FormSchema[] = [
257 { 257 {
258 field: 'type2', 258 field: 'type2',
259 label: '', 259 label: '',
260 - component: 'AutoComplete', 260 + component: 'Select',
261 componentProps: { 261 componentProps: {
262 placeholder: '请选择属性', 262 placeholder: '请选择属性',
263 }, 263 },
@@ -69,7 +69,7 @@ @@ -69,7 +69,7 @@
69 import AlarmSchedule from './AlarmSchedule.vue'; 69 import AlarmSchedule from './AlarmSchedule.vue';
70 import { useModal } from '/@/components/Modal'; 70 import { useModal } from '/@/components/Modal';
71 71
72 - defineProps({ 72 + const props = defineProps({
73 title: { 73 title: {
74 type: String, 74 type: String,
75 required: true, 75 required: true,
@@ -78,6 +78,10 @@ @@ -78,6 +78,10 @@
78 type: Number, 78 type: Number,
79 required: true, 79 required: true,
80 }, 80 },
  81 + provideOrgid: {
  82 + type: String,
  83 + default: '',
  84 + },
81 }); 85 });
82 const emit = defineEmits(['delete']); 86 const emit = defineEmits(['delete']);
83 const isUpdate = ref(false); 87 const isUpdate = ref(false);
@@ -101,19 +105,35 @@ @@ -101,19 +105,35 @@
101 options: deviceList, 105 options: deviceList,
102 onChange(e) { 106 onChange(e) {
103 if (e) { 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 const resetFieldsValueFunc = () => resetFields(); 129 const resetFieldsValueFunc = () => resetFields();
111 // 回显数据函数 130 // 回显数据函数
112 const setFieldsFormValueFun = (fieldsValue) => { 131 const setFieldsFormValueFun = (fieldsValue) => {
113 setFieldsValue(fieldsValue); 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 const options = data.map((m) => { 137 const options = data.map((m) => {
118 return { 138 return {
119 label: m, 139 label: m,
@@ -178,6 +198,7 @@ @@ -178,6 +198,7 @@
178 defineExpose({ 198 defineExpose({
179 getFieldsValueFunc, 199 getFieldsValueFunc,
180 updateFieldDeviceId, 200 updateFieldDeviceId,
  201 + updateFieldAttr,
181 resetFieldsValueFunc, 202 resetFieldsValueFunc,
182 setFieldsFormValueFun, 203 setFieldsFormValueFun,
183 childGetFieldsValue, 204 childGetFieldsValue,