Browse Source

Merge branch 'master' of http://182.92.126.35:3000/hrx/vent-forewarn-micro

lxh 1 year ago
parent
commit
b51d3bcce3

+ 5 - 4
src/api/sys/model/monitorModel.ts

@@ -59,11 +59,12 @@ export interface SaveMonitorSiteParams {
   id: string;
   parentId: string;
   label: string;
-  disasterType: string;
-  disasterName: string;
-  sensorType: string;
-  sensorTypeName: string;
+  disasterType: string | null | undefined;
+  disasterName: string | null | undefined;
+  sensorType: string | null | undefined;
+  sensorTypeName: string | null | undefined;
   systemSource: string;
+  leafNode: number;
   x: number;
   y: number;
   z: number;

+ 3 - 1
src/api/sys/monitor.ts

@@ -17,6 +17,7 @@ enum Api {
   getMonitorSiteTree = '/gis/data/gisBaseTree',
   getMonitorSite = '/gis/data/getDataByIdAndSystemCode',
   saveMonitorSite = '/gis/data/save',
+  deleteMonitorSite = '/gis/data/delete',
 }
 
 /**
@@ -61,8 +62,9 @@ export function deleteMonitorSite(
 ) {
   return defHttp.delete<MonitorSite>(
     {
-      url: Api.saveMonitorSite,
+      url: Api.deleteMonitorSite,
       params,
+      data: params,
     },
     {
       errorMessageMode: mode,

+ 44 - 33
src/views/vent/monitor/site/components/siteForm.vue

@@ -6,31 +6,38 @@
     :label-col="{ span: 9 }"
     :wrapper-col="{ span: 15 }"
     :showActionButtonGroup="false"
+    :disabled="!editable"
     size="small"
     label-align="right"
     @register="register"
   >
     <template #create-btn>
-      <Button type="primary" :rounded="true" @click="createSite">新建测点</Button>
+      <Button v-if="editable" type="primary" :rounded="true" :disabled="false" @click="save">
+        保 存
+      </Button>
+      <Button v-else type="primary" :rounded="true" :disabled="false" @click="createSite">
+        新建测点
+      </Button>
     </template>
     <template #edit-btn>
-      <Button type="primary" :rounded="true" @click="editSite">编辑测点</Button>
+      <Button v-if="editable" type="primary" :rounded="true" :disabled="false" @click="cancel">
+        取 消
+      </Button>
+      <Button v-else type="primary" :rounded="true" :disabled="false" @click="editSite">
+        编辑测点
+      </Button>
     </template>
     <!-- <template #copy-btn>
         <Button type="primary" :rounded="true" @click="copySite">复制测点</Button>
       </template> -->
     <template #pick-btn>
-      <Button type="primary" :rounded="true" @click="pickSite">拾取坐标</Button>
+      <Button type="primary" :rounded="true" :disabled="false" @click="pickSite">拾取坐标</Button>
     </template>
   </BasicForm>
 </template>
 <script setup lang="ts">
-  import {
-    MonitorSiteTreeNode,
-    MonitorSiteOperationParams,
-    SaveMonitorSiteParams,
-  } from '@/api/sys/model/monitorModel';
-  import { defineProps } from 'vue';
+  import { MonitorSiteTreeNode, MonitorSiteOperationParams } from '@/api/sys/model/monitorModel';
+  import { defineProps, ref } from 'vue';
   import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
   import { Button } from 'ant-design-vue';
   import { SensorDict, SystemSourceDict } from '../const';
@@ -38,7 +45,7 @@
   // props & emits
   const props = defineProps<{ site: Partial<MonitorSiteTreeNode> }>();
   const emit = defineEmits<{
-    save: [value: SaveMonitorSiteParams];
+    save: [value: Required<MonitorSiteTreeNode>];
     operation: [value: MonitorSiteOperationParams];
   }>();
 
@@ -82,9 +89,6 @@
       colProps: {
         span: 1,
       },
-      componentProps: {
-        size: 'small',
-      },
     };
   }
 
@@ -127,7 +131,12 @@
   const schemas: FormSchema[] = [
     generateButtonSchema({ slot: 'create-btn' }),
     generateInputSchema({ field: 'id', label: '测点编号', required: true }),
-    generateSelectSchema({ field: 'sensorType', label: '测点类型', dict: SensorDict }),
+    generateSelectSchema({
+      field: 'sensorType',
+      label: '测点类型',
+      dict: SensorDict,
+      required: false,
+    }),
     generateInputSchema({ field: 'sensorStatus', label: '测点使用状态' }),
     generateInputSchema({ field: 'label', label: '所属位置', required: true }),
     generateInputSchema({ field: 'x', label: 'X', required: true, span: 3 }),
@@ -146,30 +155,37 @@
     generateInputSchema({ field: 'z', label: 'Z', span: 3 }),
   ];
 
+  // 表单是否可以编辑
+  const editable = ref(false);
+
   // 后续操作表单必要的函数
-  const [register, { validate }] = useForm();
+  const [register, { validate, setFieldsValue }] = useForm();
 
-  // 提交创建测点所需的数据
+  // 新建测点,设置表单的数据、状态
   function createSite() {
-    validate().then((v) => {
-      emit('save', { ...props.site, ...v } as SaveMonitorSiteParams);
-    });
+    setFieldsValue({ id: '' });
+    editable.value = true;
   }
 
-  // 提交复制测点所需的数据
-  // function copySite() {
-  //   validate().then((v) => {
-  //     emit('save', { ...props.site, ...v } as SaveMonitorSiteParams);
-  //   });
-  // }
-
-  // 提交编辑测点所需的数据
+  // 编辑测点,设置表单的数据、状态
   function editSite() {
+    editable.value = true;
+  }
+
+  // 保存测点,提交表单
+  function save() {
     validate().then((v) => {
-      emit('save', { ...props.site, ...v } as SaveMonitorSiteParams);
+      cancel();
+      emit('save', { ...props.site, ...v } as Required<MonitorSiteTreeNode>);
     });
   }
 
+  // 取消编辑,表单回到默认状态
+  function cancel() {
+    setFieldsValue(props.site);
+    editable.value = false;
+  }
+
   // 拾取测点
   function pickSite() {
     emit('operation', {
@@ -177,9 +193,4 @@
       from: 'tank',
     });
   }
-
-  defineExpose({
-    schemas,
-    register,
-  });
 </script>

+ 4 - 8
src/views/vent/monitor/site/components/siteTree.vue

@@ -9,13 +9,10 @@
       @select="selectHandler"
     >
       <template #icon="scope">
-        <Icon v-if="scope.selected" icon="material-symbols:circle" color="green" />
-        <Icon v-else-if="scope.leaf && scope.selectable" icon="material-symbols:circle" />
-        <Icon
-          v-else-if="scope.leaf && !scope.selectable"
-          icon="material-symbols:circle"
-          color="red"
-        />
+        <!-- 叶节点且已选中的是绿色 -->
+        <Icon v-if="scope.leaf && scope.selected" icon="material-symbols:circle" color="green" />
+        <!-- 叶节点是白色 -->
+        <Icon v-else-if="scope.leaf" icon="material-symbols:circle" />
       </template>
     </Tree>
 
@@ -42,7 +39,6 @@
     const res: TreeNode = {
       title: node.label,
       key: node.id,
-      selectable: !!node.display,
       leaf: !!node.leafNode,
       raw: node,
       children: [],

+ 13 - 6
src/views/vent/monitor/site/index.vue

@@ -37,7 +37,6 @@
     MonitorSiteTreeParams,
     MonitorSiteTreeNode,
     MonitorSiteOperationParams,
-    SaveMonitorSiteParams,
   } from '@/api/sys/model/monitorModel';
   import {
     getMonitorSiteTree,
@@ -59,10 +58,10 @@
     });
   }
 
-  // 选中的测点
+  // 选测点
   const selectedSite = ref<Partial<MonitorSiteTreeNode>>({});
 
-  // 聚焦到测点上
+  // 聚焦到 所选测点 
   function focusOnSite(site: MonitorSiteTreeNode) {
     selectedSite.value = site;
     postMonitorOperation(iframeRef.value!, {
@@ -74,7 +73,7 @@
     });
   }
 
-  // 处理测点图返回的数据
+  // 处理测点图返回的数据,即更新 所选测点 的数据
   function handleMessage(msg: any) {
     const data = JSON.parse(msg);
     selectedSite.value = { ...selectedSite.value, ...data };
@@ -85,11 +84,19 @@
     postMonitorOperation(iframeRef.value!, formData);
   }
 
-  // 提交一些保存相关的请求
-  function handleSave(formData: SaveMonitorSiteParams) {
+  // 保存测点,处理原始的表单数据并尝试保存测点
+  function handleSave(formData: Required<MonitorSiteTreeNode>) {
+    const isLeaf = Boolean(formData.leafNode);
+    // 保存节点时,非子节点衍生的保存在该节点的子树里,根据子节点衍生的追加即可,保存的都是叶节点
+    if (!isLeaf && selectedSite.value.id) {
+      formData.parentId = selectedSite.value.id;
+    }
+    formData.leafNode = 1;
+
     saveMonitorSite(formData).then(() => {
       notification.success({ message: '保存成功' });
       // 成功保存后刷新
+      refreshTree({});
       postMonitorOperation(iframeRef.value!, {
         clickType: 'refreshPoint',
         from: 'tank',

+ 0 - 1
src/views/vent/monitor/site/types/siteTree.ts

@@ -2,7 +2,6 @@ export interface TreeNode {
   title: string;
   key: string;
   children: TreeNode[];
-  selectable: boolean;
   leaf: boolean;
   [k: string]: unknown;
 }