Răsfoiți Sursa

[Fix 0000] 关联控制无数据时初始化错误修复

houzekong 3 zile în urmă
părinte
comite
b9b7aae018
1 a modificat fișierele cu 125 adăugiri și 123 ștergeri
  1. 125 123
      src/views/vent/deviceManager/comment/warningTabel/ctrlTable.vue

+ 125 - 123
src/views/vent/deviceManager/comment/warningTabel/ctrlTable.vue

@@ -32,155 +32,157 @@
 </template>
 
 <script lang="ts" setup>
-import { ref, onMounted } from 'vue';
-import { ctrlColumns, ctrlFormSchemas } from './warning.data';
-import { getCtrlDevicePointList, addCtrlDevicePoint, editCtrlDevicePoint, getCtrlDevicePointPage, deleteDevicePonit } from './warning.api';
-import BaseModal from './BaseModalCtrl.vue';
-import { useModal } from '/@/components/Modal';
+  import { ref, onMounted } from 'vue';
+  import { ctrlColumns, ctrlFormSchemas } from './warning.data';
+  import { getCtrlDevicePointList, addCtrlDevicePoint, editCtrlDevicePoint, getCtrlDevicePointPage, deleteDevicePonit } from './warning.api';
+  import BaseModal from './BaseModalCtrl.vue';
+  import { useModal } from '/@/components/Modal';
 
-const emit = defineEmits(['register']);
+  const emit = defineEmits(['register']);
 
-const props = defineProps({
-  deviceId: { type: String },
-  deviceType: { type: String },
-});
+  const props = defineProps({
+    deviceId: { type: String },
+    deviceType: { type: String },
+  });
 
-const formSchemas = ctrlFormSchemas;
-const activeID = ref('');
-const dataSource = ref<any[]>([]);
-const ctrlList = ref<any[]>([]);
-const deviceType = ref('');
-const editRecord = ref<any>(null);
-function selectWarning(id) {
-  activeID.value = id;
-  getTableData(id);
-}
-async function getControlDevicePointList() {
-  const param = {
-    pageNo: 1,
-    pageSize: 1000,
-    devicetype: props.deviceType,
-    valuetype: 10,
-  };
-  const res = await getCtrlDevicePointList(param);
-  ctrlList.value = res.records || [];
-}
-const [register, { openModal, closeModal }] = useModal();
+  const formSchemas = ctrlFormSchemas;
+  const activeID = ref('');
+  const dataSource = ref<any[]>([]);
+  const ctrlList = ref<any[]>([]);
+  const deviceType = ref('');
+  const editRecord = ref<any>(null);
+  function selectWarning(id) {
+    activeID.value = id;
+    getTableData(id);
+  }
+  async function getControlDevicePointList() {
+    const param = {
+      pageNo: 1,
+      pageSize: 1000,
+      devicetype: props.deviceType,
+      valuetype: 10,
+    };
+    const res = await getCtrlDevicePointList(param);
+    ctrlList.value = res.records || [];
+  }
+  const [register, { openModal, closeModal }] = useModal();
 
-function handleOpen(flag?, record?) {
-  console.log(record, 'record');
-  deviceType.value = props.deviceType;
-  editRecord.value = flag == 'update' ? record : null;
-  if (record) {
-    if (flag == 'update') {
-      openModal(true, {
-        isUpdate: true,
-        record,
-      });
+  function handleOpen(flag?, record?) {
+    console.log(record, 'record');
+    deviceType.value = props.deviceType;
+    editRecord.value = flag == 'update' ? record : null;
+    if (record) {
+      if (flag == 'update') {
+        openModal(true, {
+          isUpdate: true,
+          record,
+        });
+      } else {
+        openModal(true, {
+          isUpdate: false,
+          record,
+        });
+      }
     } else {
       openModal(true, {
         isUpdate: false,
         record,
       });
     }
-  } else {
-    openModal(true, {
-      isUpdate: false,
-      record,
-    });
   }
-}
 
-async function onSubmit(flag, values) {
-  const currentItem = ctrlList.value.find((item) => item.id == activeID.value);
-  if (currentItem) {
-    values.monitorCode = currentItem.valuecode;
-    values.monitorId = currentItem.id;
-    values.monitorName = currentItem.valuename;
-  }
-  if (flag == 'update') {
-    await editCtrlDevicePoint({ id: editRecord.value?.id, ...editRecord.value, ...values });
-  } else {
-    await addCtrlDevicePoint({ ...values });
+  async function onSubmit(flag, values) {
+    const currentItem = ctrlList.value.find((item) => item.id == activeID.value);
+    if (currentItem) {
+      values.monitorCode = currentItem.valuecode;
+      values.monitorId = currentItem.id;
+      values.monitorName = currentItem.valuename;
+    }
+    if (flag == 'update') {
+      await editCtrlDevicePoint({ id: editRecord.value?.id, ...editRecord.value, ...values });
+    } else {
+      await addCtrlDevicePoint({ ...values });
+    }
+    editRecord.value = null;
+    closeModal();
+    await getTableData(activeID.value);
   }
-  editRecord.value = null;
-  closeModal();
-  await getTableData(activeID.value);
-}
 
-async function handleDelete(record) {
-  await deleteDevicePonit({ id: record.id });
-  getTableData(activeID.value);
-}
+  async function handleDelete(record) {
+    await deleteDevicePonit({ id: record.id });
+    getTableData(activeID.value);
+  }
 
-async function getTableData(id?: string) {
-  const param = {
-    pageNo: 1,
-    pageSize: 1000,
-    monitorId: id,
-    deviceId: props.deviceId,
-  };
-  const res = await getCtrlDevicePointPage(param);
-  dataSource.value = res.records || [];
-}
+  async function getTableData(id?: string) {
+    if (!id) return;
 
-onMounted(async () => {
-  await getControlDevicePointList();
-  if (ctrlList.value.length > 0) {
-    activeID.value = ctrlList.value[0].id;
+    const param = {
+      pageNo: 1,
+      pageSize: 1000,
+      monitorId: id,
+      deviceId: props.deviceId,
+    };
+    const res = await getCtrlDevicePointPage(param);
+    dataSource.value = res.records || [];
   }
-  await getTableData(activeID.value);
-});
+
+  onMounted(async () => {
+    await getControlDevicePointList();
+    if (ctrlList.value.length > 0) {
+      activeID.value = ctrlList.value[0].id;
+    }
+    await getTableData(activeID.value);
+  });
 </script>
 
 <style lang="less" scoped>
-@ventSpace: zxm;
+  @ventSpace: zxm;
 
-.warning-device-box {
-  width: 100%;
-  height: 600px;
-  overflow-y: auto;
-  display: flex;
-  .warning-box {
-    width: 200px;
-    height: 100%;
+  .warning-device-box {
+    width: 100%;
+    height: 600px;
     overflow-y: auto;
-    background: #ffffff11;
-    padding: 5px;
-    border-radius: 5px;
+    display: flex;
+    .warning-box {
+      width: 200px;
+      height: 100%;
+      overflow-y: auto;
+      background: #ffffff11;
+      padding: 5px;
+      border-radius: 5px;
 
-    .link-item {
-      position: relative;
-      cursor: pointer;
-      line-height: 30px;
-      padding-left: 30px;
-      color: #fff;
-      span:hover {
-        color: #89ffff;
+      .link-item {
+        position: relative;
+        cursor: pointer;
+        line-height: 30px;
+        padding-left: 30px;
+        color: #fff;
+        span:hover {
+          color: #89ffff;
+        }
+        &::after {
+          content: '';
+          position: absolute;
+          display: block;
+          width: 8px;
+          height: 8px;
+          top: 12px;
+          left: 10px;
+          transform: rotateZ(45deg) skew(10deg, 10deg);
+          background: #45d3fd;
+        }
       }
-      &::after {
-        content: '';
-        position: absolute;
-        display: block;
-        width: 8px;
-        height: 8px;
-        top: 12px;
-        left: 10px;
-        transform: rotateZ(45deg) skew(10deg, 10deg);
-        background: #45d3fd;
+      .active-device-title {
+        color: aqua;
       }
     }
-    .active-device-title {
-      color: aqua;
+    .device-box {
+      flex: 1;
+      margin-left: 10px;
     }
-  }
-  .device-box {
-    flex: 1;
-    margin-left: 10px;
-  }
 
-  .action-link {
-    color: #00e7ff;
+    .action-link {
+      color: #00e7ff;
+    }
   }
-}
-</style>
+</style>