zhangwencui
2 天以前 cef1acd01505b160f8cf9d5d01fb03f4feb47438
运行管理代码整理
已修改1个文件
250 ■■■■■ 文件已修改
src/pages/equipmentManagement/runManagement/index.vue 250 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/equipmentManagement/runManagement/index.vue
@@ -5,11 +5,9 @@
    <!-- 通知公告板 -->
    <view class="notice-board">
      <!-- 统一通知区域 -->
      <view class="notice-section"
            v-if="totalNoticeCount > 0">
      <view class="notice-section">
        <view class="section-header">
          <h3>设备运行记录</h3>
          <!-- <text class="section-count">{{ totalNoticeCount }}条</text> -->
        </view>
        <view class="notice-cards">
          <!-- 放假通知 -->
@@ -93,50 +91,13 @@
</template>
<script setup>
  import { onMounted, ref, reactive, toRefs } from "vue";
  import { onReachBottom } from "@dcloudio/uni-app";
  import { onMounted, ref } from "vue";
  import PageHeader from "@/components/PageHeader.vue";
  import useUserStore from "@/store/modules/user";
  import {
    addNotice,
    delNotice,
    getCount,
    listNotice,
    updateNotice,
  } from "@/api/collaborativeApproval/noticeManagement.js";
  import {
    getLedgerPage,
    editLedger,
  } from "@/api/equipmentManagement/runManagement.js";
  const userStore = useUserStore();
  // 响应式数据
  const data = reactive({
    searchForm: {
      title: "",
      type: undefined,
      status: undefined,
    },
    form: {
      id: undefined,
      title: "",
      type: null,
      content: "",
      status: 0,
      priority: 1,
      remark: "",
      expirationDate: "",
    },
    rules: {
      title: [{ required: true, message: "公告标题不能为空", trigger: "blur" }],
      type: [{ required: true, message: "请选择公告类型", trigger: "change" }],
      content: [{ required: true, message: "公告内容不能为空", trigger: "blur" }],
      expirationDate: [
        { required: true, message: "请选择日期", trigger: "change" },
      ],
    },
  });
  // 获取标签类型
  const getTagType = status => {
    switch (status) {
@@ -180,21 +141,6 @@
        return "question-circle";
    }
  };
  const { searchForm, form, rules } = toRefs(data);
  // 页面状态
  const dialogVisible = ref(false);
  const dialogTitle = ref("");
  const selectedIds = ref([]);
  const formRef = ref();
  const priorityOptions = [
    { label: "普通", value: 1 },
    { label: "重要", value: 2 },
    { label: "紧急", value: 3 },
  ];
  const goBack = () => {
    uni.navigateBack();
  };
@@ -211,23 +157,6 @@
    return currentTime > planTime;
  };
  const onExpireConfirm = e => {
    if (!e) return;
    // uview-plus datetime-picker confirm 事件返回的 value
    const value = e.value || e;
    form.value.expirationDate = value;
  };
  const getPriorityText = priority => {
    const priorityMap = { 1: "普通", 2: "重要", 3: "紧急" };
    return priorityMap[priority] || "普通";
  };
  const getStatusText = status => {
    const statusMap = { 0: "草稿", 1: "已发布", 2: "已过期" };
    return statusMap[status] || "未知";
  };
  const isNoticeExpired = notice => {
    if (!notice || !notice.expirationDate) {
      return false;
@@ -242,32 +171,6 @@
    expiration.setHours(23, 59, 59, 999);
    return new Date() > expiration;
  };
  const getNoticeStatus = notice => {
    const normalizedStatus =
      notice && notice.status !== undefined && notice.status !== null
        ? String(notice.status)
        : "0";
    return isNoticeExpired(notice) ? "2" : normalizedStatus;
  };
  const openForm = type => {
    if (type === "add") {
      dialogTitle.value = "新增公告";
      form.value = {
        id: undefined,
        title: "",
        type: undefined,
        content: "",
        status: 0,
        priority: 1,
        remark: "",
        expirationDate: "",
      };
    }
    dialogVisible.value = true;
  };
  const handleEdit = async (device, status) => {
@@ -326,167 +229,18 @@
    }
  };
  const handleDelete = id => {
    if (!id) return;
    uni.showModal({
      title: "提示",
      content: "确认删除这条公告吗?",
      success: res => {
        if (res.confirm) {
          delNotice(id).then(() => {
            uni.showToast({
              title: "删除成功",
              icon: "success",
            });
            resetTable();
          });
        }
      },
    });
  };
  // 预留批量删除(目前未实现选中逻辑,仅占位)
  const handleDeleteBatch = () => {
    if (!selectedIds.value.length) return;
    uni.showModal({
      title: "提示",
      content: "确认删除选中的公告吗?",
      success: res => {
        if (res.confirm) {
          // 根据selectedIds执行批量删除逻辑(可按需扩展)
        }
      },
    });
  };
  const submitForm = () => {
    formRef.value.validate(valid => {
      if (valid) {
        if (form.value.id) {
          // 编辑模式
          updateNotice(form.value).then(res => {
            uni.showToast({
              title: "修改成功",
              icon: "success",
            });
            resetTable();
          });
        } else {
          // 新增模式
          addNotice(form.value).then(res => {
            uni.showToast({
              title: "新增成功",
              icon: "success",
            });
            resetTable();
          });
        }
        dialogVisible.value = false;
      }
    });
  };
  const totalNoticeCount = ref(0);
  const fetchCount = () => {
    getCount().then(res => {
      totalNoticeCount.value = res.data.reduce(
        (total, item) => total + item.count,
        0
      );
    });
  };
  const holidayNotices = ref([]);
  const maintenanceNotices = ref([]);
  const holidayNoticePage = ref({
    total: 0,
    current: 1,
    size: 9,
  });
  const maintenanceNoticePage = ref({
    total: 0,
    current: 1,
    size: 9,
  });
  const isLoadingMore = ref(false);
  const fetchHolidayNotices = (append = false) => {
    getLedgerPage({}).then(res => {
      holidayNotices.value = res?.data?.records || [];
      // const records = res?.data?.records || [];
      // holidayNoticePage.value.total = res?.data?.total || 0;
      // if (append && holidayNotices.value.length) {
      //   holidayNotices.value = [...holidayNotices.value, ...records];
      // } else {
      //   holidayNotices.value = records;
      // }
    });
  };
  const fetchMaintenanceNotices = (append = false) => {
    listNotice({ ...holidayNoticePage.value, type: 2 }).then(res => {
      const records = res?.data?.records || [];
      maintenanceNoticePage.value.total = res?.data?.total || 0;
      if (append && maintenanceNotices.value.length) {
        maintenanceNotices.value = [...maintenanceNotices.value, ...records];
      } else {
        maintenanceNotices.value = records;
      }
    });
  };
  const handleCurrentChange = val => {
    holidayNoticePage.value.size = val.limit;
    holidayNoticePage.value.current = val.page;
    maintenanceNoticePage.value.size = val.limit;
    maintenanceNoticePage.value.current = val.page;
    fetchHolidayNotices();
    fetchMaintenanceNotices();
  };
  const resetTable = () => {
    holidayNoticePage.value.current = 1;
    holidayNoticePage.value.size = 9;
    maintenanceNoticePage.value.current = 1;
    maintenanceNoticePage.value.size = 9;
    fetchHolidayNotices();
    fetchMaintenanceNotices();
    fetchCount();
  };
  const resetForm = () => {
    formRef.value?.resetFields();
  };
  // 生命周期
  onMounted(() => {
    fetchCount();
    fetchHolidayNotices();
    fetchMaintenanceNotices();
  });
  // 上划加载更多
  onReachBottom(() => {
    if (isLoadingMore.value) return;
    isLoadingMore.value = true;
    holidayNoticePage.value.current += 1;
    maintenanceNoticePage.value.current += 1;
    Promise.all([
      new Promise(resolve => {
        fetchHolidayNotices(true);
        resolve();
      }),
      new Promise(resolve => {
        fetchMaintenanceNotices(true);
        resolve();
      }),
    ]).finally(() => {
      isLoadingMore.value = false;
    });
  });
</script>