Skip to content

Commit 60526ac

Browse files
author
Kerry
committed
fix(Gateway,Advanced): fix issues in auto subscribe and coap
1 parent d2c72db commit 60526ac

File tree

2 files changed

+21
-53
lines changed

2 files changed

+21
-53
lines changed

src/views/Advanced/components/subscribe.vue

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
v-for="item in subsOptions.qos"
5050
:key="item"
5151
:value="item"
52-
:label="item"
5352
></el-option>
5453
</el-select>
5554
</el-form-item>
@@ -99,7 +98,7 @@
9998
:loading="submitLoading"
10099
>{{ isEdit ? $t("Base.update") : $t("Base.add") }}</el-button
101100
>
102-
<el-button size="small" @click="opSubs = false">{{
101+
<el-button size="small" @click="closeDialog()">{{
103102
$t("Base.cancel")
104103
}}</el-button>
105104
</template>
@@ -112,6 +111,7 @@ import { defineComponent, onMounted, reactive, ref } from "vue";
112111
import { getSubscribe, editSubscribe } from "@/api/advanced";
113112
import { ElMessageBox as MB, ElMessage } from "element-plus";
114113
import { useI18n } from "vue-i18n";
114+
import _ from "lodash";
115115
116116
export default defineComponent({
117117
name: "Subscribe",
@@ -125,7 +125,6 @@ export default defineComponent({
125125
let opSubs = ref(false);
126126
let subTbData = ref([]);
127127
let subsOptions = reactive({
128-
// op: ["nl", "rap", "rh"],
129128
qos: [0, 1, 2],
130129
nl: [0, 1],
131130
rap: [0, 1],
@@ -155,67 +154,34 @@ export default defineComponent({
155154
let openOpDialog = (edit = false, origin) => {
156155
opSubs.value = true;
157156
isEdit.value = !!edit;
158-
subsForm.value?.resetFields();
159-
160-
// subsInput.topic = edit && origin.topic ? origin.topic : subsInput.topic;
161-
// subsInput.qos = edit && origin.qos ? origin.qos : subsInput.qos;
162-
// subsInput.nl=edit&&origin.nl?origin.nl:subsInput
163-
subsInput = (edit && { ...subsInput, ...origin }) || subsInput;
164157
165-
// subsInput.op =
166-
// (edit &&
167-
// (() => {
168-
// let opArr = [];
169-
// origin.nl === 1 && opArr.push("nl");
170-
// origin.rap === 1 && opArr.push("rap");
171-
// origin.rh === 1 && opArr.push("rh");
172-
// return opArr;
173-
// })()) ||
174-
// [];
158+
subsInput = (edit && _.merge(subsInput, origin)) || subsInput;
175159
176160
edit && (editPos.value = subTbData.value.findIndex((e) => e === origin));
177161
};
178162
179163
const submitSubs = async function (edit = false) {
180164
let valid = await subsForm.value?.validate().catch(() => {});
181165
if (!valid) return;
182-
183-
// let tempOpStore = {};
166+
submitLoading.value = true;
184167
let pendingTbData = Object.assign([], subTbData.value);
185168
186-
// Array.prototype.forEach.call(subsOptions.op, (v) => {
187-
// tempOpStore[v] = subsInput.op.indexOf(v) >= 0 ? 1 : 0;
188-
// });
189-
// let subjectSubData = {
190-
// topic: subsInput.topic,
191-
// qos: subsInput.qos,
192-
// ...tempOpStore,
193-
// };
194-
195169
if (!edit) {
196170
pendingTbData.push(subsInput);
197171
} else {
198-
if (editPos.value === undefined) {
199-
return;
200-
}
201-
pendingTbData.splice(editPos.value, 1, subsInput);
172+
editPos.value !== undefined &&
173+
pendingTbData.splice(editPos.value, 1, { ...subsInput });
202174
}
203-
submitLoading.value = true;
204175
205176
let res = await editSubscribe(pendingTbData).catch(() => {});
206177
if (res) {
207178
ElMessage({
208179
type: "success",
209180
message: edit ? t("Base.editSuccess") : t("Base.createSuccess"),
210181
});
211-
subTbData.value = pendingTbData;
182+
loadData();
212183
opSubs.value = false;
213184
editPos.value = undefined;
214-
} else {
215-
ElMessage({
216-
type: "error",
217-
message: t("Base.opErr"),
218-
});
219185
}
220186
submitLoading.value = false;
221187
};
@@ -236,17 +202,17 @@ export default defineComponent({
236202
type: "success",
237203
message: t("Base.deleteSuccess"),
238204
});
239-
subTbData.value = pendingTbData;
240-
} else {
241-
ElMessage({
242-
type: "error",
243-
message: t("Base.opErr"),
244-
});
205+
loadData();
245206
}
246207
})
247208
.catch(() => {});
248209
};
249210
211+
const closeDialog = () => {
212+
opSubs.value = false;
213+
subsForm.value?.resetFields();
214+
};
215+
250216
let loadData = async () => {
251217
tbLoading.value = true;
252218
let res = await getSubscribe().catch(() => {});
@@ -255,6 +221,7 @@ export default defineComponent({
255221
}
256222
tbLoading.value = false;
257223
};
224+
258225
onMounted(loadData);
259226
260227
const reloading = () => {
@@ -276,6 +243,7 @@ export default defineComponent({
276243
tbLoading,
277244
subsForm,
278245
subsRules,
246+
closeDialog,
279247
};
280248
},
281249
});

src/views/Gateway/components/coapBasic.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@
4747
<el-form-item :label="tl('subQos')">
4848
<el-select v-model="cValue.subscribe_qos">
4949
<el-option value="coap"></el-option>
50-
<el-option value="0"></el-option>
51-
<el-option value="1"></el-option>
52-
<el-option value="2"></el-option>
50+
<el-option value="qos0"></el-option>
51+
<el-option value="qos1"></el-option>
52+
<el-option value="qos2"></el-option>
5353
</el-select>
5454
</el-form-item>
5555
</el-col>
5656
<el-col :span="12">
5757
<el-form-item :label="tl('pubQos')">
5858
<el-select v-model="cValue.publish_qos">
5959
<el-option value="coap"></el-option>
60-
<el-option value="0"></el-option>
61-
<el-option value="1"></el-option>
62-
<el-option value="2"></el-option>
60+
<el-option value="qos0"></el-option>
61+
<el-option value="qos1"></el-option>
62+
<el-option value="qos2"></el-option>
6363
</el-select>
6464
</el-form-item>
6565
</el-col>

0 commit comments

Comments
 (0)