Commit 8a0ebdb83f9a96fd156807503c1989be8739de60
1 parent
49ad777a
perf: switch component add confirm modal
Showing
1 changed file
with
31 additions
and
33 deletions
... | ... | @@ -14070,46 +14070,44 @@ class HandleDataInteraction { |
14070 | 14070 | } |
14071 | 14071 | } |
14072 | 14072 | |
14073 | - // TODO switch component send command | |
14074 | - function getSwitchComponentBindValue() { | |
14075 | - return currentNode.getAttribute(SWITCH_VALUE) | |
14076 | - } | |
14077 | - | |
14078 | - async function handleSwitchComponent() { | |
14073 | + function handleSwitchComponent() { | |
14079 | 14074 | const state = currentNode.getAttribute(SWITCH_STATE) |
14080 | 14075 | const value = currentNode.getAttribute(SWITCH_VALUE) |
14081 | 14076 | if (state === SWITCH_STATE_NONE) { |
14082 | 14077 | return |
14083 | 14078 | } |
14079 | + layer.confirm('是否确认下发命令?', async function (index) { | |
14080 | + let { deviceId, attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {} | |
14081 | + let { command, way } = content | |
14082 | + const validate = new Validate([ | |
14083 | + { value, required: true, message: '下发值是必填项' }, | |
14084 | + { value: deviceId, required: true, message: '未绑定设备' }, | |
14085 | + { value: way, required: true, message: '未绑定指令下发方式(单向/双向)' }, | |
14086 | + { value: command, required: true, message: '未设置下发命令' }, | |
14087 | + { value: attr, required: true, message: '未绑定设备属性' }, | |
14088 | + ]) | |
14089 | + if (!validate.begin()) return | |
14090 | + if (typeof command === 'string') command = jsonParse(command) | |
14091 | + const data = replaceAttrPlaceholder(command, attr, value) | |
14092 | + const instructionData = { | |
14093 | + method: "methodThingskit", | |
14094 | + params: data, | |
14095 | + } | |
14084 | 14096 | |
14085 | - let { deviceId, attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {} | |
14086 | - let { command, way } = content | |
14087 | - const validate = new Validate([ | |
14088 | - { value, required: true, message: '下发值是必填项' }, | |
14089 | - { value: deviceId, required: true, message: '未绑定设备' }, | |
14090 | - { value: way, required: true, message: '未绑定指令下发方式(单向/双向)' }, | |
14091 | - { value: command, required: true, message: '未设置下发命令' }, | |
14092 | - { value: attr, required: true, message: '未绑定设备属性' }, | |
14093 | - ]) | |
14094 | - if (!validate.begin()) return | |
14095 | - if (typeof command === 'string') command = jsonParse(command) | |
14096 | - const data = replaceAttrPlaceholder(command, attr, value) | |
14097 | - const instructionData = { | |
14098 | - method: "methodThingskit", | |
14099 | - params: data, | |
14100 | - } | |
14101 | - | |
14102 | - const [err, res = []] = await to(ConfigurationNodeApi.deviceIsOnLine(deviceId)) | |
14103 | - const { value: onlineFlag } = res[0] || {} | |
14104 | - if (onlineFlag) { | |
14105 | - const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData)) | |
14106 | - if (!err) { | |
14107 | - UseLayUi.topSuccessMsg('操作成功') | |
14108 | - callback() | |
14097 | + const [err, res = []] = await to(ConfigurationNodeApi.deviceIsOnLine(deviceId)) | |
14098 | + const { value: onlineFlag } = res[0] || {} | |
14099 | + if (onlineFlag) { | |
14100 | + const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData)) | |
14101 | + if (!err) { | |
14102 | + UseLayUi.topSuccessMsg('操作成功') | |
14103 | + layer.close(index); | |
14104 | + } | |
14105 | + } else { | |
14106 | + UseLayUi.topErrorMsg('设备不在线!') | |
14109 | 14107 | } |
14110 | - } else { | |
14111 | - UseLayUi.topErrorMsg('设备不在线!') | |
14112 | - } | |
14108 | + }); | |
14109 | + | |
14110 | + | |
14113 | 14111 | } |
14114 | 14112 | |
14115 | 14113 | function replaceAttrPlaceholder(oldValue = {}, replaceAttr = '', replaceValue = '', newValue = {},) { | ... | ... |