Commit 03d6c868929c68acdabece92cfeb642ee03a91e0
Merge branch 'fix/DEFECT-1425' into 'main_dev'
Fix/defect 1425 See merge request yunteng/thingskit-scada!91
Showing
1 changed file
with
379 additions
and
205 deletions
... | ... | @@ -5075,7 +5075,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
5075 | 5075 | |
5076 | 5076 | /** |
5077 | 5077 | * @description 用于在其他位置获取数据源绑定的数据,在生成数据源面板中进行了改写 |
5078 | - * @return {{orgId: string, attr: string, deviceId: string, deviceType: string, deviceProfileId: string, deviceCode: string, registerAddress: string, method: string, dataType: string}} | |
5078 | + * @return {{orgId: string, attr: string, deviceId: string, deviceType: string, deviceProfileId: string, deviceCode: string, registerAddress: string, method: string, thingsModelDataType: string}} | |
5079 | 5079 | */ |
5080 | 5080 | function getDataSourceBindValue() { |
5081 | 5081 | |
... | ... | @@ -6371,7 +6371,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
6371 | 6371 | const { additional = {} } = dataSources[0] || {} |
6372 | 6372 | const { [enumBindKey.EFFECT_SCOPE]: effectScope = 1000 } = additional |
6373 | 6373 | linkageIntervalSelect(effectScope) |
6374 | - form.val(CONTAINER_FILTER, additional) | |
6374 | + form.val(CONTAINER_FILTER, additional) | |
6375 | 6375 | } |
6376 | 6376 | |
6377 | 6377 | const refresh = echoRefreshFn |
... | ... | @@ -6586,7 +6586,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
6586 | 6586 | function getSwitchSubmitValue(field) { |
6587 | 6587 | const dataSources = getDataSourceBindValue() |
6588 | 6588 | const enableStatus = getEnableStatus(field) |
6589 | - return { configurationId, contentId: currentPageId.id, nodeId: graphId, dataSources: { ...dataSources, additional: { deviceCode: dataSources?.deviceCode, method: dataSources?.method, registerAddress: dataSources?.registerAddress, dataType: dataSources?.dataType } }, ...enableStatus } | |
6589 | + return { configurationId, contentId: currentPageId.id, nodeId: graphId, dataSources: { ...dataSources, additional: { deviceCode: dataSources?.deviceCode, method: dataSources?.method, registerAddress: dataSources?.registerAddress, thingsModelDataType: dataSources?.thingsModelDataType } }, ...enableStatus } | |
6590 | 6590 | } |
6591 | 6591 | |
6592 | 6592 | |
... | ... | @@ -7641,7 +7641,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7641 | 7641 | |
7642 | 7642 | const COMMAND_TYPE_ENUM = { |
7643 | 7643 | CUSTOM: '0', |
7644 | - SERVICE: '1' | |
7644 | + SERVICE: '1', | |
7645 | + MODBUS: '2' | |
7645 | 7646 | } |
7646 | 7647 | |
7647 | 7648 | /** |
... | ... | @@ -7681,7 +7682,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7681 | 7682 | form.val(enumActionEl.INPUT_DATA_FORM_FILTER, content[enumConst.SERVICE_COMMAND]) |
7682 | 7683 | } |
7683 | 7684 | |
7684 | - controlFormDisplay(content.type, isTCPTransportType, isCustom) | |
7685 | + controlFormDisplay(content.type, val) | |
7685 | 7686 | |
7686 | 7687 | form.val(enumActionEl.FORM_FILTER, val) |
7687 | 7688 | } |
... | ... | @@ -7690,40 +7691,26 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7690 | 7691 | * @description 控制form |
7691 | 7692 | * @param {enumActionType} value |
7692 | 7693 | */ |
7693 | - async function controlFormDisplay(value, isTCP, isCustom) { | |
7694 | + async function controlFormDisplay(value, formValue) { | |
7695 | + $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'none' }) | |
7696 | + $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'none' }) | |
7697 | + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7698 | + $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'none' }) | |
7699 | + $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'none' }) | |
7700 | + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'none' }) | |
7701 | + $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'none' }) | |
7702 | + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: 'none' }) | |
7703 | + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7704 | + | |
7694 | 7705 | if (value === enumActionType.PAGE) { |
7695 | - $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'none' }) | |
7696 | 7706 | $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'block' }) |
7697 | - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7698 | - $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'none' }) | |
7699 | - $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'none' }) | |
7700 | - | |
7701 | - $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'none' }) | |
7702 | - $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'none' }) | |
7703 | - $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: 'none' }) | |
7704 | - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7705 | 7707 | } else if (value === enumActionType.LINK) { |
7706 | - $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'none' }) | |
7707 | 7708 | $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'block' }) |
7708 | - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7709 | - $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'none' }) | |
7710 | - $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'none' }) | |
7711 | - | |
7712 | - $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'none' }) | |
7713 | - $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'none' }) | |
7714 | - // $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: 'none' }) | |
7715 | - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7716 | 7709 | } else if (value === enumActionType.PARAMS_SETTING) { |
7717 | - $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'none' }) | |
7718 | - $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'none' }) | |
7719 | - // $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'flex' }) | |
7720 | 7710 | $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'block' }) |
7721 | - | |
7722 | - $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: isCustom ? 'none' : 'block' }) | |
7723 | - $(`#${enumActionEl.WAY_SELECT}`).css({ display: !isTCP && isCustom ? 'block' : 'none' }) | |
7724 | - $(`#${enumActionEl.SERVICE_EL}`).css({ display: isCustom ? 'none' : 'block' }) | |
7725 | - // $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: isTCP && isCustom ? 'block' : 'none' }) | |
7726 | - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: !isTCP && isCustom ? 'flex' : 'none' }) | |
7711 | + const { commandType, transportType } = formValue | |
7712 | + handleDiffCommandType(commandType, transportType === 'TCP') | |
7713 | + editorAssignValue() | |
7727 | 7714 | } |
7728 | 7715 | } |
7729 | 7716 | |
... | ... | @@ -7746,29 +7733,41 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7746 | 7733 | |
7747 | 7734 | if (isParamsSetting) { |
7748 | 7735 | const isCustom = formVal[enumConst.COMMAND_TYPE] === COMMAND_TYPE_ENUM.CUSTOM |
7736 | + const commandType = formVal[enumConst.COMMAND_TYPE] | |
7749 | 7737 | let inputData = form.val(enumActionEl.INPUT_DATA_FORM_FILTER) |
7750 | 7738 | |
7751 | 7739 | const validateParamsSetting = () => { |
7752 | - if (isCustom) { | |
7740 | + if (commandType === COMMAND_TYPE_ENUM.CUSTOM) { | |
7753 | 7741 | if (isTCPTransportType) { |
7754 | - const dataSource = currentNodeData?.dataSources?.[0] | |
7755 | - if (dataSource) { | |
7756 | - const additional = dataSource?.additional || {} | |
7757 | - if (dataSource?.deviceType !== 'SENDOR' && !additional?.deviceCode) { | |
7758 | - UseLayUi.topErrorMsg('设备地址码不存在') | |
7759 | - return false | |
7760 | - } | |
7742 | + if (!formVal[enumConst.TCP_COMMAND]) { | |
7743 | + UseLayUi.topErrorMsg('请输入自定义下发指令') | |
7744 | + return false | |
7761 | 7745 | } |
7762 | - // if (!formVal[enumConst.TCP_COMMAND]) { | |
7763 | - // UseLayUi.topErrorMsg('请输入自定义下发指令') | |
7764 | - // return false | |
7765 | - // } | |
7766 | 7746 | } else { |
7767 | 7747 | if (!isJson(formVal[enumConst.JSON_COMMAND])) { |
7768 | 7748 | UseLayUi.topErrorMsg('命令配置存在错误') |
7769 | 7749 | return false |
7770 | 7750 | } |
7771 | 7751 | } |
7752 | + } else if (commandType === COMMAND_TYPE_ENUM.MODBUS) { | |
7753 | + const dataSource = currentNodeData?.dataSources?.[0] | |
7754 | + if (dataSource) { | |
7755 | + const additional = dataSource?.additional || {} | |
7756 | + if (dataSource?.deviceType !== 'SENDOR' && !additional?.deviceCode) { | |
7757 | + UseLayUi.topErrorMsg('设备地址码不存在') | |
7758 | + return false | |
7759 | + } | |
7760 | + | |
7761 | + if (UseLayUi.isNullOrUnDef(additional?.registerAddress)) { | |
7762 | + UseLayUi.topErrorMsg('寄存器地址不存在') | |
7763 | + return false | |
7764 | + } | |
7765 | + | |
7766 | + if (UseLayUi.isNullOrUnDef(additional?.method)) { | |
7767 | + UseLayUi.topErrorMsg('操作类型不存在') | |
7768 | + return false | |
7769 | + } | |
7770 | + } | |
7772 | 7771 | } else { |
7773 | 7772 | if (!formVal[enumConst.SERVICE]) { |
7774 | 7773 | UseLayUi.topErrorMsg('请选择服务') |
... | ... | @@ -7779,6 +7778,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7779 | 7778 | return flag |
7780 | 7779 | } |
7781 | 7780 | } |
7781 | + | |
7782 | 7782 | return true |
7783 | 7783 | } |
7784 | 7784 | |
... | ... | @@ -7790,6 +7790,19 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7790 | 7790 | } |
7791 | 7791 | } |
7792 | 7792 | |
7793 | + const getParamsSettingData = (formVal = {}) => { | |
7794 | + let fields = [enumConst.COMMAND_TYPE, enumConst.TRANSPORTTYPE, enumConst.WAY] | |
7795 | + const commandType = formVal[enumConst.COMMAND_TYPE] | |
7796 | + | |
7797 | + if (commandType === COMMAND_TYPE_ENUM.CUSTOM) { | |
7798 | + fields = [...fields, enumConst.JSON_COMMAND, enumConst.TCP_COMMAND] | |
7799 | + } else if (commandType === COMMAND_TYPE_ENUM.SERVICE) { | |
7800 | + fields = [...fields, enumConst.CALL_TYPE, enumConst.IDENTIFIER, enumConst.SERVICE, enumConst.SERVICE_COMMAND, enumConst.SERVICE_ORIGINAL_CONFIGURATION] | |
7801 | + } | |
7802 | + | |
7803 | + return fields.reduce((prev, next) => ({ ...prev, [next]: formVal[next] }), {}) | |
7804 | + } | |
7805 | + | |
7793 | 7806 | const data = { |
7794 | 7807 | type: event.data.type, |
7795 | 7808 | configurationId, |
... | ... | @@ -7800,18 +7813,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7800 | 7813 | content: { |
7801 | 7814 | type: formVal[enumConst.ACTION], |
7802 | 7815 | value: formVal[enumGetValue[formVal[enumConst.ACTION]]], |
7803 | - ...(isParamsSetting ? { | |
7804 | - [enumConst.CALL_TYPE]: formVal[enumConst.CALL_TYPE], | |
7805 | - [enumConst.IDENTIFIER]: formVal[enumConst.IDENTIFIER], | |
7806 | - [enumConst.JSON_COMMAND]: formVal[enumConst.JSON_COMMAND], | |
7807 | - [enumConst.WAY]: isTCPTransportType ? 'oneway' : formVal[enumConst.WAY], | |
7808 | - [enumConst.COMMAND_TYPE]: formVal[enumConst.COMMAND_TYPE], | |
7809 | - [enumConst.TCP_COMMAND]: formVal[enumConst.TCP_COMMAND], | |
7810 | - [enumConst.TRANSPORTTYPE]: formVal[enumConst.TRANSPORTTYPE], | |
7811 | - [enumConst.SERVICE]: formVal[enumConst.SERVICE], | |
7812 | - [enumConst.SERVICE_COMMAND]: formVal[enumConst.SERVICE_COMMAND], | |
7813 | - [enumConst.SERVICE_ORIGINAL_CONFIGURATION]: formVal[enumConst.SERVICE_ORIGINAL_CONFIGURATION], | |
7814 | - } : {}), | |
7816 | + ...(isParamsSetting ? getParamsSettingData(formVal) : {}), | |
7815 | 7817 | }, |
7816 | 7818 | } |
7817 | 7819 | await to(autoSaveGraphInfo()) |
... | ... | @@ -7843,6 +7845,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7843 | 7845 | function generateCommandTypeOptions() { |
7844 | 7846 | const options = [ |
7845 | 7847 | { name: '自定义命令', id: COMMAND_TYPE_ENUM.CUSTOM }, |
7848 | + { name: 'modbus命令', id: COMMAND_TYPE_ENUM.MODBUS }, | |
7846 | 7849 | { name: '服务调用', id: COMMAND_TYPE_ENUM.SERVICE }, |
7847 | 7850 | ] |
7848 | 7851 | return UseLayUi.generateOptionTemplate({ dataSource: options, addPlaceholderOption: false }) |
... | ... | @@ -7856,6 +7859,24 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7856 | 7859 | return UseLayUi.generateOptionTemplate({ dataSource: options, addPlaceholderOption: false }) |
7857 | 7860 | } |
7858 | 7861 | |
7862 | + function handleDiffCommandType(type, isTCPTransportType) { | |
7863 | + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'none' }) | |
7864 | + $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'none' }) | |
7865 | + $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'none' }) | |
7866 | + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: 'none' }) | |
7867 | + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' }) | |
7868 | + | |
7869 | + if (type === COMMAND_TYPE_ENUM.CUSTOM) { | |
7870 | + $(`#${enumActionEl.WAY_SELECT}`).css({ display: isTCPTransportType ? 'none' : 'block' }) | |
7871 | + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: isTCPTransportType ? 'block' : 'NONE' }) | |
7872 | + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: isTCPTransportType ? 'none' : 'flex' }) | |
7873 | + } else if (type === COMMAND_TYPE_ENUM.MODBUS) { | |
7874 | + } else { | |
7875 | + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'block' }) | |
7876 | + $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'block' }) | |
7877 | + } | |
7878 | + } | |
7879 | + | |
7859 | 7880 | async function generatorEventListen(data) { |
7860 | 7881 | const info = getLayerBindInfo('event', event.data.type) || {} |
7861 | 7882 | let originType = (info.content || {}).type |
... | ... | @@ -7877,9 +7898,9 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7877 | 7898 | form.val(enumActionEl.FORM_FILTER, { |
7878 | 7899 | [enumConst.COMMAND_TYPE]: COMMAND_TYPE_ENUM.CUSTOM |
7879 | 7900 | }) |
7880 | - const isCustom = form.val(enumActionEl.FORM_FILTER)[enumConst.COMMAND_TYPE] === COMMAND_TYPE_ENUM.CUSTOM | |
7901 | + const formValue = form.val(enumActionEl.FORM_FILTER) | |
7881 | 7902 | |
7882 | - controlFormDisplay(value, transportType === 'TCP', isCustom) | |
7903 | + controlFormDisplay(value, formValue) | |
7883 | 7904 | }) |
7884 | 7905 | |
7885 | 7906 | /** |
... | ... | @@ -7887,13 +7908,9 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7887 | 7908 | */ |
7888 | 7909 | form.on(`select(${enumActionEl.COMMAND_TYPE_EL})`, (data) => { |
7889 | 7910 | const { value } = data |
7890 | - const flag = value === COMMAND_TYPE_ENUM.CUSTOM | |
7891 | 7911 | const isTCPTransportType = transportType === 'TCP' |
7892 | - $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: flag ? 'none' : 'block' }) | |
7893 | - $(`#${enumActionEl.WAY_SELECT}`).css({ display: !isTCPTransportType && flag ? 'block' : 'none' }) | |
7894 | - $(`#${enumActionEl.SERVICE_EL}`).css({ display: flag ? 'none' : 'block' }) | |
7895 | - // $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: !isTCPTransportType && flag ? 'block' : 'none' }) | |
7896 | - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: !isTCPTransportType && flag ? 'flex' : 'none' }) | |
7912 | + handleDiffCommandType(value, isTCPTransportType) | |
7913 | + | |
7897 | 7914 | form.val(enumActionEl.FORM_FILTER, { [enumConst.TCP_COMMAND]: '', [enumConst.SERVICE]: '', [enumConst.COMMAND]: '', [enumConst.IDENTIFIER]: '' }) |
7898 | 7915 | $(`#${enumActionEl.INPUT_DATA_FORM}`).html('') |
7899 | 7916 | editorAssignValue() |
... | ... | @@ -7987,6 +8004,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
7987 | 8004 | const stringValue = JSON.stringify(defaultValue, null, 2) |
7988 | 8005 | editor.insert(stringValue) |
7989 | 8006 | $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.JSON_COMMAND}"]`).val(stringValue) |
8007 | + console.log($(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.JSON_COMMAND}"]`).val()) | |
7990 | 8008 | editor.session.setMode("ace/mode/json"); |
7991 | 8009 | editor.getSession().on('change', (event, editor) => { |
7992 | 8010 | $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.JSON_COMMAND}"]`).val(editor.getValue()) |
... | ... | @@ -8069,12 +8087,12 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8069 | 8087 | <div id="${enumActionEl.EDITOR}" style="width: 100%; height: 100%;border: 2px solid #eee;"></div> |
8070 | 8088 | <textarea name="${enumConst.JSON_COMMAND}" class="layui-textarea" style="display: none;" /> |
8071 | 8089 | </div> |
8072 | - <!-- <div id="${enumActionEl.TCP_COMMAND_INPUT}" style="display: none;"> | |
8090 | + <div id="${enumActionEl.TCP_COMMAND_INPUT}" style="display: none;"> | |
8073 | 8091 | <label class="layui-form-label" style="width: 120px;">命令 ${createHelpMessage('用户预览模式下,点击参数设置后。输入的变量值将作为"attrPlaceholder"的值,并以JSON格式下发给服务器。', 'command')}</label> |
8074 | 8092 | <div class="layui-input-block" style="margin-left: 150px;"> |
8075 | 8093 | <input type="text" lay-verType="tips" name="${enumConst.TCP_COMMAND}" placeholder="请输入自定义下发命令" class="layui-input"> |
8076 | 8094 | </div> |
8077 | - </div> --> | |
8095 | + </div> | |
8078 | 8096 | <div style="display: none;"> |
8079 | 8097 | <input type="text" lay-verType="tips" name="${enumConst.TRANSPORTTYPE}" placeholder="请输入自定义下发命令" class="layui-input"> |
8080 | 8098 | </div> |
... | ... | @@ -8701,7 +8719,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8701 | 8719 | METHOD: 'method', |
8702 | 8720 | DEVICE_COED: 'deviceCode', |
8703 | 8721 | REGISTER_ADDRESS: 'registerAddress', |
8704 | - DATA_TYPE: 'dataType' | |
8722 | + DATA_TYPE: 'thingsModelDataType', | |
8723 | + ACTION_TYPE: 'actionType' | |
8705 | 8724 | } |
8706 | 8725 | |
8707 | 8726 | /** |
... | ... | @@ -8760,6 +8779,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8760 | 8779 | [enumDataSourceConst.METHOD]: null, |
8761 | 8780 | [enumDataSourceConst.REGISTER_ADDRESS]: null, |
8762 | 8781 | [enumDataSourceConst.DATA_TYPE]: null, |
8782 | + [enumDataSourceConst.ACTION_TYPE]: null, | |
8763 | 8783 | }) |
8764 | 8784 | |
8765 | 8785 | currentDataSource[enumDataSourceConst.DEVICE_TYPE] = value |
... | ... | @@ -8788,6 +8808,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8788 | 8808 | [enumDataSourceConst.METHOD]: null, |
8789 | 8809 | [enumDataSourceConst.REGISTER_ADDRESS]: null, |
8790 | 8810 | [enumDataSourceConst.DATA_TYPE]: null, |
8811 | + [enumDataSourceConst.ACTION_TYPE]: null, | |
8791 | 8812 | |
8792 | 8813 | }) |
8793 | 8814 | currentDataSource[enumDataSourceConst.DEVICE_PROFILE_ID] = value |
... | ... | @@ -8821,6 +8842,9 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8821 | 8842 | <div class="layui-form-item" style="margin-bottom: 0; display: none;"> |
8822 | 8843 | <input style="display: none" type="text" name="${enumDataSourceConst.DATA_TYPE}" class="layui-input"> |
8823 | 8844 | </div> |
8845 | + <div class="layui-form-item" style="margin-bottom: 0; display: none;"> | |
8846 | + <input style="display: none" type="text" name="${enumDataSourceConst.ACTION_TYPE}" class="layui-input"> | |
8847 | + </div> | |
8824 | 8848 | ` |
8825 | 8849 | $(component).append(template) |
8826 | 8850 | } |
... | ... | @@ -8915,7 +8939,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8915 | 8939 | |
8916 | 8940 | if (!selected) return |
8917 | 8941 | form.val(componentFilter, { |
8918 | - [enumDataSourceConst.DEVICE_NAME]: selected?.name, | |
8942 | + [enumDataSourceConst.DEVICE_NAME]: selected?.alias || selected?.name, | |
8919 | 8943 | [enumDataSourceConst.DEVICE_COED]: selected?.code, |
8920 | 8944 | [enumDataSourceConst.ATTR]: null, |
8921 | 8945 | [enumDataSourceConst.ATTR_NAME]: null, |
... | ... | @@ -8947,22 +8971,23 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8947 | 8971 | const selected = thingsModel.find(item => item.identifier === value) |
8948 | 8972 | |
8949 | 8973 | if (!selected) return |
8950 | - const type = selected?.extensionDesc?.dataType | |
8974 | + // const type = selected?.extensionDesc?.dataType | |
8951 | 8975 | |
8952 | - let method | |
8976 | + // let method | |
8953 | 8977 | |
8954 | - if (type === 'short' || type === 'unshort') { | |
8955 | - method = '06' | |
8956 | - } else if (type === 'bit') { | |
8957 | - method = '05' | |
8958 | - } else { | |
8959 | - method = '10' | |
8960 | - } | |
8978 | + // if (type === 'short' || type === 'unshort') { | |
8979 | + // method = '06' | |
8980 | + // } else if (type === 'bit') { | |
8981 | + // method = '05' | |
8982 | + // } else { | |
8983 | + // method = '10' | |
8984 | + // } | |
8961 | 8985 | |
8962 | 8986 | form.val(componentFilter, { |
8963 | - [enumDataSourceConst.METHOD]: method, | |
8987 | + [enumDataSourceConst.METHOD]: selected?.extensionDesc?.actionType, | |
8964 | 8988 | [enumDataSourceConst.REGISTER_ADDRESS]: selected?.extensionDesc?.registerAddress, |
8965 | 8989 | [enumDataSourceConst.DATA_TYPE]: selected?.extensionDesc?.dataType, |
8990 | + [enumDataSourceConst.ACTION_TYPE]: selected?.extensionDesc?.actionType, | |
8966 | 8991 | }) |
8967 | 8992 | } |
8968 | 8993 | }) |
... | ... | @@ -8974,7 +8999,7 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8974 | 8999 | * @param {{orgId: string, deviceId: string, slaveDeviceId?: string, attr: string}} dataSource |
8975 | 9000 | */ |
8976 | 9001 | function echoDataSource(dataSource = {}) { |
8977 | - const { orgId, deviceId, deviceProfileId, deviceType, attr, method, deviceCode, registerAddress, dataType } = dataSource | |
9002 | + const { orgId, deviceId, deviceProfileId, deviceType, attr, method, deviceCode, registerAddress, thingsModelDataType, actionType } = dataSource | |
8978 | 9003 | const queue = [] |
8979 | 9004 | currentDataSource = { organizationId: orgId, deviceProfileId, deviceType } |
8980 | 9005 | queue.push(getProduct(deviceType)) |
... | ... | @@ -8995,7 +9020,8 @@ DataFormatPanel.prototype.addDataFont = function (container) { |
8995 | 9020 | method, |
8996 | 9021 | deviceCode, |
8997 | 9022 | registerAddress, |
8998 | - dataType | |
9023 | + thingsModelDataType, | |
9024 | + actionType | |
8999 | 9025 | }) |
9000 | 9026 | |
9001 | 9027 | }) |
... | ... | @@ -13227,6 +13253,176 @@ class UseLayUi { |
13227 | 13253 | constructor() { |
13228 | 13254 | } |
13229 | 13255 | |
13256 | + static numberToHex(value) { | |
13257 | + function InsertString(t, c, n) { | |
13258 | + var r = new Array(); | |
13259 | + | |
13260 | + for (var i = 0; | |
13261 | + i * 2 < t.length; | |
13262 | + i++) { | |
13263 | + r.push(t.substr(i * 2, n)); | |
13264 | + | |
13265 | + } | |
13266 | + return r.join(c); | |
13267 | + | |
13268 | + } | |
13269 | + function FillString(t, c, n, b) { | |
13270 | + if ((t == "") || (c.length != 1) || (n <= t.length)) { | |
13271 | + return t; | |
13272 | + | |
13273 | + } | |
13274 | + var l = t.length; | |
13275 | + | |
13276 | + for (var i = 0; | |
13277 | + i < n - l; | |
13278 | + i++) { | |
13279 | + if (b == true) { | |
13280 | + t = c + t; | |
13281 | + | |
13282 | + } else { | |
13283 | + t += c; | |
13284 | + | |
13285 | + } | |
13286 | + } | |
13287 | + return t; | |
13288 | + | |
13289 | + } | |
13290 | + function SingleToHex(t) { | |
13291 | + if (t == "") { | |
13292 | + return ""; | |
13293 | + | |
13294 | + } | |
13295 | + t = parseFloat(t); | |
13296 | + | |
13297 | + if (isNaN(t) == true) { | |
13298 | + return "Error"; | |
13299 | + | |
13300 | + } | |
13301 | + if (t == 0) { | |
13302 | + return "00000000"; | |
13303 | + | |
13304 | + } | |
13305 | + var s, | |
13306 | + e, | |
13307 | + m; | |
13308 | + | |
13309 | + if (t > 0) { | |
13310 | + s = 0; | |
13311 | + | |
13312 | + } else { | |
13313 | + s = 1; | |
13314 | + | |
13315 | + t = 0 - t; | |
13316 | + | |
13317 | + } | |
13318 | + m = t.toString(2); | |
13319 | + | |
13320 | + if (m >= 1) { | |
13321 | + if (m.indexOf(".") == -1) { | |
13322 | + m = m + ".0"; | |
13323 | + | |
13324 | + } | |
13325 | + e = m.indexOf(".") - 1; | |
13326 | + | |
13327 | + } else { | |
13328 | + e = 1 - m.indexOf("1"); | |
13329 | + | |
13330 | + } | |
13331 | + if (e >= 0) { | |
13332 | + m = m.replace(".", ""); | |
13333 | + | |
13334 | + } else { | |
13335 | + m = m.substring(m.indexOf("1")); | |
13336 | + | |
13337 | + } | |
13338 | + if (m.length > 24) { | |
13339 | + m = m.substr(0, 24); | |
13340 | + | |
13341 | + } else { | |
13342 | + m = FillString(m, "0", 24, false) | |
13343 | + } | |
13344 | + m = m.substring(1); | |
13345 | + | |
13346 | + e = (e + 127).toString(2); | |
13347 | + | |
13348 | + e = FillString(e, "0", 8, true); | |
13349 | + | |
13350 | + var r = parseInt(s + e + m, 2).toString(16); | |
13351 | + | |
13352 | + r = FillString(r, "0", 8, true); | |
13353 | + | |
13354 | + return InsertString(r, " ", 2).toUpperCase(); | |
13355 | + | |
13356 | + } | |
13357 | + function FormatHex(t, n, ie) { | |
13358 | + var r = new Array(); | |
13359 | + | |
13360 | + var s = ""; | |
13361 | + | |
13362 | + var c = 0; | |
13363 | + | |
13364 | + for (var i = 0; | |
13365 | + i < t.length; | |
13366 | + i++) { | |
13367 | + if (t.charAt(i) != " ") { | |
13368 | + s += t.charAt(i); | |
13369 | + | |
13370 | + c += 1; | |
13371 | + | |
13372 | + if (c == n) { | |
13373 | + r.push(s); | |
13374 | + | |
13375 | + s = ""; | |
13376 | + | |
13377 | + c = 0; | |
13378 | + | |
13379 | + } | |
13380 | + } | |
13381 | + if (ie == false) { | |
13382 | + if ((i == t.length - 1) && (s != "")) { | |
13383 | + r.push(s); | |
13384 | + | |
13385 | + } | |
13386 | + } | |
13387 | + } | |
13388 | + return r.join("\n"); | |
13389 | + | |
13390 | + } | |
13391 | + function FormatHexBatch(t, n, ie) { | |
13392 | + var a = t.split("\n"); | |
13393 | + | |
13394 | + var r = new Array(); | |
13395 | + | |
13396 | + for (var i = 0; | |
13397 | + i < a.length; | |
13398 | + i++) { | |
13399 | + r[i] = FormatHex(a[i], n, ie); | |
13400 | + | |
13401 | + } | |
13402 | + return r.join("\n"); | |
13403 | + | |
13404 | + } | |
13405 | + function SingleToHexBatch(t) { | |
13406 | + var a = t.split("\n"); | |
13407 | + | |
13408 | + var r = new Array(); | |
13409 | + | |
13410 | + for (var i = 0; | |
13411 | + i < a.length; | |
13412 | + i++) { | |
13413 | + r[i] = SingleToHex(a[i]); | |
13414 | + | |
13415 | + } | |
13416 | + return r.join("\r\n"); | |
13417 | + | |
13418 | + } | |
13419 | + return SingleToHex(value) | |
13420 | + } | |
13421 | + | |
13422 | + static isNullOrUnDef = value => { | |
13423 | + return value === null || value === undefined | |
13424 | + } | |
13425 | + | |
13230 | 13426 | static isFunction = fn => { |
13231 | 13427 | const result = Object.prototype.toString.call(fn) |
13232 | 13428 | return result === '[object Function]' || result === '[object AsyncFunction]' |
... | ... | @@ -14674,16 +14870,34 @@ class DispatchCenter { |
14674 | 14870 | |
14675 | 14871 | const setSubscribeMapping = (cmdId, record) => this.subscribeIdMapping.set(cmdId, record) |
14676 | 14872 | |
14873 | + const componentType = Sidebar.prototype.enumComponentType | |
14874 | + | |
14875 | + const attributeFieldEnum = Sidebar.prototype.enumCellBasicAttribute | |
14876 | + | |
14677 | 14877 | this.deviceIdMapping.forEach((value, key) => { |
14678 | - const basicRecord = value.filter(item => !item.additional) | |
14679 | - const moreFilterRecord = value.filter(item => item.additional) | |
14680 | 14878 | |
14681 | - const message = basicRecord.length ? generateMessage({ entityId: key, cmdId, keys: getKeys(basicRecord.map(item => item.attr)) }) : null | |
14682 | - basicRecord.length && setSubscribeMapping(cmdId, basicRecord) | |
14879 | + const chartRecord = [] | |
14880 | + const otherRecord = [] | |
14881 | + for (const item of value) { | |
14882 | + const id = item.nodeId | |
14883 | + const cell = this.graph.model.getCell(id) | |
14884 | + if (cell) { | |
14885 | + const type = cell.getAttribute(attributeFieldEnum.COMPONENT_TYPE) | |
14886 | + if ([componentType.LINE_CHART, componentType.BAR_CHART, componentType.DASHBOARD_CHART].includes(type)) { | |
14887 | + chartRecord.push(item) | |
14888 | + continue | |
14889 | + } | |
14890 | + } | |
14891 | + | |
14892 | + otherRecord.push(item) | |
14893 | + } | |
14894 | + | |
14895 | + const message = otherRecord.length ? generateMessage({ entityId: key, cmdId, keys: getKeys(otherRecord.map(item => item.attr)) }) : null | |
14896 | + otherRecord.length && setSubscribeMapping(cmdId, otherRecord) | |
14683 | 14897 | cmdId++ |
14684 | 14898 | |
14685 | 14899 | // 图表控件订阅 |
14686 | - moreFilterRecord.forEach(item => { | |
14900 | + chartRecord.forEach(item => { | |
14687 | 14901 | const { additional = {} } = item |
14688 | 14902 | const { dataType = 'tsSubCmds', interval, effectScope, agg } = additional |
14689 | 14903 | const message = generateMessage({ |
... | ... | @@ -14706,7 +14920,8 @@ class DispatchCenter { |
14706 | 14920 | return messageList |
14707 | 14921 | } |
14708 | 14922 | |
14709 | - return generateGroupMessage() | |
14923 | + const returnMessage = generateGroupMessage() | |
14924 | + return returnMessage | |
14710 | 14925 | } |
14711 | 14926 | |
14712 | 14927 | /** |
... | ... | @@ -14729,49 +14944,12 @@ class DispatchCenter { |
14729 | 14944 | } |
14730 | 14945 | |
14731 | 14946 | /** |
14732 | - * @description 生成节点映射表 | |
14733 | - * @param dataSources | |
14734 | - * @return {{cmdId: number, entityType: string, keys: string, scope: string, entityId: string}[]} | |
14735 | - */ | |
14736 | - generatorDataSourceMapping(dataSources = []) { | |
14737 | - return dataSources.map((datum) => { | |
14738 | - const { deviceId, attr, nodeId, slaveDeviceId } = datum | |
14739 | - const cmdId = this.getCmdId(nodeId) | |
14740 | - const sendMsgTemplate = { | |
14741 | - entityType: "DEVICE", | |
14742 | - entityId: slaveDeviceId ? slaveDeviceId : deviceId, | |
14743 | - scope: "LATEST_TELEMETRY", | |
14744 | - cmdId, | |
14745 | - keys: attr, | |
14746 | - } | |
14747 | - this.subscribeDataSources(datum, cmdId, attr) | |
14748 | - return sendMsgTemplate | |
14749 | - }) | |
14750 | - } | |
14751 | - | |
14752 | - /** | |
14753 | 14947 | * @description 分发事件 |
14754 | 14948 | */ |
14755 | 14949 | publishEvent(eventName, data, message, event, ws) { |
14756 | 14950 | this.eventBus.emit(eventName, message, event, ws) |
14757 | 14951 | } |
14758 | 14952 | |
14759 | - /** | |
14760 | - * @description 订阅数据源 | |
14761 | - * @param datum | |
14762 | - * @param eventName | |
14763 | - * @param key | |
14764 | - */ | |
14765 | - subscribeDataSources(datum, eventName, key) { | |
14766 | - const node = this.contentAllCell.find(item => item.id === datum.nodeId) | |
14767 | - this.eventBus.on(eventName, (message) => { | |
14768 | - node && this.updatePage(() => { | |
14769 | - const { data } = message | |
14770 | - const [[timespan, value]] = data[key] | |
14771 | - node.setValue(value) | |
14772 | - }, node) | |
14773 | - }) | |
14774 | - } | |
14775 | 14953 | |
14776 | 14954 | /** |
14777 | 14955 | * @description 更新页面 |
... | ... | @@ -15177,39 +15355,7 @@ class HandleDataSource { |
15177 | 15355 | |
15178 | 15356 | const chartOption = this.getChartComponentOption(chartInstanceType, { dataList: historyDataList, attr, chartType: chartInstanceType, action, additional }) |
15179 | 15357 | |
15180 | - let interval | |
15181 | - // TODO 清除定时器 | |
15182 | - function autoMove() { | |
15183 | - if (seriesValue.length <= 5) return | |
15184 | - interval = setInterval(() => { | |
15185 | - if (Number(chartOption.dataZoom[0].endValue) === seriesValue.length - 1) { | |
15186 | - chartOption.dataZoom[0].endValue = showNumberOf | |
15187 | - chartOption.dataZoom[0].startValue = 0 | |
15188 | - } else { | |
15189 | - chartOption.dataZoom[0].endValue = chartOption.dataZoom[0].endValue + 1 | |
15190 | - chartOption.dataZoom[0].startValue = chartOption.dataZoom[0].startValue + 1 | |
15191 | - } | |
15192 | - if (!chartInstanceMap.has(chartInstanceId)) { | |
15193 | - clearInterval(interval) | |
15194 | - return | |
15195 | - } | |
15196 | - instance && instance.setOption(chartOption) | |
15197 | - | |
15198 | - }, 2000); | |
15199 | - } | |
15200 | - | |
15201 | - function stop() { | |
15202 | - clearInterval(interval) | |
15203 | - } | |
15204 | - | |
15205 | - function goMove() { | |
15206 | - autoMove() | |
15207 | - } | |
15208 | - | |
15209 | 15358 | instance.setOption(chartOption) |
15210 | - // instance.on('mouseover', stop) | |
15211 | - // instance.on('mouseout', goMove) | |
15212 | - // autoMove() | |
15213 | 15359 | } |
15214 | 15360 | |
15215 | 15361 | getChartComponentOption(chartInstanceType, params) { |
... | ... | @@ -15320,18 +15466,20 @@ class HandleDataSource { |
15320 | 15466 | getRealTimeUpdateBasicChartOption(params = { oldOptions: {}, dataList: [], additional: {} }) { |
15321 | 15467 | const { oldOptions, dataList, additional = {} } = params |
15322 | 15468 | const { slaveDeviceName, deviceName, attrName } = additional |
15323 | - const xAxisData = oldOptions.xAxis[0].data || [] | |
15324 | - const seriesValue = oldOptions.series[0].data || [] | |
15325 | - const oldEndValue = Number(oldOptions.dataZoom[0].endValue) || 0 | |
15326 | - const oldStartValue = Number(oldOptions.dataZoom[0].startValue) || 0 | |
15469 | + let xAxisData = oldOptions.xAxis[0].data || [] | |
15470 | + let seriesValue = oldOptions.series[0].data || [] | |
15327 | 15471 | const showNumberOf = 4 |
15472 | + const maxDataLength = 15 | |
15328 | 15473 | |
15329 | 15474 | for (let i = dataList.length - 1; i >= 0; i--) { |
15330 | 15475 | const [timespan, value] = dataList[i] |
15331 | 15476 | xAxisData.push(new Date(Number(timespan)).toLocaleTimeString()) |
15332 | 15477 | seriesValue.push(Number(value)) |
15333 | - xAxisData = xAxisData.slice(0, 30) | |
15334 | - seriesValue = seriesValue.slice(0, 30) | |
15478 | + } | |
15479 | + | |
15480 | + if (xAxisData?.length > maxDataLength) { | |
15481 | + xAxisData = xAxisData.slice(xAxisData.length - maxDataLength, xAxisData.length) | |
15482 | + seriesValue = seriesValue.slice(seriesValue.length - maxDataLength, seriesValue.length) | |
15335 | 15483 | } |
15336 | 15484 | |
15337 | 15485 | if (Number(oldOptions.dataZoom[0].endValue) === seriesValue.length - 1) { |
... | ... | @@ -15619,7 +15767,6 @@ class HandleDataInteraction { |
15619 | 15767 | } |
15620 | 15768 | |
15621 | 15769 | get contentAllCell() { |
15622 | - // return this.graph.getDefaultParent().children || [] | |
15623 | 15770 | return Object.entries(this.graph?.getModel()?.cells || {}).map(([_, item]) => item) || [] |
15624 | 15771 | } |
15625 | 15772 | |
... | ... | @@ -15918,7 +16065,7 @@ class HandleDataInteraction { |
15918 | 16065 | <div class="layui-form-item"> |
15919 | 16066 | <label class="layui-form-label" style="width: 120px;">自定义下发值</label> |
15920 | 16067 | <div class="layui-input-block" style="margin-left: 150px;"> |
15921 | - <input type="text" name="${enumActionEl.SERVICE_TCP_COMMAND}" lay-verify="required" autocomplete="off" disabled placeholder="请输入下发值" class="layui-input"> | |
16068 | + <input type="text" name="${enumActionEl.SERVICE_TCP_COMMAND}" lay-verify="required" autocomplete="off" placeholder="请输入下发值" class="layui-input"> | |
15922 | 16069 | </div> |
15923 | 16070 | </div> |
15924 | 16071 | </div> |
... | ... | @@ -15933,22 +16080,23 @@ class HandleDataInteraction { |
15933 | 16080 | |
15934 | 16081 | function createContent() { |
15935 | 16082 | const { commandType, tcpCommand, jsonCommand, serviceCommand, serviceOriginalConfiguration, transportType } = content |
15936 | - const isCustom = commandType === '0' | |
15937 | 16083 | const isTCP = transportType === 'TCP' |
15938 | 16084 | |
15939 | 16085 | let template |
15940 | - if (isCustom) { | |
16086 | + if (commandType == '0') { | |
15941 | 16087 | if (isTCP) { |
15942 | 16088 | template = createCustomTCPParams() |
15943 | 16089 | } else { |
15944 | 16090 | template = createCustomJSONParams() |
15945 | 16091 | } |
15946 | - } else { | |
16092 | + } else if (commandType == '1') { | |
15947 | 16093 | if (isTCP) { |
15948 | 16094 | template = createServiceTCPParams() |
15949 | 16095 | } else { |
15950 | 16096 | template = createServiceInputDataParams() |
15951 | 16097 | } |
16098 | + } else { | |
16099 | + template = createCustomTCPParams() | |
15952 | 16100 | } |
15953 | 16101 | return `<form class="layui-form" lay-filter="${enumActionEl.FORM_FILTER}">${template}</form>` |
15954 | 16102 | } |
... | ... | @@ -16056,50 +16204,65 @@ class HandleDataInteraction { |
16056 | 16204 | const { attr, additional } = dataSource |
16057 | 16205 | let flag = false |
16058 | 16206 | let value |
16059 | - | |
16060 | - const isCustom = commandType === '0' | |
16061 | 16207 | const isTCP = transportType === 'TCP' |
16062 | 16208 | |
16063 | - let template | |
16064 | - if (isCustom) { | |
16209 | + const enumCommandType = { | |
16210 | + CUSTOM: '0', | |
16211 | + SERVICE: '1', | |
16212 | + MODBUS: '2', | |
16213 | + } | |
16214 | + | |
16215 | + if (commandType == enumCommandType.MODBUS) { | |
16216 | + value = data[enumActionEl.CUSTOM_TCP_COMMAND] | |
16217 | + const { method } = additional | |
16218 | + const validate = new Validate([ | |
16219 | + { value, required: true, message: '下发值是必填项' }, | |
16220 | + ...(method == '05' ? [{ value, message: '下发类型必须为0或1', validator(value) { return value == 0 || value == 1 } }] : []), | |
16221 | + ...(method == '06' ? [{ value, message: '下发类型必须为整型', validator(value) { return !isNaN(value) && Number(value) % 1 === 0 } }, { value, message: '最大值不能超过65535', validator(value) { return Number(value) <= parseInt('ffff', 16) } }] : []), | |
16222 | + ...(method == '16' ? [{ value, message: '下发类型精确到两位小数', validator(value) { return /^\d+(\.\d{0,2})?$/.test(value) } }] : []) | |
16223 | + ]) | |
16224 | + | |
16225 | + if (method == '16') { | |
16226 | + const hexValue = UseLayUi.numberToHex(value).split(' ').slice(0, 2).join('') | |
16227 | + value = [parseInt(hexValue, 16), 0] | |
16228 | + } | |
16229 | + | |
16230 | + if (validate.begin()) flag = true | |
16231 | + } else if (commandType == enumCommandType.SERVICE) { | |
16065 | 16232 | if (isTCP) { |
16066 | - value = data[enumActionEl.CUSTOM_TCP_COMMAND] | |
16067 | - const { dataType } = additional | |
16233 | + value = content.serviceCommand | |
16068 | 16234 | const validate = new Validate([ |
16069 | 16235 | { value, required: true, message: '下发值是必填项' }, |
16070 | - ...(dataType === 'bit' ? [{ value, message: '下发类型必须为0或1', validator(value) { return value == 0 || value == 1 } }] : []), | |
16071 | - ...(dataType === 'short' || dataType === 'unshort' ? [{ value, message: '下发类型必须为整型', validator(value) { return value % 1 === 0 } }, { value, message: '最大值不能超过65535', validator(value) { return Number(value) <= parseInt('ffff', 16) } }] : []) | |
16072 | 16236 | ]) |
16073 | 16237 | if (validate.begin()) flag = true |
16074 | 16238 | } else { |
16075 | - value = data[enumActionEl.CUSTOM_JSON_COMMAND] | |
16076 | - const validate = new Validate([ | |
16077 | - { value, required: true, message: '下发值是必填项' }, | |
16078 | - { value, message: 'json格式校验不正确', validator: isJson }, | |
16079 | - ]) | |
16080 | - if (validate.begin()) { | |
16081 | - const replaceValue = currentNode.getAttribute(SWITCH_SEND_VALUE) | |
16239 | + value = data | |
16240 | + const { flag: validateFlag, value: validateValue } = UseLayUi.validateThingsModelInputDataForm(Utils.stringToJSON(content.serviceOriginalConfiguration), value, true) | |
16241 | + if (validateFlag) { | |
16082 | 16242 | flag = true |
16083 | - value = jsonParse(value) | |
16084 | - value = replaceAttrPlaceholder(value, attr) | |
16243 | + value = validateValue | |
16085 | 16244 | } |
16086 | - template = createCustomJSONParams() | |
16087 | 16245 | } |
16088 | 16246 | } else { |
16089 | 16247 | if (isTCP) { |
16090 | - value = content.serviceCommand | |
16248 | + value = data[enumActionEl.CUSTOM_TCP_COMMAND] | |
16091 | 16249 | const validate = new Validate([ |
16092 | 16250 | { value, required: true, message: '下发值是必填项' }, |
16093 | 16251 | ]) |
16094 | 16252 | if (validate.begin()) flag = true |
16095 | 16253 | } else { |
16096 | - value = data | |
16097 | - const { flag: validateFlag, value: validateValue } = UseLayUi.validateThingsModelInputDataForm(Utils.stringToJSON(content.serviceOriginalConfiguration), value, true) | |
16098 | - if (validateFlag) { | |
16254 | + value = data[enumActionEl.CUSTOM_JSON_COMMAND] | |
16255 | + const validate = new Validate([ | |
16256 | + { value, required: true, message: '下发值是必填项' }, | |
16257 | + { value, message: 'json格式校验不正确', validator: isJson }, | |
16258 | + ]) | |
16259 | + if (validate.begin()) { | |
16099 | 16260 | flag = true |
16100 | - value = validateValue | |
16261 | + value = jsonParse(value) | |
16262 | + value = replaceAttrPlaceholder(value, attr) | |
16101 | 16263 | } |
16102 | 16264 | } |
16265 | + | |
16103 | 16266 | } |
16104 | 16267 | |
16105 | 16268 | return { flag, value } |
... | ... | @@ -16117,13 +16280,18 @@ class HandleDataInteraction { |
16117 | 16280 | const { additional } = dataSource || {} |
16118 | 16281 | const { method, deviceCode, registerAddress } = additional || {} |
16119 | 16282 | |
16283 | + if (Number(deviceCode) > parseInt('ff', 16) || Number(deviceCode) <= 1) { | |
16284 | + UseLayUi.topErrorMsg('设备地址码范围不在1~255之间') | |
16285 | + return | |
16286 | + } | |
16287 | + | |
16120 | 16288 | const params = { |
16121 | 16289 | crc: 'CRC_16_LOWER', |
16122 | - deviceCode, | |
16123 | - method, | |
16290 | + deviceCode: Number(deviceCode).toString(16).padStart(2, 0).toUpperCase(), | |
16291 | + method: Number(method).toString(16).padStart(2, 0), | |
16124 | 16292 | registerAddr: Number(registerAddress), |
16125 | - registerNumber: 1, | |
16126 | - registerValues: [Number(registerValue)] | |
16293 | + registerNumber: Array.isArray(registerValue) ? 2 : 1, | |
16294 | + registerValues: Array.isArray(registerValue) ? registerValue.map(item => Number(item)) : [Number(registerValue)] | |
16127 | 16295 | } |
16128 | 16296 | |
16129 | 16297 | const command = await ConfigurationNodeApi.getModbusCommand(params) |
... | ... | @@ -16139,15 +16307,29 @@ class HandleDataInteraction { |
16139 | 16307 | */ |
16140 | 16308 | let { command, way, service, callType } = content |
16141 | 16309 | const identifier = content?.identifier |
16142 | - const params = content?.transportType === 'TCP' | |
16143 | - ? await getTCPCommand(value, dataSource) | |
16144 | - : identifier | |
16310 | + | |
16311 | + let params | |
16312 | + | |
16313 | + if (content?.commandType == '0') { | |
16314 | + params = value | |
16315 | + } | |
16316 | + | |
16317 | + if (content?.commandType == '1') { | |
16318 | + params = identifier | |
16145 | 16319 | ? { [identifier]: value } |
16146 | 16320 | : value |
16321 | + } | |
16322 | + | |
16323 | + if (content?.commandType == '2') { | |
16324 | + params = await getTCPCommand(value, dataSource) | |
16325 | + } | |
16326 | + | |
16327 | + if (!params) return | |
16147 | 16328 | |
16148 | 16329 | if (service) { |
16149 | 16330 | way = callType === 'ASYNC' ? 'oneway' : 'twoway' |
16150 | 16331 | } |
16332 | + | |
16151 | 16333 | const instructionData = { |
16152 | 16334 | method: "methodThingskit", |
16153 | 16335 | additionalInfo: { cmdType: service ? '1' : 'API' }, |
... | ... | @@ -16364,7 +16546,6 @@ class HandleDynamicEffect { |
16364 | 16546 | } |
16365 | 16547 | |
16366 | 16548 | get contentAllCell() { |
16367 | - // return this.graph.getDefaultParent().children || [] | |
16368 | 16549 | return Object.entries(this.graph?.getModel()?.cells || {}).map(([_, item]) => item) || [] |
16369 | 16550 | } |
16370 | 16551 | |
... | ... | @@ -16399,14 +16580,7 @@ class HandleDynamicEffect { |
16399 | 16580 | if (!this.actNodeMapping.has(id)) this.actNodeMapping.set(id, { display: true, value: new Map() }) |
16400 | 16581 | const temp = this.actNodeMapping.get(id) |
16401 | 16582 | temp.value.set(type, each) |
16402 | - | |
16403 | - // const cmdId = this.DispatchInstance.getCmdId(id) | |
16404 | - | |
16405 | - // tsSubCmds.push(this.generatorMessage(slaveDeviceId ? slaveDeviceId : deviceId, cmdId, attr)) | |
16406 | - | |
16407 | - // this.subscribeEvent(cmdId, this.dispatch(type)) | |
16408 | 16583 | }) |
16409 | - // if (tsSubCmds.length) this.sendMsg({ tsSubCmds }) | |
16410 | 16584 | } |
16411 | 16585 | |
16412 | 16586 | /** | ... | ... |