ソースを参照

全局配置-增删改联调

wangwenhua 4 ヶ月 前
コミット
869020e5c9

+ 85 - 0
src/api/config/index.ts

@@ -2,6 +2,12 @@ import request from "@/utils/request";
 import { AxiosPromise } from "axios";
 // import {} from "./types";
 
+/**
+ * 测试仪器配置分页查询接口
+ *
+ * @param queryParams - 查询参数对象,可选
+ * @returns AxiosPromise<any> - 返回一个 AxiosPromise 对象,包含分页查询的结果
+ */
 //测试仪器配置分页查询
 export function instrumentConfigPage(queryParams?: object): AxiosPromise<any> {
   return request({
@@ -11,6 +17,12 @@ export function instrumentConfigPage(queryParams?: object): AxiosPromise<any> {
   });
 }
 
+/**
+ * 发送全局数据分页查询请求
+ *
+ * @param queryParams - 查询参数对象,可选
+ * @returns AxiosPromise<any> - 返回一个 AxiosPromise 对象,包含请求的响应数据
+ */
 //测试全局数据分页查询
 export function globalDataPage(queryParams?: object): AxiosPromise<any> {
   return request({
@@ -19,3 +31,76 @@ export function globalDataPage(queryParams?: object): AxiosPromise<any> {
     data: queryParams,
   });
 }
+
+/**
+ * 更新仪器配置
+ *
+ * @param queryParams - 可选的查询参数对象,包含要更新的配置数据。
+ * @returns 返回一个 AxiosPromise 对象,表示更新请求的结果。
+ */
+export function configUpdate(queryParams?: object): AxiosPromise<any> {
+  return request({
+    url: "/api/v1/instrumentConfig/update",
+    method: "post",
+    data: queryParams,
+  });
+}
+
+/**
+ * 添加仪器配置
+ *
+ * @param queryParams - 要添加的仪器配置参数,默认为空对象。
+ * @returns 返回一个 AxiosPromise 对象,表示添加仪器配置的请求结果。
+ */
+export function configAdd(queryParams?: object): AxiosPromise<any> {
+  return request({
+    url: "/api/v1/instrumentConfig/add",
+    method: "post",
+    data: queryParams,
+  });
+}
+
+/**
+ * 删除仪器配置
+ *
+ * @param queryParams - 可选的查询参数对象,包含要删除的仪器配置数据。
+ * @returns 返回一个 AxiosPromise 对象,表示删除操作的结果。
+ */
+export function configDel(queryParams?: object): AxiosPromise<any> {
+  return request({
+    url: "/api/v1/instrumentConfig/del",
+    method: "post",
+    data: queryParams,
+  });
+}
+
+/**
+ * 向全局数据新增接口发送请求
+ *
+ * @param queryParams - 可选的查询参数对象,包含要新增的全局数据
+ * @returns AxiosPromise<any> - 返回一个 AxiosPromise 对象,表示请求的结果
+ */
+//全局数据新增
+export function globalDataAdd(queryParams?: object): AxiosPromise<any> {
+  return request({
+    url: "/api/v1/globalData/add",
+    method: "post",
+    data: queryParams,
+  });
+}
+
+export function globalDataDel(queryParams?: object): AxiosPromise<any> {
+  return request({
+    url: "/api/v1/globalData/del",
+    method: "post",
+    data: queryParams,
+  });
+}
+
+export function globalDataUpdate(queryParams?: object): AxiosPromise<any> {
+  return request({
+    url: "/api/v1/globalData/update",
+    method: "post",
+    data: queryParams,
+  });
+}

+ 44 - 40
src/views/modules/global-config/components/ConfigAdd.vue

@@ -1,31 +1,39 @@
 <template>
   <div class="add">
-    <el-dialog
-      v-model="dialogVisible"
-      title="新建测试工程"
-      width="500"
-      @closed="emitHidden"
-    >
+    <el-dialog v-model="dialogVisible" title="新建测试工程" width="500">
       <el-form
         :label-position="labelPosition"
         label-width="auto"
         :model="formLabelAlign"
         style="max-width: 600px"
+        ref="ruleFormRef"
       >
-        <el-form-item label="产品" :label-position="itemLabelPosition">
-          <el-input v-model="formLabelAlign.name" />
+        <el-form-item
+          label="所需仪器类型"
+          :label-position="itemLabelPosition"
+          prop="instrumentType"
+        >
+          <el-input v-model="formLabelAlign.instrumentType" />
         </el-form-item>
-        <el-form-item label="类型" :label-position="itemLabelPosition">
-          <el-input v-model="formLabelAlign.type" />
+        <el-form-item
+          label="名称"
+          :label-position="itemLabelPosition"
+          prop="configName"
+        >
+          <el-input v-model="formLabelAlign.configName" />
         </el-form-item>
-        <el-form-item label="版本" :label-position="itemLabelPosition">
-          <el-input v-model="formLabelAlign.region" />
+        <el-form-item
+          label="仪器地址"
+          :label-position="itemLabelPosition"
+          prop="configIp"
+        >
+          <el-input v-model="formLabelAlign.configIp" />
         </el-form-item>
       </el-form>
 
       <template #footer>
         <div class="dialog-footer">
-          <el-button @click="emitHidden">取消</el-button>
+          <el-button @click="dialogVisible = false">取消</el-button>
           <el-button type="primary" @click="saveFun"> 保存 </el-button>
         </div>
       </template>
@@ -44,42 +52,38 @@ const labelPosition = ref<FormProps["labelPosition"]>("right");
 const itemLabelPosition = ref<FormItemProps["labelPosition"]>("");
 
 interface VersionItem {
-  name: string;
-  type: string;
-  region: string;
+  instrumentType: string;
+  configName: string;
+  configIp: string;
 }
 
 const formLabelAlign = ref<VersionItem>({
-  name: "name1",
-  type: "实现基础框架搭建,包含权限管理、路由系统等核心功能。",
-  region: "v2.4.0",
+  instrumentType: "",
+  configName: "",
+  configIp: "",
 });
 
-// const handleClose = (done: () => void) => {};
+const emit = defineEmits(["save"]);
 
-let { options } = defineProps({
-  options: {
-    type: Object,
-    required: false,
-  },
-});
-
-watch(
-  () => options,
-  (newVal, oldVal) => {
-    console.log(newVal);
-    // dialogVisible.value = newVal.show;
-  }
-);
-
-const emit = defineEmits(["handleCancel", "save"]);
-const emitHidden = () => {
-  emit("handleCancel", false);
+const saveFun = () => {
+  emit("save", formLabelAlign.value, flag.value);
 };
 
-const saveFun = () => {
-  emit("save", formLabelAlign.value);
+const ruleFormRef = ref();
+const flag = ref("");
+const showDialog = (type: string, data: any) => {
+  dialogVisible.value = true;
+  ruleFormRef.value && ruleFormRef.value.resetFields();
+  flag.value = type;
+  formLabelAlign.value = JSON.parse(JSON.stringify(data));
+};
+const hiddenDialog = () => {
+  dialogVisible.value = false;
 };
+defineExpose({
+  showDialog,
+  hiddenDialog,
+});
 </script>
 <style scoped lang="scss">
 // .add {

+ 87 - 0
src/views/modules/global-config/components/globalDataAdd.vue

@@ -0,0 +1,87 @@
+<template>
+  <div class="add">
+    <el-dialog v-model="dialogVisible" title="新建测试工程" width="500">
+      <el-form
+        :label-position="labelPosition"
+        label-width="auto"
+        :model="formLabelAlign"
+        style="max-width: 600px"
+        ref="ruleFormRef"
+      >
+        <el-form-item
+          label="数据项名称	"
+          :label-position="itemLabelPosition"
+          prop="dataItemName"
+        >
+          <el-input v-model="formLabelAlign.dataItemName" />
+        </el-form-item>
+        <el-form-item
+          label="名称"
+          :label-position="itemLabelPosition"
+          prop="setValue"
+        >
+          <el-input v-model="formLabelAlign.setValue" />
+        </el-form-item>
+      </el-form>
+
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button @click="dialogVisible = false">取消</el-button>
+          <el-button type="primary" @click="saveFun"> 保存 </el-button>
+        </div>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+
+<script lang="ts" setup>
+import { reactive, ref, watch } from "vue";
+
+const dialogVisible = ref(false);
+
+import type { FormItemProps, FormProps } from "element-plus";
+
+const labelPosition = ref<FormProps["labelPosition"]>("right");
+const itemLabelPosition = ref<FormItemProps["labelPosition"]>("");
+
+interface VersionItem {
+  dataItemName: string;
+  setValue: string;
+}
+
+const formLabelAlign = ref<VersionItem>({
+  dataItemName: "",
+  setValue: "",
+});
+
+const emit = defineEmits(["save"]);
+
+const saveFun = () => {
+  emit("save", formLabelAlign.value, flag.value);
+};
+
+const ruleFormRef = ref();
+const flag = ref("");
+const showDialog = (type: string, data: any) => {
+  dialogVisible.value = true;
+  ruleFormRef.value && ruleFormRef.value.resetFields();
+  flag.value = type;
+  formLabelAlign.value = JSON.parse(JSON.stringify(data));
+};
+const hiddenDialog = () => {
+  dialogVisible.value = false;
+};
+defineExpose({
+  showDialog,
+  hiddenDialog,
+});
+</script>
+<style scoped lang="scss">
+// .add {
+//   // position: fixed;
+//   // width: 100%;
+//   // height: 100%;
+//   // z-index: 10;
+//   // background-color: #000;
+// }
+</style>

+ 113 - 36
src/views/modules/global-config/global-config.vue

@@ -1,23 +1,26 @@
 <script lang="ts" setup>
 import { computed, ref } from "vue";
 import type { TabsPaneContext } from "element-plus";
-import { instrumentConfigPage, globalDataPage } from "@/api/config";
+import {
+  instrumentConfigPage,
+  globalDataPage,
+  configUpdate,
+  configAdd,
+  configDel,
+  globalDataAdd,
+  globalDataDel,
+  globalDataUpdate,
+} from "@/api/config";
 
 const activeName = ref("仪器配置");
 
-import ConfigAdd from "./components/ConfigAdd.vue";
-import { fa } from "element-plus/es/locale";
-import { dataTool } from "echarts";
+import configAddVue from "./components/ConfigAdd.vue";
+import globalAddVue from "./components/globalDataAdd.vue";
 
 const handleClick = (tab: TabsPaneContext, event: Event) => {
   // console.log(tab, event);
 };
 
-//
-
-const handleDelete = (index: number, row: any) => {
-  console.log(index, row);
-};
 //配置列表请求参数
 const configParams = ref({
   orders: [
@@ -68,11 +71,11 @@ const globalHandleChange = (currentPage: number, pageSize: number) => {
   getglobalData();
 };
 
-//测试仪器配置数组
+//全局数据数组
 const globalDataList = ref([]);
-//数据total
+//全局数据数据total
 const globalDataTotal = ref(1);
-//请求数据
+//请求数据 全局数据
 const getglobalData = () => {
   globalDataPage(globalParams.value).then((res) => {
     console.log(res);
@@ -86,23 +89,80 @@ onMounted?.(() => {
   getglobalData();
 });
 
-//仪器配置弹框数据
-const configAdd = ref({
-  show: false,
-  type: "add", //add新增,edit修改
-  data: {},
-});
+const configChildRef = ref();
+const configHandleEdit = (index: number, row: any) => {
+  configChildRef.value && configChildRef.value.showDialog("change", row);
+};
+
+const addConfigFun = () => {
+  configChildRef.value && configChildRef.value.showDialog("add", {});
+};
 
-const handleEdit = (index: number, row: any) => {
-  // console.log(index, row);
-  // console.log(row);
-  showConfigAdd("edit", row);
+/**
+//新增或修改仪器配置
+ *
+ * @param {any} data - 要保存的仪器配置数据
+ * @param {string} flag - 操作标识,"add" 表示新增,其他值表示修改
+ *
+ * 根据 flag 的值调用相应的 API 进行新增或修改操作,
+ * 操作完成后关闭弹框并重新请求仪器配置数据。
+ */
+const configSaveFun = (data: any, flag: string) => {
+  if (flag === "add") {
+    configAdd(data).then((res) => {
+      configChildRef.value && configChildRef.value.hiddenDialog(); //关闭弹框
+      getInstrumentConfig(); //重新请求数据
+    });
+  } else {
+    configUpdate(data).then((res) => {
+      configChildRef.value && configChildRef.value.hiddenDialog(); //关闭弹框
+      getInstrumentConfig(); //重新请求数据
+    });
+  }
+};
+
+/**
+ * 处理删除配置项的函数
+ * @param {number} index - 配置项在列表中的索引
+ * @param {any} row - 当前配置项的数据对象
+ *
+ * 此函数调用 configDel 方法删除指定的配置项,并在成功后重新请求配置数据。
+ */
+const configHandleDelete = (index: number, row: any) => {
+  configDel({ id: row.id }).then((res) => {
+    getInstrumentConfig(); //重新请求数据
+  });
+};
+
+// =======================
+const globalChildRef = ref();
+
+const globalHandleEdit = (index: number, row: any) => {
+  globalChildRef.value && globalChildRef.value.showDialog("change", row);
+};
+
+const addglobalFun = () => {
+  globalChildRef.value && globalChildRef.value.showDialog("add", {});
+};
+
+const globalSaveFun = (data: any, flag: string) => {
+  if (flag === "add") {
+    globalDataAdd(data).then((res) => {
+      globalChildRef.value && globalChildRef.value.hiddenDialog(); //关闭弹框
+      getglobalData(); //重新请求数据
+    });
+  } else {
+    globalDataUpdate(data).then((res) => {
+      globalChildRef.value && globalChildRef.value.hiddenDialog(); //关闭弹框
+      getglobalData(); //重新请求数据
+    });
+  }
 };
-const showConfigAdd = (type: string, data: any) => {
-  console.log("1");
-  configAdd.value.show = true;
-  configAdd.value.type = type;
-  configAdd.value.data = data;
+
+const globalHandledel = (index: number, row: any) => {
+  globalDataDel({ id: row.id }).then((res) => {
+    getglobalData(); //重新请求数据
+  });
 };
 </script>
 
@@ -112,7 +172,7 @@ const showConfigAdd = (type: string, data: any) => {
       <el-tab-pane label="仪器配置" name="仪器配置">
         <div class="global-config-pane">
           <div class="btns">
-            <el-button type="primary">
+            <el-button type="primary" @click="addConfigFun">
               <span class="add">+</span>
               新增
             </el-button>
@@ -130,7 +190,7 @@ const showConfigAdd = (type: string, data: any) => {
                     text
                     size="small"
                     type="primary"
-                    @click="handleDelete(scope.$index, scope.row)"
+                    @click="configHandleDelete(scope.$index, scope.row)"
                   >
                     删除
                   </el-button>
@@ -138,7 +198,7 @@ const showConfigAdd = (type: string, data: any) => {
                     text
                     size="small"
                     type="primary"
-                    @click="handleEdit(scope.$index, scope.row)"
+                    @click="configHandleEdit(scope.$index, scope.row)"
                   >
                     修改
                   </el-button>
@@ -159,7 +219,7 @@ const showConfigAdd = (type: string, data: any) => {
       <el-tab-pane label="全局数据" name="全局数据">
         <div class="global-config-pane">
           <div class="btns">
-            <el-button type="primary" @click="">
+            <el-button type="primary" @click="addglobalFun">
               <span class="add">+</span>
               新增
             </el-button>
@@ -168,11 +228,27 @@ const showConfigAdd = (type: string, data: any) => {
           <div>
             <el-table :data="globalDataList" style="width: 100%">
               <el-table-column label="序号" type="index" width="80" />
-              <el-table-column label="所需仪器类型" prop="instrumentType" />
-              <el-table-column label="名称" prop="configName" />
-              <el-table-column label="仪器地址" prop="configIp" />
+              <el-table-column label="数据项名称" prop="dataItemName" />
+              <el-table-column label="设定值" prop="setValue" />
               <el-table-column label="操作" prop="操作" fixed="right">
-                <template #default="scope"> </template>
+                <template #default="scope">
+                  <el-button
+                    text
+                    size="small"
+                    type="primary"
+                    @click="globalHandledel(scope.$index, scope.row)"
+                  >
+                    删除
+                  </el-button>
+                  <el-button
+                    text
+                    size="small"
+                    type="primary"
+                    @click="globalHandleEdit(scope.$index, scope.row)"
+                  >
+                    修改
+                  </el-button>
+                </template>
               </el-table-column>
             </el-table>
             <el-pagination
@@ -188,7 +264,8 @@ const showConfigAdd = (type: string, data: any) => {
       </el-tab-pane>
     </el-tabs>
 
-    <ConfigAdd :options="configAdd"></ConfigAdd>
+    <configAddVue ref="configChildRef" @save="configSaveFun"></configAddVue>
+    <globalAddVue ref="globalChildRef" @save="globalSaveFun"></globalAddVue>
   </div>
 </template>