zouyu
10 天以前 1c0863efe062af3ebcdecb8c10568d779f5c8295
src/views/equipmentManagement/inspectionManagement/index.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,354 @@
<template>
   <div class="app-container">
      <el-form :inline="true" :model="queryParams" class="search-form">
         <el-form-item label="巡检任务名称">
            <el-input
               v-model="queryParams.taskName"
               placeholder="请输入巡检任务名称"
               clearable
               :style="{ width: '100%' }"
            />
         </el-form-item>
         <el-form-item>
            <el-button type="primary" @click="handleQuery">查询</el-button>
            <el-button @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>
      <el-card>
         <div style="display: flex;flex-direction: row;justify-content: space-between;margin-bottom: 10px;">
            <el-radio-group v-model="activeRadio" @change="radioChange">
               <el-radio-button v-for="tab in radios"
                                        :key="tab.name"
                                        :label="tab.label"
                                        :value="tab.name"/>
            </el-radio-group>
            <!-- æ“ä½œæŒ‰é’®åŒº -->
            <el-space v-if="activeRadio !== 'task'">
               <el-button type="primary" :icon="Plus" @click="handleAdd(undefined)">新建</el-button>
               <el-button type="danger" :icon="Delete" @click="handleDelete">删除</el-button>
               <el-button @click="handleOut">导出</el-button>
            </el-space>
            <el-space v-else>
               <el-button @click="handleOut">导出</el-button>
            </el-space>
         </div>
         <div>
            <div>
               <PIMTable :table-loading="tableLoading"
                              :table-data="tableData"
                              :column="tableColumns"
                              @selection-change="handleSelectionChange"
                              :is-selection="true"
                              :border="true"
                              :table-style="{ width: '100%', height: 'calc(100vh - 23em)' }"
                              :page="{
          current: pageNum,
          size: pageSize,
          total: total,
        }"
                              @pagination="pagination"
               >
                  <template #inspector="{ row }">
                     <div class="person-tags">
                        <!-- è°ƒè¯•信息,上线时删除 -->
                        <!-- {{ console.log('inspector data:', row.inspector) }} -->
                        <template v-if="row.inspector && row.inspector.length > 0">
                           <el-tag
                              v-for="(person, index) in row.inspector"
                              :key="index"
                              size="small"
                              type="primary"
                              class="person-tag"
                           >
                              {{ person }}
                           </el-tag>
                        </template>
                        <span v-else class="no-data">--</span>
                     </div>
                  </template>
               </PIMTable>
            </div>
         </div>
      </el-card>
      <form-dia ref="formDia" @closeDia="handleQuery"></form-dia>
      <view-files ref="viewFiles"></view-files>
   </div>
</template>
<script setup>
import { Delete, Plus } from "@element-plus/icons-vue";
import { onMounted, ref, reactive, getCurrentInstance, nextTick } from "vue";
import { ElMessageBox } from "element-plus";
// ç»„件引入
import Pagination from "@/components/Pagination/index.vue";
import PIMTable from "@/components/PIMTable/PIMTable.vue";
import FormDia from "@/views/equipmentManagement/inspectionManagement/components/formDia.vue";
import ViewFiles from "@/views/equipmentManagement/inspectionManagement/components/viewFiles.vue";
// æŽ¥å£å¼•å…¥
import {
   delTimingTask,
   inspectionTaskList,
   timingTaskList
} from "@/api/inspectionManagement/index.js";
// å…¨å±€å˜é‡
const { proxy } = getCurrentInstance();
const formDia = ref();
const viewFiles = ref();
// æŸ¥è¯¢å‚æ•°
const queryParams = reactive({
   taskName: "",
});
// å•选框配置
const activeRadio = ref("taskManage");
const radios = reactive([
   { name: "taskManage", label: "定时任务管理" },
   { name: "task", label: "定时任务记录" },
]);
// è¡¨æ ¼æ•°æ®
const selectedRows = ref([]);
const tableData = ref([]);
const operationsArr = ref([]);
const tableColumns = ref([]);
const tableLoading = ref(false);
const total = ref(0);
const pageNum = ref(1);
const pageSize = ref(10);
// åˆ—配置
const columns = ref([
   { prop: "taskName", label: "巡检任务名称", minWidth: 160 },
   { prop: "remarks", label: "备注", minWidth: 150 },
   { prop: "inspector", label: "执行巡检人", minWidth: 150, slot: "inspector" },
   {
      prop: "frequencyType",
      label: "频次",
      minWidth: 150,
      formatData: (cell) => ({
         DAILY: "每日",
         WEEKLY: "每周",
         MONTHLY: "每月",
         QUARTERLY: "季度"
      }[cell] || "")
   },
   {
      prop: "frequencyDetail",
      label: "开始日期与时间",
      minWidth: 150,
      formatter: (row, column, cellValue) => {
         // å…ˆåˆ¤æ–­æ˜¯å¦æ˜¯å­—符串
         if (typeof cellValue !== 'string') return '';
         let val = cellValue;
         const replacements = {
            MON: '周一',
            TUE: '周二',
            WED: '周三',
            THU: '周四',
            FRI: '周五',
            SAT: '周六',
            SUN: '周日'
         };
         // ä½¿ç”¨æ­£åˆ™ä¸€æ¬¡æ€§æ›¿æ¢æ‰€æœ‰åŒ¹é…é¡¹
         return val.replace(/MON|TUE|WED|THU|FRI|SAT|SUN/g, match => replacements[match]);
      }
   },
   { prop: "registrant", label: "登记人", minWidth: 100 },
   { prop: "dateStr", label: "登记日期", minWidth: 100 },
]);
// æ“ä½œåˆ—配置
const getOperationColumn = (operations) => {
   if (!operations || operations.length === 0) return null;
   const operationConfig = {
      label: "操作",
      width: 130,
      fixed: "right",
      dataType: "action",
      operation: operations.map(op => {
         switch (op) {
            case 'edit':
               return {
                  name: "编辑",
                  clickFun: handleAdd,
                  color: "#409EFF"
               };
            case 'viewFile':
               return {
                  name: "查看附件",
                  clickFun: viewFile,
                  color: "#67C23A"
               };
            default:
               return null;
         }
      }).filter(Boolean)
   };
   return operationConfig;
};
onMounted(() => {
   radioChange('taskManage');
});
// å•选变化
const radioChange = (value) => {
   if (value === "taskManage") {
      const operationColumn = getOperationColumn(['edit']);
      tableColumns.value = [...columns.value, ...(operationColumn ? [operationColumn] : [])];
      operationsArr.value = ['edit'];
   } else if (value === "task") {
      const operationColumn = getOperationColumn(['viewFile']);
      tableColumns.value = [...columns.value, ...(operationColumn ? [operationColumn] : [])];
      operationsArr.value = ['viewFile'];
   }
   pageNum.value = 1;
   pageSize.value = 10;
   getList();
};
// æŸ¥è¯¢æ“ä½œ
const handleQuery = () => {
   pageNum.value = 1;
   pageSize.value = 10;
   getList();
};
const pagination = (obj) => {
   pageNum.value = obj.page;
   pageSize.value = obj.limit;
   getList();
};
// èŽ·å–åˆ—è¡¨æ•°æ®
const getList = () => {
   tableLoading.value = true;
   const params = { ...queryParams, size: pageSize.value, current: pageNum.value };
   let apiCall;
   if (activeRadio.value === "task") {
      apiCall = inspectionTaskList(params);
   } else {
      apiCall = timingTaskList(params);
   }
   apiCall.then(res => {
      const rawData = res.data.records || [];
      // å¤„理 inspector å­—段,将字符串转换为数组(适用于所有情况)
      tableData.value = rawData.map(item => {
         const processedItem = { ...item };
         // å¤„理 inspector å­—段
         if (processedItem.inspector) {
            if (typeof processedItem.inspector === 'string') {
               // å­—符串按逗号分割
               processedItem.inspector = processedItem.inspector.split(',').map(s => s.trim()).filter(s => s);
            } else if (!Array.isArray(processedItem.inspector)) {
               // éžæ•°ç»„转为数组
               processedItem.inspector = [processedItem.inspector];
            }
         } else {
            // ç©ºå€¼è®¾ä¸ºç©ºæ•°ç»„
            processedItem.inspector = [];
         }
         return processedItem;
      });
      total.value = res.data.total || 0;
   }).finally(() => {
      tableLoading.value = false;
   });
};
// é‡ç½®æŸ¥è¯¢
const resetQuery = () => {
   for (const key in queryParams) {
      if (!["pageNum", "pageSize"].includes(key)) {
         queryParams[key] = "";
      }
   }
   handleQuery();
};
// æ–°å¢ž / ç¼–辑
const handleAdd = (row) => {
   const type = row ? 'edit' : 'add';
   nextTick(() => {
      formDia.value?.openDialog(type, row);
   });
};
// æŸ¥çœ‹é™„ä»¶
const viewFile = (row) => {
   nextTick(() => {
      viewFiles.value?.openDialog(row);
   });
};
// åˆ é™¤æ“ä½œ
const handleDelete = () => {
   if (!selectedRows.value.length) {
      proxy.$modal.msgWarning("请选择要删除的数据");
      return;
   }
   const deleteIds = selectedRows.value.map(item => item.id);
   proxy.$modal.confirm('是否确认删除所选数据项?').then(() => {
      return delTimingTask(deleteIds);
   }).then(() => {
      proxy.$modal.msgSuccess("删除成功");
      handleQuery();
   }).catch(() => {});
};
// å¤šé€‰å˜æ›´
const handleSelectionChange = (selection) => {
   selectedRows.value = selection;
};
// å¯¼å‡º
const handleOut = () => {
   ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
   })
      .then(() => {
         // æ ¹æ®å½“前选中的标签页调用不同的导出接口
         if (activeRadio.value === "taskManage") {
            // å®šæ—¶ä»»åŠ¡ç®¡ç†
            proxy.download("/timingTask/export", {}, "定时任务管理.xlsx");
         } else if (activeRadio.value === "task") {
            // å®šæ—¶ä»»åŠ¡è®°å½•
            proxy.download("/inspectionTask/export", {}, "定时任务记录.xlsx");
         }
      })
      .catch(() => {
         proxy.$modal.msg("已取消");
      });
};
</script>
<style scoped>
.person-tags {
   display: flex;
   flex-wrap: wrap;
   gap: 4px;
}
.person-tag {
   margin-right: 4px;
   margin-bottom: 2px;
}
.no-data {
   color: #909399;
   font-size: 14px;
}
</style>