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,统一日期维度的展示规范
| | |
| | | */
|
| | |
|
| | | // 日期格式化
|
| | | 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
|
| | |
| | | { label: "备件名称", prop: "sparePartsName" }, |
| | | { label: "领用数量", prop: "quantity" }, |
| | | { label: "操作人", prop: "operator" }, |
| | | { label: "时间", prop: "createTime" }, |
| | | { label: "时间", prop: "createTime",dataType:"date" }, |
| | | ]); |
| | | |
| | | const handleTabChange = async (name) => { |
| | |
| | | label: "登记日期", |
| | | minWidth: 100, |
| | | formatData: cell => |
| | | cell ? dayjs(cell).format("YYYY-MM-DD HH:mm:ss") : "-", |
| | | cell ? dayjs(cell).format("YYYY-MM-DD") : "-", |
| | | }, |
| | | { |
| | | fixed: "right", |