|
| 1 | +<template> |
| 2 | + <BasePage :title="$t('modbusadmin.ModbusSettings')" :isLoading="dataLoading"> |
| 3 | + <BootstrapAlert v-model="showAlert" dismissible :variant="alertType"> |
| 4 | + {{ alertMessage }} |
| 5 | + </BootstrapAlert> |
| 6 | + |
| 7 | + <form @submit="saveModbusConfig"> |
| 8 | + <CardElement :text="$t('modbusadmin.ModbusConfiguration')" textVariant="text-bg-primary"> |
| 9 | + <InputElement :label="$t('modbusadmin.EnableModbusTCP')" |
| 10 | + v-model="modbusConfigList.modbus_tcp_enabled" |
| 11 | + type="checkbox" wide/> |
| 12 | + <InputElement :label="$t('modbusadmin.Clients')" |
| 13 | + v-model="modbusConfigList.modbus_clients" |
| 14 | + type="number" min="1" max="4"/> |
| 15 | + <InputElement :label="$t('modbusadmin.IDDTUPro')" |
| 16 | + v-model="modbusConfigList.modbus_id_dtupro" |
| 17 | + type="number" min="1" max="255"/> |
| 18 | + <InputElement :label="$t('modbusadmin.IDTotal')" |
| 19 | + v-model="modbusConfigList.modbus_id_total" |
| 20 | + type="number" min="1" max="255"/> |
| 21 | + <InputElement :label="$t('modbusadmin.IDMeter')" |
| 22 | + v-model="modbusConfigList.modbus_id_meter" |
| 23 | + type="number" min="1" max="255"/> |
| 24 | + </CardElement> |
| 25 | + |
| 26 | + <FormFooter @reload="getModbusConfig"/> |
| 27 | + </form> |
| 28 | + </BasePage> |
| 29 | +</template> |
| 30 | + |
| 31 | +<script lang="ts"> |
| 32 | +import BasePage from '@/components/BasePage.vue'; |
| 33 | +import BootstrapAlert from "@/components/BootstrapAlert.vue"; |
| 34 | +import CardElement from '@/components/CardElement.vue'; |
| 35 | +import FormFooter from '@/components/FormFooter.vue'; |
| 36 | +import InputElement from '@/components/InputElement.vue'; |
| 37 | +import type { ModbusConfig } from "@/types/ModbusConfig"; |
| 38 | +import { authHeader, handleResponse } from '@/utils/authentication'; |
| 39 | +import { defineComponent } from 'vue'; |
| 40 | +
|
| 41 | +export default defineComponent({ |
| 42 | + components: { |
| 43 | + BasePage, |
| 44 | + BootstrapAlert, |
| 45 | + CardElement, |
| 46 | + FormFooter, |
| 47 | + InputElement, |
| 48 | + }, |
| 49 | + data() { |
| 50 | + return { |
| 51 | + dataLoading: true, |
| 52 | + modbusConfigList: {} as ModbusConfig, |
| 53 | + alertMessage: "", |
| 54 | + alertType: "info", |
| 55 | + showAlert: false, |
| 56 | + }; |
| 57 | + }, |
| 58 | + created() { |
| 59 | + this.getModbusConfig(); |
| 60 | + }, |
| 61 | + methods: { |
| 62 | + getModbusConfig() { |
| 63 | + this.dataLoading = true; |
| 64 | + fetch("/api/modbus/config", { headers: authHeader() }) |
| 65 | + .then((response) => handleResponse(response, this.$emitter, this.$router)) |
| 66 | + .then((data) => { |
| 67 | + this.modbusConfigList = data; |
| 68 | + this.dataLoading = false; |
| 69 | + }); |
| 70 | + }, |
| 71 | + saveModbusConfig(e: Event) { |
| 72 | + e.preventDefault(); |
| 73 | +
|
| 74 | + const formData = new FormData(); |
| 75 | + formData.append("data", JSON.stringify(this.modbusConfigList)); |
| 76 | +
|
| 77 | + fetch("/api/modbus/config", { |
| 78 | + method: "POST", |
| 79 | + headers: authHeader(), |
| 80 | + body: formData, |
| 81 | + }) |
| 82 | + .then((response) => handleResponse(response, this.$emitter, this.$router)) |
| 83 | + .then( |
| 84 | + (response) => { |
| 85 | + this.alertMessage = this.$t('apiresponse.' + response.code, response.param); |
| 86 | + this.alertType = response.type; |
| 87 | + this.showAlert = true; |
| 88 | + } |
| 89 | + ); |
| 90 | + }, |
| 91 | + }, |
| 92 | +}); |
| 93 | +</script> |
0 commit comments