410 lines
11 KiB
Vue
410 lines
11 KiB
Vue
<template>
|
||
<header class="report-header" :class="['report-header__' + size]">
|
||
<!-- 左侧区域:标题 -->
|
||
<div class="left-content" :style="{ marginLeft: leftMargin }">
|
||
<div class="top-title">{{ topTitle }}</div>
|
||
</div>
|
||
|
||
<!-- 右侧区域:全屏按钮 -->
|
||
<div class="right-content">
|
||
<el-dropdown trigger="click">
|
||
<el-button type="text" class="logout-btn" :title="'退出'">
|
||
<svg-icon style="color: #0B58FF;" icon-class="logout" />
|
||
</el-button>
|
||
<el-dropdown-menu slot="dropdown">
|
||
<el-dropdown-item @click.native='logout'>退出登录</el-dropdown-item>
|
||
<el-dropdown-item @click.native='handleToggle'>切换账号</el-dropdown-item>
|
||
</el-dropdown-menu>
|
||
</el-dropdown>
|
||
<el-button type="text" class="return-btn" :title="'返回'" @click="handleReturn">
|
||
<svg-icon style="color: #0B58FF;" icon-class="returnIcon" />
|
||
</el-button>
|
||
<el-button type="text" class="screen-btn" :title="isFullScreen ? '退出全屏' : '全屏'" @click="changeFullScreen">
|
||
<svg-icon style="color: #0B58FF;" v-if="isFullScreen" icon-class="unFullScreenView" />
|
||
<svg-icon style="color: #0B58FF;" v-else icon-class="fullScreenView" />
|
||
</el-button>
|
||
</div>
|
||
|
||
<!-- 时间选择区域:时间维度下拉框(月/年) + 日期选择下拉框 -->
|
||
<div class="timeType" v-if="isBudget">
|
||
<div class="dateP">
|
||
<div class="label">
|
||
<span class="label-text">时间范围</span>
|
||
</div>
|
||
<!-- 第一步:时间维度下拉框(月/年) -->
|
||
<el-select v-model="timeDimension" class="time-dimension-select" @change="handleDimensionChange"
|
||
style="width: 150px; height: 29px; margin-right: 8px;">
|
||
<el-option label="月预算" value="month" />
|
||
<el-option label="年预算" value="year" />
|
||
</el-select>
|
||
</div>
|
||
</div>
|
||
</header>
|
||
</template>
|
||
|
||
<script>
|
||
import moment from 'moment'; // 引入moment
|
||
import {getPath} from "@/utils/ruoyi";
|
||
export default {
|
||
name: 'Header',
|
||
props: {
|
||
isFullScreen: { type: Boolean, default: false },
|
||
topTitle: { type: String, default: '' },
|
||
size: { type: String, default: 'basic' },
|
||
leftMargin: {
|
||
type: [String, Number],
|
||
default: '350px' // 默认值设为350px
|
||
},
|
||
isBudget: { type: Boolean, default: false },
|
||
},
|
||
data() {
|
||
return {
|
||
currentTime: '',
|
||
timeTimer: null,
|
||
timeDimension: 'month', // 默认时间维度:月(可选值:month/year)
|
||
selectedDate: '', // 选中的日期(格式:YYYY-MM 或 YYYY)
|
||
dateOptions: [] // 日期下拉框选项(动态生成)
|
||
}
|
||
},
|
||
mounted() {
|
||
// 初始化默认时间维度和日期
|
||
// this.initDateOptions();
|
||
// 默认选中当前月/年
|
||
// if (this.timeDimension === 'month') {
|
||
// this.selectedDate = moment().format('YYYY-MM');
|
||
// } else {
|
||
// this.selectedDate = moment().format('YYYY');
|
||
// }
|
||
// this.$nextTick(() => this.emitTimeRange());
|
||
},
|
||
methods: {
|
||
changeFullScreen() {
|
||
this.$emit('screenfullChange');
|
||
},
|
||
handleReturn() {
|
||
this.$router.go(-1);
|
||
},
|
||
async logout() {
|
||
this.$modal.confirm('确定注销并退出系统吗?', '提示').then(() => {
|
||
this.$store.dispatch('LogOut').then(() => {
|
||
location.href = getPath('/index');
|
||
})
|
||
}).catch(() => {});
|
||
},
|
||
handleToggle() {
|
||
this.$store.dispatch('LogOut').then(() => {
|
||
location.href = getPath('/index');
|
||
})
|
||
},
|
||
exportPDF() {
|
||
this.$emit('exportPDF');
|
||
},
|
||
|
||
/**
|
||
* 初始化日期下拉框选项(生成近10年的年份/月份选项,可自定义范围)
|
||
*/
|
||
initDateOptions() {
|
||
this.dateOptions = [];
|
||
const currentYear = moment().year();
|
||
const range = 10; // 生成近10年的选项
|
||
|
||
if (this.timeDimension === 'month') {
|
||
// 月维度:生成近10年的所有月份(格式:YYYY-MM)
|
||
for (let y = currentYear; y >= currentYear - range; y--) {
|
||
for (let m = 12; m >= 1; m--) {
|
||
const monthStr = m < 10 ? `0${m}` : `${m}`;
|
||
const value = `${y}-${monthStr}`;
|
||
const label = `${y}年${monthStr}月`;
|
||
this.dateOptions.push({ value, label });
|
||
}
|
||
}
|
||
} else if (this.timeDimension === 'year') {
|
||
// 年维度:生成近10年的年份(格式:YYYY)
|
||
for (let y = currentYear; y >= currentYear - range; y--) {
|
||
this.dateOptions.push({
|
||
value: `${y}`,
|
||
label: `${y}年`
|
||
});
|
||
}
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 时间维度切换回调(月→年 / 年→月)
|
||
*/
|
||
handleDimensionChange() {
|
||
// 重新初始化日期选项
|
||
this.$emit('getTimeType', this. timeDimension)
|
||
},
|
||
|
||
/**
|
||
* 核心方法:根据选中的维度和日期,计算时间范围(时间戳格式)
|
||
*/
|
||
calculateTimeRange() {
|
||
// 初始化时间戳为0(兜底值)
|
||
let startTime = 0;
|
||
let endTime = 0;
|
||
// 时间维度对应mode(2=月,3=年,保持和原有逻辑一致)
|
||
const mode = this.timeDimension === 'month' ? 2 : 3;
|
||
// 默认当前时间
|
||
const defaultMoment = moment();
|
||
|
||
try {
|
||
let targetMoment;
|
||
// 根据维度解析选中的日期
|
||
if (this.timeDimension === 'month') {
|
||
targetMoment = this.selectedDate ? moment(this.selectedDate, 'YYYY-MM') : defaultMoment;
|
||
} else {
|
||
targetMoment = this.selectedDate ? moment(this.selectedDate, 'YYYY') : defaultMoment;
|
||
}
|
||
|
||
// 验证日期是否有效,无效则使用当前时间兜底
|
||
if (!targetMoment.isValid()) {
|
||
console.warn('无效的日期格式,已使用当前时间:', this.selectedDate);
|
||
targetMoment = defaultMoment;
|
||
}
|
||
|
||
// 根据维度计算时间范围
|
||
if (this.timeDimension === 'month') {
|
||
// 月维度:当月第一天00:00:00 → 当月最后一天23:59:59
|
||
startTime = targetMoment.startOf('month').millisecond(0).valueOf();
|
||
endTime = targetMoment.endOf('month').millisecond(0).valueOf();
|
||
} else if (this.timeDimension === 'year') {
|
||
// 年维度:当年第一天00:00:00 → 当年最后一天23:59:59
|
||
startTime = targetMoment.startOf('year').millisecond(0).valueOf();
|
||
endTime = targetMoment.endOf('year').millisecond(0).valueOf();
|
||
}
|
||
} catch (error) {
|
||
console.error('计算时间范围时出错:', error);
|
||
}
|
||
|
||
// 返回时间范围信息
|
||
return {
|
||
startTime,
|
||
endTime,
|
||
mode
|
||
};
|
||
},
|
||
|
||
// 传递时间范围给父组件
|
||
// emitTimeRange() {
|
||
// const timeRange = this.calculateTimeRange();
|
||
// this.$emit('timeRangeChange', timeRange);
|
||
// }
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
/* 字体引入 */
|
||
@font-face {
|
||
font-family: "YouSheBiaoTiHei";
|
||
src: url('../../../assets/fonts/YouSheBiaoTiHe.ttf') format('truetype');
|
||
}
|
||
|
||
/* 头部容器基础样式 */
|
||
.report-header {
|
||
height: 117px;
|
||
width: 100%;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
box-sizing: border-box;
|
||
position: relative;
|
||
|
||
&__basic {
|
||
background: url(../../../assets/img/topBg.png) no-repeat;
|
||
background-size: cover;
|
||
background-position: 0 0;
|
||
}
|
||
|
||
&__psi {
|
||
background: url(../../../assets/img/psiTopTitle.png) no-repeat;
|
||
background-size: 100% 100%;
|
||
background-position: 0 0;
|
||
}
|
||
|
||
/* 左侧标题区域 */
|
||
.left-content {
|
||
margin-top: 11px;
|
||
// margin-left: 350px;
|
||
height: 55px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
}
|
||
|
||
.top-title {
|
||
height: 55px;
|
||
font-family: "YouSheBiaoTiHei", sans-serif;
|
||
font-size: 42px;
|
||
color: #1E1651;
|
||
line-height: 55px;
|
||
letter-spacing: 6px;
|
||
text-align: left;
|
||
}
|
||
|
||
/* 时间选择区域 */
|
||
.timeType {
|
||
position: absolute;
|
||
display: flex;
|
||
align-items: center;
|
||
top: 42px;
|
||
right: 0px;
|
||
margin-top: 18px;
|
||
gap: 0;
|
||
}
|
||
|
||
.timeType .item {
|
||
width: 50px;
|
||
height: 28px;
|
||
background: rgba(236, 244, 254, 1);
|
||
transform: skew(-25deg);
|
||
font-family: PingFangSC, PingFang SC;
|
||
font-weight: 400;
|
||
font-size: 14px;
|
||
color: rgba(11, 88, 255, 1);
|
||
line-height: 28px;
|
||
letter-spacing: 2px;
|
||
text-align: center;
|
||
cursor: pointer;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.timeType .item .item-text {
|
||
display: inline-block;
|
||
transform: skew(25deg);
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.timeType .item.no-skew {
|
||
background: rgba(11, 88, 255, 1);
|
||
color: rgba(249, 252, 255, 1);
|
||
transform: skew(-25deg) !important;
|
||
box-shadow: 0 2px 8px rgba(11, 88, 255, 0.3);
|
||
}
|
||
|
||
.timeType .item.no-skew .item-text {
|
||
transform: skew(25deg) !important;
|
||
}
|
||
|
||
.dateP {
|
||
position: relative;
|
||
margin-left: 10px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0;
|
||
}
|
||
|
||
.dateP .label {
|
||
width: 165px;
|
||
height: 28px;
|
||
background: rgba(236, 244, 254, 1);
|
||
transform: skew(-25deg);
|
||
font-family: PingFangSC, PingFang SC;
|
||
font-weight: 400;
|
||
font-size: 14px;
|
||
color: #0B58FF;
|
||
line-height: 28px;
|
||
text-align: center;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.dateP .label-text {
|
||
display: inline-block;
|
||
transform: skew(25deg);
|
||
}
|
||
|
||
/* 右侧全屏按钮区域 */
|
||
.right-content {
|
||
display: flex;
|
||
// flex-direction: column;
|
||
margin-top: 12px;
|
||
margin-right: 10px;
|
||
gap: 21px;
|
||
height: 35px;
|
||
}
|
||
|
||
// .current-time {
|
||
// color: #FFFFFF;
|
||
// font-family: PingFangSC, PingFang SC;
|
||
// font-weight: 500;
|
||
// font-size: 22px;
|
||
// line-height: 24px;
|
||
// letter-spacing: 1px;
|
||
// }
|
||
|
||
.screen-btn {
|
||
width: 26px;
|
||
height: 26px;
|
||
color: #00fff0;
|
||
font-size: 26px;
|
||
padding: 0;
|
||
}
|
||
|
||
.home-btn {
|
||
width: 26px;
|
||
height: 26px;
|
||
// margin-left: 300px;
|
||
color: #00fff0;
|
||
font-size: 26px;
|
||
padding: 0;
|
||
margin: 0;
|
||
}
|
||
|
||
.return-btn {
|
||
width: 26px;
|
||
height: 26px;
|
||
// margin-left: 300px;
|
||
color: #00fff0;
|
||
font-size: 26px;
|
||
padding: 0;
|
||
}
|
||
|
||
.logout-btn {
|
||
width: 28px;
|
||
height: 28px;
|
||
font-size: 28px;
|
||
padding: 0;
|
||
}
|
||
}
|
||
|
||
/* 自定义下拉框样式(替换原有日期选择器样式) */
|
||
::v-deep .time-dimension-select,
|
||
::v-deep .custom-date-select {
|
||
height: 28px !important;
|
||
|
||
.el-input__inner {
|
||
height: 28px !important;
|
||
font-size: 14px !important;
|
||
line-height: 28px !important;
|
||
color: #fff !important;
|
||
background-color: rgba(11, 88, 255, 1) !important;
|
||
border: none !important;
|
||
box-shadow: none !important;
|
||
text-align: center;
|
||
}
|
||
|
||
.el-input__icon {
|
||
color: #fff !important;
|
||
font-size: 16px !important;
|
||
line-height: 28px !important;
|
||
}
|
||
|
||
.el-select-dropdown__item {
|
||
font-size: 14px !important;
|
||
padding: 6px 16px !important;
|
||
}
|
||
}
|
||
|
||
/* 时间维度下拉框额外样式 */
|
||
::v-deep .time-dimension-select .el-input__inner {
|
||
border-right: 1px solid rgba(255, 255, 255, 0.2) !important;
|
||
border-radius: 4px 0 0 4px !important;
|
||
}
|
||
|
||
/* 日期选择下拉框额外样式 */
|
||
::v-deep .custom-date-select .el-input__inner {
|
||
border-radius: 0 4px 4px 0 !important;
|
||
}
|
||
</style>
|