Commit 49ad777a0a00b26c25aa3b21ea5956220555ffc4
1 parent
4a851038
perf: switch component cancel fill commond
Showing
3 changed files
with
102 additions
and
21 deletions
... | ... | @@ -249,8 +249,23 @@ |
249 | 249 | */ |
250 | 250 | DEFAULT: 'default', |
251 | 251 | |
252 | + /** | |
253 | + * @description 开关组件 value | |
254 | + */ | |
255 | + SWITCH_VALUE: 'switchValue', | |
256 | + | |
257 | + /** | |
258 | + * @description 开关组件状态 {true | false | null} | |
259 | + */ | |
260 | + SWITCH_STATE: 'switchState' | |
252 | 261 | } |
253 | 262 | |
263 | + Sidebar.prototype.enumComponentTypeValue = { | |
264 | + SWITCH_STATE_ENABLED: 'enabled', | |
265 | + SWITCH_STATE_CLOSE: 'close', | |
266 | + SWITCH_STATE_NONE: 'none', | |
267 | + } | |
268 | + | |
254 | 269 | /** |
255 | 270 | * @description 组件权限map |
256 | 271 | * @type {Map<string, string[]>} | ... | ... |
... | ... | @@ -4,7 +4,8 @@ |
4 | 4 | // Control Component 控制元件 |
5 | 5 | Sidebar.prototype.addControlComponentsPalette = function () { |
6 | 6 | const { COMPONENT_TYPE } = this.enumCellBasicAttribute |
7 | - const { SWITCH, PARAMS_SETTING_BUTTON } = this.enumComponentType | |
7 | + const { SWITCH, PARAMS_SETTING_BUTTON, SWITCH_VALUE, SWITCH_STATE } = this.enumComponentType | |
8 | + const { SWITCH_STATE_NONE } = this.enumComponentTypeValue | |
8 | 9 | const gn = 'mxgraph.control'; |
9 | 10 | const dt = 'control'; |
10 | 11 | const label = '控制元件' |
... | ... | @@ -15,14 +16,14 @@ |
15 | 16 | const defaultStyle = ';imageAspect=0;' |
16 | 17 | this.setCurrentSearchEntryLibrary(dt); |
17 | 18 | |
18 | - | |
19 | - | |
20 | 19 | const fns = [ |
21 | 20 | this.addEntry(this.getTagsForStencil(gn, 'Switch', dt).join(' '), mxUtils.bind(this, function () { |
22 | 21 | const cell = new mxCell('', new mxGeometry(0, 0, 48, 48), `image;image=images/thingskit/switch-on.svg;${defaultStyle}`); |
23 | 22 | // 自定义属性 |
24 | 23 | const cellAttribute = { |
25 | - [COMPONENT_TYPE]: SWITCH | |
24 | + [COMPONENT_TYPE]: SWITCH, | |
25 | + [SWITCH_VALUE]: 1, | |
26 | + [SWITCH_STATE]: SWITCH_STATE_NONE | |
26 | 27 | } |
27 | 28 | cell.setVertex(true) |
28 | 29 | this.setCellAttributes(cell, cellAttribute) | ... | ... |
... | ... | @@ -6923,9 +6923,17 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
6923 | 6923 | async function submit(callback) { |
6924 | 6924 | const formVal = form.val(enumActionEl.FORM_FILTER) |
6925 | 6925 | const isParamsSetting = formVal[enumConst.ACTION] === enumActionType.PARAMS_SETTING |
6926 | + const { COMPONENT_TYPE } = Sidebar.prototype.enumCellBasicAttribute | |
6927 | + const { SWITCH } = Sidebar.prototype.enumComponentType | |
6928 | + const isSwitchComponent = vertices[0].getAttribute(COMPONENT_TYPE) === SWITCH | |
6929 | + | |
6930 | + if (isParamsSetting && isSwitchComponent && (!currentNodeData.act || !currentNodeData.act.find(item => item.type === enumDynamicEffectType.SWITCH))) { | |
6931 | + UseLayUi.topErrorMsg('请先配置数据动效中的状态设置') | |
6932 | + return | |
6933 | + } | |
6934 | + | |
6926 | 6935 | if (isParamsSetting) { |
6927 | 6936 | if (!isJson(formVal[enumConst.COMMAND])) { |
6928 | - console.log() | |
6929 | 6937 | UseLayUi.topErrorMsg('命令配置存在错误') |
6930 | 6938 | return |
6931 | 6939 | } |
... | ... | @@ -12994,6 +13002,7 @@ class DispatchCenter { |
12994 | 13002 | DISPLAY: 'DISPLAY', |
12995 | 13003 | FLASH: 'FLASH', |
12996 | 13004 | ROTATE: 'ROTATE', |
13005 | + SWITCH: 'SWITCH', | |
12997 | 13006 | } |
12998 | 13007 | |
12999 | 13008 | static enumPageType = { |
... | ... | @@ -13396,13 +13405,18 @@ class HandleDataSource { |
13396 | 13405 | const { condition = [] } = switchConfig || {} |
13397 | 13406 | let reg = /image=[^;]+/g |
13398 | 13407 | let flag = false |
13408 | + const { SWITCH_STATE, SWITCH_VALUE } = Sidebar.prototype.enumComponentType | |
13409 | + const { SWITCH_STATE_NONE } = Sidebar.prototype.enumComponentTypeValue | |
13399 | 13410 | for (const item of condition) { |
13400 | - const { value, imagePath } = item || {} | |
13411 | + const { value, imagePath, type } = item || {} | |
13401 | 13412 | if (Number(receiveValue) === Number(value)) { |
13402 | 13413 | flag = true |
13403 | 13414 | this.updatePage(() => { |
13404 | 13415 | const style = node.getStyle() |
13405 | 13416 | node.setStyle(style.replace(reg, `image=${imagePath}`)) |
13417 | + node.setAttribute('label', '') | |
13418 | + node.setAttribute(SWITCH_VALUE, receiveValue) | |
13419 | + node.setAttribute(SWITCH_STATE, type) | |
13406 | 13420 | }, node) |
13407 | 13421 | break |
13408 | 13422 | } |
... | ... | @@ -13411,6 +13425,9 @@ class HandleDataSource { |
13411 | 13425 | this.updatePage(() => { |
13412 | 13426 | const style = node.getStyle() |
13413 | 13427 | node.setStyle(style.replace(reg, `image=images/thingskit/not-standard-value.svg`)) |
13428 | + node.setAttribute('label', receiveValue) | |
13429 | + node.setAttribute(SWITCH_VALUE, receiveValue) | |
13430 | + node.setAttribute(SWITCH_STATE, SWITCH_STATE_NONE) | |
13414 | 13431 | }, node) |
13415 | 13432 | } |
13416 | 13433 | } |
... | ... | @@ -14010,7 +14027,12 @@ class HandleDataInteraction { |
14010 | 14027 | */ |
14011 | 14028 | paramsSetting(nodeId, content) { |
14012 | 14029 | const { layer, jquery: $, form } = layui |
14030 | + const { SWITCH_STATE, SWITCH_VALUE, SWITCH, PARAMS_SETTING_BUTTON } = Sidebar.prototype.enumComponentType | |
14031 | + const { SWITCH_STATE_ENABLED, SWITCH_STATE_NONE, SWITCH_STATE_CLOSE } = Sidebar.prototype.enumComponentTypeValue | |
14032 | + const { COMPONENT_TYPE } = Sidebar.prototype.enumCellBasicAttribute | |
14013 | 14033 | const contentData = this.contentData |
14034 | + const currentNode = this.DispatchInstance.contentAllCell.find(item => item.id === nodeId) | |
14035 | + | |
14014 | 14036 | const enumConst = { |
14015 | 14037 | VALUE: 'value', |
14016 | 14038 | ISSUED_WAY: 'way', |
... | ... | @@ -14040,20 +14062,6 @@ class HandleDataInteraction { |
14040 | 14062 | </div>` |
14041 | 14063 | } |
14042 | 14064 | |
14043 | - function isJson(string) { | |
14044 | - if (typeof string === 'string') { | |
14045 | - try { | |
14046 | - const obj = JSON.parse(string) | |
14047 | - if (typeof obj === 'object' && obj !== null) { | |
14048 | - return true | |
14049 | - } | |
14050 | - } catch (e) { | |
14051 | - return false | |
14052 | - } | |
14053 | - } | |
14054 | - return false | |
14055 | - } | |
14056 | - | |
14057 | 14065 | function jsonParse(value) { |
14058 | 14066 | try { |
14059 | 14067 | return JSON.parse(value) |
... | ... | @@ -14062,6 +14070,48 @@ class HandleDataInteraction { |
14062 | 14070 | } |
14063 | 14071 | } |
14064 | 14072 | |
14073 | + // TODO switch component send command | |
14074 | + function getSwitchComponentBindValue() { | |
14075 | + return currentNode.getAttribute(SWITCH_VALUE) | |
14076 | + } | |
14077 | + | |
14078 | + async function handleSwitchComponent() { | |
14079 | + const state = currentNode.getAttribute(SWITCH_STATE) | |
14080 | + const value = currentNode.getAttribute(SWITCH_VALUE) | |
14081 | + if (state === SWITCH_STATE_NONE) { | |
14082 | + return | |
14083 | + } | |
14084 | + | |
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() | |
14109 | + } | |
14110 | + } else { | |
14111 | + UseLayUi.topErrorMsg('设备不在线!') | |
14112 | + } | |
14113 | + } | |
14114 | + | |
14065 | 14115 | function replaceAttrPlaceholder(oldValue = {}, replaceAttr = '', replaceValue = '', newValue = {},) { |
14066 | 14116 | if (typeof oldValue !== 'object') return newValue |
14067 | 14117 | |
... | ... | @@ -14135,7 +14185,22 @@ class HandleDataInteraction { |
14135 | 14185 | }) |
14136 | 14186 | } |
14137 | 14187 | |
14138 | - createLayer() | |
14188 | + | |
14189 | + function startProcess() { | |
14190 | + const componentType = currentNode.getAttribute(COMPONENT_TYPE) | |
14191 | + const handle = { | |
14192 | + [SWITCH]: handleSwitchComponent, | |
14193 | + [PARAMS_SETTING_BUTTON]: createLayer | |
14194 | + } | |
14195 | + | |
14196 | + try { | |
14197 | + handle[componentType]() | |
14198 | + } catch (error) { | |
14199 | + | |
14200 | + } | |
14201 | + } | |
14202 | + console.log('enter') | |
14203 | + startProcess() | |
14139 | 14204 | } |
14140 | 14205 | } |
14141 | 14206 | ... | ... |