新增页面

This commit is contained in:
‘937886381’
2025-12-25 16:48:17 +08:00
parent 2d200dd1a6
commit 80deffbb42
406 changed files with 108362 additions and 189 deletions

View File

@@ -1,7 +1,7 @@
<template>
<header class="report-header" :class="['report-header__' + size]">
<!-- 左侧区域标题 -->
<div class="left-content">
<div class="left-content" :style="{ marginLeft: leftMargin }">
<div class="top-title">{{ topTitle }}</div>
</div>
@@ -18,15 +18,15 @@
<!-- 时间选择区域//年按钮 + 日期选择器 -->
<div class="timeType">
<div class="item" v-for="(item, index) in timeTypes" :key="index" @click="activeTime = index"
<!-- <div class="item" v-for="(item, index) in timeTypes" :key="index" @click="activeTime = index"
:class="{ 'no-skew': activeTime === index }">
<span class="item-text">{{ item.text }}</span>
</div>
</div> -->
<div class="dateP">
<div class="label">
<span class="label-text">日期选择</span>
<span class="label-text">月份选择</span>
</div>
<el-date-picker v-model="date" :type="getPickerType" :placeholder="getPickerPlaceholder"
<el-date-picker v-model="date" type="month" placeholder="请选择月份"
class="custom-date-picker" value-format="yyyy-MM-dd" :clearable="false" style="width: 132px;height: 29px;"
@change="emitTimeRange" />
</div>
@@ -43,6 +43,10 @@ export default {
isFullScreen: { type: Boolean, default: false },
topTitle: { type: String, default: '' },
size: { type: String, default: 'basic' },
leftMargin: {
type: [String, Number],
default: '350px' // 默认值设为350px
}
},
data() {
return {
@@ -50,20 +54,20 @@ export default {
timeTimer: null,
date: undefined, // 存储选择的日期字符串格式yyyy-MM-dd/yyyy-MM/yyyy
activeTime: 1, // 默认月维度0=日1=月2=年)
timeTypes: [
{ text: '日', pickerType: 'date', placeholder: '选择日期' },
{ text: '月', pickerType: 'month', placeholder: '选择月份' },
{ text: '年', pickerType: 'year', placeholder: '选择年份' }
]
// timeTypes: [
// { text: '日', pickerType: 'date', placeholder: '选择日期' },
// { text: '月', pickerType: 'month', placeholder: '选择月份' },
// { text: '年', pickerType: 'year', placeholder: '选择年份' }
// ]
}
},
computed: {
getPickerType() {
return this.timeTypes[this.activeTime].pickerType;
},
getPickerPlaceholder() {
return this.timeTypes[this.activeTime].placeholder;
}
// getPickerType() {
// return this.timeTypes[this.activeTime].pickerType;
// },
// getPickerPlaceholder() {
// return this.timeTypes[this.activeTime].placeholder;
// }
},
watch: {
activeTime(newVal, oldVal) {
@@ -98,49 +102,102 @@ export default {
* 年当年1月1日00:00:00 → 次年1月1日00:00:00
*/
calculateTimeRange() {
// 固定为月维度
const mode = 2;
// 初始化时间戳为0兜底值
let startTime = 0;
let endTime = 0;
const mode = this.activeTime + 1; // 1=日2=月3=年
const defaultMoment = moment(); // 默认当前时间
// 存储目标月份仅数字如10、12
let targetMonth = '';
// 默认当前月份
const defaultMoment = moment();
const targetMoment = this.date
? moment(this.date, this.getPickerType === 'date' ? 'YYYY-MM-DD' : (this.getPickerType === 'month' ? 'YYYY-MM' : 'YYYY'))
: defaultMoment;
try {
// 仅处理月份维度固定使用YYYY-MM格式解析日期
let targetMoment = this.date
? moment(this.date, 'YYYY-MM') // 解析传入的月份(如"2025-10"
: defaultMoment;
if (!targetMoment.isValid()) {
console.error('无效日期:', this.date);
return { startTime, endTime, mode };
}
// 验证日期是否有效,无效则使用当前月份兜底
if (!targetMoment.isValid()) {
console.warn('无效的月份格式请使用YYYY-MM已使用当前月份:', this.date);
targetMoment = defaultMoment;
}
// 1. 日维度00:00:00 → 23:59:59无毫秒
if (this.activeTime === 0) {
startTime = targetMoment.startOf('day').millisecond(0).valueOf();
endTime = targetMoment.endOf('day').millisecond(0).valueOf();
}
// 仅获取月份数字格式如10、12若要两位格式如01、10使用'MM'
targetMonth = targetMoment.format('M'); // 'M'是1-12'MM'是01-12可按需选择
// 2. 月维度当月1日00:00:00 → 当月最后一天23:59:59无毫秒
else if (this.activeTime === 1) {
// 打印仅含月份的结果
console.log('targetMonth', targetMonth);
// 计算当月第一天00:00:00去掉毫秒的毫秒级时间戳
startTime = targetMoment.startOf('month').millisecond(0).valueOf();
// 计算当月最后一天23:59:59去掉毫秒的毫秒级时间戳
endTime = targetMoment.endOf('month').millisecond(0).valueOf();
// 【可选】调试输出:查看时间范围详情
// console.log('月份时间范围:', {
// startTime: moment(startTime).format('YYYY-MM-DD HH:mm:ss'),
// endTime: moment(endTime).format('YYYY-MM-DD HH:mm:ss'),
// startTimeStamp: startTime,
// endTimeStamp: endTime
// });
} catch (error) {
console.error('计算月份时间范围时出错:', error);
}
// 3. 年维度当年1月1日00:00:00 → 当年最后一天23:59:59无毫秒
else if (this.activeTime === 2) {
startTime = targetMoment.startOf('year').millisecond(0).valueOf();
endTime = targetMoment.endOf('year').millisecond(0).valueOf();
}
// 调试输出:验证是否去掉毫秒
console.log('时间范围计算结果:', {
// 返回月份相关的所有信息:时间戳、维度、仅月份值
return {
startTime,
endTime,
mode,
startTime: moment(startTime * 1000).format('YYYY-MM-DD HH:mm:ss'), // 格式2025-11-30 00:00:00
endTime: moment(endTime * 1000).format('YYYY-MM-DD HH:mm:ss'), // 格式2025-11-30 23:59:59无毫秒
startTimeStamp: startTime, // 秒级时间戳1764422400
endTimeStamp: endTime // 秒级时间戳1764508799
});
return { startTime, endTime, mode };
targetMonth // 现在仅为月份数字,如"10"
};
},
// calculateTimeRange() {
// let startTime = 0;
// let endTime = 0;
// const mode = 2; // 1=日2=月3=年
// const defaultMoment = moment(); // 默认当前时间
// const targetMoment = this.date
// ? moment(this.date, this.getPickerType === 'date' ? 'YYYY-MM-DD' : (this.getPickerType === 'month' ? 'YYYY-MM' : 'YYYY'))
// : defaultMoment;
// // if (!targetMoment.isValid()) {
// // console.error('无效日期:', this.date);
// // return { startTime, endTime, mode };
// // }
// // // 1. 日维度00:00:00 → 23:59:59无毫秒
// // if (this.activeTime === 0) {
// // startTime = targetMoment.startOf('day').millisecond(0).valueOf();
// // endTime = targetMoment.endOf('day').millisecond(0).valueOf();
// // }
// // 2. 月维度当月1日00:00:00 → 当月最后一天23:59:59无毫秒
// // else if (this.activeTime === 1) {
// startTime = targetMoment.startOf('month').millisecond(0).valueOf();
// endTime = targetMoment.endOf('month').millisecond(0).valueOf();
// // }
// // // 3. 年维度当年1月1日00:00:00 → 当年最后一天23:59:59无毫秒
// // else if (this.activeTime === 2) {
// // startTime = targetMoment.startOf('year').millisecond(0).valueOf();
// // endTime = targetMoment.endOf('year').millisecond(0).valueOf();
// // }
// // // 调试输出:验证是否去掉毫秒
// // console.log('时间范围计算结果:', {
// // mode,
// // startTime: moment(startTime * 1000).format('YYYY-MM-DD HH:mm:ss'), // 格式2025-11-30 00:00:00
// // endTime: moment(endTime * 1000).format('YYYY-MM-DD HH:mm:ss'), // 格式2025-11-30 23:59:59无毫秒
// // startTimeStamp: startTime, // 秒级时间戳1764422400
// // endTimeStamp: endTime // 秒级时间戳1764508799
// // });
// return { startTime, endTime, mode };
// },
// 传递时间范围给父组件
emitTimeRange() {
@@ -182,7 +239,7 @@ export default {
/* 左侧标题区域 */
.left-content {
margin-top: 11px;
margin-left: 350px;
// margin-left: 350px;
height: 55px;
display: flex;
align-items: center;
@@ -252,7 +309,7 @@ export default {
}
.dateP .label {
width: 70px;
width: 165px;
height: 28px;
background: rgba(236, 244, 254, 1);
transform: skew(-25deg);
@@ -319,14 +376,14 @@ export default {
::v-deep .custom-date-picker {
position: absolute;
right: 8px;
width: 132px !important;
width: 165px !important;
height: 28px !important;
position: relative;
margin: 0 !important;
.el-input__inner {
height: 28px !important;
width: 132px !important;
width: 165px !important;
text-align: center;
padding-left: 15px !important;
padding-right: 32px !important;