fix(wms): 调整退火绩效和异常报表默认查询时间为昨日到今日
统一两个报表页面的默认查询时间范围,将初始默认时间改为昨日00:00:00到当日00:00:00,简化了异常报表的时间处理逻辑,移除冗余的日期范围工具函数。
This commit is contained in:
@@ -81,8 +81,14 @@ export default {
|
|||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
queryParams: {
|
queryParams: {
|
||||||
startTime: undefined,
|
startTime: (() => {
|
||||||
endTime: undefined,
|
const d = new Date(); d.setDate(d.getDate() - 1);
|
||||||
|
return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')} 00:00:00`;
|
||||||
|
})(),
|
||||||
|
endTime: (() => {
|
||||||
|
const d = new Date();
|
||||||
|
return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')} 00:00:00`;
|
||||||
|
})(),
|
||||||
targetFurnaceId: undefined,
|
targetFurnaceId: undefined,
|
||||||
planNo: undefined,
|
planNo: undefined,
|
||||||
enterCoilNo: undefined,
|
enterCoilNo: undefined,
|
||||||
|
|||||||
@@ -155,52 +155,14 @@ export default {
|
|||||||
},
|
},
|
||||||
dicts: ['product_coil_status', 'coil_material', 'coil_itemname', 'coil_manufacturer', 'coil_quality_status'],
|
dicts: ['product_coil_status', 'coil_material', 'coil_itemname', 'coil_manufacturer', 'coil_quality_status'],
|
||||||
data() {
|
data() {
|
||||||
// 工具函数:个位数补零
|
|
||||||
const addZero = (num) => num.toString().padStart(2, '0')
|
const addZero = (num) => num.toString().padStart(2, '0')
|
||||||
|
|
||||||
// 获取当前日期(默认选中当天)
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const currentDate = `${now.getFullYear()}-${addZero(now.getMonth() + 1)}`
|
const yesterday = new Date(now)
|
||||||
|
yesterday.setDate(yesterday.getDate() - 1)
|
||||||
|
|
||||||
/**
|
const start = `${yesterday.getFullYear()}-${addZero(yesterday.getMonth() + 1)}-${addZero(yesterday.getDate())} 00:00:00`
|
||||||
* 生成指定日期/月份的时间范围字符串
|
const end = `${now.getFullYear()}-${addZero(now.getMonth() + 1)}-${addZero(now.getDate())} 00:00:00`
|
||||||
* @param {string} dateStr - 支持格式:yyyy-MM(月份) 或 yyyy-MM-dd(具体日期)
|
|
||||||
* @returns {object} 包含start(开始时间)和end(结束时间)的对象
|
|
||||||
*/
|
|
||||||
const getDayTimeRange = (dateStr) => {
|
|
||||||
// 先校验输入格式是否合法
|
|
||||||
const monthPattern = /^\d{4}-\d{2}$/; // yyyy-MM 正则
|
|
||||||
const dayPattern = /^\d{4}-\d{2}-\d{2}$/; // yyyy-MM-dd 正则
|
|
||||||
|
|
||||||
if (!monthPattern.test(dateStr) && !dayPattern.test(dateStr)) {
|
|
||||||
throw new Error('输入格式错误,请传入 yyyy-MM 或 yyyy-MM-dd 格式的字符串');
|
|
||||||
}
|
|
||||||
|
|
||||||
let startDate, endDate;
|
|
||||||
|
|
||||||
if (monthPattern.test(dateStr)) {
|
|
||||||
// 处理 yyyy-MM 格式:获取本月第一天和最后一天
|
|
||||||
const [year, month] = dateStr.split('-').map(Number);
|
|
||||||
// 月份是0基的(0=1月,1=2月...),所以要减1
|
|
||||||
// 第一天:yyyy-MM-01
|
|
||||||
startDate = `${dateStr}-01`;
|
|
||||||
// 最后一天:通过 new Date(year, month, 0) 计算(month是原始月份,比如2代表2月,传2则取3月0日=2月最后一天)
|
|
||||||
const lastDayOfMonth = new Date(year, month, 0).getDate();
|
|
||||||
endDate = `${dateStr}-${lastDayOfMonth.toString().padStart(2, '0')}`;
|
|
||||||
} else {
|
|
||||||
// 处理 yyyy-MM-dd 格式:直接使用传入的日期
|
|
||||||
startDate = dateStr;
|
|
||||||
endDate = dateStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拼接时间部分
|
|
||||||
return {
|
|
||||||
start: `${startDate} 00:00:00`,
|
|
||||||
end: `${endDate} 23:59:59`
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const { start, end } = getDayTimeRange(currentDate)
|
|
||||||
return {
|
return {
|
||||||
lossList: [],
|
lossList: [],
|
||||||
outList: [],
|
outList: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user