Showing
2 changed files
with
121 additions
and
50 deletions
| ... | ... | @@ -119,45 +119,81 @@ |
| 119 | 119 | const handleSuccess = () => { |
| 120 | 120 | reload(); |
| 121 | 121 | }; |
| 122 | + | |
| 123 | + const findName = (item: any, curr: any) => { | |
| 124 | + return item.attribute.find((item) => item.identifier === curr.key)?.name; | |
| 125 | + }; | |
| 126 | + | |
| 127 | + const findLogin = (curr: any) => { | |
| 128 | + return [...operationNumber_OR_TIME, ...operationString, ...operationBoolean].find( | |
| 129 | + (item) => item.value === curr.logic | |
| 130 | + )?.symbol; | |
| 131 | + }; | |
| 132 | + | |
| 133 | + const findAttribute = (item: any, curr: any) => { | |
| 134 | + item.attribute.find((findItem) => findItem.identifier === curr.key); | |
| 135 | + }; | |
| 136 | + | |
| 137 | + const findValue = (item: any, curr: any) => { | |
| 138 | + return { | |
| 139 | + ['触发属性']: findName(item, curr), | |
| 140 | + ['触发条件']: `${findLogin(curr)}${curr.logicValue}`, | |
| 141 | + ['触发值']: `${curr.realValue}${ | |
| 142 | + findAttribute(item, curr)?.detail?.dataType?.specs?.unit?.key ?? '' | |
| 143 | + }`, | |
| 144 | + }; | |
| 145 | + }; | |
| 146 | + | |
| 147 | + const handleAlarmText = (text: string) => (text === 'triggerData' ? '触发器' : '执行条件'); | |
| 148 | + | |
| 122 | 149 | const handleViewAlarmDetails = async (record: Recordable) => { |
| 123 | 150 | await nextTick(); |
| 124 | 151 | const { details } = record; |
| 152 | + if (!details) return; | |
| 125 | 153 | const deviceIdKeys = Object.keys(details); |
| 126 | 154 | const detailObject = deviceIdKeys.map((key) => ({ label: key, value: details[key] })); |
| 127 | 155 | const dataFormat = await handleAlarmDetailFormat(deviceIdKeys); |
| 128 | - const dataFormats = detailObject.reduce((acc: any, curr: any) => { | |
| 156 | + const dataFormats = detailObject.reduce((acc: Recordable[], curr: Recordable) => { | |
| 157 | + let currentObj: Recordable = {}; | |
| 129 | 158 | dataFormat.forEach((item) => { |
| 130 | 159 | if (item.tbDeviceId === curr.label) { |
| 131 | - const findName = item.attribute.find( | |
| 132 | - (item) => item.identifier === curr.value.key | |
| 133 | - )?.name; | |
| 134 | - const findLogin = [ | |
| 135 | - ...operationNumber_OR_TIME, | |
| 136 | - ...operationString, | |
| 137 | - ...operationBoolean, | |
| 138 | - ].find((item) => item.value === curr.value.logic)?.symbol; | |
| 139 | - const findAttribute = item.attribute.find( | |
| 140 | - (findItem) => findItem.identifier === curr.value.key | |
| 141 | - ); | |
| 142 | - const value = { | |
| 143 | - ['触发属性']: findName, | |
| 144 | - ['触发条件']: `${findLogin}${curr.value.logicValue}`, | |
| 145 | - ['触发值']: `${curr.value.realValue}${ | |
| 146 | - findAttribute.detail?.dataType?.specs?.unit?.key ?? '' | |
| 147 | - }`, | |
| 148 | - }; | |
| 149 | - const data = { | |
| 150 | - [item.name]: value, | |
| 151 | - }; | |
| 152 | - acc.push(data); | |
| 160 | + const { triggerData, conditionData } = curr.value; | |
| 161 | + if (triggerData || conditionData) { | |
| 162 | + for (let currItem in curr.value) { | |
| 163 | + const value = findValue(item, curr.value[currItem]); | |
| 164 | + currentObj = { | |
| 165 | + [item.name]: { | |
| 166 | + [handleAlarmText(currItem)]: value, | |
| 167 | + }, | |
| 168 | + }; | |
| 169 | + acc.push(currentObj); | |
| 170 | + } | |
| 171 | + } else { | |
| 172 | + const value = findValue(item, curr.value); | |
| 173 | + currentObj = { | |
| 174 | + [item.name]: value, | |
| 175 | + }; | |
| 176 | + acc.push(currentObj); | |
| 177 | + } | |
| 153 | 178 | } |
| 154 | 179 | }); |
| 155 | 180 | return [...acc]; |
| 156 | 181 | }, []); |
| 157 | - const objectFormat = dataFormats.reduce((acc: any, curr: any) => { | |
| 182 | + let tempList: Recordable[] = []; | |
| 183 | + const objectFormat = dataFormats.reduce((acc: Recordable, curr: Recordable) => { | |
| 184 | + const keys = Object.keys(curr); | |
| 185 | + const values = Object.values(curr); | |
| 186 | + tempList.push(...values); | |
| 187 | + acc = { | |
| 188 | + [keys[0]]: tempList.reduce((acc: Recordable, curr: Recordable) => { | |
| 189 | + return { | |
| 190 | + ...acc, | |
| 191 | + ...curr, | |
| 192 | + }; | |
| 193 | + }, {}), | |
| 194 | + }; | |
| 158 | 195 | return { |
| 159 | 196 | ...acc, |
| 160 | - ...curr, | |
| 161 | 197 | }; |
| 162 | 198 | }, {}); |
| 163 | 199 | Modal.info({ | ... | ... |
| ... | ... | @@ -80,45 +80,80 @@ |
| 80 | 80 | const handleSuccess = () => { |
| 81 | 81 | reload(); |
| 82 | 82 | }; |
| 83 | + const findName = (item: any, curr: any) => { | |
| 84 | + return item.attribute.find((item) => item.identifier === curr.key)?.name; | |
| 85 | + }; | |
| 86 | + | |
| 87 | + const findLogin = (curr: any) => { | |
| 88 | + return [...operationNumber_OR_TIME, ...operationString, ...operationBoolean].find( | |
| 89 | + (item) => item.value === curr.logic | |
| 90 | + )?.symbol; | |
| 91 | + }; | |
| 92 | + | |
| 93 | + const findAttribute = (item: any, curr: any) => { | |
| 94 | + item.attribute.find((findItem) => findItem.identifier === curr.key); | |
| 95 | + }; | |
| 96 | + | |
| 97 | + const findValue = (item: any, curr: any) => { | |
| 98 | + return { | |
| 99 | + ['触发属性']: findName(item, curr), | |
| 100 | + ['触发条件']: `${findLogin(curr)}${curr.logicValue}`, | |
| 101 | + ['触发值']: `${curr.realValue}${ | |
| 102 | + findAttribute(item, curr)?.detail?.dataType?.specs?.unit?.key ?? '' | |
| 103 | + }`, | |
| 104 | + }; | |
| 105 | + }; | |
| 106 | + | |
| 107 | + const handleAlarmText = (text: string) => (text === 'triggerData' ? '触发器' : '执行条件'); | |
| 108 | + | |
| 83 | 109 | const handleViewAlarmDetails = async (record: Recordable) => { |
| 84 | 110 | await nextTick(); |
| 85 | 111 | const { details } = record; |
| 112 | + if (!details) return; | |
| 86 | 113 | const deviceIdKeys = Object.keys(details); |
| 87 | 114 | const detailObject = deviceIdKeys.map((key) => ({ label: key, value: details[key] })); |
| 88 | 115 | const dataFormat = await handleAlarmDetailFormat(deviceIdKeys); |
| 89 | - const dataFormats = detailObject.reduce((acc: any, curr: any) => { | |
| 116 | + const dataFormats = detailObject.reduce((acc: Recordable[], curr: Recordable) => { | |
| 117 | + let currentObj: Recordable = {}; | |
| 90 | 118 | dataFormat.forEach((item) => { |
| 91 | 119 | if (item.tbDeviceId === curr.label) { |
| 92 | - const findName = item.attribute.find( | |
| 93 | - (item) => item.identifier === curr.value.key | |
| 94 | - )?.name; | |
| 95 | - const findLogin = [ | |
| 96 | - ...operationNumber_OR_TIME, | |
| 97 | - ...operationString, | |
| 98 | - ...operationBoolean, | |
| 99 | - ].find((item) => item.value === curr.value.logic)?.symbol; | |
| 100 | - const findAttribute = item.attribute.find( | |
| 101 | - (findItem) => findItem.identifier === curr.value.key | |
| 102 | - ); | |
| 103 | - const value = { | |
| 104 | - ['触发属性']: findName, | |
| 105 | - ['触发条件']: `${findLogin}${curr.value.logicValue}`, | |
| 106 | - ['触发值']: `${curr.value.realValue}${ | |
| 107 | - findAttribute.detail?.dataType?.specs?.unit?.key ?? '' | |
| 108 | - }`, | |
| 109 | - }; | |
| 110 | - const data = { | |
| 111 | - [item.name]: value, | |
| 112 | - }; | |
| 113 | - acc.push(data); | |
| 120 | + const { triggerData, conditionData } = curr.value; | |
| 121 | + if (triggerData || conditionData) { | |
| 122 | + for (let currItem in curr.value) { | |
| 123 | + const value = findValue(item, curr.value[currItem]); | |
| 124 | + currentObj = { | |
| 125 | + [item.name]: { | |
| 126 | + [handleAlarmText(currItem)]: value, | |
| 127 | + }, | |
| 128 | + }; | |
| 129 | + acc.push(currentObj); | |
| 130 | + } | |
| 131 | + } else { | |
| 132 | + const value = findValue(item, curr.value); | |
| 133 | + currentObj = { | |
| 134 | + [item.name]: value, | |
| 135 | + }; | |
| 136 | + acc.push(currentObj); | |
| 137 | + } | |
| 114 | 138 | } |
| 115 | 139 | }); |
| 116 | 140 | return [...acc]; |
| 117 | 141 | }, []); |
| 118 | - const objectFormat = dataFormats.reduce((acc: any, curr: any) => { | |
| 142 | + let tempList: Recordable[] = []; | |
| 143 | + const objectFormat = dataFormats.reduce((acc: Recordable, curr: Recordable) => { | |
| 144 | + const keys = Object.keys(curr); | |
| 145 | + const values = Object.values(curr); | |
| 146 | + tempList.push(...values); | |
| 147 | + acc = { | |
| 148 | + [keys[0]]: tempList.reduce((acc: Recordable, curr: Recordable) => { | |
| 149 | + return { | |
| 150 | + ...acc, | |
| 151 | + ...curr, | |
| 152 | + }; | |
| 153 | + }, {}), | |
| 154 | + }; | |
| 119 | 155 | return { |
| 120 | 156 | ...acc, |
| 121 | - ...curr, | |
| 122 | 157 | }; |
| 123 | 158 | }, {}); |
| 124 | 159 | Modal.info({ | ... | ... |