Commit f78ff140c9245eb84e5d7582c484852b165b9047

Authored by xp.Huang
2 parents 9942b5cc d772720e

Merge branch 'main_dev' into 'main'

thingskit1.1.0 version merge

See merge request yunteng/thingskit-scada!65
... ... @@ -22,26 +22,26 @@
22 22 <meta name="mobile-web-app-capable" content="yes">
23 23 <meta name="theme-color" content="#d89000">
24 24
25   - <link rel="stylesheet" href="./js/plugin/layui/css/layui.css?v=1679478216446">
  25 + <link rel="stylesheet" href="./js/plugin/layui/css/layui.css?v=1681890411146">
26 26
27 27 <!-- load configure file -->
28   - <script src="./js/config/config.js?v=1679478216446"></script>
  28 + <script src="./js/config/config.js?v=1681890411146"></script>
29 29
30 30 <!-- crypto-js -->
31   - <script src="./js/plugin/crypto-js/crypto-js.js?v=1679478216446"></script>
  31 + <script src="./js/plugin/crypto-js/crypto-js.js?v=1681890411146"></script>
32 32
33 33 <!-- storage persistent -->
34   - <script src="./js/const/persistentStorage.js?v=1679478216446"></script>
  34 + <script src="./js/const/persistentStorage.js?v=1681890411146"></script>
35 35 <!-- Global const -->
36   - <script src="./js/const/const.js?v=1679478216446"></script>
  36 + <script src="./js/const/const.js?v=1681890411146"></script>
37 37
38 38 <!-- Axios -->
39   - <script src="./js/plugin/axios/axios.min.js?v=1679478216446"></script>
40   - <script src="./js/plugin/axios/DefHttp.js?v=1679478216446"></script>
41   - <script src="./js/api/index.js?v=1679478216446"></script>
  39 + <script src="./js/plugin/axios/axios.min.js?v=1681890411146"></script>
  40 + <script src="./js/plugin/axios/DefHttp.js?v=1681890411146"></script>
  41 + <script src="./js/api/index.js?v=1681890411146"></script>
42 42
43 43 <!-- load script -->
44   - <script src="./js/config/loadScript.js?v=1679478216446"></script>
  44 + <script src="./js/config/loadScript.js?v=1681890411146"></script>
45 45
46 46 <!-- act editor -->
47 47 <!-- <script src="https://oss.yuntengcloud.com/iotdocs/thingskit-scada/ace.js"></script> -->
... ... @@ -54,7 +54,7 @@
54 54 <!-- <script src="https://vjs.zencdn.net/7.10.2/video.min.js"></script> -->
55 55 <!-- <script src="https://oss.yuntengcloud.com/iotdocs/thingskit-scada/video.min.js"></script> -->
56 56
57   - <script src="./js/plugin/layui/layui.js?v=1679478216446"></script>
  57 + <script src="./js/plugin/layui/layui.js?v=1681890411146"></script>
58 58 <!-- <link rel="stylesheet" href="https://cdnjs.loli.net/ajax/libs/layui/2.6.8/css/layui.min.css"
59 59 integrity="sha512-iQBJbsNHXUcgEIgWThd2dr8tOdKPvICwqjPEZYY81z3eMya44A5MiAqfWSCh+Ee1YzNYkdrI982Qhwgr8LEYOQ=="
60 60 crossorigin="anonymous" referrerpolicy="no-referrer" />
... ... @@ -63,7 +63,7 @@
63 63 crossorigin="anonymous" referrerpolicy="no-referrer"></script> -->
64 64
65 65 <!-- 引入修改样式 -->
66   - <link rel="stylesheet" href="./styles/formatChange.css?v=1679478216446">
  66 + <link rel="stylesheet" href="./styles/formatChange.css?v=1681890411146">
67 67
68 68 <script type="text/javascript">
69 69 /**
... ... @@ -306,7 +306,7 @@
306 306 var supportedDomain = (hostName.substring(hostName.length - 8, hostName.length) === '.draw.io') ||
307 307 (hostName.substring(hostName.length - 13, hostName.length) === '.diagrams.net');
308 308
309   - const releaseVersion = '1679478216446'
  309 + const releaseVersion = '1681890411146'
310 310 const appMinSrc = Enable_OSS ? `${OSS_Prefix}app.min.js?v=${releaseVersion}` : `js/app.min.js?v=${releaseVersion}`
311 311 function loadAppJS() {
312 312 mxscript(appMinSrc, function () {
... ...
... ... @@ -209,4 +209,22 @@ class ConfigurationNodeApi {
209 209 static getDictionaryValue(dictCode) {
210 210 return defHttp.post('/yt/dict_item/find', {dictCode})
211 211 }
  212 +
  213 + /**
  214 + * @description 获取设备配置详情通过id
  215 + * @param {string} id
  216 + * @returns
  217 + */
  218 + static getDeviceProfileDetailById(id) {
  219 + return defHttp.get('/yt/device_profile/' + id)
  220 + }
  221 +
  222 + /**
  223 + * @description 获取产品服务通过设备配置id
  224 + * @param {string} id
  225 + * @returns
  226 + */
  227 + static getThingsModelServiceByDeviceProfileId(id) {
  228 + return defHttp.get('/yt/things_model/get_services/' + id)
  229 + }
212 230 }
... ...
  1 +const isShareMode = (() => {
  2 + const urlParams = Array.from(new URLSearchParams(window.location.href)).reduce((prev, [key, value]) => ({ ...prev, [key]: value }), {})
  3 + return urlParams.share && urlParams.share === 'SCADA'
  4 +})()
  5 +
1 6 const GLOBAL_STORAGE_KEY = (() => {
2 7 const isDEV = location.href.includes('dev=1')
3 8 const DEVELOPMENT = 'DEVELOPMENT'
... ... @@ -19,10 +24,16 @@ const GLOBAL_TOKEN = (() => {
19 24 * @type {{JWT_TOKEN: {value: string}}}
20 25 */
21 26 const common = ls.get(GLOBAL_STORAGE_KEY)
22   - return {
23   - token: common && common.JWT_TOKEN && common.JWT_TOKEN.value,
24   - refreshToken: common && common.REFRESH_TOKEN && common.REFRESH_TOKEN.value,
25   - }
  27 +
  28 + return isShareMode
  29 + ? {
  30 + token: common && common.SHARE_JWT_TOKEN && common.SHARE_JWT_TOKEN.value,
  31 + refreshToken: common && common.SHARE_REFRESH_TOKEN && common.SHARE_REFRESH_TOKEN.value,
  32 + }
  33 + : {
  34 + token: common && common.JWT_TOKEN && common.JWT_TOKEN.value,
  35 + refreshToken: common && common.REFRESH_TOKEN && common.REFRESH_TOKEN.value,
  36 + }
26 37 })()
27 38
28 39
... ... @@ -45,8 +56,15 @@ const USER_PERMISSION = {
45 56 permission: []
46 57 }
47 58
  59 +const IS_CUSTOMER_USER = (() => {
  60 + const ls = createStorage({ storage: localStorage })
  61 + const common = ls.get(GLOBAL_STORAGE_KEY) || { USER__INFO__: {} }
  62 + const userInfo = ((common || {}).USER__INFO__ || {}).value || {}
  63 + return (((userInfo || {})).roles || [])[0] === 'CUSTOMER_USER'
  64 +})()
  65 +
48 66 const hasSavePermission = () => {
49   - return USER_PERMISSION.permission.includes(CAN_WRITE)
  67 + return USER_PERMISSION.permission.includes(CAN_WRITE) && !IS_CUSTOMER_USER
50 68 }
51 69
52 70 const GLOBAL_WS_URL = () => {
... ... @@ -54,3 +72,6 @@ const GLOBAL_WS_URL = () => {
54 72 const reg = /^https/
55 73 return `${reg.test(href) ? 'wss' : 'ws'}://${host}/api/ws/plugins/telemetry?token=${GLOBAL_TOKEN.token}`
56 74 }
  75 +
  76 +
  77 +
... ...
... ... @@ -4009,7 +4009,7 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
4009 4009 * @description
4010 4010 * @type {{userId: string, dev?: string, share?: string, configuration: string, publicId?: string }}
4011 4011 */
4012   - const urlParams = (function () {
  4012 + var urlParams = (function () {
4013 4013 var result = new Object();
4014 4014 var params = window.location.search.slice(1).split('&');
4015 4015
... ... @@ -4023,7 +4023,7 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
4023 4023
4024 4024 return result;
4025 4025 })();
4026   - console.log(urlParams)
  4026 +
4027 4027 if (urlParams.userId) {
4028 4028 /**
4029 4029 * @description 小程序第三方登录获取token
... ... @@ -4121,21 +4121,28 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
4121 4121 function createAccessTokenFormLayer() {
4122 4122 var field = 'accessCredentials'
4123 4123 var formSubmitFilter = 'formData'
  4124 + var tokenForm = 'tokenForm'
4124 4125 var index = layer.open({
4125 4126 type: 1,
4126   - title: '访问令牌',
  4127 + title: null,
4127 4128 area: ['350px', '200px'],
4128 4129 closeBtn: 0,
4129 4130 content: `
4130   - <section style="padding: 20px;display: flex;justify-content: center;align-items: center;flex-direction: column;">
4131   - <form class="layui-form" action="">
4132   - <div class="layui-form-item">
4133   - <label class="layui-form-label" style="width: 60px;padding: 9px 0;">访问令牌</label>
4134   - <div class="layui-input-block" style="margin-left: 70px;">
4135   - <input required lay-verify="required" type="text" name="${field}" lay-verify="title" autocomplete="off" placeholder="请输入访问令牌" class="layui-input">
  4131 + <section style="padding: 20px;display: flex;justify-content: center;align-items: center;flex-direction: column;height: 160px;">
  4132 + <form id="${tokenForm}" class="layui-form" style="width: 100%;">
  4133 + <label style="margin-bottom: 10px; display: block;">访问令牌</label>
  4134 + <div class="layui-form-item" style="display: flex; justify-content: center; aligns-item: center;">
  4135 + <div style="width: 70%">
  4136 + <input required lay-verify="required" type="password" name="${field}" lay-verify="title" autocomplete="off" placeholder="请输入访问令牌" class="layui-input">
4136 4137 </div>
  4138 + <button lay-submit lay-filter="${formSubmitFilter}" class="layui-btn layui-btn-normal" style="width: 30%;display: flex; justify-content: center; align-items: center;background-color: #1E9FFF;">
  4139 + <svg style="transform: rotate(180deg);" t="1682068997810" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="79416" width="24" height="24">
  4140 + <path d="M512 928H128c-19.2 0-32-12.8-32-32V128c0-19.2 12.8-32 32-32h384c19.2 0 32 12.8 32 32s-12.8 32-32 32H160v704h352c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#fff" p-id="79417" />
  4141 + <path d="M534.4 736c-9.6 0-16-3.2-22.4-9.6l-192-192c-12.8-12.8-12.8-32 0-44.8l192-192c12.8-12.8 32-12.8 44.8 0 12.8 12.8 12.8 32 0 44.8L387.2 512l169.6 169.6c12.8 12.8 12.8 32 0 44.8-6.4 6.4-16 9.6-22.4 9.6z" fill="#fff" p-id="79418"/>
  4142 + <path d="M896 544H342.4c-19.2 0-32-12.8-32-32s12.8-32 32-32H896c19.2 0 32 12.8 32 32s-12.8 32-32 32z" fill="#fff" p-id="79419" />
  4143 + </svg>
  4144 + </button>
4137 4145 </div>
4138   - <button lay-submit lay-filter="${formSubmitFilter}" type="button" class="layui-btn layui-btn-normal" style="width: 100%; margin-top: 10px;">进入</button>
4139 4146 </form>
4140 4147 </section>
4141 4148 `,
... ... @@ -4144,6 +4151,17 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) {
4144 4151 form.on(`submit(${formSubmitFilter})`, function (data) {
4145 4152 var value = data.field.accessCredentials
4146 4153 getShareContentData(value, index)
  4154 + return false
  4155 + })
  4156 +
  4157 + var formEl = document.getElementById(tokenForm)
  4158 + formEl.addEventListener('keyup', (event) => {
  4159 + event.preventDefault()
  4160 + return false
  4161 + })
  4162 +
  4163 + formEl.addEventListener('submit', (event) => {
  4164 + return false
4147 4165 })
4148 4166 }
4149 4167
... ...
... ... @@ -136,7 +136,7 @@ LocalFile.prototype.getLatestVersion = function (success, error) {
136 136 LocalFile.prototype.saveFile = function (title, revision, success, error, useCurrentData) {
137 137 // TODO thingskit 保存权限
138 138 var flag = hasSavePermission()
139   - if (!flag) return error({error: '没有权限'})
  139 + if (!flag) return error({ error: '没有权限' })
140 140 if (title != this.title) {
141 141 this.fileHandle = null;
142 142 this.desc = null;
... ... @@ -147,7 +147,7 @@ LocalFile.prototype.saveFile = function (title, revision, success, error, useCur
147 147 // Updates data after changing file name
148 148 if (!useCurrentData) {
149 149 this.updateFileData();
150   - }
  150 + }
151 151 var binary = this.ui.useCanvasForExport && /(\.png)$/i.test(this.getTitle());
152 152 this.setShadowModified(false);
153 153 var savedData = this.getData();
... ... @@ -162,7 +162,7 @@ LocalFile.prototype.saveFile = function (title, revision, success, error, useCur
162 162 });
163 163
164 164 var doSave = mxUtils.bind(this, function (data) {
165   - if(!this.fileHandle) {
  165 + if (!this.fileHandle) {
166 166 this.fileHandle = {
167 167 kind: 'file',
168 168 name: '未命名.xml'
... ... @@ -215,7 +215,7 @@ LocalFile.prototype.saveFile = function (title, revision, success, error, useCur
215 215 };
216 216 configurationContentList.push(configurationContent);
217 217 var parmam = { configurationId: Editor.configurationId, configurationContentList };
218   - defHttp.put("/yt/configuration/content", parmam).then(res => {
  218 + !IS_CUSTOMER_USER && defHttp.put("/yt/configuration/content", parmam).then(res => {
219 219 // console.log(res)
220 220 })
221 221 }
... ...
... ... @@ -6527,7 +6527,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6527 6527 * @description 将设备选项挂载到节点中
6528 6528 */
6529 6529 function mountAllDeviceToSelect() {
6530   - const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions })
  6530 + const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions, alias: 'alias' })
6531 6531 $(`#${enumActionEl.DEVICE_DATA_BODY_EL}`).find(`select[name="${enumConst.DEVICE}"]`).html(generateOption)
6532 6532 UseLayUi.nextTick(() => form.render('select'))
6533 6533 }
... ... @@ -6635,7 +6635,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6635 6635 function createAddRowListenEvent() {
6636 6636 $(`#${enumActionEl.ADD_ROW_EL}`).on('click', () => {
6637 6637 addRecord()
6638   - const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions })
  6638 + const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions, alias: 'alias' })
6639 6639 $(`#${enumActionEl.DEVICE_DATA_BODY_EL} tr`).last().find(`select[name="${enumConst.DEVICE}"]`).html(generateOption)
6640 6640 form.render('select')
6641 6641 })
... ... @@ -6645,7 +6645,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6645 6645 * @description 设置设备选项
6646 6646 */
6647 6647 function setDeviceOptions(row) {
6648   - const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions })
  6648 + const generateOption = UseLayUi.generateOptionTemplate({ dataSource: allDeviceOptions, alias: 'alias' })
6649 6649 $(`#${enumActionEl.DEVICE_DATA_BODY_EL} tr[lay-filter="${getRowFilter(row)}"]`).find(`select[name="${enumConst.DEVICE}"]`).html(generateOption)
6650 6650 }
6651 6651
... ... @@ -6890,6 +6890,41 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6890 6890 COMMAND: 'command',
6891 6891
6892 6892 /**
  6893 + * @description TCP命令
  6894 + */
  6895 + TCP_COMMAND: 'tcpCommand',
  6896 +
  6897 + /**
  6898 + * @description json命令
  6899 + */
  6900 + JSON_COMMAND: 'jsonCommand',
  6901 +
  6902 + /**
  6903 + * @description 命令下发方式
  6904 + */
  6905 + COMMAND_TYPE: 'commandType',
  6906 +
  6907 + /**
  6908 + * @description 服务命令
  6909 + */
  6910 + SERVICE_COMMAND: 'serviceCommand',
  6911 +
  6912 + /**
  6913 + * @description 服务原始配置
  6914 + */
  6915 + SERVICE_ORIGINAL_CONFIGURATION: 'serviceOriginalConfiguration',
  6916 +
  6917 + /**
  6918 + * @description 服务
  6919 + */
  6920 + SERVICE: 'service',
  6921 +
  6922 + /**
  6923 + * @description 传输协议
  6924 + */
  6925 + TRANSPORTTYPE: 'transportType',
  6926 +
  6927 + /**
6893 6928 * @description 属性占位符
6894 6929 */
6895 6930 ATTR_PLACEHOLDER: 'attrPlaceholder',
... ... @@ -6919,6 +6954,11 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6919 6954 FORM_FILTER: 'formModelFilter',
6920 6955
6921 6956 /**
  6957 + * @description 表单
  6958 + */
  6959 + FORM_EL: 'formModelEl',
  6960 +
  6961 + /**
6922 6962 * @description 动作 lay-filter
6923 6963 */
6924 6964 ACTION_SELECT_FILTER: 'actionSelectFilter',
... ... @@ -6948,7 +6988,47 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6948 6988 */
6949 6989 EDITOR: 'EDITOR',
6950 6990
6951   - WAY_SELECT: 'dynamicWaySelectEl'
  6991 + /**
  6992 + * @description 命令类型选择器
  6993 + */
  6994 + COMMAND_TYPE_EL: 'commandTypeEl',
  6995 +
  6996 + /**
  6997 + * @description 服务选择器
  6998 + */
  6999 + SERVICE_EL: 'serviceEl',
  7000 +
  7001 + /**
  7002 + * @description 命令下发输入框
  7003 + */
  7004 + COMMAND_INPUT: 'commandInput',
  7005 +
  7006 + /**
  7007 + * @description TCP 命令下发输入框
  7008 + */
  7009 + TCP_COMMAND_INPUT: 'tcpCommandInput',
  7010 +
  7011 + /**
  7012 + * @description 输入参数表单
  7013 + */
  7014 + INPUT_DATA_FORM: 'inputDataForm',
  7015 +
  7016 + /**
  7017 + * @description 服务命令
  7018 + */
  7019 + SERVICE_COMMAND: 'serviceCommand',
  7020 +
  7021 + WAY_SELECT: 'dynamicWaySelectEl',
  7022 +
  7023 + /**
  7024 + * @description 输入参数表单控件
  7025 + */
  7026 + INPUT_DATA_FORM_FILTER: 'inputDataFilter'
  7027 + }
  7028 +
  7029 + const COMMAND_TYPE_ENUM = {
  7030 + CUSTOM: '0',
  7031 + SERVICE: '1'
6952 7032 }
6953 7033
6954 7034 /**
... ... @@ -6966,9 +7046,28 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6966 7046 const val = {
6967 7047 [enumConst.ACTION]: content.type,
6968 7048 [enumGetValue[content.type]]: content.value,
6969   - [enumConst.WAY]: content[enumConst.WAY]
  7049 +
  7050 + // 参数设置
  7051 + [enumConst.JSON_COMMAND]: content[enumConst.JSON_COMMAND],
  7052 + [enumConst.WAY]: content[enumConst.WAY],
  7053 + [enumConst.COMMAND_TYPE]: content[enumConst.COMMAND_TYPE],
  7054 + [enumConst.TCP_COMMAND]: content[enumConst.TCP_COMMAND],
  7055 + [enumConst.TRANSPORTTYPE]: content[enumConst.TRANSPORTTYPE],
  7056 + [enumConst.SERVICE]: content[enumConst.SERVICE],
  7057 + [enumConst.SERVICE_COMMAND]: content[enumConst.SERVICE_COMMAND],
  7058 + [enumConst.SERVICE_ORIGINAL_CONFIGURATION]: content[enumConst.SERVICE_ORIGINAL_CONFIGURATION],
  7059 + }
  7060 +
  7061 +
  7062 + const isTCPTransportType = content[enumConst.TRANSPORTTYPE] === 'TCP'
  7063 + const isCustom = content[enumConst.COMMAND_TYPE] === COMMAND_TYPE_ENUM.CUSTOM
  7064 +
  7065 + if (content[enumConst.SERVICE] && !isCustom) {
  7066 + form.val(enumActionEl.INPUT_DATA_FORM_FILTER, content[enumConst.SERVICE_COMMAND])
6970 7067 }
6971   - controlFormDisplay(content.type)
  7068 +
  7069 + controlFormDisplay(content.type, isTCPTransportType, isCustom)
  7070 +
6972 7071 form.val(enumActionEl.FORM_FILTER, val)
6973 7072 }
6974 7073
... ... @@ -6976,22 +7075,40 @@ DataFormatPanel.prototype.addDataFont = function (container) {
6976 7075 * @description 控制form
6977 7076 * @param {enumActionType} value
6978 7077 */
6979   - function controlFormDisplay(value) {
  7078 + async function controlFormDisplay(value, isTCP, isCustom) {
6980 7079 if (value === enumActionType.PAGE) {
6981 7080 $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'none' })
6982 7081 $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'block' })
6983 7082 $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' })
6984 7083 $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'none' })
  7084 + $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'none' })
  7085 +
  7086 + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'none' })
  7087 + $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'none' })
  7088 + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: 'none' })
  7089 + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' })
6985 7090 } else if (value === enumActionType.LINK) {
6986 7091 $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'none' })
6987 7092 $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'block' })
6988 7093 $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' })
6989 7094 $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'none' })
  7095 + $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'none' })
  7096 +
  7097 + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: 'none' })
  7098 + $(`#${enumActionEl.SERVICE_EL}`).css({ display: 'none' })
  7099 + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: 'none' })
  7100 + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'none' })
6990 7101 } else if (value === enumActionType.PARAMS_SETTING) {
6991 7102 $(`#${enumActionEl.LINK_EL_ID}`).css({ display: 'none' })
6992 7103 $(`#${enumActionEl.PAGE_EL_ID}`).css({ display: 'none' })
6993   - $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'flex' })
  7104 + // $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: 'flex' })
6994 7105 $(`#${enumActionEl.WAY_SELECT}`).css({ display: 'block' })
  7106 + $(`#${enumActionEl.COMMAND_TYPE_EL}`).css({ display: 'block' })
  7107 +
  7108 + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: isCustom ? 'none' : 'block' })
  7109 + $(`#${enumActionEl.SERVICE_EL}`).css({ display: isCustom ? 'none' : 'block' })
  7110 + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: isTCP && isCustom ? 'block' : 'none' })
  7111 + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: !isTCP && isCustom ? 'flex' : 'none' })
6995 7112 }
6996 7113 }
6997 7114
... ... @@ -7012,9 +7129,42 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7012 7129 }
7013 7130
7014 7131 if (isParamsSetting) {
7015   - if (!isJson(formVal[enumConst.COMMAND])) {
7016   - UseLayUi.topErrorMsg('命令配置存在错误')
7017   - return
  7132 + const isTCPTransportType = formVal[enumConst.TRANSPORTTYPE] === 'TCP'
  7133 + const isCustom = formVal[enumConst.COMMAND_TYPE] === COMMAND_TYPE_ENUM.CUSTOM
  7134 + let inputData = form.val(enumActionEl.INPUT_DATA_FORM_FILTER)
  7135 +
  7136 + const validateParamsSetting = () => {
  7137 + if (isCustom) {
  7138 + if (isTCPTransportType) {
  7139 + if (!formVal[enumConst.TCP_COMMAND]) {
  7140 + UseLayUi.topErrorMsg('请输入自定义下发指令')
  7141 + return false
  7142 + }
  7143 + } else {
  7144 + console.log(formVal)
  7145 + if (!isJson(formVal[enumConst.JSON_COMMAND])) {
  7146 + UseLayUi.topErrorMsg('命令配置存在错误')
  7147 + return false
  7148 + }
  7149 + }
  7150 + } else {
  7151 + if (!formVal[enumConst.SERVICE]) {
  7152 + UseLayUi.topErrorMsg('请选择服务')
  7153 + return false
  7154 + } else {
  7155 + const { flag, value } = UseLayUi.validateThingsModelInputDataForm(Utils.stringToJSON(formVal[enumConst.SERVICE_ORIGINAL_CONFIGURATION], []), inputData)
  7156 + inputData = value
  7157 + return flag
  7158 + }
  7159 + }
  7160 + return true
  7161 + }
  7162 +
  7163 + if (!validateParamsSetting()) return
  7164 +
  7165 + // 选择服务的方式下发命令
  7166 + if (!isCustom && formVal[enumConst.SERVICE] && !isTCPTransportType) {
  7167 + formVal[enumConst.SERVICE_COMMAND] = inputData
7018 7168 }
7019 7169 }
7020 7170
... ... @@ -7029,8 +7179,14 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7029 7179 type: formVal[enumConst.ACTION],
7030 7180 value: formVal[enumGetValue[formVal[enumConst.ACTION]]],
7031 7181 ...(isParamsSetting ? {
7032   - [enumConst.COMMAND]: formVal[enumConst.COMMAND],
7033   - [enumConst.WAY]: formVal[enumConst.WAY]
  7182 + [enumConst.JSON_COMMAND]: formVal[enumConst.JSON_COMMAND],
  7183 + [enumConst.WAY]: formVal[enumConst.WAY],
  7184 + [enumConst.COMMAND_TYPE]: formVal[enumConst.COMMAND_TYPE],
  7185 + [enumConst.TCP_COMMAND]: formVal[enumConst.TCP_COMMAND],
  7186 + [enumConst.TRANSPORTTYPE]: formVal[enumConst.TRANSPORTTYPE],
  7187 + [enumConst.SERVICE]: formVal[enumConst.SERVICE],
  7188 + [enumConst.SERVICE_COMMAND]: formVal[enumConst.SERVICE_COMMAND],
  7189 + [enumConst.SERVICE_ORIGINAL_CONFIGURATION]: formVal[enumConst.SERVICE_ORIGINAL_CONFIGURATION],
7034 7190 } : {}),
7035 7191 },
7036 7192 }
... ... @@ -7057,6 +7213,18 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7057 7213 }
7058 7214
7059 7215 /**
  7216 + * @description 生成命令类型选项
  7217 + * @returns
  7218 + */
  7219 + function generateCommandTypeOptions() {
  7220 + const options = [
  7221 + { name: '自定义命令', id: COMMAND_TYPE_ENUM.CUSTOM },
  7222 + { name: '服务调用', id: COMMAND_TYPE_ENUM.SERVICE },
  7223 + ]
  7224 + return UseLayUi.generateOptionTemplate({ dataSource: options, addPlaceholderOption: false })
  7225 + }
  7226 +
  7227 + /**
7060 7228 * @description 生产页面选项
7061 7229 */
7062 7230 function generatorPageOptions() {
... ... @@ -7064,11 +7232,87 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7064 7232 return UseLayUi.generateOptionTemplate({ dataSource: options, addPlaceholderOption: false })
7065 7233 }
7066 7234
7067   - function generatorEventListen() {
  7235 + async function generatorEventListen(data) {
  7236 + const info = getLayerBindInfo('event', event.data.type) || {}
  7237 + let originType = (info.content || {}).type
  7238 + const dataSource = getDataSourceBindValue()
  7239 + let transportType
  7240 + let deviceProfileServices = []
  7241 +
  7242 + /**
  7243 + * @description 动作下拉 change event
  7244 + */
7068 7245 form.on(`select(${enumActionEl.ACTION_SELECT_FILTER})`, (data) => {
7069 7246 const { value } = data
7070   - controlFormDisplay(value)
  7247 + if (value === enumActionType.PARAMS_SETTING && !dataSource.deviceProfileId) {
  7248 + UseLayUi.topErrorMsg('请先绑定数据源!')
  7249 + form.val(enumActionEl.FORM_FILTER, { [enumConst.ACTION]: originType })
  7250 + return
  7251 + }
  7252 + originType = value
  7253 + const isCustom = form.val(enumActionEl.ACTION_SELECT_FILTER)[enumConst.COMMAND_TYPE] === COMMAND_TYPE_ENUM.CUSTOM
  7254 + controlFormDisplay(value, transportType, isCustom)
  7255 + })
  7256 +
  7257 + /**
  7258 + * @description 命令类型下拉 change event
  7259 + */
  7260 + form.on(`select(${enumActionEl.COMMAND_TYPE_EL})`, (data) => {
  7261 + const { value } = data
  7262 + const flag = value === COMMAND_TYPE_ENUM.CUSTOM
  7263 + const isTCPTransportType = transportType === 'TCP'
  7264 + $(`#${enumActionEl.INPUT_DATA_FORM}`).css({ display: flag ? 'none' : 'block' })
  7265 + $(`#${enumActionEl.SERVICE_EL}`).css({ display: flag ? 'none' : 'block' })
  7266 + $(`#${enumActionEl.TCP_COMMAND_INPUT}`).css({ display: isTCPTransportType && flag ? 'block' : 'none' })
  7267 + $(`#${enumActionEl.EDITOR_CONTAINER}`).css({ display: !isTCPTransportType && flag ? 'flex' : 'none' })
  7268 + form.val(enumActionEl.FORM_FILTER, { [enumConst.TCP_COMMAND]: '', [enumConst.SERVICE]: '', [enumConst.COMMAND]: '' })
  7269 + $(`#${enumActionEl.INPUT_DATA_FORM}`).html('')
  7270 + editorAssignValue()
  7271 + })
  7272 +
  7273 + /**
  7274 + * @description 服务下拉选择change event
  7275 + */
  7276 + form.on(`select(${enumActionEl.SERVICE_EL})`, (data) => {
  7277 + const { value } = data
  7278 + const needRender = deviceProfileServices.find(item => item.identifier === value) || {}
  7279 + const isTCPTransportType = transportType === 'TCP'
  7280 +
  7281 + if (!isTCPTransportType) {
  7282 + const template = UseLayUi.genThingsModelInputDataForm(needRender.functionJson?.inputData || [], 120)
  7283 + $(`#${enumActionEl.INPUT_DATA_FORM}`).html(template)
  7284 + } else {
  7285 + form.val(enumActionEl.FORM_FILTER, { [enumConst.SERVICE_COMMAND]: needRender.functionJson?.inputData?.[0]?.serviceCommand || '' })
  7286 + }
  7287 + form.val(enumActionEl.FORM_FILTER, { [enumConst.SERVICE_ORIGINAL_CONFIGURATION]: JSON.stringify(needRender.functionJson?.inputData || []) })
7071 7288 })
  7289 +
  7290 + try {
  7291 + if (!dataSource.deviceProfileId) return
  7292 + const detail = await ConfigurationNodeApi.getDeviceProfileDetailById(dataSource.deviceProfileId)
  7293 + transportType = detail.transportType
  7294 + const { content = {} } = data
  7295 + form.val(enumActionEl.FORM_FILTER, { [enumConst.TRANSPORTTYPE]: transportType })
  7296 + const service = await ConfigurationNodeApi.getThingsModelServiceByDeviceProfileId(dataSource.deviceProfileId)
  7297 + deviceProfileServices = service || []
  7298 + const template = UseLayUi.generateOptionTemplate({ dataSource: deviceProfileServices, labelField: 'functionName', valueField: 'identifier' })
  7299 + $(`#${enumActionEl.SERVICE_EL} > .layui-input-block > select`).html(template)
  7300 + form.val(enumActionEl.FORM_FILTER, { [enumConst.SERVICE]: content[enumConst.SERVICE] })
  7301 +
  7302 + // 服务有值回显表单
  7303 + if (content[enumConst.SERVICE]) {
  7304 + const needRender = deviceProfileServices.find(item => item.identifier === content[enumConst.SERVICE]) || {}
  7305 + if (transportType !== 'TCP') {
  7306 + const template = UseLayUi.genThingsModelInputDataForm(needRender.functionJson?.inputData || [], 120)
  7307 + $(`#${enumActionEl.INPUT_DATA_FORM}`).html(template)
  7308 + form.val(enumActionEl.INPUT_DATA_FORM_FILTER, content[enumConst.SERVICE_COMMAND])
  7309 + }
  7310 + }
  7311 +
  7312 + form.render('select', enumActionEl.FORM_FILTER)
  7313 + } catch (error) {
  7314 + throw error
  7315 + }
7072 7316 }
7073 7317
7074 7318 function isJson(string) {
... ... @@ -7093,6 +7337,9 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7093 7337 }
7094 7338 }
7095 7339
  7340 + const editorAssignValue = (value = JSON.stringify({ [enumConst.ATTR_PLACEHOLDER]: 0 }, null, 2)) => {
  7341 + $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.JSON_COMMAND}"]`).val(value)
  7342 + }
7096 7343
7097 7344 /**
7098 7345 * @description 创建JSON编辑器
... ... @@ -7107,13 +7354,13 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7107 7354 fontSize: 14, // 编辑器内字体大小
7108 7355 tabSize: 2, // 制表符设置为 4 个空格大小
7109 7356 });
7110   - if (record.content && record.content[enumConst.COMMAND]) defaultValue = jsonParse(record.content[enumConst.COMMAND])
  7357 + if (record.content && record.content[enumConst.JSON_COMMAND]) defaultValue = jsonParse(record.content[enumConst.JSON_COMMAND])
7111 7358 const stringValue = JSON.stringify(defaultValue, null, 2)
7112 7359 editor.insert(stringValue)
7113   - $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.COMMAND}"]`).val(stringValue)
  7360 + $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.JSON_COMMAND}"]`).val(stringValue)
7114 7361 editor.session.setMode("ace/mode/json");
7115 7362 editor.getSession().on('change', (event, editor) => {
7116   - $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.COMMAND}"]`).val(editor.getValue())
  7363 + $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumConst.JSON_COMMAND}"]`).val(editor.getValue())
7117 7364 })
7118 7365 }
7119 7366
... ... @@ -7123,48 +7370,80 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7123 7370 function createLayerForm(type) {
7124 7371
7125 7372 const content = `
7126   - <form class="layui-form" lay-filter="${enumActionEl.FORM_FILTER}">
  7373 + <form id="${enumActionEl.FORM_EL}" class="layui-form" lay-filter="${enumActionEl.FORM_FILTER}">
7127 7374 <div style="width: 450px">
7128 7375 <div class="layui-form-item">
7129   - <label class="layui-form-label">事件</label>
7130   - <div class="layui-input-block">
  7376 + <label class="layui-form-label" style="width: 120px;">事件</label>
  7377 + <div class="layui-input-block" style="margin-left: 150px;">
7131 7378 <input type="text" name="${enumConst.EVENT}" disabled class="layui-input" value="${enumEventType[type]}">
7132 7379 </div>
7133 7380 </div>
7134 7381 <div class="layui-form-item">
7135   - <label class="layui-form-label">动作</label>
7136   - <div class="layui-input-block">
  7382 + <label class="layui-form-label" style="width: 120px;">动作</label>
  7383 + <div class="layui-input-block" style="margin-left: 150px;">
7137 7384 <select name="${enumConst.ACTION}" lay-verType="tips" lay-verify="required" lay-filter="${enumActionEl.ACTION_SELECT_FILTER}">
7138 7385 ${generatorActionOptions()}
7139 7386 </select>
7140 7387 </div>
7141 7388 </div>
7142 7389 <div class="layui-form-item" id="${enumActionEl.LINK_EL_ID}">
7143   - <label class="layui-form-label">链接</label>
7144   - <div class="layui-input-block">
  7390 + <label class="layui-form-label" style="width: 120px;">链接</label>
  7391 + <div class="layui-input-block" style="margin-left: 150px;">
7145 7392 <input type="text" lay-verType="tips" name="${enumConst.LINK_VALUE}" class="layui-input">
7146 7393 </div>
7147 7394 </div>
7148 7395 <div class="layui-form-item" id="${enumActionEl.PAGE_EL_ID}" style="display:none">
7149   - <label class="layui-form-label">页面</label>
7150   - <div class="layui-input-block">
  7396 + <label class="layui-form-label" style="width: 120px;">页面</label>
  7397 + <div class="layui-input-block" style="margin-left: 150px;">
7151 7398 <select name="${enumConst.PAGE_VALUE}" lay-verType="tips" id="pageSelect">
7152 7399 ${generatorPageOptions()}
7153 7400 </select>
7154 7401 </div>
7155 7402 </div>
7156   - <div class="layui-form-item" id="${enumActionEl.WAY_SELECT}" style="display:none">
7157   - <label class="layui-form-label">单向/双向 ${createHelpMessage(`单向:服务器向网关设备、直连设备发送指令。发送指令后,设备不会返回任何信息。\n
  7403 + <div class="layui-form-item" id="${enumActionEl.WAY_SELECT}" style="display:none;">
  7404 + <label class="layui-form-label" style="width: 120px;">单向/双向 ${createHelpMessage(`单向:服务器向网关设备、直连设备发送指令。发送指令后,设备不会返回任何信息。\n
7158 7405 双向:服务器向网关设备、直连设备发送指令。发送指令后,设备返回响应信息。`, 'way')}</label>
7159   - <div class="layui-input-block">
  7406 + <div class="layui-input-block" style="margin-left: 150px;">
7160 7407 <input type="radio" name="${enumConst.WAY}" value="${enumWayType.ONE_WAY}" title="单向" checked="">
7161 7408 <input type="radio" name="${enumConst.WAY}" value="${enumWayType.TWO_WAY}" title="双向">
7162 7409 </div>
7163 7410 </div>
7164   - <div id="${enumActionEl.EDITOR_CONTAINER}" style="display: none;">
7165   - <div style="width: 80px; text-align: right; padding: 9px 15px;flex: 0 0 80px;">命令 ${createHelpMessage('用户预览模式下,点击参数设置后。输入的变量值将作为"attrPlaceholder"的值,并以JSON格式下发给服务器。', 'command')}</div>
  7411 + <div id="${enumActionEl.COMMAND_TYPE_EL}" class="layui-form-item" style="display: none;">
  7412 + <label class="layui-form-label" style="width: 120px;">命令下发方式</label>
  7413 + <div class="layui-input-block" style="margin-left: 150px;">
  7414 + <select name="${enumConst.COMMAND_TYPE}" lay-verType="tips" required lay-filter="${enumActionEl.COMMAND_TYPE_EL}">
  7415 + ${generateCommandTypeOptions()}
  7416 + </select>
  7417 + </div>
  7418 + </div>
  7419 + <div class="layui-form-item" id="${enumActionEl.SERVICE_EL}" style="display: none;">
  7420 + <label class="layui-form-label" style="width: 120px;">服务</label>
  7421 + <div class="layui-input-block" style="margin-left: 150px;">
  7422 + <select name="${enumConst.SERVICE}" lay-verType="tips" lay-filter="${enumActionEl.SERVICE_EL}">
  7423 + </select>
  7424 + </div>
  7425 + </div>
  7426 + <div style="display: none;">
  7427 + <input type="text" name="${enumConst.SERVICE_COMMAND}" placeholder="服务命令" />
  7428 + </div>
  7429 + <div style="display: none;">
  7430 + <input type="text" name="${enumConst.SERVICE_ORIGINAL_CONFIGURATION}" placeholder="服务命令" />
  7431 + </div>
  7432 + <div id="${enumActionEl.EDITOR_CONTAINER}" class="layui-form-item" style="display: none; margin-bottom: 15px;">
  7433 + <div style="width: 120px; text-align: right; padding: 9px 15px;flex: 0 0 120px;">命令 ${createHelpMessage('用户预览模式下,点击参数设置后。输入的变量值将作为"attrPlaceholder"的值,并以JSON格式下发给服务器。', 'command')}</div>
7166 7434 <div id="${enumActionEl.EDITOR}" style="width: 100%; height: 100%;border: 2px solid #eee;"></div>
7167   - <textarea name="${enumConst.COMMAND}" style="display: none;" />
  7435 + <textarea name="${enumConst.JSON_COMMAND}" class="layui-textarea" style="display: none;" />
  7436 + </div>
  7437 + <div id="${enumActionEl.TCP_COMMAND_INPUT}" style="display: none;">
  7438 + <label class="layui-form-label" style="width: 120px;">命令 ${createHelpMessage('用户预览模式下,点击参数设置后。输入的变量值将作为"attrPlaceholder"的值,并以JSON格式下发给服务器。', 'command')}</label>
  7439 + <div class="layui-input-block" style="margin-left: 150px;">
  7440 + <input type="text" lay-verType="tips" name="${enumConst.TCP_COMMAND}" placeholder="请输入自定义下发命令" class="layui-input">
  7441 + </div>
  7442 + </div>
  7443 + <div style="display: none;">
  7444 + <input type="text" lay-verType="tips" name="${enumConst.TRANSPORTTYPE}" placeholder="请输入自定义下发命令" class="layui-input">
  7445 + </div>
  7446 + <div id="${enumActionEl.INPUT_DATA_FORM}" class="layui-form" lay-filter="${enumActionEl.INPUT_DATA_FORM_FILTER}">
7168 7447 </div>
7169 7448 </div>
7170 7449 </form>
... ... @@ -7173,7 +7452,7 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7173 7452 layer.open({
7174 7453 title: "创建交互",
7175 7454 content,
7176   - area: ["800px", "500px"],
  7455 + area: ["800px", "650px"],
7177 7456 btn: ["保存", "取消"],
7178 7457 yes(index) {
7179 7458 form.on(`submit(${enumActionEl.LAYER_SUBMIT_FILTER})`, data => {
... ... @@ -7191,8 +7470,8 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7191 7470 'lay-submit': '',
7192 7471 'lay-filter': enumActionEl.LAYER_SUBMIT_FILTER,
7193 7472 })
7194   - generatorEventListen()
7195 7473 const info = getLayerBindInfo('event', type)
  7474 + generatorEventListen(info)
7196 7475 Object.assign(recordData, { enabled: info.enabled })
7197 7476 createEditor(info)
7198 7477 form.render(null, enumActionEl.FORM_FILTER)
... ... @@ -7823,7 +8102,6 @@ DataFormatPanel.prototype.addDataFont = function (container) {
7823 8102 [enumDataSourceConst.DEVICE_ID]: null,
7824 8103 [enumDataSourceConst.ATTR]: null,
7825 8104 [enumDataSourceConst.ATTR_NAME]: null,
7826   - [enumDataSourceConst.ORG_ID]: null
7827 8105 })
7828 8106
7829 8107 currentDataSource[enumDataSourceConst.DEVICE_TYPE] = value
... ... @@ -12250,6 +12528,131 @@ class UseLayUi {
12250 12528
12251 12529 static dynamicAttr = (attr, value) => value ? `${attr}="${value}"` : ''
12252 12530
  12531 +
  12532 + static createHelpMessage(message, className) {
  12533 + return `
  12534 + <div class="thingskit-help-message ${className}">
  12535 + <img src="${Proxy_Prefix}/images/thingskit/question.svg"/>
  12536 + <div class="thingskit-help-container">
  12537 + <div class="thingskit-help-content">${message}</div>
  12538 + <div class="thingskit-help-arrow"></div>
  12539 + </div>
  12540 + </div>
  12541 + `
  12542 + }
  12543 +
  12544 + /**
  12545 + * @description 生成输入框控件
  12546 + * @param {{label: string, value: string, labelWidth: number, numberInput: boolean}} params
  12547 + * @returns
  12548 + */
  12549 + static createInputTemplate({ label, value, labelWidth = 80, required = false, type = 'TEXT' }) {
  12550 + return `
  12551 + <div class="layui-form-item" >
  12552 + <label class="layui-form-label" style="width: ${labelWidth}px">${label}</label>
  12553 + <div class="layui-input-block" style="margin-left: ${labelWidth + 30}px">
  12554 + <input type="text" name="${value}" value-type="${type}" ${required && 'required'} lay-verType="tips" lay-verify="${required && 'required'}" placeholder="请输入${label}" autocomplete="off" class="layui-input">
  12555 + </div>
  12556 + </div>
  12557 + `
  12558 + }
  12559 +
  12560 + static createJSONTemplate() {
  12561 +
  12562 + }
  12563 +
  12564 + /**
  12565 + *
  12566 + * @param {{
  12567 + * accessMode: 'r' | 'w',
  12568 + * functionName: string,
  12569 + * id: string,
  12570 + * identifier: string,
  12571 + * dataType: {
  12572 + * type: 'TEXT' | 'INT' | 'DOUBLE' | 'STRUCT',
  12573 + * specs: { unit: {value: string, label: string},
  12574 + * unitName: string,
  12575 + * valueRange: {min: number, max: number},
  12576 + * length: number
  12577 + * }}}[]} inputData
  12578 + * @param {number} labelWidth = 80
  12579 + * @param {}
  12580 + */
  12581 + static genThingsModelInputDataForm(inputData, labelWidth = 80, formFilter = 'inputDataFilter') {
  12582 + const list = []
  12583 + inputData.forEach(item => {
  12584 + const { identifier, functionName, dataType = {} } = item
  12585 + const { type } = dataType
  12586 + list.push(UseLayUi.createInputTemplate({ label: functionName, value: identifier, labelWidth, type }))
  12587 + })
  12588 + const template = `
  12589 + <form class="layui-form" action="" lay-filter="${formFilter}">
  12590 + ${list.join('')}
  12591 + </form>`
  12592 + return template
  12593 + }
  12594 + /**
  12595 + *
  12596 + * @param {{
  12597 + * accessMode: 'r' | 'w',
  12598 + * functionName: string,
  12599 + * id: string,
  12600 + * identifier: string,
  12601 + * dataType: {
  12602 + * type: 'TEXT' | 'INT' | 'DOUBLE' | 'STRUCT',
  12603 + * specs: { unit: {value: string, label: string},
  12604 + * unitName: string,
  12605 + * valueRange: {min: number, max: number},
  12606 + * length: number
  12607 + * }}}[]} inputData
  12608 + * @param {Record<string, any>} value = 80
  12609 + */
  12610 + static validateThingsModelInputDataForm(inputData, value, needFormat = false) {
  12611 + let flag = true
  12612 + const error = (message) => {
  12613 + UseLayUi.topErrorMsg(message)
  12614 + return false
  12615 + }
  12616 +
  12617 + const validate = (item) => {
  12618 + const { dataType, identifier, functionName } = item
  12619 + const { type } = dataType || {}
  12620 + const identifierValue = value[identifier]
  12621 + switch (type) {
  12622 + case UseLayUi.thingsModelType.INT:
  12623 + if (isNaN(identifierValue)) return error(`${functionName}字段需要一个数字`)
  12624 + needFormat && (value[identifier] = parseInt(identifierValue))
  12625 + break
  12626 + case UseLayUi.thingsModelType.DOUBLE:
  12627 + if (isNaN(identifierValue)) return error(`${functionName}字段需要一个数字`)
  12628 + needFormat && (value[identifier] = Number(identifierValue))
  12629 + break
  12630 + case UseLayUi.thingsModelType.STRUCT:
  12631 + if (identifierValue && !Utils.stringIsJSON(identifierValue)) return error(`${functionName}字段需要一个JSON对象`)
  12632 + needFormat && (value[identifier] = Utils.stringToJSON(identifierValue))
  12633 + break
  12634 + default:
  12635 + break
  12636 + }
  12637 + return true
  12638 + }
  12639 +
  12640 + for (const item of inputData) {
  12641 + if (!validate(item)) return { flag: false, value }
  12642 +
  12643 + }
  12644 +
  12645 + return { flag, value }
  12646 +
  12647 + }
  12648 +
  12649 + static thingsModelType = {
  12650 + TEXT: 'TEXT',
  12651 + INT: 'INT',
  12652 + DOUBLE: 'DOUBLE',
  12653 + STRUCT: 'STRUCT',
  12654 + }
  12655 +
12253 12656 /**
12254 12657 * @description format data source to tree structure
12255 12658 * @param {object[]} data - data source
... ... @@ -12698,6 +13101,34 @@ class UseLayUi {
12698 13101 }
12699 13102 }
12700 13103
  13104 +class Utils {
  13105 + /**
  13106 + * @description 字符串是否能转换为对象
  13107 + * @param {string} value
  13108 + */
  13109 + static stringIsJSON(value) {
  13110 + try {
  13111 + const res = JSON.parse(value)
  13112 + if (typeof res !== 'object') return false
  13113 + return true
  13114 + } catch (error) {
  13115 + return false
  13116 + }
  13117 + }
  13118 +
  13119 + /**
  13120 + * @description 字符串转对象
  13121 + * @param {string} value
  13122 + * @returns
  13123 + */
  13124 + static stringToJSON(value, defaultValue = {}) {
  13125 + try {
  13126 + return JSON.parse(value)
  13127 + } catch (error) {
  13128 + return defaultValue
  13129 + }
  13130 + }
  13131 +}
12701 13132
12702 13133 /**
12703 13134 * @description use to function capture await throw error
... ... @@ -13882,14 +14313,12 @@ class HandleDataSource {
13882 14313 const realDataList = data[attr] || []
13883 14314
13884 14315 const action = agg === 'NONE' ? 'unshift' : 'push'
13885   -
13886 14316 // chart insstance 是否已经接受过一次消息推送
13887 14317 const isActive = instance.isActive
13888 14318 if (!isActive) {
13889 14319 instance.isActive = true
13890 14320 const chartOption = this.getChartComponentOption(chartInstanceType, { chartType: chartInstanceType, attr, dataList: realDataList, action, nodeId: node.id, additional })
13891 14321 instance.setOption(chartOption)
13892   -
13893 14322 } else {
13894 14323 const oldOptions = instance.getOption()
13895 14324 const options = this.getRealTimeUpdateChartOption(chartInstanceType, { oldOptions, dataList: realDataList, additional })
... ... @@ -14116,6 +14545,7 @@ class HandleDataSource {
14116 14545 const { additional: { unit = '°C' } = {} } = dataSource
14117 14546
14118 14547 const [timespan, value] = dataList[0] || []
  14548 + const { min, max } = this.getRange(value)
14119 14549 return {
14120 14550 title: {
14121 14551 text: slaveDeviceName || deviceName
... ... @@ -14127,8 +14557,8 @@ class HandleDataSource {
14127 14557 radius: '100%',
14128 14558 startAngle: 200,
14129 14559 endAngle: -20,
14130   - min: 0,
14131   - max: 100,
  14560 + min,
  14561 + max,
14132 14562 splitNumber: 10,
14133 14563 itemStyle: {
14134 14564 color: '#5479c6'
... ... @@ -14202,9 +14632,12 @@ class HandleDataSource {
14202 14632 const { dataList = [], oldOptions, additional } = params
14203 14633 const { attrName } = additional
14204 14634 const [timespan, value] = dataList[0] || []
  14635 + const { min, max } = this.getRange(value)
14205 14636 return {
14206 14637 series: [
14207 14638 {
  14639 + min,
  14640 + max,
14208 14641 name: attrName,
14209 14642 data: [
14210 14643 {
... ... @@ -14216,6 +14649,25 @@ class HandleDataSource {
14216 14649 }
14217 14650 }
14218 14651
  14652 + getRange(value) {
  14653 + if (isNaN(value)) return { min: 0, max: 100 }
  14654 +
  14655 + const numberValue = Number(value)
  14656 +
  14657 + let newMax = Number('1'.padEnd(parseInt(value).toString().length + 1, 0))
  14658 +
  14659 + newMax = newMax < 100 ? 100 : newMax
  14660 +
  14661 + let max
  14662 + if (numberValue < newMax / 2) {
  14663 + max = newMax / 2
  14664 + } else {
  14665 + max = newMax
  14666 + }
  14667 +
  14668 + return { min: 0, max }
  14669 + }
  14670 +
14219 14671 /**
14220 14672 * @description 获取绑定的数据
14221 14673 * @param subscriptionId
... ... @@ -14473,7 +14925,7 @@ class HandleDataInteraction {
14473 14925 sendInstruction(list = []) {
14474 14926 const queue = []
14475 14927 const fn = async (way, deviceId, data) => {
14476   - const [err, res = []] = await to(ConfigurationNodeApi.deviceIsOnLine(deviceId))
  14928 + const [err, res = []] = way === 'twoway' ? await to(ConfigurationNodeApi.deviceIsOnLine(deviceId)) : [null, [{ value: true }]]
14477 14929 const { value } = res[0] || {}
14478 14930 if (value) {
14479 14931 await to(ConfigurationNodeApi.sendInstruction(way, deviceId, data))
... ... @@ -14495,15 +14947,6 @@ class HandleDataInteraction {
14495 14947 fn(way, deviceId, data)
14496 14948 })
14497 14949 }
14498   - // if (slaveDeviceId) {
14499   - // queue.push(() => {
14500   - // fn(way, slaveDeviceId, data)
14501   - // })
14502   - // } else if (deviceId) {
14503   - // queue.push(() => {
14504   - // fn(way, deviceId, data)
14505   - // })
14506   - // }
14507 14950 }
14508 14951
14509 14952 Promise.all(queue.map(fn => fn()))
... ... @@ -14554,24 +14997,151 @@ class HandleDataInteraction {
14554 14997 const enumActionEl = {
14555 14998 CONTAINER: 'container',
14556 14999 EDITOR: 'editor',
14557   - ISSUED_WAY_FILTER: 'wayFilter'
  15000 + ISSUED_WAY_FILTER: 'wayFilter',
  15001 +
  15002 + /**
  15003 + * @description 表单filter
  15004 + */
  15005 + FORM_FILTER: 'formFilter',
  15006 +
  15007 + /**
  15008 + * @description 编辑器容器
  15009 + */
  15010 + EDITOR_CONTAINER: 'editorContainer',
  15011 +
  15012 + /**
  15013 + * @description 编辑器
  15014 + */
  15015 + EDITOR: 'editor',
  15016 +
  15017 + /**
  15018 + * @description 自定义TCP下发命令
  15019 + */
  15020 + CUSTOM_TCP_COMMAND: 'customTCPCommand',
  15021 +
  15022 + /**
  15023 + * @description 自定义JSON下发命令
  15024 + */
  15025 + CUSTOM_JSON_COMMAND: 'customJSONCommand',
  15026 +
  15027 + /**
  15028 + * @description 服务TCP命令
  15029 + */
  15030 + SERVICE_TCP_COMMAND: 'serviceTCPCommand',
14558 15031
  15032 + /**
  15033 + * @description 服务JSON命令
  15034 + */
  15035 + SERVICE_JSON_COMMAND: 'serviceTCPCommand',
14559 15036 }
14560 15037
14561   - function createContent() {
  15038 + function createCustomTCPParams() {
14562 15039 return `
14563   - <div>
14564   - <div class="layui-form" lay-filter="${enumActionEl.ISSUED_WAY_FILTER}">
14565   - <div class="layui-form-item">
14566   - <label class="layui-form-label">下发值</label>
14567   - <div class="layui-input-block">
14568   - <input type="text" name="${enumConst.VALUE}" lay-verify="required" autocomplete="off" placeholder="请输入下发值" class="layui-input">
  15040 + <div>
  15041 + <div class="layui-form" lay-filter="${enumActionEl.CUSTOM_TCP_COMMAND}">
  15042 + <div class="layui-form-item">
  15043 + <label class="layui-form-label" style="width: 120px;">自定义下发值</label>
  15044 + <div class="layui-input-block" style="margin-left: 150px;">
  15045 + <input type="text" name="${enumActionEl.CUSTOM_TCP_COMMAND}" lay-verify="required" autocomplete="off" placeholder="请输入下发值" class="layui-input">
  15046 + </div>
14569 15047 </div>
14570 15048 </div>
14571 15049 </div>
14572   - </div>`
  15050 + `
  15051 + }
  15052 +
  15053 + function createEditor() {
  15054 + if (content.transportType === 'TCP' || content.commandType === '1') return
  15055 + const jsonCommand = content.jsonCommand || ''
  15056 + let defaultValue = { [enumConst.ATTR_PLACEHOLDER]: 0 }
  15057 + const editor = ace.edit(enumActionEl.EDITOR, {
  15058 + maxLines: 18, // 最大行数,超过会自动出现滚动条
  15059 + minLines: 10, // 最小行数,还未到最大行数时,编辑器会自动伸缩大小
  15060 + fontSize: 14, // 编辑器内字体大小
  15061 + tabSize: 2, // 制表符设置为 4 个空格大小
  15062 + });
  15063 + if (jsonCommand) defaultValue = jsonParse(jsonCommand)
  15064 + const stringValue = JSON.stringify(defaultValue, null, 2)
  15065 + editor.insert(stringValue)
  15066 + $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumActionEl.CUSTOM_JSON_COMMAND}"]`).val(stringValue)
  15067 + editor.session.setMode("ace/mode/json");
  15068 + editor.getSession().on('change', (event, editor) => {
  15069 + $(`#${enumActionEl.EDITOR_CONTAINER}`).parent().find(`textarea[name="${enumActionEl.CUSTOM_JSON_COMMAND}"]`).val(editor.getValue())
  15070 + })
  15071 + }
  15072 +
  15073 + function createCustomJSONParams() {
  15074 + return `
  15075 + <div id="${enumActionEl.EDITOR_CONTAINER}" class="layui-form-item" style="disable: flex;">
  15076 + <div style="width: 120px; text-align: right; padding: 9px 15px;flex: 0 0 120px;text-align: left;">命令</div>
  15077 + <div id="${enumActionEl.EDITOR}" style="width: 100%; height: 100%;border: 2px solid #eee;"></div>
  15078 + <textarea name="${enumActionEl.CUSTOM_JSON_COMMAND}" class="layui-textarea" style="display: none;" />
  15079 + </div>
  15080 + `
  15081 + }
  15082 +
  15083 + function createServiceTCPParams() {
  15084 + return `
  15085 + <div>
  15086 + <div class="layui-form" lay-filter="${enumActionEl.SERVICE_TCP_COMMAND}">
  15087 + <div class="layui-form-item">
  15088 + <label class="layui-form-label" style="width: 120px;">自定义下发值</label>
  15089 + <div class="layui-input-block" style="margin-left: 150px;">
  15090 + <input type="text" name="${enumActionEl.SERVICE_TCP_COMMAND}" lay-verify="required" autocomplete="off" disabled placeholder="请输入下发值" class="layui-input">
  15091 + </div>
  15092 + </div>
  15093 + </div>
  15094 + </div>
  15095 + `
14573 15096 }
14574 15097
  15098 + function createServiceInputDataParams() {
  15099 + const inputData = jsonParse(content.serviceOriginalConfiguration)
  15100 + return UseLayUi.genThingsModelInputDataForm(inputData)
  15101 + }
  15102 +
  15103 + function createContent() {
  15104 + const { commandType, tcpCommand, jsonCommand, serviceCommand, serviceOriginalConfiguration, transportType } = content
  15105 + const isCustom = commandType === '0'
  15106 + const isTCP = transportType === 'TCP'
  15107 +
  15108 + let template
  15109 + if (isCustom) {
  15110 + if (isTCP) {
  15111 + template = createCustomTCPParams()
  15112 + } else {
  15113 + template = createCustomJSONParams()
  15114 + }
  15115 + } else {
  15116 + if (isTCP) {
  15117 + template = createServiceTCPParams()
  15118 + } else {
  15119 + template = createServiceInputDataParams()
  15120 + }
  15121 + }
  15122 + return `<form class="layui-form" lay-filter="${enumActionEl.FORM_FILTER}">${template}</form>`
  15123 + }
  15124 +
  15125 + function echoPresetValue() {
  15126 + form.val(enumActionEl.FORM_FILTER, {
  15127 + // 如果是自定义并且不是TCP设备 回显inputData
  15128 + ...(content.commandType === '1' && content.transportType !== 'TCP' ? content.serviceCommand : {}),
  15129 + [enumActionEl.CUSTOM_JSON_COMMAND]: content.jsonCommand,
  15130 + [enumActionEl.CUSTOM_TCP_COMMAND]: content.tcpCommand,
  15131 + [enumActionEl.SERVICE_TCP_COMMAND]: content.serviceCommand,
  15132 + })
  15133 + }
  15134 +
  15135 + function isJson(value) {
  15136 + try {
  15137 + JSON.parse(value)
  15138 + return true
  15139 + } catch (error) {
  15140 + return false
  15141 + }
  15142 + }
  15143 +
  15144 +
14575 15145 function jsonParse(value) {
14576 15146 try {
14577 15147 return JSON.parse(value)
... ... @@ -14580,12 +15150,49 @@ class HandleDataInteraction {
14580 15150 }
14581 15151 }
14582 15152
  15153 + const validateSwitchCommand = () => {
  15154 + const { commandType, transportType } = content
  15155 + const isCustom = commandType === '0'
  15156 + const isTCP = transportType === 'TCP'
  15157 + let { attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {}
  15158 +
  15159 + let flag = false
  15160 + let value
  15161 +
  15162 + if (isCustom) {
  15163 + if (isTCP) {
  15164 + value = content.tcpCommand
  15165 + if (value) flag = true
  15166 + } else {
  15167 + const replaceValue = currentNode.getAttribute(SWITCH_SEND_VALUE)
  15168 + value = jsonParse(content.jsonCommand)
  15169 + value = replaceAttrPlaceholder(value, attr, replaceValue)
  15170 + if (value) flag = true
  15171 + }
  15172 + } else {
  15173 + if (isTCP) {
  15174 + value = content.serviceCommand
  15175 + if (value) flag = true
  15176 + } else {
  15177 + value = content.serviceCommand
  15178 + const { flag: validateFlag, value: validateValue } = UseLayUi.validateThingsModelInputDataForm(Utils.stringToJSON(content.serviceOriginalConfiguration), value, true)
  15179 + if (validateFlag) {
  15180 + value = validateValue
  15181 + flag = true
  15182 + }
  15183 + }
  15184 + }
  15185 + return { flag, value }
  15186 + }
  15187 +
14583 15188 function handleSwitchComponent() {
14584 15189 const state = currentNode.getAttribute(SWITCH_STATE)
14585   - const value = currentNode.getAttribute(SWITCH_SEND_VALUE)
14586 15190 if (state === SWITCH_STATE_NONE) {
14587 15191 return
14588 15192 }
  15193 + const { flag, value } = validateSwitchCommand()
  15194 + if (!flag) return
  15195 +
14589 15196 layer.confirm('是否确认下发命令?', async function (index) {
14590 15197 defaultHandler(value, () => layer.close(index))
14591 15198 });
... ... @@ -14598,7 +15205,7 @@ class HandleDataInteraction {
14598 15205
14599 15206 for (const key of Object.keys(oldValue)) {
14600 15207 if (key === enumConst.ATTR_PLACEHOLDER) {
14601   - newValue[replaceAttr] = replaceValue
  15208 + newValue[replaceAttr] = replaceValue ? replaceValue : oldValue[key]
14602 15209 continue
14603 15210 }
14604 15211 if (typeof oldValue[key] === 'object') {
... ... @@ -14611,33 +15218,81 @@ class HandleDataInteraction {
14611 15218 return newValue
14612 15219 }
14613 15220
  15221 + const validate = (data) => {
  15222 + const { commandType, transportType } = content
  15223 + let { attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {}
  15224 + let flag = false
  15225 + let value
  15226 +
  15227 + const isCustom = commandType === '0'
  15228 + const isTCP = transportType === 'TCP'
  15229 +
  15230 + let template
  15231 + if (isCustom) {
  15232 + if (isTCP) {
  15233 + value = data[enumActionEl.CUSTOM_TCP_COMMAND]
  15234 + const validate = new Validate([
  15235 + { value, required: true, message: '下发值是必填项' },
  15236 + ])
  15237 + if (validate.begin()) flag = true
  15238 + } else {
  15239 + value = data[enumActionEl.CUSTOM_JSON_COMMAND]
  15240 + const validate = new Validate([
  15241 + { value, required: true, message: '下发值是必填项' },
  15242 + { value, message: 'json格式校验不正确', validator: isJson },
  15243 + ])
  15244 + if (validate.begin()) {
  15245 + const replaceValue = currentNode.getAttribute(SWITCH_SEND_VALUE)
  15246 + flag = true
  15247 + value = jsonParse(value)
  15248 + value = replaceAttrPlaceholder(value, attr)
  15249 + }
  15250 + template = createCustomJSONParams()
  15251 + }
  15252 + } else {
  15253 + if (isTCP) {
  15254 + value = content.serviceCommand
  15255 + const validate = new Validate([
  15256 + { value, required: true, message: '下发值是必填项' },
  15257 + ])
  15258 + if (validate.begin()) flag = true
  15259 + } else {
  15260 + value = data
  15261 + const { flag: validateFlag, value: validateValue } = UseLayUi.validateThingsModelInputDataForm(Utils.stringToJSON(content.serviceOriginalConfiguration), value, true)
  15262 + if (validateFlag) {
  15263 + flag = true
  15264 + value = validateValue
  15265 + }
  15266 + }
  15267 + }
  15268 +
  15269 + return { flag, value }
  15270 + }
  15271 +
14614 15272 const submitThrottle = this.throttle(submit)
14615 15273 async function submit(callback) {
14616   - const { value } = form.val(enumActionEl.ISSUED_WAY_FILTER)
14617   - defaultHandler(value, callback)
  15274 + const value = form.val(enumActionEl.FORM_FILTER)
  15275 + const { flag, value: result } = validate(value)
  15276 + if (!flag) return
  15277 + defaultHandler(result, callback)
14618 15278 }
14619 15279
14620 15280 async function defaultHandler(value, callback) {
14621 15281 let { deviceId, attr } = contentData.dataSources.find(item => item.nodeId === nodeId) || {}
14622   - let { command, way } = content
14623   - const validate = new Validate([
14624   - { value, required: true, message: '下发值是必填项' },
14625   - { value: deviceId, required: true, message: '未绑定设备' },
14626   - { value: way, required: true, message: '未绑定指令下发方式(单向/双向)' },
14627   - { value: command, required: true, message: '未设置下发命令' },
14628   - { value: attr, required: true, message: '未绑定设备属性' },
14629   - ])
14630   - if (!validate.begin()) return
14631   - if (typeof command === 'string') command = jsonParse(command)
14632   - const data = replaceAttrPlaceholder(command, attr, value)
  15282 +
  15283 + /**
  15284 + * @type {command: string , commandType: string, service: string, wary: string, tcpCommand: string}
  15285 + */
  15286 + let { command, way, tcpCommand } = content
  15287 +
14633 15288 const instructionData = {
14634 15289 method: "methodThingskit",
14635 15290 additionalInfo: { cmdType: 'API' },
14636 15291 persistent: true,
14637   - params: data,
  15292 + params: value,
14638 15293 }
14639 15294
14640   - const [err, res = []] = await to(ConfigurationNodeApi.deviceIsOnLine(deviceId))
  15295 + const [err, res = []] = way === 'twoway' ? await to(ConfigurationNodeApi.deviceIsOnLine(deviceId)) : [null, [{ value: true }]]
14641 15296 const { value: onlineFlag } = res[0] || {}
14642 15297 if (onlineFlag) {
14643 15298 const [err, res] = await to(ConfigurationNodeApi.sendInstruction(way, deviceId, instructionData))
... ... @@ -14645,13 +15300,15 @@ class HandleDataInteraction {
14645 15300 UseLayUi.topSuccessMsg('操作成功')
14646 15301 callback && typeof callback === 'function' && callback()
14647 15302 }
  15303 + if (err) {
  15304 + UseLayUi.topErrorMsg(err?.response?.data || err)
  15305 + }
14648 15306 } else {
14649 15307 UseLayUi.topErrorMsg('设备不在线!')
14650 15308 }
14651 15309 }
14652 15310
14653 15311 function createLayer() {
14654   -
14655 15312 layer.open({
14656 15313 title: '参数设置',
14657 15314 content: createContent(),
... ... @@ -14665,7 +15322,9 @@ class HandleDataInteraction {
14665 15322 but2(index, layero) {
14666 15323
14667 15324 },
14668   - async success(layero, index) {
  15325 + success(layero, index) {
  15326 + createEditor()
  15327 + echoPresetValue()
14669 15328 $('.layui-layer-setwin a').removeAttr('href')
14670 15329 form.render()
14671 15330 },
... ... @@ -14683,7 +15342,7 @@ class HandleDataInteraction {
14683 15342 try {
14684 15343 handle[componentType]()
14685 15344 } catch (error) {
14686   -
  15345 + throw error
14687 15346 }
14688 15347 }
14689 15348 startProcess()
... ... @@ -15445,6 +16104,10 @@ class Validate {
15445 16104 this.list = ruleList
15446 16105 }
15447 16106
  16107 + static isFunction(value) {
  16108 + return Object.prototype.toString.call(value) === '[object Function]'
  16109 + }
  16110 +
15448 16111 /**
15449 16112 * @description 设置规则
15450 16113 * @param {{value: any, message: string, required?: boolean, validator?: any}} rule
... ... @@ -15460,6 +16123,12 @@ class Validate {
15460 16123 UseLayUi.topErrorMsg(message)
15461 16124 return false
15462 16125 }
  16126 +
  16127 + if (validator && Validate.isFunction(validator) && !validator(value)) {
  16128 + UseLayUi.topErrorMsg(message)
  16129 + return false
  16130 + }
  16131 +
15463 16132 }
15464 16133 return true
15465 16134 }
... ...
... ... @@ -2,10 +2,14 @@ let requestQueue = []
2 2
3 3 const JWT_TOKEN_KEY = 'JWT_TOKEN';
4 4 const REFRESH_TOKEN_KEY = 'REFRESH_TOKEN';
  5 +
  6 +const SHARE_JWT_TOKEN_KEY = 'SHARE_JWT_TOKEN';
  7 +const SHARE_REFRESH_TOKEN_KEY = 'SHARE_REFRESH_TOKEN';
5 8 /**
6 9 * custom http request
7 10 */
8 11 function createAxios(options) {
  12 +
9 13 /**
10 14 * 创建实例
11 15 */
... ... @@ -48,6 +52,7 @@ function createAxios(options) {
48 52 // }
49 53
50 54 doRefreshToken()
  55 + return
51 56 }
52 57
53 58 const message = error.response && error.response.data && error.response.data.message
... ... @@ -84,9 +89,11 @@ function doRefreshToken(params) {
84 89 Object.assign(GLOBAL_TOKEN, { refreshToken, token })
85 90 const ls = createStorage({ storage: localStorage })
86 91 const originData = ls.get(GLOBAL_STORAGE_KEY)
87   - const newRefreshToken = ls.generatorValue(REFRESH_TOKEN_KEY, refreshToken, true)
88   - const newToken = ls.generatorValue(REFRESH_TOKEN_KEY, token, true)
89   - ls.set(GLOBAL_STORAGE_KEY, Object.assign(originData, { [REFRESH_TOKEN_KEY]: newRefreshToken, [JWT_TOKEN_KEY]: newToken }), true)
  92 + const refreshTokenKey = isShareMode ? SHARE_REFRESH_TOKEN_KEY : REFRESH_TOKEN_KEY
  93 + const tokenKey = isShareMode ? SHARE_JWT_TOKEN_KEY : JWT_TOKEN_KEY
  94 + const newRefreshToken = ls.generatorValue(refreshTokenKey, refreshToken, true)
  95 + const newToken = ls.generatorValue(tokenKey, token, true)
  96 + ls.set(GLOBAL_STORAGE_KEY, Object.assign(originData, { [refreshTokenKey]: newRefreshToken, [tokenKey]: newToken }), true)
90 97
91 98 // try {
92 99 // requestQueue.forEach(item => {
... ...