Commit fece6599 by Lin

fix(strategyAnalysis): 优化盯防类型逻辑与数据处理

- 移除不必要的指标类型相关代码,简化组件逻辑,提升可维护性。
- 更新盯防类型选项生成逻辑,确保在没有监控类型数据时返回空数组,避免不必要的默认选项。
- 修改数据请求逻辑,使用getStrategyAnalysisEffect替代getStrategyEffectList,确保数据获取的准确性与一致性。
1 parent 9b925606
......@@ -70,17 +70,6 @@
trigger-icon-type="image"
:value="currentWatchType"
@change="selectWatchType" />
<!-- <span class="v-divider">|</span> -->
<!-- 指标类型 -->
<SelectCustom v-if="false"
label="指标类型"
:options="indicatorTypeOptions"
:trigger-icon="require('@/assets/strategy/icon-strategy-type06.png')"
trigger-icon-type="image"
:value="currentIndicatorType"
@change="selectIndicatorType" />
</div>
</d2-table-header>
<d2-table ref="table"
......@@ -189,7 +178,7 @@
<script>
import dayjs from "dayjs";
import { getStrategyEffectList, getStrategyOnlineDist, getStrategyTotal, getStrategyTypeDist, getWarningMetricList, getWarningTypeList } from "@/api/earlyWarningManager";
import { getStrategyAnalysisEffect, getStrategyEffectList, getStrategyOnlineDist, getStrategyTotal, getStrategyTypeDist, getWarningTypeList } from "@/api/earlyWarningManager";
import noDataImg from "@/assets/strategy/emepty-strategy.png";
import { deepClone } from "@/common/util";
import calendarCustom from "../strategyCentre/compoments/clendarCustom.vue";
......@@ -275,9 +264,7 @@ export default {
// 存储原始监控类型数据(接口返回的完整数据)
monitorTypeData: [],
// 当前选中的盯防类型
currentWatchType: { label: "全部", value: null },
// 当前选中的指标类型
currentIndicatorType: { label: "全部", value: null },
currentWatchType: { label: "", value: null },
// 表格相关数据
searchFormSearch: {},
getListApi: null, // 在 mounted 中初始化
......@@ -399,55 +386,29 @@ export default {
computed: {
// 盯防类型选项(自动根据原始数据生成)
watchTypeOptions() {
const allOption = { label: "全部", value: null };
if (!this.monitorTypeData || this.monitorTypeData.length === 0) {
return [allOption];
return [];
}
return [
allOption,
...this.monitorTypeData.map((item) => {
const iconConfig = WATCH_TYPE_ICON_CONFIG[item.typeCode] || WATCH_TYPE_ICON_CONFIG.default;
return {
label: item.typeName,
value: item.typeCode,
icon: iconConfig.icon,
iconUrl: iconConfig.iconUrl,
};
}),
];
return this.monitorTypeData.map((item) => {
const iconConfig = WATCH_TYPE_ICON_CONFIG[item.typeCode] || WATCH_TYPE_ICON_CONFIG.default;
return {
label: item.typeName,
value: item.typeCode,
icon: iconConfig.icon,
iconUrl: iconConfig.iconUrl,
};
});
},
effectSearchParams() {
return {
startDate: this.startDate,
endDate: this.endDate,
businessType: this.currentTab.value,
monitorType: this.currentWatchType.value || null,
metricTypeId: this.currentIndicatorType.value || null,
warningType: this.currentWatchType.value || null,
periodType: this.timeRangeType.value,
};
},
// 指标类型选项(自动根据当前盯防类型生成)
indicatorTypeOptions() {
if (this.currentWatchType.value == null) {
return [{ label: "全部", value: null }];
}
const currentTypeData = this.monitorTypeData.find(
item => item.typeCode === this.currentWatchType.value,
);
if (!currentTypeData || !currentTypeData.rules || currentTypeData.rules.length === 0) {
return [{ label: "全部", value: null }];
}
return [
{ label: "全部", value: null },
...currentTypeData.rules.map(rule => ({
label: rule.rule,
value: rule.id,
})),
];
},
},
watch: {
// 监听业务类型变化,重新获取数据
......@@ -460,19 +421,6 @@ export default {
this.strategyTypeOperatorFilter = null;
}
},
// 监听盯防类型变化,自动重置指标类型为「全部」
"currentWatchType.value": function (newValue, oldValue) {
if (newValue !== oldValue) {
this.currentIndicatorType = { label: "全部", value: null };
}
},
// 监听指标类型变化,触发数据查询
"currentIndicatorType.value": function (newValue, oldValue) {
if (newValue !== oldValue) {
this.$refs.table && this.$refs.table.refreshTable();
}
},
// 监听策略类型分布运营人员筛选变化,防抖请求数据
strategyTypeOperatorFilter(newValue, oldValue) {
if (newValue !== oldValue && oldValue !== undefined) {
......@@ -512,7 +460,9 @@ export default {
*/
async wrapStrategyEffectList(params) {
try {
const data = await getStrategyEffectList(params);
// const data = await getStrategyEffectList(params);
params.cycleType = params.periodType;
const data = await getStrategyAnalysisEffect(params);
// axios 响应拦截器已返回 data 字段的内容(数组)
// 需要包装成 d2-table 期望的格式:{ data: [...], total: number }
return {
......@@ -539,20 +489,19 @@ export default {
*/
async beforeSearchFn(type = 1) {
try {
// 先获取指标类型列表(若已存在数据则不需要再次调用)
// 先获取盯防类型列表(若已存在数据则不需要再次调用)
if (!this.monitorTypeData || this.monitorTypeData.length === 0) {
await this.getIndicatorTypeList();
await this.getWatchTypeList();
}
} catch (error) {
console.error("获取指标类型列表失败,继续执行:", error);
console.error("获取盯防类型列表失败,继续执行:", error);
}
// 构建搜索参数,即使字段为空也先构建(避免首次加载时参数缺失)
this.searchFormSearch = deepClone({
startDate: this.startDate,
endDate: this.endDate,
businessType: this.currentTab.value,
monitorType: this.currentWatchType.value || null,
metricTypeId: this.currentIndicatorType.value || null,
warningType: this.currentWatchType.value || null,
periodType: this.timeRangeType.value,
});
},
......@@ -593,93 +542,38 @@ export default {
label: item.label,
value: item.value !== undefined ? item.value : item.label,
};
if (this.currentWatchType.value != null) {
this.getWarningMetricListData();
}
// watch 会自动处理后续逻辑(重置指标类型、触发查询)
// 使用 $nextTick 确保数据更新后再更新搜索参数
this.$nextTick(() => {
// 确保 searchFormSearch 参数已更新
this.searchFormSearch = deepClone({
startDate: this.startDate,
endDate: this.endDate,
businessType: this.currentTab.value,
monitorType: this.currentWatchType.value || null,
metricTypeId: this.currentIndicatorType.value || null,
warningType: this.currentWatchType.value || null,
periodType: this.timeRangeType.value,
});
// watch 会自动触发 refreshTable,这里不需要手动调用
this.$refs.table && this.$refs.table.refreshTable();
});
console.log("选择盯防类型:", item.label);
},
/**
* 选择指标类型
*/
selectIndicatorType(item) {
// this.currentIndicatorType = {
// label: item.label,
// value: item.value !== undefined ? item.value : null,
// };
// // watch会自动处理后续逻辑(触发查询)
// // 使用 $nextTick 确保数据更新后再更新搜索参数
// this.$nextTick(() => {
// // 确保 searchFormSearch 参数已更新
// this.searchFormSearch = deepClone({
// startDate: this.startDate,
// endDate: this.endDate,
// businessType: this.currentTab.value,
// monitorType: this.currentWatchType.value || null,
// metricTypeId: this.currentIndicatorType.value || null,
// periodType: this.timeRangeType.value,
// });
// // watch 会自动触发 refreshTable,这里不需要手动调用
// });
// console.log("选择指标类型:", item.label);
},
/**
* 获取盯防类型列表(扁平结构,指标类型在选中盯防类型后动态加载)
* 获取盯防类型列表
*/
async getIndicatorTypeList() {
async getWatchTypeList() {
try {
const res = await getWarningTypeList();
if (res && res.length) {
this.monitorTypeData = res.map(item => ({
typeName: item.warningTypeName,
typeCode: item.warningType,
rules: [],
}));
this.currentWatchType = { label: "全部", value: null };
this.currentIndicatorType = { label: "全部", value: null };
const first = this.monitorTypeData[0];
this.currentWatchType = {
label: first.typeName,
value: first.typeCode,
};
} else {
console.warn("指标类型列表接口返回为空");
}
} catch (error) {
console.error("获取指标类型列表失败:", error);
}
},
// 根据当前盯防类型动态获取指标类型选项
async getWarningMetricListData() {
const warningType = this.currentWatchType.value;
if (warningType == null) {
return;
}
try {
const res = await getWarningMetricList({
businessType: this.currentTab.value,
warningType,
});
const rules = Array.isArray(res) && res.length
? res.map(item => ({
rule: item.categoryExtension.includes("全部") ? item.metricName : (item.categoryExtension + item.metricName),
id: item.metricId,
}))
: [];
const typeIndex = this.monitorTypeData.findIndex(item => item.typeCode === warningType);
if (typeIndex !== -1) {
this.$set(this.monitorTypeData[typeIndex], "rules", rules);
console.warn("盯防类型列表接口返回为空");
}
} catch (error) {
console.error("获取指标列表失败:", error);
console.error("获取盯防类型列表失败:", error);
}
},
/**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!