Commit 4a513b7a7901870d1ca56c1044e17f59caa34c63
1 parent
0770fed5
fix: swtich component send command not send negation value
Showing
2 changed files
with
24 additions
and
35 deletions
@@ -260,9 +260,15 @@ | @@ -260,9 +260,15 @@ | ||
260 | SWITCH_VALUE: 'switchValue', | 260 | SWITCH_VALUE: 'switchValue', |
261 | 261 | ||
262 | /** | 262 | /** |
263 | + * @description 开关组件 下发值 | ||
264 | + */ | ||
265 | + SWITCH_SEND_VALUE: 'switchSendValue', | ||
266 | + | ||
267 | + /** | ||
263 | * @description 开关组件状态 {true | false | null} | 268 | * @description 开关组件状态 {true | false | null} |
264 | */ | 269 | */ |
265 | - SWITCH_STATE: 'switchState' | 270 | + SWITCH_STATE: 'switchState', |
271 | + | ||
266 | } | 272 | } |
267 | 273 | ||
268 | Sidebar.prototype.enumComponentTypeValue = { | 274 | Sidebar.prototype.enumComponentTypeValue = { |
@@ -13431,17 +13431,23 @@ class HandleDataSource { | @@ -13431,17 +13431,23 @@ class HandleDataSource { | ||
13431 | const { condition = [] } = switchConfig || {} | 13431 | const { condition = [] } = switchConfig || {} |
13432 | let reg = /image=[^;]+/g | 13432 | let reg = /image=[^;]+/g |
13433 | let flag = false | 13433 | let flag = false |
13434 | - const { SWITCH_STATE, SWITCH_VALUE } = Sidebar.prototype.enumComponentType | 13434 | + const { SWITCH_STATE, SWITCH_VALUE, SWITCH_SEND_VALUE } = Sidebar.prototype.enumComponentType |
13435 | const { SWITCH_STATE_NONE } = Sidebar.prototype.enumComponentTypeValue | 13435 | const { SWITCH_STATE_NONE } = Sidebar.prototype.enumComponentTypeValue |
13436 | + | ||
13437 | + const getSendValue = (type) => { | ||
13438 | + return (condition.find(item => item.type !== type) || {}).value | ||
13439 | + } | ||
13436 | for (const item of condition) { | 13440 | for (const item of condition) { |
13437 | const { value, imagePath, type } = item || {} | 13441 | const { value, imagePath, type } = item || {} |
13438 | if (Number(receiveValue) === Number(value)) { | 13442 | if (Number(receiveValue) === Number(value)) { |
13439 | flag = true | 13443 | flag = true |
13440 | this.updatePage(() => { | 13444 | this.updatePage(() => { |
13441 | const style = node.getStyle() | 13445 | const style = node.getStyle() |
13446 | + const sendValue = getSendValue(type) | ||
13442 | node.setStyle(style.replace(reg, `image=${imagePath}`)) | 13447 | node.setStyle(style.replace(reg, `image=${imagePath}`)) |
13443 | node.setAttribute('label', '') | 13448 | node.setAttribute('label', '') |
13444 | node.setAttribute(SWITCH_VALUE, receiveValue) | 13449 | node.setAttribute(SWITCH_VALUE, receiveValue) |
13450 | + node.setAttribute(SWITCH_SEND_VALUE, sendValue) | ||
13445 | node.setAttribute(SWITCH_STATE, type) | 13451 | node.setAttribute(SWITCH_STATE, type) |
13446 | }, node) | 13452 | }, node) |
13447 | break | 13453 | break |
@@ -13456,6 +13462,7 @@ class HandleDataSource { | @@ -13456,6 +13462,7 @@ class HandleDataSource { | ||
13456 | node.setAttribute(SWITCH_STATE, SWITCH_STATE_NONE) | 13462 | node.setAttribute(SWITCH_STATE, SWITCH_STATE_NONE) |
13457 | }, node) | 13463 | }, node) |
13458 | } | 13464 | } |
13465 | + | ||
13459 | } | 13466 | } |
13460 | 13467 | ||
13461 | handleParamSettingButton(message) { | 13468 | handleParamSettingButton(message) { |
@@ -14159,8 +14166,8 @@ class HandleDataInteraction { | @@ -14159,8 +14166,8 @@ class HandleDataInteraction { | ||
14159 | */ | 14166 | */ |
14160 | paramsSetting(nodeId, content) { | 14167 | paramsSetting(nodeId, content) { |
14161 | const { layer, jquery: $, form } = layui | 14168 | const { layer, jquery: $, form } = layui |
14162 | - const { SWITCH_STATE, SWITCH_VALUE, SWITCH, PARAMS_SETTING_BUTTON } = Sidebar.prototype.enumComponentType | ||
14163 | - const { SWITCH_STATE_ENABLED, SWITCH_STATE_NONE, SWITCH_STATE_CLOSE } = Sidebar.prototype.enumComponentTypeValue | 14169 | + const { SWITCH_STATE, SWITCH_VALUE, SWITCH_SEND_VALUE, SWITCH, PARAMS_SETTING_BUTTON } = Sidebar.prototype.enumComponentType |
14170 | + const { SWITCH_STATE_NONE } = Sidebar.prototype.enumComponentTypeValue | ||
14164 | const { COMPONENT_TYPE } = Sidebar.prototype.enumCellBasicAttribute | 14171 | const { COMPONENT_TYPE } = Sidebar.prototype.enumCellBasicAttribute |
14165 | const contentData = this.contentData | 14172 | const contentData = this.contentData |
14166 | const currentNode = this.contentAllCell.find(item => item.id === nodeId) | 14173 | const currentNode = this.contentAllCell.find(item => item.id === nodeId) |
@@ -14204,39 +14211,12 @@ class HandleDataInteraction { | @@ -14204,39 +14211,12 @@ class HandleDataInteraction { | ||
14204 | 14211 | ||
14205 | function handleSwitchComponent() { | 14212 | function handleSwitchComponent() { |
14206 | const state = currentNode.getAttribute(SWITCH_STATE) | 14213 | const state = currentNode.getAttribute(SWITCH_STATE) |
14207 | - const value = currentNode.getAttribute(SWITCH_VALUE) | 14214 | + const value = currentNode.getAttribute(SWITCH_SEND_VALUE) |
14208 | if (state === SWITCH_STATE_NONE) { | 14215 | if (state === SWITCH_STATE_NONE) { |
14209 | return | 14216 | return |
14210 | } | 14217 | } |
14211 | layer.confirm('是否确认下发命令?', async function (index) { | 14218 | layer.confirm('是否确认下发命令?', async function (index) { |
14212 | - let { deviceId, attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {} | ||
14213 | - let { command, way } = content | ||
14214 | - const validate = new Validate([ | ||
14215 | - { value, required: true, message: '下发值是必填项' }, | ||
14216 | - { value: deviceId, required: true, message: '未绑定设备' }, | ||
14217 | - { value: way, required: true, message: '未绑定指令下发方式(单向/双向)' }, | ||
14218 | - { value: command, required: true, message: '未设置下发命令' }, | ||
14219 | - { value: attr, required: true, message: '未绑定设备属性' }, | ||
14220 | - ]) | ||
14221 | - if (!validate.begin()) return | ||
14222 | - if (typeof command === 'string') command = jsonParse(command) | ||
14223 | - const data = replaceAttrPlaceholder(command, attr, value) | ||
14224 | - const instructionData = { | ||
14225 | - method: "methodThingskit", | ||
14226 | - params: data, | ||
14227 | - } | ||
14228 | - | ||
14229 | - const [err, res = []] = await to(ConfigurationNodeApi.deviceIsOnLine(deviceId)) | ||
14230 | - const { value: onlineFlag } = res[0] || {} | ||
14231 | - if (onlineFlag) { | ||
14232 | - const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData)) | ||
14233 | - if (!err) { | ||
14234 | - UseLayUi.topSuccessMsg('操作成功') | ||
14235 | - layer.close(index); | ||
14236 | - } | ||
14237 | - } else { | ||
14238 | - UseLayUi.topErrorMsg('设备不在线!') | ||
14239 | - } | 14219 | + defaultHandler(value, () => layer.close(index)) |
14240 | }); | 14220 | }); |
14241 | 14221 | ||
14242 | 14222 | ||
@@ -14263,6 +14243,10 @@ class HandleDataInteraction { | @@ -14263,6 +14243,10 @@ class HandleDataInteraction { | ||
14263 | const submitThrottle = this.throttle(submit) | 14243 | const submitThrottle = this.throttle(submit) |
14264 | async function submit(callback) { | 14244 | async function submit(callback) { |
14265 | const { value } = form.val(enumActionEl.ISSUED_WAY_FILTER) | 14245 | const { value } = form.val(enumActionEl.ISSUED_WAY_FILTER) |
14246 | + defaultHandler(value, callback) | ||
14247 | + } | ||
14248 | + | ||
14249 | + async function defaultHandler(value, callback) { | ||
14266 | let { deviceId, attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {} | 14250 | let { deviceId, attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {} |
14267 | let { command, way } = content | 14251 | let { command, way } = content |
14268 | const validate = new Validate([ | 14252 | const validate = new Validate([ |
@@ -14286,7 +14270,7 @@ class HandleDataInteraction { | @@ -14286,7 +14270,7 @@ class HandleDataInteraction { | ||
14286 | const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData)) | 14270 | const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData)) |
14287 | if (!err) { | 14271 | if (!err) { |
14288 | UseLayUi.topSuccessMsg('操作成功') | 14272 | UseLayUi.topSuccessMsg('操作成功') |
14289 | - callback() | 14273 | + callback && typeof callback === 'function' && callback() |
14290 | } | 14274 | } |
14291 | } else { | 14275 | } else { |
14292 | UseLayUi.topErrorMsg('设备不在线!') | 14276 | UseLayUi.topErrorMsg('设备不在线!') |
@@ -14329,7 +14313,6 @@ class HandleDataInteraction { | @@ -14329,7 +14313,6 @@ class HandleDataInteraction { | ||
14329 | 14313 | ||
14330 | } | 14314 | } |
14331 | } | 14315 | } |
14332 | - console.log('enter') | ||
14333 | startProcess() | 14316 | startProcess() |
14334 | } | 14317 | } |
14335 | } | 14318 | } |