Commit 87fd3fd60fb8ae9a3522ad2e52972902a2d8dbab

Authored by fengwotao
1 parent b027663b

pref:优化命令下发记录

... ... @@ -88,24 +88,39 @@
88 88 unref(jsonInstance).set({});
89 89 };
90 90 const handleOk = async () => {
  91 + disable.value = true;
91 92 try {
92   - disable.value = true;
93 93 // 验证
94 94 const valid = await validate();
95 95 if (!valid) return;
96 96 // 收集表单数据
97 97 const field = getFieldsValue();
  98 + let passStatus = false;
98 99 if (field.valueType === 'json') {
99 100 const getJson = unref(jsonInstance).get();
  101 + if (Object.prototype.isPrototypeOf(getJson) && Object.keys(getJson).length === 0) {
  102 + createMessage.error('命令内容不能为空');
  103 + passStatus = true;
  104 + }
  105 + if (getJson === '') {
  106 + passStatus = true;
  107 + createMessage.error('命令内容不能为空');
  108 + }
100 109 jsonData.value.params = getJson;
101 110 } else {
102 111 jsonData.value.params = field.commandText;
  112 + if (!jsonData.value.params) {
  113 + createMessage.error('命令内容不能为空');
  114 + passStatus = true;
  115 + }
  116 + if (jsonData.value.params == '""' || jsonData.value.params == "''") {
  117 + createMessage.error('命令内容不能为空');
  118 + passStatus = true;
  119 + }
103 120 }
104 121 jsonData.value.persistent = true;
105   - // jsonData.value.additionalInfo = {
106   - // cmdType: 'API',
107   - // };
108 122 jsonData.value.method = 'methodThingskit';
  123 + if (passStatus) return;
109 124 commandIssuanceApi(field.commandType, props.deviceDetail.tbDeviceId, jsonData.value)
110 125 .then((res) => {
111 126 if (!res) return;
... ... @@ -126,8 +141,8 @@
126 141 }, 300);
127 142 });
128 143 } catch (e) {
  144 + } finally {
129 145 //这里捕获json插件的错误
130   - createMessage.error('请填写正确的json格式数据');
131 146 disable.value = false;
132 147 }
133 148 };
... ...
... ... @@ -49,12 +49,9 @@
49 49 });
50 50 };
51 51 const handleRecordContent = (record) => {
52   - try {
53   - //如果是正常格式则返回params,否则输入什么内容则显示什么内容
54   - const jsonParams = JSON.parse(record?.request?.body?.params);
55   - commonModalInfo('命令下发内容', jsonParams.params ? jsonParams.params : jsonParams);
56   - } catch (e) {
57   - console.log('位置/device/list/cpns/tabs/commandRecord/index.vue', e);
58   - }
  52 + if (!record?.request?.body?.params) return;
  53 + //如果是正常格式则返回params,否则输入什么内容则显示什么内容
  54 + const jsonParams = JSON.parse(record?.request?.body?.params);
  55 + commonModalInfo('命令下发内容', jsonParams?.params ? jsonParams?.params : jsonParams);
59 56 };
60 57 </script>
... ...