zhang_nuo
3 天以前 1ac0a9ee5b9703505626154a109eb22ff0dfa9b5
feat[date]: 新增 parseDate 工具函数并统一日期展示格式

- 在 src/utils/ruoyi.js 中新增 parseDate 日期格式化函数,
支持时间戳、字符串、Date 对象等多种输入格式,默认输出
YYYY-MM-DD 格式,可自定义格式化 pattern
- 调整设备管理模块多个页面的登记日期展示格式,由精确到秒
改为仅展示日期,涉及 inspectionManagement、spareParts、
upkeep 三个子模块
- 在库存报表页面(stockReport)新增日期格式化逻辑,使用
dayjs 对 createTime 字段进行 YYYY-MM-DD 格式展示
- 将生产追溯页面(productionTraceability)的所有日期展示
由 parseTime 替换为 parseDate,统一日期维度的展示规范
已修改6个文件
76 ■■■■ 文件已修改
src/utils/ruoyi.js 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/equipmentManagement/inspectionManagement/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/equipmentManagement/spareParts/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/equipmentManagement/upkeep/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/stockReport/index.vue 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productionManagement/productionTraceability/index.vue 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/ruoyi.js
@@ -4,6 +4,47 @@
 */
// 日期格式化
export function parseDate(time, pattern) {
    if (arguments.length === 0 || !time) {
        return null
    }
    const format = pattern || '{y}-{m}-{d}'
    let date
    if (typeof time === 'object') {
        date = time
    } else {
        if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
            time = parseInt(time)
        } else if (typeof time === 'string') {
            time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '')
        }
        if ((typeof time === 'number') && (time.toString().length === 10)) {
            time = time * 1000
        }
        date = new Date(time)
    }
    const formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay()
    }
    const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
        let value = formatObj[key]
        // Note: getDay() returns 0 on Sunday
        if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
        if (result.length > 0 && value < 10) {
            value = '0' + value
        }
        return value || 0
    })
    return time_str
}
// 日期格式化
export function parseTime(time, pattern) {
  if (arguments.length === 0 || !time) {
    return null
src/views/equipmentManagement/inspectionManagement/index.vue
@@ -224,7 +224,7 @@
    { prop: "registrant", label: "登记人", minWidth: 120 },
    {
      prop: "createTime", label: "登记日期", minWidth: 180,
      formatData: cell => { if (!cell) return "-"; try { return dayjs(cell).format("YYYY-MM-DD HH:mm:ss"); } catch { return cell; } },
      formatData: cell => { if (!cell) return "-"; try { return dayjs(cell).format("YYYY-MM-DD"); } catch { return cell; } },
    },
    { prop: "abnormalDescription", label: "异常描述", minWidth: 150 },
  ]);
src/views/equipmentManagement/spareParts/index.vue
@@ -243,7 +243,7 @@
  { label: "备件名称", prop: "sparePartsName" },
  { label: "领用数量", prop: "quantity" },
  { label: "操作人", prop: "operator" },
  { label: "时间", prop: "createTime" },
  { label: "时间", prop: "createTime",dataType:"date" },
]);
const handleTabChange = async (name) => {
src/views/equipmentManagement/upkeep/index.vue
@@ -422,7 +422,7 @@
      label: "登记日期",
      minWidth: 100,
      formatData: cell =>
        cell ? dayjs(cell).format("YYYY-MM-DD HH:mm:ss") : "-",
        cell ? dayjs(cell).format("YYYY-MM-DD") : "-",
    },
    {
      fixed: "right",
src/views/inventoryManagement/stockReport/index.vue
@@ -152,7 +152,11 @@
                           prop="createTime"
                           width="200"
                           show-overflow-tooltip
                           v-if="searchForm.reportType !== 'inout'" />
                           v-if="searchForm.reportType !== 'inout'" >
            <template #default="scope">
              {{ getDate(scope.row.createTime) }}
            </template>
          </el-table-column>
          <el-table-column label="入库批次"
                           prop="inboundBatches"
                           width="180"
@@ -216,6 +220,7 @@
  import { ref, reactive, onMounted, nextTick, getCurrentInstance } from "vue";
  import { ElMessage } from "element-plus";
  import * as echarts from "echarts";
  import dayjs from "dayjs";
  import pagination from "@/components/PIMTable/Pagination.vue";
  import {
    getStockInventoryInAndOutReportList,
@@ -261,6 +266,14 @@
    );
  };
  const getDate = val =>{
    console.log(val)
    if(!val){
      return "--"
    }
    return dayjs(val).isValid() ? dayjs(val).format('YYYY‑MM‑DD') : '--'
  }
  // 获取来源类型选项
  const fetchStockRecordTypeOptions = () => {
    findAllQualifiedStockInRecordTypeOptions().then(res => {
src/views/productionManagement/productionTraceability/index.vue
@@ -56,7 +56,7 @@
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="客户名称">{{ rowData.productionOrderDto?.customerName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="开始日期">{{ parseTime(rowData.productionOrderDto?.startTime) || '-' }}</el-descriptions-item>
          <el-descriptions-item label="开始日期">{{ parseDate(rowData.productionOrderDto?.startTime) || '-' }}</el-descriptions-item>
          <el-descriptions-item label="完成进度">
            <el-progress :percentage="rowData.productionOrderDto?.completionStatus>=100?100:rowData.productionOrderDto?.completionStatus"
                         :color="customColors(rowData.productionOrderDto?.completionStatus)"
@@ -144,8 +144,8 @@
            <el-descriptions-item label="生产工单号">{{ detailData.workOrder.workOrderNo || '-' }}</el-descriptions-item>
            <el-descriptions-item label="计划数量">{{ detailData.workOrder.planQuantity || 0 }}</el-descriptions-item>
            <el-descriptions-item label="完成数量">{{ detailData.workOrder.completeQuantity || 0 }}</el-descriptions-item>
            <el-descriptions-item label="实际开始时间">{{ parseTime(detailData.workOrder.actualStartTime) || '-' }}</el-descriptions-item>
            <el-descriptions-item label="实际结束时间">{{ parseTime(detailData.workOrder.actualEndTime) || '-' }}</el-descriptions-item>
            <el-descriptions-item label="实际开始时间">{{ parseDate(detailData.workOrder.actualStartTime) || '-' }}</el-descriptions-item>
            <el-descriptions-item label="实际结束时间">{{ parseDate(detailData.workOrder.actualEndTime) || '-' }}</el-descriptions-item>
            <!-- <el-descriptions-item label="完成进度">
              <el-progress :percentage="detailData.workOrder.completionStatus >= 100 ? 100 : (detailData.workOrder.completionStatus || 0)"
                           :color="customColors(detailData.workOrder.completionStatus)"
@@ -169,7 +169,7 @@
            <el-table-column label="创建时间"
                             align="center">
              <template #default="{ row }">
                {{ parseTime(row.createTime) }}
                {{ parseDate(row.createTime) }}
              </template>
            </el-table-column>
            <el-table-column label="工时(h)"
@@ -242,10 +242,10 @@
             :key="record.id"
             class="quality-record-block">
          <div class="detail-section">
            <h3 class="section-title">检测记录 {{ index + 1 }} - {{ parseTime(record.createTime) }}</h3>
            <h3 class="section-title">检测记录 {{ index + 1 }} - {{ parseDate(record.createTime) }}</h3>
            <el-descriptions :column="3"
                             border>
              <el-descriptions-item label="检测日期">{{ parseTime(record.createTime) || '-' }}</el-descriptions-item>
              <el-descriptions-item label="检测日期">{{ parseDate(record.createTime) || '-' }}</el-descriptions-item>
              <el-descriptions-item label="报工单号">{{ record.reportNo || '-' }}</el-descriptions-item>
              <el-descriptions-item label="检验员">{{ record.userName || '-' }}</el-descriptions-item>
              <el-descriptions-item label="产品名称">{{ record.productName || '-' }}</el-descriptions-item>
@@ -299,7 +299,7 @@
  import { ref, reactive, onMounted, computed } from "vue";
  import { useRoute, useRouter } from "vue-router";
  import { ElMessage } from "element-plus";
  import { parseTime } from "@/utils/ruoyi";
  import { parseDate } from "@/utils/ruoyi";
  import InputModal from "@/views/productionManagement/productionReporting/Input.vue";
  import {
    getOrderDetail,