新增页面
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<header class="report-header">
|
||||
<!-- 左侧区域:logo + 标题 -->
|
||||
<div class="left-content">
|
||||
<img style="height: 36px;" src="../../../assets/img/cnbm.png" alt="benmaLogo" >
|
||||
<img style="height: 36px;" src="../../../assets/img/cnbm.png" alt="benmaLogo">
|
||||
<div class="top-title">{{ topTitle }}</div>
|
||||
</div>
|
||||
|
||||
@@ -24,16 +24,16 @@
|
||||
|
||||
<!-- 时间选择区域:日/月/年按钮 + label + 日期选择器 -->
|
||||
<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"
|
||||
class="custom-date-picker" style="width: 132px;height: 29px;" @change="emitTimeRange" />
|
||||
<el-date-picker v-model="date" type="month" placeholder="请选择月份" class="custom-date-picker"
|
||||
style="width: 132px;height: 29px;" @change="emitTimeRange" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
@@ -52,32 +52,32 @@ export default {
|
||||
currentTime: '',
|
||||
timeTimer: null,
|
||||
date: undefined,
|
||||
activeIndex: -1,
|
||||
// activeIndex: -1,
|
||||
activeTime: 1, // 0=日,1=月,2=年(默认选中“日”)
|
||||
pageRoutes: [
|
||||
{ text: '营业收入', path: '/operatingRevenue' },
|
||||
{ text: '营业收入', path: '/operatingRevenue/operatingRevenueIndex' },
|
||||
{ text: '利润分析', path: '/profitAnalysis' },
|
||||
{ text: '产销率库存分析', path: '/PSIAnal' },
|
||||
{ text: '成本分析', path: '/cost/cost' },
|
||||
{ text: '驾驶舱报表', path: '/cockpit' }
|
||||
],
|
||||
// 定义时间类型配置:text=按钮文字,pickerType=选择器类型,placeholder=占位符
|
||||
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;
|
||||
// }
|
||||
},
|
||||
methods: {
|
||||
goToPage(path, index) {
|
||||
@@ -93,48 +93,57 @@ export default {
|
||||
* @returns {Object} 包含 start(开始时间)、end(结束时间)、dimension(维度)的区间对象
|
||||
*/
|
||||
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"
|
||||
};
|
||||
},
|
||||
/**
|
||||
* 核心方法2:传递时间区间给父组件(首次进入时触发,传递“当月第一天0点→次月第一天0点”)
|
||||
@@ -305,7 +314,7 @@ export default {
|
||||
}
|
||||
|
||||
.dateP .label {
|
||||
width: 70px;
|
||||
width: 165px;
|
||||
height: 28px;
|
||||
background: rgba(236, 244, 254, 1);
|
||||
transform: skew(-25deg);
|
||||
@@ -356,7 +365,7 @@ 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;
|
||||
@@ -364,7 +373,7 @@ export default {
|
||||
/* 1. 调整输入框文字:确保行高与输入框高度一致,垂直居中 */
|
||||
.el-input__inner {
|
||||
height: 28px !important;
|
||||
width: 132px !important;
|
||||
width: 165px !important;
|
||||
text-align: center;
|
||||
padding-left: 15px !important;
|
||||
padding-right: 32px !important;
|
||||
|
||||
Reference in New Issue
Block a user