This commit is contained in:
‘937886381’
2026-01-07 16:47:49 +08:00
parent 51e66cf6e1
commit b76f3bfd37
164 changed files with 4179 additions and 2297 deletions

View File

@@ -6,16 +6,12 @@
<div class="top-title">{{ topTitle }}</div>
</div>
<div class="center-content">
<!-- 循环 pageRoutes不再硬编码文字 -->
<!-- <div class="item" v-for="(page, index) in pageRoutes" :key="index" @click="goToPage(page.path, index)">
<span class="item-text">{{ page.text }}</span>
</div> -->
</div>
<!-- :class="{ 'no-skew': activeIndex === index }
" -->
<!-- 右侧区域全屏按钮 -->
<div class="right-content">
<el-button type="text" class="screen-btn" @click="changeHomeSider">
<svg-icon style="color: #0B58FF;" v-if="openSider" icon-class="closeSider" />
<svg-icon style="color: #0B58FF;" v-else icon-class="openSider" />
</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" />
@@ -24,16 +20,15 @@
<!-- 时间选择区域//年按钮 + label + 日期选择器 -->
<div class="timeType">
<!-- <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 class="dateP">
<div class="label">
<span class="label-text">月份选择</span>
</div>
<el-date-picker :clearable="false" v-model="date" type="month" placeholder="请选择月份" class="custom-date-picker"
style="width: 132px;height: 29px;" @change="emitTimeRange" />
value-format="timestamp"
style="width: 132px;height: 29px;"
@change="emitTimeRange"
/>
</div>
</div>
</header>
@@ -45,19 +40,19 @@ export default {
name: 'Header',
props: {
isFullScreen: { type: Boolean, default: false },
openSider: { type: Boolean, default: false },
topTitle: { type: String, default: '' },
dateData: {
type: Object,
default: {} // 默认值设为350px
default: () => ({})
},
},
data() {
return {
currentTime: '',
timeTimer: null,
date: undefined,
// activeIndex: -1,
activeTime: 1, // 0=日1=月2=年(默认选中“日”)
date: Date.now(), // 使用时间戳格式
activeTime: 1, // 0=日1=月2=年(默认选中"月"
pageRoutes: [
{ text: '营业收入', path: '/operatingRevenue/operatingRevenueIndex' },
{ text: '利润分析', path: '/profitAnalysis' },
@@ -65,132 +60,109 @@ export default {
{ text: '成本分析', path: '/cost/cost' },
{ text: '驾驶舱报表', path: '/cockpit' }
],
// 定义时间类型配置text=按钮文字pickerType=选择器类型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;
// }
},
methods: {
goToPage(path, index) {
// 1. 跳转到对应路由
this.$router.push(path);
// 2. 更新activeIndex让当前点击项高亮
this.activeIndex = index;
},
changeHomeSider() { this.$emit('siderOpenChange') },
changeFullScreen() { this.$emit('screenfullChange') },
padZero(num) { return num < 10 ? '0' + num : num },
/**
* 核心方法1根据维度计算时间区间首次进入时基于赋值的当月日期计算“当月第一天0点→次月第一天0点”
* @returns {Object} 包含 start开始时间、end结束时间、dimension维度的区间对象
*/
* 计算时间区间
* @returns {Object} 包含 startTime、endTime、mode、targetMonth 的区间对象
*/
calculateTimeRange() {
// 固定为月维度
const mode = 2;
// 初始化时间戳为0兜底值
let startTime = 0;
let endTime = 0;
// 存储目标月份仅数字如10、12
// 存储目标月份
let targetMonth = '';
// 默认当前月份
const defaultMoment = moment();
try {
// 仅处理月份维度固定使用YYYY-MM格式解析日期
// 使用 this.date时间戳创建 moment 对象
let targetMoment = this.date
? moment(this.date, 'YYYY-MM') // 解析传入的月份(如"2025-10"
: defaultMoment;
? moment(this.date) // 解析时间戳
: moment(); // 如果 date 无效,使用当前时间
// 验证日期是否有效,无效则使用当前月份兜底
// 验证日期是否有效
if (!targetMoment.isValid()) {
console.warn('无效的月份格式请使用YYYY-MM,已使用当前月份:', this.date);
targetMoment = defaultMoment;
console.warn('无效的日期,已使用当前月份:', this.date);
targetMoment = moment();
}
// 获取月份(数字格式,如10、12若要两位格式如01、10使用'MM'
targetMonth = targetMoment.format('M'); // 'M'是1-12'MM'是01-12可按需选择
// 获取月份(数字格式,1-12
targetMonth = targetMoment.format('M');
console.log('当前选择的月份:', targetMonth);
// 打印仅含月份的结果
console.log('targetMonth', targetMonth);
// 计算当月第一天00:00:00的时间戳
startTime = targetMoment.startOf('month').valueOf();
// 计算当月最后一天23:59:59的时间戳
endTime = targetMoment.endOf('month').valueOf();
// 计算当月第一天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
// });
// 调试输出
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 // 现在仅为月份数字,如"10"
targetMonth
};
},
/**
* 核心方法2传递时间区间给父组件首次进入时触发传递“当月第一天0点→次月第一天0点”
* 传递时间区间给父组件
*/
emitTimeRange() {
const timeRange = this.calculateTimeRange();
this.$emit('timeRangeChange', timeRange);
// 调试用:查看首次传递的区间(如{start: "2025-10-01T00:00:00", end: "2025-11-01T00:00:00", dimension: "月"}
console.log('当前时间区间:', timeRange);
console.log('触发时间范围变化:', timeRange);
}
},
watch: {
// 维度切换时:清空选择的日期,并传递当前维度的默认区间
// 维度切换时:清空选择的日期
activeTime(newVal, oldVal) {
if (newVal !== oldVal) {
this.date = undefined;
// this.emitTimeRange();
this.date = Date.now(); // 重置为当前时间戳
this.emitTimeRange();
}
},
dateData: {
immediate: true, // 初始化时立即执行
handler(newVal) {
console.log('dateData 变化:', newVal);
if (newVal && (newVal.startTime || newVal.endTime)) {
// 优先使用 startTime 转换为月份格式
// 优先使用 startTime
const timeStamp = newVal.startTime || newVal.endTime;
if (timeStamp !== 0) {
const monthStr = moment(timeStamp).format('YYYY-MM');
this.date = monthStr; // 赋值给选择器
if (timeStamp && timeStamp !== 0) {
console.log('设置日期选择器时间为:', timeStamp);
this.date = timeStamp; // 直接使用时间戳
}
}
}
}
},
mounted() {
// 核心逻辑:首次进入页面,计算当月默认日期并赋值给选择器,同时传递区间
const now = new Date();
const year = now.getFullYear();
const month = this.padZero(now.getMonth() + 1); // 月份从0开始+1后补零如1月→01
// 赋值当月默认日期格式YYYY-MM适配month类型选择器
this.date = `${year}-${month}`;
// 确保选择器渲染完成后传递“当月第一天0点→次月第一天0点”的区间
this.$nextTick(() => this.emitTimeRange());
},
// 初始化默认日期为当前月份
console.log('初始化日期选择器,当前时间戳:', this.date);
this.$nextTick(() => {
this.emitTimeRange();
});
}
}
</script>
@@ -211,7 +183,6 @@ export default {
background-position: 0 0;
box-sizing: border-box;
position: relative;
/* 确保timeType绝对定位生效 */
.left-content {
margin-top: 11px;
@@ -278,12 +249,10 @@ export default {
position: absolute;
display: flex;
align-items: center;
/* 垂直居中,避免元素高低错位 */
top: 42px;
right:10px;
right: 10px;
margin-top: 18px;
gap: 0;
/* 清除间隙,让按钮与选择器紧密连接 */
}
.timeType .item {
@@ -300,7 +269,6 @@ export default {
text-align: center;
cursor: pointer;
overflow: hidden;
/* 选中按钮与未选中按钮倾斜角度统一,避免切换时跳动 */
}
.timeType .item .item-text {
@@ -313,13 +281,11 @@ export default {
background: rgba(11, 88, 255, 1);
color: rgba(249, 252, 255, 1);
transform: skew(-20deg) !important;
/* 统一倾斜角度修复原30deg的错位 */
box-shadow: 0 2px 8px rgba(11, 88, 255, 0.3);
}
.timeType .item.no-skew .item-text {
transform: skew(20deg) !important;
/* 同步统一文字倾斜角度 */
}
.dateP {
@@ -335,7 +301,6 @@ export default {
height: 28px;
background: rgba(236, 244, 254, 1);
transform: skew(-25deg);
/* 与按钮倾斜角度统一原30deg改为25deg避免视觉错位 */
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 14px;
@@ -345,19 +310,17 @@ export default {
overflow: hidden;
}
/* 补充label文字抵消倾斜原代码遗漏导致文字倾斜 */
.dateP .label-text {
display: inline-block;
transform: skew(25deg);
/* 与label倾斜角度相反确保文字正立 */
}
.right-content {
display: flex;
flex-direction: column;
margin-top: 12px;
margin-bottom: 60px;
margin-right: 16px;
gap: 20px;
justify-content: flex-end;
gap: 10px;
}
.current-time {
@@ -371,7 +334,6 @@ export default {
.screen-btn {
width: 26px;
margin-left: 300px;
color: #00fff0;
font-size: 26px;
padding: 0;
@@ -387,20 +349,16 @@ export default {
position: relative;
margin: 0 !important;
/* 1. 调整输入框文字:确保行高与输入框高度一致,垂直居中 */
.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;
@@ -408,38 +366,27 @@ export default {
border-left: 1px solid rgba(255, 255, 255, 0.2);
}
/* 2. 调整图标容器:让图标与文字在同一水平线上 */
.el-input__prefix {
left: auto !important;
right: 8px !important;
top: 50% !important;
/* 从40%改为50%,基于输入框垂直居中 */
transform: translateY(-50%) !important;
/* 向上偏移自身50%,精准居中 */
display: inline-flex !important;
/* 让容器内图标垂直居中 */
align-items: center !important;
/* 图标在容器内垂直居中 */
height: 28px !important;
/* 容器高度=输入框高度,避免偏移 */
}
/* 3. 调整图标本身:确保图标大小和对齐方式 */
.el-input__icon {
color: #ffffff !important;
font-size: 16px !important;
line-height: 28px !important;
/* 图标行高=输入框高度,与文字对齐 */
vertical-align: middle !important;
/* 强制图标垂直对齐 */
}
/* 4. 图标伪类:确保颜色和对齐继承 */
.el-icon-date::before {
color: #ffffff !important;
font-size: 16px !important;
line-height: inherit !important;
/* 继承父级行高,避免错位 */
}
}
</style>

View File

@@ -97,21 +97,11 @@ export default {
overflow: 'break',
formatter: (value) => {
const dateParts = value.split('-'); // ["2025", "07", "01"]
if (dateParts.length < 2) return value; // 处理异常格式
if (dateParts.length < 2) return value;
switch (this.dateData.mode) {
case 1: // 日模式,显示“月-日”
// 确保有日的部分
return dateParts.length >= 3
? `${dateParts[1]}${dateParts[2]}`
: `${dateParts[1]}`; // fallback
case 2: // 月模式,显示“月”
return `${dateParts[1]}`;
case 3: // 年模式,显示“年”
return `${dateParts[1]}`;
default: // 默认月模式
return `${dateParts[1]}`;
}
// 去掉月份前面的0然后加上"月"
const month = dateParts[1].replace(/^0+/, '');
return `${month}`;
}
},
data: this.xAxisData

View File

@@ -18,17 +18,12 @@
<!-- 时间选择区域//年按钮 + 日期选择器 -->
<div class="timeType">
<!-- <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 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="yyyy-MM-dd" :clearable="false" style="width: 132px;height: 29px;"
@change="emitTimeRange" />
<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>
@@ -49,76 +44,65 @@ export default {
},
dateData: {
type: Object,
default: {} // 默认值设为350px
default: () => ({})
},
},
data() {
return {
currentTime: '',
timeTimer: null,
date: undefined, // 存储选择的日期字符串格式yyyy-MM-dd/yyyy-MM/yyyy
date: Date.now(), // 使用当前时间戳作为初始值
activeTime: 1, // 默认月维度0=日1=月2=年)
// 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;
// }
},
watch: {
activeTime(newVal, oldVal) {
if (newVal !== oldVal) {
this.date = undefined;
// this.emitTimeRange();
this.date = Date.now();
this.emitTimeRange();
}
},
dateData: {
immediate: true, // 初始化时立即执行
handler(newVal) {
console.log('newVal', newVal);
console.log('dateData 变化:', newVal);
if (newVal && (newVal.startTime || newVal.endTime)) {
// 优先使用 startTime 转换为月份格式
// 优先使用 startTime,如果没有则使用 endTime
const timeStamp = newVal.startTime || newVal.endTime;
if (timeStamp !== 0) {
const monthStr = moment(timeStamp).format('YYYY-MM');
this.date = monthStr; // 赋值给选择器
if (timeStamp && timeStamp !== 0) {
console.log('设置日期选择器时间为:', timeStamp);
this.date = timeStamp; // 直接使用时间戳
}
}
}
}
},
mounted() {
// 初始化默认日期当前月格式yyyy-MM
// console.log(this.$router);
this.date = moment().format('YYYY-MM');
this.$nextTick(() => this.emitTimeRange());
// 初始化默认日期当前月
console.log('初始化日期选择器,当前时间戳:', this.date);
this.$nextTick(() => {
this.emitTimeRange();
});
},
beforeDestroy() {
// 清理定时器
if (this.timeTimer) {
clearInterval(this.timeTimer);
}
},
methods: {
changeFullScreen() {
this.$emit('screenfullChange');
},
handleReturn() {
console.log(this.$router);
this.$router.go(-1);
},
exportPDF() {
this.$emit('exportPDF');
console.log('返回上一页');
if (this.$router) {
this.$router.go(-1);
}
},
/**
* 核心方法用moment计算时间范围(时间戳格式)
* 日:选择日00:00:00 → 次日00:00:00
* 月当月1日00:00:00 → 次月1日00:00:00
* 年当年1月1日00:00:00 → 次年1月1日00:00:00
* 计算时间范围(时间戳格式)
* 固定为月维度当月1日00:00:00 → 当月最后一天23:59:59
*/
calculateTimeRange() {
// 固定为月维度
@@ -128,99 +112,53 @@ export default {
let endTime = 0;
// 存储目标月份仅数字如10、12
let targetMonth = '';
// 默认当前月份
const defaultMoment = moment();
try {
// 仅处理月份维度固定使用YYYY-MM格式解析日期
// 使用 this.date时间戳创建 moment 对象
let targetMoment = this.date
? moment(this.date, 'YYYY-MM') // 解析传入的月份(如"2025-10"
: defaultMoment;
? moment(this.date)
: moment(); // 如果 date 无效,使用当前时间
// 验证日期是否有效,无效则使用当前月份兜底
// 验证日期是否有效
if (!targetMoment.isValid()) {
console.warn('无效的月份格式请使用YYYY-MM,已使用当前月份:', this.date);
targetMoment = defaultMoment;
console.warn('无效的日期,已使用当前月份:', this.date);
targetMoment = moment();
}
// 获取月份(数字格式,如10、12若要两位格式如01、10使用'MM'
targetMonth = targetMoment.format('M'); // 'M'是1-12'MM'是01-12可按需选择
// 获取月份(数字格式,1-12
targetMonth = targetMoment.format('M');
console.log('当前选择的月份:', targetMonth);
// 打印仅含月份的结果
console.log('targetMonth', targetMonth);
// 计算当月第一天00:00:00的时间戳
startTime = targetMoment.startOf('month').valueOf();
// 计算当月最后一天23:59:59的时间戳
endTime = targetMoment.endOf('month').valueOf();
// 计算当月第一天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
// });
// 调试输出
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 // 现在仅为月份数字,如"10"
targetMonth
};
},
// 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() {
const timeRange = this.calculateTimeRange();
console.log('触发时间范围变化:', timeRange);
this.$emit('timeRangeChange', timeRange);
}
}
@@ -258,7 +196,6 @@ export default {
/* 左侧标题区域 */
.left-content {
margin-top: 11px;
// margin-left: 350px;
height: 55px;
display: flex;
align-items: center;
@@ -347,48 +284,36 @@ export default {
}
/* 右侧全屏按钮区域 */
.right-content {
display: flex;
// flex-direction: column;
margin-top: 12px;
margin-right: 10px;
gap: 21px;
}
.right-content {
display: flex;
margin-top: 12px;
margin-right: 10px;
gap: 21px;
}
// .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;
}
.screen-btn {
width: 26px;
height: 26px;
color: #00fff0;
font-size: 26px;
padding: 0;
}
.home-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;
}
.return-btn {
width: 26px;
height: 26px;
// margin-left: 300px;
color: #00fff0;
font-size: 26px;
padding: 0;
}
.return-btn {
width: 26px;
height: 26px;
color: #00fff0;
font-size: 26px;
padding: 0;
}
}
/* 日期选择器自定义样式 */

View File

@@ -115,27 +115,18 @@ export default {
color: 'rgba(0, 0, 0, 0.45)',
fontSize: 12,
interval: 0,
// 这里可以根据需要调整标签的显示方式
// width: 38,
overflow: 'break',
formatter: (value) => {
const dateParts = value.split('-'); // ["2025", "07", "01"]
if (dateParts.length < 2) return value; // 处理异常格式
if (dateParts.length < 2) return value;
switch (this.dateData.mode) {
case 1: // 日模式,显示“月-日”
// 确保有日的部分
return dateParts.length >= 3
? `${dateParts[1]}${dateParts[2]}`
: `${dateParts[1]}`; // fallback
case 2: // 月模式,显示“月”
return `${dateParts[1]}`;
case 3: // 年模式,显示“年”
return `${dateParts[0]}`;
default: // 默认月模式
return `${dateParts[1]}`;
}
// 去掉月份前面的0然后加上"月"
const month = dateParts[1].replace(/^0+/, '');
return `${month}`;
}
},
data: xAxisData // 使用提取出的 X 轴数据
data: xAxisData
}
],
yAxis: {

View File

@@ -25,7 +25,7 @@
<!-- 进度条同步绑定类名 -->
<div class="progress-group">
<div class="progress-container">
<div class="progress-bar" :style="{ width: item.progress + '%' }" :class="{
<div class="progress-bar" :style="{ width: item.progressWidth + '%' }" :class="{
'bar-exceed': item.currentValue >= item.targetValue,
'bar-below': item.currentValue < item.targetValue
}"></div>
@@ -42,7 +42,7 @@
'percent-exceed': item.currentValue >= item.targetValue,
'percent-below': item.currentValue < item.targetValue
}">
{{ item.progress }}%
{{ item.progressDisplay }}
</div>
</div>
</div>
@@ -88,29 +88,101 @@ export default {
}
},
methods: {
// 解析rate字符串提取百分比数值
parseRateString(rateStr) {
if (!rateStr || typeof rateStr !== 'string') {
return { displayText: '0%', progressValue: 0 };
}
// 尝试匹配百分比数字,如"减亏93%"中的93
const match = rateStr.match(/(\d+(\.\d+)?)%/);
if (match) {
const percentValue = parseFloat(match[1]);
return {
displayText: rateStr, // 保持原字符串显示
progressValue: percentValue // 提取的百分比数值用于进度条
};
}
// 如果没有匹配到百分比,尝试解析纯数字
const numMatch = rateStr.match(/\d+(\.\d+)?/);
if (numMatch) {
const numValue = parseFloat(numMatch[0]);
return {
displayText: rateStr,
progressValue: numValue
};
}
// 默认返回
return {
displayText: '0%',
progressValue: 0
};
},
transformData(rawData) {
// 定义指标映射关系,包括名称、对应的数据键和路由
const Mapping = [
{ key: 'operatingRevenue', name: '营业收入·万元', route: '/operatingRevenue/operatingRevenueIndex' },
{ key: 'operatingIncome', name: '经营性利润·万元', route: '/operatingProfit/operatingProfit' },
{ key: 'totalProfit', name: '利润总额·万元', route: '/totalProfit/totalProfit' },
{ key: 'grossMargin', name: '毛利率·%', route: '/grossMargin/grossMargin' }
{
key: 'operatingRevenue',
name: '营业收入·万元',
route: '/operatingRevenue/operatingRevenueIndex',
isPercentage: true // 需要加%符号
},
{
key: 'operatingIncome',
name: '经营性利润·万元',
route: '/operatingProfit/operatingProfit',
isPercentage: false // 不需要加%符号使用原始rate字符串
},
{
key: 'totalProfit',
name: '利润总额·万元',
route: '/totalProfit/totalProfit',
isPercentage: false // 不需要加%符号使用原始rate字符串
},
{
key: 'grossMargin',
name: '毛利率·%',
route: '/grossMargin/grossMargin',
isPercentage: true // 需要加%符号
}
];
// 遍历映射关系,转换数据
return Mapping.map(mappingItem => {
// 关键修复3兜底更严谨避免rawData[mappingItem.key]不存在导致报错
const data = rawData[mappingItem.key] || { rate: 0, real: 0, target: 0 };
const data = rawData[mappingItem.key] || { rate: '0%', real: 0, target: 0 };
// 额外兜底避免data中的属性为undefined
const target = data.target || 0;
const real = data.real || 0;
const rate = data.rate || 0;
const rate = data.rate || '0%';
// 解析rate字符串
const parsedRate = this.parseRateString(rate);
// 进度条宽度限制在0-100之间
const progressWidth = Math.min(Math.max(parsedRate.progressValue, 0), 100);
// 显示文本处理
let progressDisplay;
if (mappingItem.isPercentage) {
// 对于需要加%的指标,确保有%符号
progressDisplay = parsedRate.displayText.includes('%')
? parsedRate.displayText
: `${parsedRate.displayText}%`;
} else {
// 对于经营性利润和利润总额直接使用原始rate字符串
progressDisplay = parsedRate.displayText;
}
return {
name: mappingItem.name,
targetValue: target,
currentValue: real,
progress: Math.round(rate), // 将小数率转换为百分比并四舍五入
progressWidth: progressWidth, // 用于进度条宽度
progressDisplay: progressDisplay, // 用于显示文本
route: mappingItem.route
};
});