Commit 2c0c6452 by Lin

feat: 策略分析页面接口对齐/补充日期筛选组件

1 parent d74ffebc
<template>
<div class="dashboard-page">
<!-- 1. 顶部导航栏 -->
<header-custom
v-model="currentTab"
:tabs="tabs"
></header-custom>
<div class="top-header-wrapper">
<header-custom
v-model="currentTab"
:tabs="tabs"
></header-custom>
<calendar-custom
v-model="timeRangeType"
:time-range-options="timeRangeOptions"
:date-range.sync="dateRange"
:date-format="dateFormat"
@time-range-change="handleTimeRangeChange"
@date-range-change="handleDateRangeChange"
/>
</div>
<div class="content-area">
<!-- 2. KPI 核心指标 -->
<div class="top-content">
......@@ -188,16 +198,19 @@
<script>
import HeaderCustom from '../strategyCentre/compoments/headerCustom.vue';
import SelectCustom from '../strategyCentre/compoments/selectCustom.vue';
import calendarCustom from '../strategyCentre/compoments/clendarCustom.vue';
import * as echarts from 'echarts';
import { getBIMatterList,getStrategyTotal,getStrategyTypeDist,getStrategyOnlineDist,getMonitorList, getMonitorTypeDictList } from "@/api/earlyWarningManager";
import { Util, deepClone } from "@/common/util";
import dayjs from 'dayjs';
import log from '../../../libs/util.log';
export default {
name: 'strategyAnalysis',
components: {
HeaderCustom,
SelectCustom
SelectCustom,
calendarCustom
},
data() {
return {
......@@ -205,25 +218,21 @@ export default {
tabs: [
{label:'延保',value:1},
],
// KPI 指标数据列表
kpiList: [
{
label: '策略总数',
value: 3456,
unit: '个',
subLabel: '本月策略总数',
subValue: '200个',
trendClass: 'trend-up'
},
{
label: '门店总数',
value: 567,
unit: '家',
subLabel: '本月门店总数',
subValue: '200个',
trendClass: 'trend-up'
}
// 时间范围类型
timeRangeType: { label: '周', value: 1 },
timeRangeOptions: [
{ label: '周', value: 1 },
{ label: '月', value: 2 },
{ label: '自定义', value: 4 }
],
// 日期范围
dateRange: {
startDate: null,
endDate: null
},
dateFormat: 'YYYY-MM-DD', // 日期格式化模式
// KPI 指标数据列表
kpiList: [],
operatorFilter: 'all',
myChart: null,
// 日期范围
......@@ -652,6 +661,7 @@ export default {
value: item.value !== undefined ? item.value : item.label
};
// 这里可以触发数据更新逻辑
this.getIndicatorTypeList();
console.log('选择指标类型:', item.label);
},
/**
......@@ -693,14 +703,32 @@ export default {
const params = {
startDate: this.startDate,
endDate: this.endDate,
businessType: 1
businessType: this.currentTab.value
};
const res = await getStrategyTotal(params);
if (res && res.code === 200) {
this.strategyTotalData = res.data;
// 可以在这里处理返回的数据,更新页面显示
console.log('策略总数数据:', this.strategyTotalData);
// const res = await getStrategyTotal(params);
// if (res && res.code === 200) {
// this.strategyTotalData = res.data;
// // 可以在这里处理返回的数据,更新页面显示
// console.log('策略总数数据:', this.strategyTotalData);
// }
this.kpiList = [
{
label: '策略总数',
value: 3555,
unit: '个',
subLabel: '本月策略总数',
subValue: '200个',
trendClass: 'trend-up'
},
{
label: '门店总数',
value: 655,
unit: '家',
subLabel: '本月门店总数',
subValue: '200个',
trendClass: 'trend-up'
}
];
} catch (error) {
console.error('获取策略总数失败:', error);
}
......@@ -757,6 +785,61 @@ export default {
} catch (error) {
console.error('获取线上运营分布失败:', error);
}
},
/**
* 更新日期范围并刷新数据(公共方法)
*/
_updateDateRangeAndRefresh(dateRange) {
if (!dateRange) return;
this.dateRange = { ...dateRange };
// 组件已根据 dateFormat 返回格式化后的字符串,直接使用即可
// 保留类型判断以兼容可能的 Date 对象(当 dateFormat 未传递时)
this.startDate = dateRange.startDate
? (typeof dateRange.startDate === 'string'
? dateRange.startDate
: dayjs(dateRange.startDate).format('YYYY-MM-DD'))
: this.startDate;
this.endDate = dateRange.endDate
? (typeof dateRange.endDate === 'string'
? dateRange.endDate
: dayjs(dateRange.endDate).format('YYYY-MM-DD'))
: this.endDate;
// 重新获取数据
this.fetchStrategyTotal();
this.fetchStrategyTypeDist();
this.fetchStrategyOnlineDist();
},
/**
* 处理时间范围类型变化
*/
handleTimeRangeChange(type, dateRange) {
console.log('时间范围类型变化:', type, dateRange);
// 更新时间范围类型
if (typeof type === 'string') {
const option = this.timeRangeOptions.find(opt => opt.label === type);
if (option) {
this.timeRangeType = { label: option.label, value: option.value };
} else {
console.warn('未找到匹配的时间范围类型:', type);
}
} else if (typeof type === 'object' && type !== null) {
this.timeRangeType = type;
}
// 更新日期范围并刷新数据
this._updateDateRangeAndRefresh(dateRange);
},
/**
* 处理日期范围变化
*/
handleDateRangeChange(dateRange) {
console.log('日期范围变化:', dateRange);
this._updateDateRangeAndRefresh(dateRange);
}
}
};
......@@ -773,6 +856,13 @@ $bg-white: #fff;
overflow: visible;
}
.top-header-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
background-color: #fff;
}
.content-area {
min-height: 0;
width: 100%;
......@@ -1002,6 +1092,7 @@ $bg-white: #fff;
word-break: break-all;
line-height: 1.5;
padding: 0 10px;
color: #2A58AD;
}
.tool-left {
......
......@@ -291,13 +291,6 @@ export default {
endDate: null
})
},
// 日期格式化模式,支持以下格式:
// 'YYYY-MM-DD' - 默认格式,如:2024-01-15
// 'YYYY/MM/DD' - 斜杠分隔,如:2024/01/15
// 'YYYYMMDD' - 无分隔符,如:20240115
// 'YYYY-MM-DD HH:mm:ss' - 包含时间,如:2024-01-15 14:30:00
// 'YYYY/MM/DD HH:mm:ss' - 斜杠分隔含时间,如:2024/01/15 14:30:00
// 如果为 null 或空字符串,则返回 Date 对象
dateFormat: {
type: String,
default: null
......@@ -399,7 +392,27 @@ export default {
this.initDateRange();
// emit 对象格式,与 value prop 类型一致
this.$emit('input', { label: selectedOption.label, value: selectedOption.value });
this.$emit('time-range-change', timeRangeLabel, { ...this.internalDateRange });
// 根据 dateFormat 格式化日期范围
let formattedDateRange;
if (this.dateFormat && this.dateFormat.trim() !== '') {
formattedDateRange = {
startDate: this.internalDateRange.startDate
? DateUtils.formatDateByPattern(this.internalDateRange.startDate, this.dateFormat)
: null,
endDate: this.internalDateRange.endDate
? DateUtils.formatDateByPattern(this.internalDateRange.endDate, this.dateFormat)
: null
};
} else {
// 如果没有指定格式化模式,返回 Date 对象
formattedDateRange = {
startDate: this.internalDateRange.startDate ? new Date(this.internalDateRange.startDate) : null,
endDate: this.internalDateRange.endDate ? new Date(this.internalDateRange.endDate) : null
};
}
this.$emit('time-range-change', timeRangeLabel, formattedDateRange);
},
// 初始化日期范围
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!