Explorar el Código

模块配置 页面

uncledong hace 1 año
padre
commit
eea063cb70
Se han modificado 2 ficheros con 76 adiciones y 14 borrados
  1. 18 2
      src/api/system/config.js
  2. 58 12
      src/views/system/config/index.vue

+ 18 - 2
src/api/system/config.js

@@ -77,7 +77,7 @@ export function sensorDisConnect(data) {
 
 export function sensorStartGather(data) {
   return request({
-    url: '/system/startGather',
+    url: '/sensor/startGather',
     method: 'post',
     data: data
   })
@@ -85,7 +85,23 @@ export function sensorStartGather(data) {
 
 export function sensorStopGather(data) {
   return request({
-    url: '/system/stopGather',
+    url: '/sensor/stopGather',
+    method: 'post',
+    data: data
+  })
+}
+
+
+export function sensorInfo() {
+  return request({
+    url: '/sensor/get',
+    method: 'post',
+  })
+}
+
+export function sensorSave(data) {
+  return request({
+    url: '/sensor/save',
     method: 'post',
     data: data
   })

+ 58 - 12
src/views/system/config/index.vue

@@ -107,9 +107,6 @@
          </el-table-column>
       </el-table>
 
-      <div class="dialog-footer" style="margin-top: 12px;display: flex;justify-content: end">
-         <el-button type="primary" @click="submitForm">保存</el-button>
-      </div>
       <p style="font-size: 16px;font-weight: bold;margin-top: 24px">电流传感器配置:</p>
       <el-row :gutter="10" class="mb8" style="margin-top: 24px">
          <el-col :span="1.5">
@@ -182,12 +179,10 @@
          </el-table-column>
       </el-table>
 
-      <div class="dialog-footer" style="margin-top: 24px;display: flex;justify-content: end">
-         <el-button type="primary" @click="submitForm">保存</el-button>
-      </div>
       <div class="dialog-footer" style="margin-top: 24px;display: flex;justify-content: center">
-         <el-button type="primary" @click="submitForm">开始采集</el-button>
-         <el-button type="primary" @click="submitForm">停止采集</el-button>
+         <el-button type="primary" @click="save">保存配置</el-button>
+         <el-button type="primary" @click="start">开始采集</el-button>
+         <el-button type="primary" @click="stop">停止采集</el-button>
       </div>
       <!--<pagination-->
       <!--   v-show="total > 0"-->
@@ -233,7 +228,8 @@
 </template>
 
 <script setup name="Config">
-import { listConfig, getConfig, delConfig, addConfig, updateConfig, refreshCache, sensorConnect, sensorDisConnect, sensorStartGather,
+import { listConfig, getConfig, delConfig, addConfig, sensorInfo, sensorSave,
+   updateConfig, refreshCache, sensorConnect, sensorDisConnect, sensorStartGather,
 sensorStopGather} from "@/api/system/config";
 
 const { proxy } = getCurrentInstance();
@@ -257,6 +253,7 @@ const data = reactive({
 
   },
   queryParams: {
+     id: '',
     pageNum: 1,
     pageSize: 10,
     ip: undefined,
@@ -275,6 +272,16 @@ const { queryParams, form, rules } = toRefs(data);
 /** 查询参数列表 */
 function getList() {
   loading.value = true;
+   sensorInfo().then(res => {
+      if (res.data && res.data.length > 0){
+         queryParams.value.ip =  res.data[0].ip
+         queryParams.value.id =  res.data[0].id
+         queryParams.value.port =  res.data[0].port
+         queryParams.value.frequency =  res.data[0].frequency
+         configList.value = JSON.parse( res.data[0].vibrateSensor);
+         configList1.value = JSON.parse( res.data[0].electricSensor);
+      }
+   });
   // listConfig(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
   //   configList.value = response.rows;
   //   total.value = response.total;
@@ -310,8 +317,8 @@ function handleQuery() {
 function startConnect() {
    sensorConnect({
       ...data.queryParams,
-      vibrateSensor: configList.value,
-      electricSensor: configList1.value
+      vibrateSensor: JSON.stringify(configList.value),
+      electricSensor: JSON.stringify(configList1.value)
    }).then(response => {
       proxy.$modal.msgSuccess("连接成功");
       isConnect.value = true;
@@ -319,7 +326,17 @@ function startConnect() {
 }
 
 function closeConnect() {
-
+   queryParams.ip = undefined;
+   queryParams.port = undefined;
+   queryParams.frequency = undefined;
+    sensorDisConnect({
+       ...data.queryParams,
+       vibrateSensor: JSON.stringify(configList.value),
+       electricSensor: JSON.stringify(configList1.value)
+    }).then(response => {
+        proxy.$modal.msgSuccess("断开连接成功");
+        isConnect.value = false;
+    });
 }
 
 
@@ -376,6 +393,35 @@ function handleUpdate(row) {
     title.value = "修改参数";
   });
 }
+
+function start(){
+   sensorStartGather({
+      ...data.queryParams,
+      vibrateSensor: JSON.stringify(configList.value),
+      electricSensor: JSON.stringify(configList1.value)
+   }).then(response => {
+      proxy.$modal.msgSuccess("开始采集成功");
+   })
+}
+function stop(){
+   sensorStopGather({
+      ...data.queryParams,
+      vibrateSensor: JSON.stringify(configList.value),
+      electricSensor: JSON.stringify(configList1.value)
+   }).then(response => {
+      proxy.$modal.msgSuccess("停止采集成功");
+   })
+}
+function save(){
+   sensorSave({
+      ...data.queryParams,
+      vibrateSensor: JSON.stringify(configList.value),
+      electricSensor: JSON.stringify(configList1.value)
+   }).then(response => {
+      proxy.$modal.msgSuccess("保存成功");
+   });
+}
+
 /** 提交按钮 */
 function submitForm() {
   proxy.$refs["configRef"].validate(valid => {