Commit 01e2632e4a88531b9bb890e8b4247243ca81d098
1 parent
1e7a7fa9
feat: basic switch component preview issues instruction event
Showing
2 changed files
with
184 additions
and
7 deletions
| ... | ... | @@ -6869,12 +6869,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
| 6869 | 6869 | /** |
| 6870 | 6870 | * @description 动作类型 |
| 6871 | 6871 | */ |
| 6872 | - const enumActionType = { | |
| 6873 | - PAGE: 'PAGE', | |
| 6874 | - LINK: 'LINK', | |
| 6875 | - PROPS: 'PROPS', | |
| 6876 | - PARAMS_SETTING: 'PARAMS_SETTING' | |
| 6877 | - } | |
| 6872 | + const enumActionType = DispatchCenter.enumPageType | |
| 6878 | 6873 | |
| 6879 | 6874 | const enumGetValue = { |
| 6880 | 6875 | [enumActionType.PAGE]: enumConst.PAGE_VALUE, |
| ... | ... | @@ -6955,6 +6950,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
| 6955 | 6950 | const [err, res] = await to(ConfigurationNodeApi.updateNodeEvent(data)) |
| 6956 | 6951 | if (err) return |
| 6957 | 6952 | isControlComponent && overrideCurrentData('event', 'type', res) |
| 6953 | + isControlComponent && echoActionType() | |
| 6958 | 6954 | UseLayUi.successMsg() |
| 6959 | 6955 | callback() |
| 6960 | 6956 | } |
| ... | ... | @@ -12919,7 +12915,8 @@ class DispatchCenter { |
| 12919 | 12915 | static enumPageType = { |
| 12920 | 12916 | PAGE: 'PAGE', |
| 12921 | 12917 | LINK: 'LINK', |
| 12922 | - | |
| 12918 | + PROPS: 'PROPS', | |
| 12919 | + PARAMS_SETTING: 'PARAMS_SETTING' | |
| 12923 | 12920 | } |
| 12924 | 12921 | |
| 12925 | 12922 | |
| ... | ... | @@ -13190,6 +13187,14 @@ class HandleDataSource { |
| 13190 | 13187 | return this.DispatchInstance.cmdIdMapping |
| 13191 | 13188 | } |
| 13192 | 13189 | |
| 13190 | + get basicAttr() { | |
| 13191 | + return Sidebar.prototype.enumCellBasicAttribute | |
| 13192 | + } | |
| 13193 | + | |
| 13194 | + get componentType() { | |
| 13195 | + return Sidebar.prototype.enumComponentType | |
| 13196 | + } | |
| 13197 | + | |
| 13193 | 13198 | /** |
| 13194 | 13199 | * @description 生成普通数据源绑定映射关系 |
| 13195 | 13200 | * @param dataSources |
| ... | ... | @@ -13279,6 +13284,11 @@ class HandleDataSource { |
| 13279 | 13284 | const { attr } = this.getBindData(subscriptionId) |
| 13280 | 13285 | node && this.updatePage(() => { |
| 13281 | 13286 | const { data } = message |
| 13287 | + const type = this.getComponentType(node) | |
| 13288 | + if (type === this.componentType.SWITCH) { | |
| 13289 | + this.handleSwitchComponent(message) | |
| 13290 | + return | |
| 13291 | + } | |
| 13282 | 13292 | if (!data) return |
| 13283 | 13293 | const [[timespan, value]] = data[attr] |
| 13284 | 13294 | node.setValue(value) |
| ... | ... | @@ -13286,6 +13296,34 @@ class HandleDataSource { |
| 13286 | 13296 | } |
| 13287 | 13297 | |
| 13288 | 13298 | /** |
| 13299 | + * @description 处理switch 组件 | |
| 13300 | + * @param {} message | |
| 13301 | + */ | |
| 13302 | + handleSwitchComponent(message) { | |
| 13303 | + const { subscriptionId, data = {} } = message | |
| 13304 | + const node = this.getNodeByCmdId(subscriptionId) | |
| 13305 | + const { nodeId, attr } = this.getBindData(subscriptionId) | |
| 13306 | + const [[timespan, receiveValue] = []] = data[attr] || [] | |
| 13307 | + const switchConfig = this.DispatchInstance.contentData.act.find(item => item.id === nodeId && item.type === 'SWITCH') | |
| 13308 | + const { condition = [] } = switchConfig || {} | |
| 13309 | + let reg = /image=images[^;]+/g | |
| 13310 | + let flag = false | |
| 13311 | + for (const item of condition) { | |
| 13312 | + const { value, imagePath } = item || {} | |
| 13313 | + if (Number(receiveValue) === Number(value)) { | |
| 13314 | + flag = true | |
| 13315 | + const style = node.getStyle() | |
| 13316 | + node.setStyle(style.replace(reg, `image=${imagePath}`)) | |
| 13317 | + break | |
| 13318 | + } | |
| 13319 | + } | |
| 13320 | + if (!flag) { | |
| 13321 | + const style = node.getStyle() | |
| 13322 | + node.setStyle(style.replace(reg, `image=images/thingskit/not-standard-value.svg`)) | |
| 13323 | + } | |
| 13324 | + } | |
| 13325 | + | |
| 13326 | + /** | |
| 13289 | 13327 | * @description 更新实时数据 |
| 13290 | 13328 | * @param {} message |
| 13291 | 13329 | * @param {} agg 聚合方式 |
| ... | ... | @@ -13599,6 +13637,10 @@ class HandleDataSource { |
| 13599 | 13637 | return this.DispatchInstance.contentAllCell.find(item => item.id === nodeId) |
| 13600 | 13638 | } |
| 13601 | 13639 | |
| 13640 | + getComponentType(node) { | |
| 13641 | + return node.getAttribute(this.basicAttr.COMPONENT_TYPE) | |
| 13642 | + } | |
| 13643 | + | |
| 13602 | 13644 | /** |
| 13603 | 13645 | * @description 发送socket 消息 |
| 13604 | 13646 | * @param {any} msg |
| ... | ... | @@ -13766,6 +13808,8 @@ class HandleDataInteraction { |
| 13766 | 13808 | this.jumpPage(value) |
| 13767 | 13809 | } else if (type === DispatchCenter.enumPageType.LINK && value) { |
| 13768 | 13810 | window.open(value) |
| 13811 | + } else if (type === DispatchCenter.enumPageType.PARAMS_SETTING) { | |
| 13812 | + this.paramsSetting(id) | |
| 13769 | 13813 | } |
| 13770 | 13814 | } |
| 13771 | 13815 | } |
| ... | ... | @@ -13849,6 +13893,134 @@ class HandleDataInteraction { |
| 13849 | 13893 | throw error |
| 13850 | 13894 | } |
| 13851 | 13895 | } |
| 13896 | + | |
| 13897 | + /** | |
| 13898 | + * @description 参数设置 | |
| 13899 | + */ | |
| 13900 | + paramsSetting(nodeId) { | |
| 13901 | + const { layer, jquery: $, form } = layui | |
| 13902 | + const enumConst = { | |
| 13903 | + VALUE: 'value', | |
| 13904 | + ISSUED_WAY: 'way', | |
| 13905 | + ONE_WAR: 'oneway', | |
| 13906 | + TWO_WAY: 'twoway' | |
| 13907 | + } | |
| 13908 | + | |
| 13909 | + const enumActionEl = { | |
| 13910 | + CONTAINER: 'container', | |
| 13911 | + EDITOR: 'editor', | |
| 13912 | + ISSUED_WAY_FILTER: 'wayFilter' | |
| 13913 | + | |
| 13914 | + } | |
| 13915 | + | |
| 13916 | + /** | |
| 13917 | + * @description 创建JSON编辑器 | |
| 13918 | + * @param el | |
| 13919 | + * @param datum | |
| 13920 | + */ | |
| 13921 | + function createEditor() { | |
| 13922 | + const editor = ace.edit(enumActionEl.EDITOR, { | |
| 13923 | + maxLines: 18, // 最大行数,超过会自动出现滚动条 | |
| 13924 | + minLines: 10, // 最小行数,还未到最大行数时,编辑器会自动伸缩大小 | |
| 13925 | + fontSize: 14, // 编辑器内字体大小 | |
| 13926 | + tabSize: 2, // 制表符设置为 4 个空格大小 | |
| 13927 | + }); | |
| 13928 | + editor.session.setMode("ace/mode/json"); | |
| 13929 | + editor.getSession().on('change', (event, editor) => { | |
| 13930 | + $(`#${enumActionEl.CONTAINER}`).parent().find(`textarea[name="${enumConst.VALUE}"]`).val(editor.getValue()) | |
| 13931 | + }) | |
| 13932 | + } | |
| 13933 | + | |
| 13934 | + function createContent() { | |
| 13935 | + return ` | |
| 13936 | + <div> | |
| 13937 | + <div class="layui-form" lay-filter="${enumActionEl.ISSUED_WAY_FILTER}"> | |
| 13938 | + <div class="layui-form-item"> | |
| 13939 | + <label class="layui-form-label">单向/双向</label> | |
| 13940 | + <div class="layui-input-block"> | |
| 13941 | + <input type="radio" name="${enumConst.ISSUED_WAY}" value="${enumConst.ONE_WAR}" title="单向" checked=""> | |
| 13942 | + <input type="radio" name="${enumConst.ISSUED_WAY}" value="${enumConst.TWO_WAY}" title="双向"> | |
| 13943 | + </div> | |
| 13944 | + </div> | |
| 13945 | + </div> | |
| 13946 | + <div id="${enumActionEl.CONTAINER}"> | |
| 13947 | + <div id="${enumActionEl.EDITOR}"></div> | |
| 13948 | + <textarea name="${enumConst.VALUE}" style="display: none;" /> | |
| 13949 | + </div> | |
| 13950 | + </div>` | |
| 13951 | + } | |
| 13952 | + | |
| 13953 | + function isJson(string) { | |
| 13954 | + if (typeof string === 'string') { | |
| 13955 | + try { | |
| 13956 | + const obj = JSON.parse(string) | |
| 13957 | + if (typeof obj === 'object' && obj !== null) { | |
| 13958 | + return true | |
| 13959 | + } | |
| 13960 | + } catch (e) { | |
| 13961 | + return false | |
| 13962 | + } | |
| 13963 | + } | |
| 13964 | + return false | |
| 13965 | + } | |
| 13966 | + const submitThrottle = this.throttle(submit) | |
| 13967 | + async function submit() { | |
| 13968 | + const value = $(`#${enumActionEl.CONTAINER}`).parent().find(`textarea[name="${enumConst.VALUE}"]`).val() || '' | |
| 13969 | + if (!isJson(value)) { | |
| 13970 | + UseLayUi.topErrorMsg('下发值不正确') | |
| 13971 | + return | |
| 13972 | + } | |
| 13973 | + const { way } = form.val(enumActionEl.ISSUED_WAY_FILTER) | |
| 13974 | + const data = JSON.parse(value) | |
| 13975 | + let { deviceId, slaveDeviceId } = DispatchCenter.instance.contentData.dataSources.find(item => item.nodeId === nodeId) || {} | |
| 13976 | + | |
| 13977 | + if (!value || !deviceId) return | |
| 13978 | + const instructionData = { | |
| 13979 | + method: "methodThingskit", | |
| 13980 | + params: data, | |
| 13981 | + } | |
| 13982 | + if (slaveDeviceId) { | |
| 13983 | + deviceId = slaveDeviceId | |
| 13984 | + } | |
| 13985 | + | |
| 13986 | + const [err, res = []] = await to(ConfigurationNodeApi.deviceIsOnLine(deviceId)) | |
| 13987 | + const { value: onlineFlag } = res[0] || {} | |
| 13988 | + if (onlineFlag) { | |
| 13989 | + const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData)) | |
| 13990 | + if (!err) { | |
| 13991 | + UseLayUi.topSuccessMsg('操作成功') | |
| 13992 | + } | |
| 13993 | + } else { | |
| 13994 | + UseLayUi.topErrorMsg('设备不在线!') | |
| 13995 | + } | |
| 13996 | + } | |
| 13997 | + | |
| 13998 | + function createLayer() { | |
| 13999 | + | |
| 14000 | + layer.open({ | |
| 14001 | + title: '参数设置', | |
| 14002 | + content: createContent(), | |
| 14003 | + area: '600px', | |
| 14004 | + btn: ["应用", "取消"], | |
| 14005 | + yes(index) { | |
| 14006 | + submitThrottle() | |
| 14007 | + }, | |
| 14008 | + but2(index, layero) { | |
| 14009 | + | |
| 14010 | + }, | |
| 14011 | + async success(layero, index) { | |
| 14012 | + createEditor(enumActionEl.EDITOR) | |
| 14013 | + form.render() | |
| 14014 | + // $(layero).addClass('layui-form').find('.layui-layer-btn0').attr({ | |
| 14015 | + // 'lay-submit': '', | |
| 14016 | + // 'lay-filter': enumActionEl.IMAGE_LAYER_FILTER, | |
| 14017 | + // }) | |
| 14018 | + }, | |
| 14019 | + }) | |
| 14020 | + } | |
| 14021 | + | |
| 14022 | + createLayer() | |
| 14023 | + } | |
| 13852 | 14024 | } |
| 13853 | 14025 | |
| 13854 | 14026 | /** | ... | ... |