Commit 9277d329753036253a09d0800ea6acd7ba691013

Authored by fengtao
1 parent 9386a4a1

fix:回退场景联动代码--修改属性选择问题

... ... @@ -56,16 +56,6 @@ export const screenLinkPageAddApi = (params: ScreenAddModel, isUpdate: boolean)
56 56 };
57 57
58 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   -/**
69 59 * 删除场景联动
70 60 * @param params pageSize page name
71 61 */
... ... @@ -107,6 +97,7 @@ export const getOrganizationAlarmConfig = (params: { organizationId }) => {
107 97 });
108 98 };
109 99
  100 +//TODO-fengtao
110 101 /**
111 102 * 获取设备属性列表
112 103 */
... ... @@ -116,3 +107,14 @@ export const getAttribute = (orgId, deviceIds) => {
116 107 url: ScreenManagerApi.GET_ATTRBUTELIST + '/' + orgId + joinText,
117 108 });
118 109 };
  110 +
  111 +/**
  112 + * 获取主设备列表(exclude子设备)---执行动作
  113 + * @param params organizationId
  114 + */
  115 +export const byOganizationIdGetMasterDevice = (params) => {
  116 + return defHttp.get({
  117 + url: ScreenManagerApi.MASTER_GET_DEVICE + '/' + params,
  118 + });
  119 +};
  120 +//TODO-fengtao
... ...
... ... @@ -99,7 +99,6 @@
99 99 screenLinkPageByDeptIdGetDevice,
100 100 getOrganizationAlarmConfig,
101 101 byOganizationIdGetMasterDevice,
102   - getAttribute,
103 102 } from '/@/api/ruleengine/ruleengineApi';
104 103 import TriggerOrCondition from './cpns/Trigger-Condition.vue';
105 104 import Action from './cpns/Action.vue';
... ... @@ -107,8 +106,8 @@
107 106 import { formatToDateTime } from '/@/utils/dateUtil';
108 107
109 108 const emit = defineEmits(['register', 'success']);
110   -
111 109 const provideOrgid = ref('');
  110 +
112 111 const { createMessage } = useMessage();
113 112 const triggerData = ref([]);
114 113 const conditionData = ref([]);
... ... @@ -125,8 +124,6 @@
125 124 let getConditionFormValue = ref([]);
126 125 let getActionFormValue = ref([]);
127 126 const editEntryIdData = ref([]);
128   - const editEntryIdExcludeDoActionData = ref([]);
129   - let editAttrIdData = [];
130 127 const editAlarmConfigData = ref([]);
131 128 const isUpdate = ref(false);
132 129 const id = ref(undefined);
... ... @@ -158,31 +155,24 @@
158 155 await setFieldsValue(data.record);
159 156 id.value = recordId;
160 157 tenantId.value = recordTenantId;
  158 + //TODO-fengtao-把组织id传给子组件
161 159 provideOrgid.value = organizationId;
  160 + //TODO-fengtao获取当前执行动作下的设备(master那个接口)
  161 + getMasterDeviceList.value = await byOganizationIdGetMasterDevice(organizationId);
  162 + //TODO-fengtao
162 163 // 获取当前组织下的设备列表
163   - const options = await byOganizationIdGetMasterDevice(organizationId);
164   - const optionsExcludeDoAction = await screenLinkPageByDeptIdGetDevice({ organizationId });
  164 + const options = await screenLinkPageByDeptIdGetDevice({
  165 + organizationId,
  166 + });
165 167 // 获取当前组织下的告警配置
166 168 const alarmConfig = await getOrganizationAlarmConfig({ organizationId });
167   - // 获取当前组织下的属性列表
168   - const attrList = await getAttribute(
169   - organizationId,
170   - triggers.map((m) => m.entityId).join(',')
171   - );
172   - watchAttrList.value = await getAttribute(organizationId, null);
173 169
174 170 // 生成回显时对应得组件数量
175 171 triggerData.value = [...new Array(triggers.length).keys()];
176 172 conditionData.value = [...new Array(doConditions.length).keys()];
177 173 actionData.value = [...new Array(doActions.length).keys()];
178 174 // 回显设备列表
179   - editEntryIdData.value = options.map((item) => {
180   - return {
181   - value: item.id,
182   - label: item.name,
183   - };
184   - });
185   - editEntryIdExcludeDoActionData.value = optionsExcludeDoAction.items.map((item) => {
  175 + editEntryIdData.value = options.items.map((item) => {
186 176 return {
187 177 value: item.tbDeviceId,
188 178 label: item.name,
... ... @@ -195,17 +185,11 @@
195 185 };
196 186 });
197 187 deviceList.value = editEntryIdData.value;
198   - deviceExcludeDoAction.value = editEntryIdExcludeDoActionData.value;
199   -
200   - //回显属性列表
201   - editAttrIdData = attrList;
202 188 nextTick(() => {
203   - setEditFields(skipUnwrap.triggerItemRefs, editEntryIdExcludeDoActionData);
204   - setEditFields(skipUnwrap.conditionItemRefs, editEntryIdExcludeDoActionData);
  189 + setEditFields(skipUnwrap.triggerItemRefs, editEntryIdData);
  190 + setEditFields(skipUnwrap.conditionItemRefs, editEntryIdData);
205 191 setEditFields(skipUnwrap.actionItemRefs, editEntryIdData);
206 192 setEditAlarmConfig(skipUnwrap.actionItemRefs, editAlarmConfigData);
207   - setEditAttr(skipUnwrap.triggerItemRefs, editAttrIdData);
208   - setEditAttr(skipUnwrap.conditionItemRefs, editAttrIdData);
209 193 });
210 194
211 195 const map = {
... ... @@ -216,6 +200,7 @@
216 200 // 回显触发器数据---此处是个闭包!
217 201 triggers.forEach((trigger, index) => {
218 202 nextTick(async () => {
  203 + const selectDeviceId = ref('');
219 204 // 回显启用规则
220 205 unref(skipUnwrap.triggerItemRefs)[index].currentIndex =
221 206 map[trigger.triggerCondition.schedule.type];
... ... @@ -223,15 +208,12 @@
223 208 unref(skipUnwrap.triggerItemRefs)[index].isUpdate = true;
224 209 unref(skipUnwrap.triggerItemRefs)[index].alarmScheduleRef.scheduleData =
225 210 trigger.triggerCondition.schedule;
226   - const getAttrKeyOption = trigger?.triggerCondition?.condition?.condition?.map(
227   - (m) => m.key.key
228   - );
229 211 unref(skipUnwrap.triggerItemRefs)[index].setFieldsFormValueFun({
230 212 triggered: trigger?.triggerCondition?.condition?.spec?.type,
231 213 device: trigger?.entityType,
232 214 triggerType: trigger?.triggerType,
233 215 type1: trigger?.triggerCondition?.condition?.condition[0]?.key?.type,
234   - type2: getAttrKeyOption,
  216 + type2: trigger?.triggerCondition?.condition?.condition[0]?.key?.key,
235 217 operationType: trigger?.triggerCondition?.condition?.condition[0]?.valueType,
236 218 detail: trigger?.triggerCondition?.alarmDetails,
237 219 entityId: trigger?.entityId,
... ... @@ -239,6 +221,15 @@
239 221 time: trigger?.triggerCondition?.condition?.spec?.predicate?.defaultValue,
240 222 timeUnit: trigger?.triggerCondition?.condition?.spec?.unit,
241 223 });
  224 + if (trigger.entityId != undefined) {
  225 + selectDeviceId.value = trigger?.entityId;
  226 + }
  227 + //fengtao-把设备id回传给子组件
  228 + unref(skipUnwrap.triggerItemRefs)[index].updateFieldAttributeFunc(
  229 + selectDeviceId.value,
  230 + provideOrgid.value
  231 + );
  232 + //fengtao
242 233 // 设置值operationType
243 234 unref(skipUnwrap.triggerItemRefs)[index].operationType =
244 235 trigger.triggerCondition?.condition.condition[0].valueType;
... ... @@ -298,15 +289,12 @@
298 289 unref(skipUnwrap.conditionItemRefs)[index].isUpdate = true;
299 290 unref(skipUnwrap.conditionItemRefs)[index].alarmScheduleRef.scheduleData =
300 291 condition.triggerCondition.schedule;
301   - const getAttrKeyOption = condition?.triggerCondition?.condition?.condition?.map(
302   - (m) => m.key.key
303   - );
304 292 unref(skipUnwrap.conditionItemRefs)[index].setFieldsFormValueFun({
305 293 triggered: condition?.triggerCondition?.condition?.spec?.type,
306 294 device: condition?.entityType,
307 295 triggerType: condition?.triggerType,
308 296 type1: condition?.triggerCondition?.condition?.condition[0]?.key?.type,
309   - type2: getAttrKeyOption,
  297 + type2: condition?.triggerCondition?.condition?.condition[0]?.key?.key,
310 298 operationType: condition?.triggerCondition?.condition?.condition[0]?.valueType,
311 299 detail: condition?.triggerCondition?.alarmDetails,
312 300 entityId: condition?.entityId,
... ... @@ -493,11 +481,9 @@
493 481 // 设置设备的options
494 482 const setEditFields = (linkAge, deviceList) => {
495 483 unref(linkAge).map((item) => {
496   - if (item.isTriggerAndConditionFlag == 'isTriggerAndConditionFlag') {
497   - item.updateExcludeActionFieldDeviceId(deviceList);
498   - } else {
499   - item.updateFieldDeviceId(deviceList);
500   - }
  484 + //TODO-fengtao
  485 + item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList);
  486 + //TODO-fengtao
501 487 });
502 488 };
503 489 // 设置告警配置options
... ... @@ -506,29 +492,21 @@
506 492 item.updateEditFieldAlarmConfig(alarmConfigList);
507 493 });
508 494 };
509   - //设置设备属性的options
510   - const setEditAttr = (linkAge, attrList) => {
511   - unref(linkAge).map((item) => {
512   - item.updateFieldAttr(attrList);
513   - });
514   - };
515   -
516 495 // 监听组织变化更新设备列表
517 496 const deviceList = ref([]);
  497 + const getMasterDeviceList = ref([]);
  498 + const orgId = ref('');
518 499 const alarmConfigList = ref([]);
519   - const watchAttrList = ref([]);
520   - const deviceExcludeDoAction = ref([]);
521 500 watch(organizationId, async (newValue: string) => {
522 501 if (!newValue) return;
523   - provideOrgid.value = newValue;
524   - const items = await byOganizationIdGetMasterDevice(newValue);
525   - const itemExcludeDoAction = await screenLinkPageByDeptIdGetDevice({ organizationId: newValue });
526   - deviceExcludeDoAction.value = itemExcludeDoAction.items.map((item) => ({
527   - label: item.name,
528   - value: item.tbDeviceId,
529   - }));
530   - deviceList.value = items.map((item) => ({ label: item.name, value: item.id }));
531   - watchAttrList.value = await getAttribute(newValue, null);
  502 + const { items } = await screenLinkPageByDeptIdGetDevice({ organizationId: newValue });
  503 + //TODO fengtao
  504 + getMasterDeviceList.value = await byOganizationIdGetMasterDevice(newValue);
  505 + //TODO fengtao
  506 + deviceList.value = items.map((item) => ({ label: item.name, value: item.tbDeviceId }));
  507 + //TODO fengtao
  508 + orgId.value = newValue;
  509 + //TODO fengtao
532 510 setFields(skipUnwrap.triggerItemRefs, true);
533 511 setFields(skipUnwrap.conditionItemRefs, true);
534 512 setFields(skipUnwrap.actionItemRefs, true);
... ... @@ -541,12 +519,9 @@
541 519 function setFields(linkAge, isOrganizationChange = false) {
542 520 unref(linkAge).map((item) => {
543 521 isOrganizationChange && item.resetFieldsValueFunc();
544   - if (item.isTriggerAndConditionFlag == 'isTriggerAndConditionFlag') {
545   - item.updateExcludeActionFieldDeviceId(deviceExcludeDoAction);
546   - item.updateFieldAttr(watchAttrList);
547   - } else {
548   - item.updateFieldDeviceId(deviceList);
549   - }
  522 + //TODO fengtao
  523 + item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList);
  524 + //TODO fengtao
550 525 });
551 526 }
552 527 function setAlarmConfig(linkAge, isOrganizationChange = false) {
... ... @@ -609,7 +584,20 @@
609 584 id: unref(id),
610 585 tenantId: unref(tenantId),
611 586 };
612   -
  587 + //TODO fengtao---修改之前如果是新增,如果条件筛选页面打开,但没填值,还是可以新增成功
  588 + const typeBoolean = postAddOrEditData?.triggers?.some((f) => {
  589 + let type = false;
  590 + f?.triggerCondition?.condition?.condition?.some((s) => {
  591 + if (s?.predicate?.value?.defaultValue == undefined) {
  592 + type = true;
  593 + } else {
  594 + type = false;
  595 + }
  596 + });
  597 + return type;
  598 + });
  599 + if (typeBoolean) return createMessage.error('请填写条件筛选');
  600 + //TODO fengtao
613 601 await screenLinkPageAddApi(postAddOrEditData, unref(isUpdate));
614 602 createMessage.success(`${unref(isUpdate) ? '编辑' : '新增'}成功`);
615 603 closeDrawer();
... ... @@ -659,8 +647,14 @@
659 647 </script>
660 648
661 649 <style lang="less" scoped>
662   - ///统一下拉选择框宽度,否则超出默认宽度会造成页面样式错乱
663   - :deep(.ant-select-selector) {
664   - max-width: 14.2rem;
  650 + //TODO-fengtao
  651 + ///移除选择框默认样式(24px)否则超出默认宽度会造成页面样式错乱
  652 + ::v-deep(.ant-select-selector) {
  653 + padding-right: 0px !important;
  654 + }
  655 +
  656 + ::v-deep(.ant-select-selection-overflow) {
  657 + max-width: 10vw !important;
665 658 }
  659 + //TODO-fengtao
666 660 </style>
... ...
... ... @@ -257,7 +257,7 @@ export const trigger_condition_schema: FormSchema[] = [
257 257 {
258 258 field: 'type2',
259 259 label: '',
260   - component: 'Select',
  260 + component: 'AutoComplete',
261 261 componentProps: {
262 262 placeholder: '请选择属性',
263 263 },
... ...
... ... @@ -98,42 +98,96 @@
98 98 );
99 99 return { ...getFieldsValue(), predicate, schedule: alarmScheduleRef.value.scheduleData };
100 100 };
101   - const updateExcludeActionFieldDeviceId = (deviceList: any[]) => {
  101 +
  102 + //TODO-fengtao
  103 + const updateFieldDeviceId = (deviceList: any[], orgId, isUpdate) => {
  104 + //用于编辑回显
  105 + if (isUpdate.value != 3 && isUpdate.value) {
  106 + updateSchema({
  107 + field: 'entityId',
  108 + componentProps: {
  109 + options: deviceList,
  110 + },
  111 + });
  112 + }
  113 + //新增、编辑都会触发onChang事件
102 114 updateSchema({
103   - field: 'entityId',
  115 + field: 'device',
104 116 componentProps: {
105   - options: deviceList,
106   - onChange(e) {
  117 + options: [
  118 + { label: '全部', value: 'ALL' },
  119 + { label: '部分', value: 'PART' },
  120 + ],
  121 + async onChange(e) {
  122 + setFieldsValue({ type2: '' });
  123 + //部分切换-清空或者重置为初始值
  124 + updateSchema({
  125 + field: 'type2',
  126 + componentProps: {
  127 + options: [],
  128 + },
  129 + });
107 130 if (e) {
108   - updateFieldAttributeFunc(e);
  131 + //fengtao
  132 + if (e == 'ALL') {
  133 + const data = await getAttribute(props.provideOrgid || orgId.value, null);
  134 + //fengtao
  135 + const options = data.map((m) => {
  136 + return {
  137 + label: m,
  138 + value: m,
  139 + };
  140 + });
  141 + updateSchema({
  142 + field: 'type2',
  143 + componentProps: {
  144 + placeholder: '请选择属性',
  145 + options,
  146 + },
  147 + });
  148 + } else {
  149 + const getT = getFieldsValue();
  150 + const entityId = getT.entityId;
  151 + if (entityId !== undefined && entityId.length > 0) {
  152 + updateFieldAttributeFunc(entityId, orgId.value);
  153 + }
  154 + updateSchema({
  155 + field: 'entityId',
  156 + componentProps: {
  157 + options: deviceList,
  158 + onChange(e) {
  159 + if (e) {
  160 + //fengtao
  161 + updateFieldAttributeFunc(e, orgId.value);
  162 + //fengtao
  163 + }
  164 + },
  165 + },
  166 + });
  167 + }
  168 + //fengtao
109 169 }
110 170 },
111 171 },
112 172 });
113 173 };
114   - const updateFieldAttr = (attrList: any[]) => {
115   - const attrMapList = attrList.value?.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   - };
  174 + //TODO-fengtao
129 175 const resetFieldsValueFunc = () => resetFields();
130 176 // 回显数据函数
131 177 const setFieldsFormValueFun = (fieldsValue) => {
132 178 setFieldsValue(fieldsValue);
133 179 };
134   - const updateFieldAttributeFunc = async (e) => {
135   - const joinDeviceIds = e.join(',');
136   - const data = await getAttribute(props.provideOrgid, joinDeviceIds);
  180 + //TODO-fengtao
  181 + const updateFieldAttributeFunc = async (deviceId, orgId) => {
  182 + //TODO-fengtao
  183 + let data;
  184 + if (deviceId !== undefined && deviceId.length > 0) {
  185 + const joinDeviceIds = deviceId.join(',');
  186 + data = await getAttribute(orgId || props.provideOrgid, joinDeviceIds);
  187 + } else {
  188 + data = await getAttribute(orgId || props.provideOrgid, null);
  189 + }
  190 + //TODO-fengtao
137 191 const options = data.map((m) => {
138 192 return {
139 193 label: m,
... ... @@ -144,11 +198,11 @@
144 198 field: 'type2',
145 199 componentProps: {
146 200 placeholder: '请选择属性',
147   - options,
  201 + options: options,
148 202 },
149 203 });
150 204 };
151   -
  205 + //TODO-fengtao
152 206 const handleDelete = (params: { index: number; title: string }) => {
153 207 emit('delete', params);
154 208 };
... ... @@ -195,12 +249,9 @@
195 249 currentIndex.value = index;
196 250 };
197 251 const scheduleData = ref(null);
198   - const isTriggerAndConditionFlag = 'isTriggerAndConditionFlag';
199 252 defineExpose({
200   - isTriggerAndConditionFlag,
201 253 getFieldsValueFunc,
202   - updateExcludeActionFieldDeviceId,
203   - updateFieldAttr,
  254 + updateFieldDeviceId,
204 255 resetFieldsValueFunc,
205 256 setFieldsFormValueFun,
206 257 childGetFieldsValue,
... ... @@ -212,9 +263,17 @@
212 263 scheduleData,
213 264 isUpdate,
214 265 alarmScheduleRef,
  266 + updateFieldAttributeFunc,
215 267 });
216 268 </script>
217 269
  270 +<style lang="less" scoped>
  271 + ///移除选择框默认样式(24px)否则超出默认宽度会造成页面样式错乱
  272 + ::v-deep(.ant-select-selector) {
  273 + padding-right: 0px !important;
  274 + }
  275 +</style>
  276 +
218 277 <style>
219 278 .active {
220 279 color: #377dff;
... ...
... ... @@ -140,14 +140,25 @@
140 140 setFieldsValue(fieldsValue);
141 141 };
142 142 const resetFieldsValueFunc = () => resetFields();
143   - const updateFieldDeviceId = (deviceList) => {
  143 +
  144 + //TODO-fengtao
  145 + const updateFieldDeviceId = (deviceList, e, i, masterList) => {
  146 + console.log(deviceList, e, i);
  147 + console.log(masterList.value);
  148 + const options = masterList.value.map((m) => {
  149 + return {
  150 + value: m.id,
  151 + label: m.name,
  152 + };
  153 + });
144 154 updateSchema({
145 155 field: 'deviceId',
146 156 componentProps: {
147   - options: deviceList,
  157 + options,
148 158 },
149 159 });
150 160 };
  161 + //TODO-fengtao
151 162 const updateEditFieldAlarmConfig = (alarmConfigList) => {
152 163 updateSchema({
153 164 field: 'alarm_config',
... ...