Commit 31440c851290ac2ba056d3d27571ec9d51e23b1f

Authored by fengtao
1 parent 03b52f86

pref:场景联动设备属性接口更换为设备接口里的获取属性

... ... @@ -108,10 +108,10 @@ export const getOrganizationAlarmConfig = (params: { organizationId }) => {
108 108 // url: ScreenManagerApi.GET_ATTRBUTELIST + '/' + orgId + joinText,
109 109 // });
110 110 // };
111   -export const getAttribute = (orgId, deviceIds) => {
  111 +export const getAttribute = (orgId) => {
112 112 // const joinText = deviceIds == null ? [] : '?deviceIds=' + deviceIds;
113 113 return defHttp.get({
114   - url: `${ScreenManagerApi.GET_ATTRBUTELIST}${orgId}/${deviceIds}`,
  114 + url: `${ScreenManagerApi.GET_ATTRBUTELIST}${orgId}`,
115 115 });
116 116 };
117 117
... ...
... ... @@ -228,7 +228,7 @@
228 228 // 回显触发器数据---此处是个闭包!
229 229 triggers.forEach((trigger, index) => {
230 230 nextTick(async () => {
231   - const selectDeviceId = ref('');
  231 + const selectProductId = ref('');
232 232 // 回显启用规则
233 233 unref(skipUnwrap.triggerItemRefs)[index].currentIndex =
234 234 map[trigger.triggerCondition.schedule.type];
... ... @@ -245,18 +245,16 @@
245 245 operationType: trigger?.triggerCondition?.condition?.condition[0]?.valueType,
246 246 detail: trigger?.triggerCondition?.alarmDetails,
247 247 entityId: trigger?.entityId,
  248 + deviceProfileId: trigger?.deviceProfileId,
248 249 replaceValue: trigger?.triggerCondition?.condition?.spec?.predicate?.defaultValue,
249 250 time: trigger?.triggerCondition?.condition?.spec?.predicate?.defaultValue,
250 251 timeUnit: trigger?.triggerCondition?.condition?.spec?.unit,
251 252 });
252   - if (trigger.entityId != undefined) {
253   - selectDeviceId.value = trigger?.entityId;
  253 + if (trigger.deviceProfileId != undefined) {
  254 + selectProductId.value = trigger?.deviceProfileId;
254 255 }
255 256 //fengtao-把设备id回传给子组件
256   - unref(skipUnwrap.triggerItemRefs)[index].updateFieldAttributeFunc(
257   - selectDeviceId.value,
258   - provideOrgid.value
259   - );
  257 + unref(skipUnwrap.triggerItemRefs)[index].updateFieldAttributeFunc(selectProductId.value);
260 258 //fengtao
261 259 // 设置值operationType
262 260 unref(skipUnwrap.triggerItemRefs)[index].operationType =
... ... @@ -309,7 +307,7 @@
309 307
310 308 doConditions.forEach((condition, index) => {
311 309 nextTick(async () => {
312   - const selectDeviceId = ref('');
  310 + const selectProductId = ref('');
313 311 // 回显启用规则
314 312 unref(skipUnwrap.conditionItemRefs)[index].currentIndex =
315 313 map[condition.triggerCondition.schedule.type];
... ... @@ -327,17 +325,17 @@
327 325 operationType: condition?.triggerCondition?.condition?.condition[0]?.valueType,
328 326 detail: condition?.triggerCondition?.alarmDetails,
329 327 entityId: condition?.entityId,
  328 + deviceProfileId: condition?.deviceProfileId,
330 329 replaceValue: condition?.triggerCondition?.condition?.spec?.predicate?.defaultValue,
331 330 time: condition?.triggerCondition?.condition?.spec?.predicate?.defaultValue,
332 331 timeUnit: condition?.triggerCondition?.condition?.spec?.unit,
333 332 });
334   - if (condition?.entityId != undefined) {
335   - selectDeviceId.value = condition?.entityId;
  333 + if (condition?.deviceProfileId != undefined) {
  334 + selectProductId.value = condition?.deviceProfileId;
336 335 }
337 336 //fengtao-把设备id回传给子组件
338 337 unref(skipUnwrap.conditionItemRefs)[index].updateFieldAttributeFunc(
339   - selectDeviceId.value,
340   - provideOrgid.value
  338 + selectProductId.value
341 339 );
342 340 //fengtao
343 341 // 设置值operationType
... ... @@ -391,7 +389,7 @@
391 389
392 390 doActions.forEach((action, index) => {
393 391 nextTick(() => {
394   - const selectDeviceId = ref('');
  392 + const selectProductId = ref('');
395 393 // 设置执行动作外层值
396 394 unref(skipUnwrap.actionItemRefs)[index].setFieldsFormValueFun({
397 395 ...action,
... ... @@ -439,6 +437,7 @@
439 437 .valueType,
440 438 detail: action.doContext.clearRule[index].triggerCondition.alarmDetails,
441 439 entityId: action.doContext.clearRule[index].entityId,
  440 + deviceProfileId: action.doContext.clearRule[index]?.deviceProfileId,
442 441 replaceValue:
443 442 action.doContext.clearRule[index].triggerCondition.condition.spec.predicate
444 443 .defaultValue,
... ... @@ -447,17 +446,12 @@
447 446 timeUnit:
448 447 action.doContext.clearRule[index].triggerCondition.condition.spec.unit,
449 448 });
450   - if (action.doContext.clearRule[index].entityId != undefined) {
451   - selectDeviceId.value = action.doContext.clearRule[index].entityId;
  449 + if (action.doContext.clearRule[index]?.deviceProfileId != undefined) {
  450 + selectProductId.value = action.doContext.clearRule[index]?.deviceProfileId;
452 451 }
453 452 //fengtao-把设备id回传给子组件
454   - item.updateFieldAttributeFunc(selectDeviceId.value, provideOrgid.value);
455   - // item.updateFieldDeviceId(
456   - // deviceList.value,
457   - // provideOrgid.value,
458   - // isUpdate.value,
459   - // getMasterDeviceList.value
460   - // );
  453 + item.updateFieldAttributeFunc(selectProductId.value);
  454 + item.updateFieldDeviceId(deviceList.value, provideOrgid.value, isUpdate.value);
461 455 //fengtao
462 456 // 单独设置operationType值 操作符类型 NUMERIC|String|Boolean|DATE_TIME
463 457 item.operationType =
... ... @@ -534,12 +528,12 @@
534 528 });
535 529
536 530 // 设置设备的options
537   - const setEditFields = (_linkAge, _deviceList) => {
538   - // unref(linkAge).map((item) => {
539   - //TODO-fengtao
540   - // item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList);
541   - //TODO-fengtao
542   - // });
  531 + const setEditFields = (linkAge, deviceList) => {
  532 + unref(linkAge).map((item) => {
  533 + // TODO-fengtao
  534 + item.updateFieldDeviceId(deviceList, orgId, isUpdate);
  535 + // TODO-fengtao
  536 + });
543 537 };
544 538 // 设置告警配置options
545 539 const setEditAlarmConfig = (linkAge, alarmConfigList) => {
... ... @@ -600,7 +594,7 @@
600 594 unref(linkAge).map((item) => {
601 595 isOrganizationChange && item.resetFieldsValueFunc();
602 596 //TODO fengtao
603   - // item.updateFieldDeviceId(deviceList, orgId, isUpdate, getMasterDeviceList);
  597 + item.updateFieldDeviceId(deviceList, orgId, isUpdate);
604 598 if (isUpdate.value) {
605 599 item.updateEditFieldAlarmConfig(editAlarmConfigData);
606 600 } else {
... ...
... ... @@ -3,6 +3,7 @@ import { BasicColumn, FormSchema } from '/@/components/Table';
3 3 import {
4 4 byOrganizationIdGetMasterDevice,
5 5 screenLinkOrganizationGetApi,
  6 + getAttribute,
6 7 } from '/@/api/ruleengine/ruleengineApi';
7 8 import { scheduleOptions } from './formatData';
8 9 import { copyTransFun } from '/@/utils/fnUtils';
... ... @@ -196,6 +197,52 @@ export const trigger_condition_schema: FormSchema[] = [
196 197 colProps: { span: 6 },
197 198 },
198 199 {
  200 + field: 'deviceProfileId',
  201 + label: '',
  202 + component: 'ApiSelect',
  203 + colProps: { span: 6 },
  204 + componentProps: ({ formActionType }) => {
  205 + const { updateSchema, setFieldsValue } = formActionType;
  206 + return {
  207 + api: deviceProfile,
  208 + placeholder: '请选择产品',
  209 + labelField: 'name',
  210 + valueField: 'id',
  211 + getPopupContainer: () => document.body,
  212 + onChange: async (e) => {
  213 + if (e) {
  214 + setFieldsValue({ type2: '' });
  215 + const res = await getAttribute(e);
  216 + let options: any = [];
  217 + if (Array.isArray(res)) {
  218 + options = res.map((m) => {
  219 + return {
  220 + label: m?.identifier,
  221 + value: m?.identifier,
  222 + };
  223 + });
  224 + updateSchema({
  225 + field: 'type2',
  226 + componentProps: {
  227 + placeholder: '请选择属性',
  228 + options,
  229 + },
  230 + });
  231 + } else {
  232 + updateSchema({
  233 + field: 'type2',
  234 + componentProps: {
  235 + placeholder: '请选择属性',
  236 + options,
  237 + },
  238 + });
  239 + }
  240 + }
  241 + },
  242 + };
  243 + },
  244 + },
  245 + {
199 246 field: 'device',
200 247 label: '',
201 248 component: 'Select',
... ... @@ -208,6 +255,7 @@ export const trigger_condition_schema: FormSchema[] = [
208 255 },
209 256 colProps: { span: 6 },
210 257 },
  258 +
211 259 {
212 260 field: 'entityId',
213 261 label: '',
... ... @@ -219,6 +267,7 @@ export const trigger_condition_schema: FormSchema[] = [
219 267 ifShow: ({ values }) => isPart(values.device),
220 268 colProps: { span: 6 },
221 269 },
  270 +
222 271 {
223 272 field: 'time',
224 273 label: '',
... ... @@ -370,17 +419,19 @@ export const actionSchema: FormSchema[] = [
370 419 component: 'ApiSelect',
371 420 componentProps: ({ formModel }) => {
372 421 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   - };
  422 + if (unref(organizationId)) {
  423 + return {
  424 + placeholder: '请选择设备',
  425 + mode: 'multiple',
  426 + api: byOrganizationIdGetMasterDevice,
  427 + params: {
  428 + organizationId: unref(organizationId),
  429 + deviceProfileId,
  430 + },
  431 + labelField: 'name',
  432 + valueField: 'id',
  433 + };
  434 + }
384 435 },
385 436 ifShow: ({ values }) => isPart(values.device) && isDeviceOut(values.outTarget),
386 437 colProps: { span: 6 },
... ... @@ -394,7 +445,7 @@ export const actionSchema: FormSchema[] = [
394 445 colProps: {
395 446 span: 6,
396 447 },
397   - defaultValue: '0',
  448 + defaultValue: 0,
398 449 componentProps: ({ formActionType }) => {
399 450 const { setFieldsValue } = formActionType;
400 451 return {
... ...
... ... @@ -17,6 +17,7 @@ export const genTriggerOrConditionData = (triggerData) => {
17 17 time,
18 18 timeUnit,
19 19 replaceValue,
  20 + deviceProfileId,
20 21 } = triggerData;
21 22 const mapPredicate = predicate?.map((item) => {
22 23 return {
... ... @@ -40,6 +41,7 @@ export const genTriggerOrConditionData = (triggerData) => {
40 41 };
41 42 });
42 43 return {
  44 + deviceProfileId,
43 45 triggerType,
44 46 entityType: device,
45 47 entityId: entityId?.length ? entityId : null,
... ... @@ -115,6 +117,7 @@ export const genActionData = (actionData) => {
115 117 triggerType: item.triggerType,
116 118 entityType: item.device,
117 119 entityId: item.device === 'PART' ? item.entityId : null,
  120 + deviceProfileId: item.deviceProfileId,
118 121 triggerCondition: {
119 122 alarmDetails: item.detail,
120 123 condition: {
... ...
... ... @@ -62,10 +62,10 @@
62 62 import { CollapseContainer } from '/@/components/Container/index';
63 63 import { BasicForm, useForm } from '/@/components/Form/index';
64 64 import { Card, Select, Input, Tooltip } from 'ant-design-vue';
65   - import { trigger_condition_schema } from '../config/config.data.ts';
  65 + import { trigger_condition_schema } from '../config/config.data';
66 66 import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
67 67 import ConditionScreening from './ConditionScreening.vue';
68   - import { scheduleOptions, timeUnitOptions, options } from '../config/formatData.ts';
  68 + import { scheduleOptions, timeUnitOptions, options } from '../config/formatData';
69 69 import { Icon } from '/@/components/Icon';
70 70 import AlarmSchedule from './AlarmSchedule.vue';
71 71 import { useModal } from '/@/components/Modal';
... ... @@ -99,22 +99,12 @@
99 99 return { ...getFieldsValue(), predicate, schedule: alarmScheduleRef.value.scheduleData };
100 100 };
101 101
102   - const updateFieldDeviceId = (deviceList: any[], orgId, isUpdate) => {
  102 + const updateFieldDeviceId = (deviceList: any[], _, isUpdate) => {
103 103 if (isUpdate) {
104 104 updateSchema({
105 105 field: 'entityId',
106 106 componentProps: {
107 107 options: deviceList,
108   - onChange(e) {
109   - if (e) {
110   - if (isUpdate) {
111   - setFieldsValue({ type2: '' });
112   - }
113   - //fengtao
114   - updateFieldAttributeFunc(e, orgId);
115   - //fengtao
116   - }
117   - },
118 108 },
119 109 });
120 110 }
... ... @@ -127,53 +117,15 @@
127 117 { label: '部分', value: 'PART' },
128 118 ],
129 119 async onChange(e) {
130   - setFieldsValue({ type2: '' });
131 120 setFieldsValue({ entityId: [] });
132   - //部分切换-清空或者重置为初始值
133   - updateSchema({
134   - field: 'type2',
135   - componentProps: {
136   - options: [],
137   - },
138   - });
139 121 if (e) {
140 122 //fengtao
141 123 if (e == 'ALL') {
142   - if (orgId) {
143   - const data = await getAttribute(orgId, null);
144   - //fengtao
145   - const options = data.map((m) => {
146   - return {
147   - label: m,
148   - value: m,
149   - };
150   - });
151   - updateSchema({
152   - field: 'type2',
153   - componentProps: {
154   - placeholder: '请选择属性',
155   - options,
156   - },
157   - });
158   - }
159 124 } else {
160   - const getT = getFieldsValue();
161   - const entityId = getT.entityId;
162   - if (entityId !== undefined && entityId.length > 0) {
163   - updateFieldAttributeFunc(entityId, orgId);
164   - }
165 125 updateSchema({
166 126 field: 'entityId',
167 127 componentProps: {
168 128 options: deviceList,
169   - onChange(e) {
170   - if (e) {
171   - setFieldsValue({ type2: '' });
172   - //fengtao
173   - updateFieldAttributeFunc(e, orgId);
174   - //fengtao
175   - }
176   - },
177 129 },
178 130 });
179 131 }
... ... @@ -189,30 +141,32 @@
189 141 const setFieldsFormValueFun = (fieldsValue) => {
190 142 setFieldsValue(fieldsValue);
191 143 };
192   - //TODO-fengtao
193   - const updateFieldAttributeFunc = async (deviceId, orgId) => {
194   - //TODO-fengtao
195   - let data;
196   - if (deviceId !== undefined && deviceId.length > 0) {
197   - const joinDeviceIds = deviceId.join(',');
198   - data = await getAttribute(orgId, joinDeviceIds);
  144 + const updateFieldAttributeFunc = async (e) => {
  145 + const res = await getAttribute(e);
  146 + let options: any = [];
  147 + if (Array.isArray(res)) {
  148 + options = res.map((m) => {
  149 + return {
  150 + label: m?.identifier,
  151 + value: m?.identifier,
  152 + };
  153 + });
  154 + updateSchema({
  155 + field: 'type2',
  156 + componentProps: {
  157 + placeholder: '请选择属性',
  158 + options,
  159 + },
  160 + });
199 161 } else {
200   - data = await getAttribute(orgId, null);
  162 + updateSchema({
  163 + field: 'type2',
  164 + componentProps: {
  165 + placeholder: '请选择属性',
  166 + options,
  167 + },
  168 + });
201 169 }
202   - //TODO-fengtao
203   - const options = data.map((m) => {
204   - return {
205   - label: m,
206   - value: m,
207   - };
208   - });
209   - updateSchema({
210   - field: 'type2',
211   - componentProps: {
212   - placeholder: '请选择属性',
213   - options: options,
214   - },
215   - });
216 170 };
217 171 //TODO-fengtao
218 172 const schedule = ref('ANY_TIME');
... ...
... ... @@ -62,16 +62,16 @@
62 62 import { BasicForm, useForm } from '/@/components/Form/index';
63 63 import { Icon } from '/@/components/Icon';
64 64 import { Tooltip, Card, Select, Input } from 'ant-design-vue';
65   - import { trigger_condition_schema } from '../config/config.data.ts';
  65 + import { trigger_condition_schema } from '../config/config.data';
66 66 import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
67 67 import ConditionScreening from './ConditionScreening.vue';
68   - import { scheduleOptions, timeUnitOptions, options } from '../config/formatData.ts';
  68 + import { scheduleOptions, timeUnitOptions, options } from '../config/formatData';
69 69 import AlarmSchedule from './AlarmSchedule.vue';
70 70 import { useModal } from '/@/components/Modal';
71 71 import { cloneDeep } from 'lodash-es';
72 72 import { useMessage } from '/@/hooks/web/useMessage';
73 73
74   - const props = defineProps({
  74 + defineProps({
75 75 title: {
76 76 type: String,
77 77 required: true,
... ... @@ -139,23 +139,13 @@
139 139 };
140 140
141 141 //TODO-fengtao
142   - const updateFieldDeviceId = (deviceList: any[], orgId, isUpdate) => {
  142 + const updateFieldDeviceId = (deviceList: any[], _, isUpdate) => {
143 143 //用于编辑回显
144 144 if (isUpdate.value) {
145 145 updateSchema({
146 146 field: 'entityId',
147 147 componentProps: {
148 148 options: deviceList,
149   - onChange(e) {
150   - if (e) {
151   - if (isUpdate.value) {
152   - setFieldsValue({ type2: '' });
153   - }
154   - //fengtao
155   - updateFieldAttributeFunc(e, orgId.value);
156   - //fengtao
157   - }
158   - },
159 149 },
160 150 });
161 151 }
... ... @@ -168,52 +158,15 @@
168 158 { label: '部分', value: 'PART' },
169 159 ],
170 160 async onChange(e) {
171   - setFieldsValue({ type2: '' });
172 161 setFieldsValue({ entityId: [] });
173   - updateSchema({
174   - field: 'type2',
175   - componentProps: {
176   - options: [],
177   - },
178   - });
179 162 if (e) {
180 163 //fengtao
181 164 if (e == 'ALL') {
182   - if (props.provideOrgid || orgId.value) {
183   - const data = await getAttribute(props.provideOrgid || orgId.value, null);
184   - //fengtao
185   - const options = data.map((m) => {
186   - return {
187   - label: m,
188   - value: m,
189   - };
190   - });
191   - updateSchema({
192   - field: 'type2',
193   - componentProps: {
194   - placeholder: '请选择属性',
195   - options,
196   - },
197   - });
198   - }
199 165 } else {
200   - const getT = getFieldsValue();
201   - const entityId = getT.entityId;
202   - if (entityId !== undefined && entityId.length > 0) {
203   - updateFieldAttributeFunc(entityId, orgId.value);
204   - }
205 166 updateSchema({
206 167 field: 'entityId',
207 168 componentProps: {
208 169 options: deviceList,
209   - onChange(e) {
210   - if (e) {
211   - setFieldsValue({ type2: '' });
212   - //fengtao
213   - updateFieldAttributeFunc(e, orgId.value);
214   - //fengtao
215   - }
216   - },
217 170 },
218 171 });
219 172 }
... ... @@ -233,29 +186,32 @@
233 186 setFieldsValue(fieldsValue);
234 187 };
235 188 //TODO-fengtao
236   - const updateFieldAttributeFunc = async (deviceId, orgId) => {
237   - //TODO-fengtao
238   - let data;
239   - if (deviceId !== undefined && deviceId.length > 0) {
240   - const joinDeviceIds = deviceId.join(',');
241   - data = await getAttribute(orgId || props.provideOrgid, joinDeviceIds);
  189 + const updateFieldAttributeFunc = async (e) => {
  190 + const res = await getAttribute(e);
  191 + let options: any = [];
  192 + if (Array.isArray(res)) {
  193 + options = res.map((m) => {
  194 + return {
  195 + label: m?.identifier,
  196 + value: m?.identifier,
  197 + };
  198 + });
  199 + updateSchema({
  200 + field: 'type2',
  201 + componentProps: {
  202 + placeholder: '请选择属性',
  203 + options,
  204 + },
  205 + });
242 206 } else {
243   - data = await getAttribute(orgId || props.provideOrgid, null);
  207 + updateSchema({
  208 + field: 'type2',
  209 + componentProps: {
  210 + placeholder: '请选择属性',
  211 + options,
  212 + },
  213 + });
244 214 }
245   - //TODO-fengtao
246   - const options = data.map((m) => {
247   - return {
248   - label: m,
249   - value: m,
250   - };
251   - });
252   - updateSchema({
253   - field: 'type2',
254   - componentProps: {
255   - placeholder: '请选择属性',
256   - options: options,
257   - },
258   - });
259 215 };
260 216 //TODO-fengtao
261 217 const handleDelete = (params: { index: number; title: string }) => {
... ...
... ... @@ -170,11 +170,10 @@
170 170 const changeOutTarget = () => {
171 171 emit('getActionFormArr');
172 172 };
173   - const [registerAction, { getFieldsValue, resetFields, updateSchema, setFieldsValue, validate }] =
174   - useForm({
175   - schemas: actionSchema,
176   - showActionButtonGroup: false,
177   - });
  173 + const [registerAction, { getFieldsValue, resetFields, setFieldsValue, validate }] = useForm({
  174 + schemas: actionSchema,
  175 + showActionButtonGroup: false,
  176 + });
178 177
179 178 // 获取整个执行动作表单值
180 179 const getFieldsValueFunc = () => {
... ... @@ -274,26 +273,14 @@
274 273 const isUpdateItem = ref('');
275 274 const deviceListItem = ref([]);
276 275
277   - //TODO-fengtao
278   - const updateFieldDeviceId = (deviceList, orgId, isUpdate, getMasterDeviceList) => {
  276 + //update 2022-11-28
  277 + const updateFieldDeviceId = (deviceList, orgId, isUpdate) => {
279 278 if (isUpdate.value) {
280 279 orgIdItem.value = orgId.value;
281 280 }
282 281 orgIdItem.value = orgId.value;
283 282 isUpdateItem.value = isUpdate.value;
284   - const options = getMasterDeviceList.value.map((m) => {
285   - return {
286   - value: m.id,
287   - label: m.name,
288   - };
289   - });
290 283 deviceListItem.value = deviceList.value;
291   - updateSchema({
292   - field: 'deviceId',
293   - componentProps: {
294   - options,
295   - },
296   - });
297 284 };
298 285 //FT add 2022-10-27
299 286 const updateEditFieldAlarmConfig = (alarmConfigList) => {
... ...