Files
yudao-dev/src/views/home/components/noRouterHeader.vue
2026-03-05 16:09:07 +08:00

408 lines
10 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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">
<div class="dateP">
<div class="label">
<span class="label-text">月份选择</span>
</div>
<el-date-picker v-model="date" type="month" placeholder="请选择月份" class="custom-date-picker"
value-format="timestamp" :clearable="false" style="width: 132px;height: 29px;" @change="emitTimeRange" />
</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
},
dateData: {
type: Object,
default: () => ({})
},
},
data() {
return {
currentTime: '',
timeTimer: null,
date: Date.now(), // 使用当前时间戳作为初始值
activeTime: 1, // 默认月维度0=日1=月2=年)
}
},
watch: {
activeTime(newVal, oldVal) {
if (newVal !== oldVal) {
this.date = Date.now();
this.emitTimeRange();
}
},
dateData: {
immediate: true, // 初始化时立即执行
handler(newVal) {
console.log('dateData 变化:', newVal);
if (newVal && (newVal.startTime || newVal.endTime)) {
// 优先使用 startTime如果没有则使用 endTime
const timeStamp = newVal.startTime || newVal.endTime;
if (timeStamp && timeStamp !== 0) {
console.log('设置日期选择器时间为:', timeStamp);
this.date = timeStamp; // 直接使用时间戳
}
}
}
}
},
mounted() {
// 初始化默认日期为当前月份
console.log('初始化日期选择器,当前时间戳:', this.date);
this.$nextTick(() => {
this.emitTimeRange();
});
},
beforeDestroy() {
// 清理定时器
if (this.timeTimer) {
clearInterval(this.timeTimer);
}
},
methods: {
changeFullScreen() {
this.$emit('screenfullChange');
},
handleReturn() {
console.log('返回上一页');
if (this.$router) {
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');
})
},
/**
* 计算时间范围(时间戳格式)
* 固定为月维度当月1日00:00:00 → 当月最后一天23:59:59
*/
calculateTimeRange() {
// 固定为月维度
const mode = 2;
// 初始化时间戳为0兜底值
let startTime = 0;
let endTime = 0;
// 存储目标月份仅数字如10、12
let targetMonth = '';
try {
// 使用 this.date时间戳创建 moment 对象
let targetMoment = this.date
? moment(this.date)
: moment(); // 如果 date 无效,使用当前时间
// 验证日期是否有效
if (!targetMoment.isValid()) {
console.warn('无效的日期,已使用当前月份:', this.date);
targetMoment = moment();
}
// 获取月份数字格式1-12
targetMonth = targetMoment.format('M');
console.log('当前选择的月份:', targetMonth);
// 计算当月第一天00:00:00的时间戳
startTime = targetMoment.startOf('month').valueOf();
// 计算当月最后一天23:59:59的时间戳
endTime = targetMoment.clone()
.endOf('month')
.set({
hour: 23,
minute: 59,
second: 59,
millisecond: 0 // 毫秒设为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,
targetMonth: targetMonth
});
} catch (error) {
console.error('计算月份时间范围时出错:', error);
}
// 返回月份相关的所有信息:时间戳、维度、月份值
return {
startTime,
endTime,
mode,
targetMonth
};
},
// 传递时间范围给父组件
emitTimeRange() {
const timeRange = this.calculateTimeRange();
console.log('触发时间范围变化:', timeRange);
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;
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;
margin-top: 12px;
margin-right: 10px;
gap: 21px;
height: 35px;
}
.screen-btn {
width: 26px;
height: 26px;
color: #00fff0;
font-size: 26px;
padding: 0;
margin: 0;
}
.home-btn {
width: 26px;
height: 26px;
color: #00fff0;
font-size: 26px;
padding: 0;
}
.return-btn {
width: 26px;
height: 26px;
color: #00fff0;
font-size: 26px;
padding: 0;
}
.logout-btn {
width: 28px;
height: 28px;
font-size: 28px;
padding: 0;
}
}
/* 日期选择器自定义样式 */
::v-deep .custom-date-picker {
position: absolute;
right: 8px;
width: 165px !important;
height: 28px !important;
position: relative;
margin: 0 !important;
.el-input__inner {
height: 28px !important;
width: 165px !important;
text-align: center;
padding-left: 15px !important;
padding-right: 32px !important;
font-size: 14px !important;
line-height: 28px !important;
color: rgba(237, 245, 253, 1) !important;
vertical-align: middle !important;
clip-path: polygon(18px 0, 100% 0, 100% 100%, 0 100%);
border: none !important;
box-shadow: none !important;
background-color: rgba(11, 88, 255, 1) !important;
border-left: 1px solid rgba(255, 255, 255, 0.2);
}
.el-input__prefix {
left: auto !important;
right: 8px !important;
top: 50% !important;
transform: translateY(-50%) !important;
display: inline-flex !important;
align-items: center !important;
height: 28px !important;
}
.el-input__icon {
color: #ffffff !important;
font-size: 16px !important;
line-height: 28px !important;
vertical-align: middle !important;
}
.el-icon-date::before {
color: #ffffff !important;
font-size: 16px !important;
line-height: inherit !important;
}
}
</style>