Commit fece6599 by Lin

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

- 移除不必要的指标类型相关代码,简化组件逻辑,提升可维护性。
- 更新盯防类型选项生成逻辑,确保在没有监控类型数据时返回空数组,避免不必要的默认选项。
- 修改数据请求逻辑,使用getStrategyAnalysisEffect替代getStrategyEffectList,确保数据获取的准确性与一致性。
1 parent 9b925606
...@@ -70,17 +70,6 @@ ...@@ -70,17 +70,6 @@
trigger-icon-type="image" trigger-icon-type="image"
:value="currentWatchType" :value="currentWatchType"
@change="selectWatchType" /> @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> </div>
</d2-table-header> </d2-table-header>
<d2-table ref="table" <d2-table ref="table"
...@@ -189,7 +178,7 @@ ...@@ -189,7 +178,7 @@
<script> <script>
import dayjs from "dayjs"; 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 noDataImg from "@/assets/strategy/emepty-strategy.png";
import { deepClone } from "@/common/util"; import { deepClone } from "@/common/util";
import calendarCustom from "../strategyCentre/compoments/clendarCustom.vue"; import calendarCustom from "../strategyCentre/compoments/clendarCustom.vue";
...@@ -275,9 +264,7 @@ export default { ...@@ -275,9 +264,7 @@ export default {
// 存储原始监控类型数据(接口返回的完整数据) // 存储原始监控类型数据(接口返回的完整数据)
monitorTypeData: [], monitorTypeData: [],
// 当前选中的盯防类型 // 当前选中的盯防类型
currentWatchType: { label: "全部", value: null }, currentWatchType: { label: "", value: null },
// 当前选中的指标类型
currentIndicatorType: { label: "全部", value: null },
// 表格相关数据 // 表格相关数据
searchFormSearch: {}, searchFormSearch: {},
getListApi: null, // 在 mounted 中初始化 getListApi: null, // 在 mounted 中初始化
...@@ -399,55 +386,29 @@ export default { ...@@ -399,55 +386,29 @@ export default {
computed: { computed: {
// 盯防类型选项(自动根据原始数据生成) // 盯防类型选项(自动根据原始数据生成)
watchTypeOptions() { watchTypeOptions() {
const allOption = { label: "全部", value: null };
if (!this.monitorTypeData || this.monitorTypeData.length === 0) { if (!this.monitorTypeData || this.monitorTypeData.length === 0) {
return [allOption]; return [];
} }
return [ return this.monitorTypeData.map((item) => {
allOption, const iconConfig = WATCH_TYPE_ICON_CONFIG[item.typeCode] || WATCH_TYPE_ICON_CONFIG.default;
...this.monitorTypeData.map((item) => { return {
const iconConfig = WATCH_TYPE_ICON_CONFIG[item.typeCode] || WATCH_TYPE_ICON_CONFIG.default; label: item.typeName,
return { value: item.typeCode,
label: item.typeName, icon: iconConfig.icon,
value: item.typeCode, iconUrl: iconConfig.iconUrl,
icon: iconConfig.icon, };
iconUrl: iconConfig.iconUrl, });
};
}),
];
}, },
effectSearchParams() { effectSearchParams() {
return { return {
startDate: this.startDate, startDate: this.startDate,
endDate: this.endDate, endDate: this.endDate,
businessType: this.currentTab.value, businessType: this.currentTab.value,
monitorType: this.currentWatchType.value || null, warningType: this.currentWatchType.value || null,
metricTypeId: this.currentIndicatorType.value || null,
periodType: this.timeRangeType.value, 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: { watch: {
// 监听业务类型变化,重新获取数据 // 监听业务类型变化,重新获取数据
...@@ -460,19 +421,6 @@ export default { ...@@ -460,19 +421,6 @@ export default {
this.strategyTypeOperatorFilter = null; 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) { strategyTypeOperatorFilter(newValue, oldValue) {
if (newValue !== oldValue && oldValue !== undefined) { if (newValue !== oldValue && oldValue !== undefined) {
...@@ -512,7 +460,9 @@ export default { ...@@ -512,7 +460,9 @@ export default {
*/ */
async wrapStrategyEffectList(params) { async wrapStrategyEffectList(params) {
try { try {
const data = await getStrategyEffectList(params); // const data = await getStrategyEffectList(params);
params.cycleType = params.periodType;
const data = await getStrategyAnalysisEffect(params);
// axios 响应拦截器已返回 data 字段的内容(数组) // axios 响应拦截器已返回 data 字段的内容(数组)
// 需要包装成 d2-table 期望的格式:{ data: [...], total: number } // 需要包装成 d2-table 期望的格式:{ data: [...], total: number }
return { return {
...@@ -539,20 +489,19 @@ export default { ...@@ -539,20 +489,19 @@ export default {
*/ */
async beforeSearchFn(type = 1) { async beforeSearchFn(type = 1) {
try { try {
// 先获取指标类型列表(若已存在数据则不需要再次调用) // 先获取盯防类型列表(若已存在数据则不需要再次调用)
if (!this.monitorTypeData || this.monitorTypeData.length === 0) { if (!this.monitorTypeData || this.monitorTypeData.length === 0) {
await this.getIndicatorTypeList(); await this.getWatchTypeList();
} }
} catch (error) { } catch (error) {
console.error("获取指标类型列表失败,继续执行:", error); console.error("获取盯防类型列表失败,继续执行:", error);
} }
// 构建搜索参数,即使字段为空也先构建(避免首次加载时参数缺失) // 构建搜索参数,即使字段为空也先构建(避免首次加载时参数缺失)
this.searchFormSearch = deepClone({ this.searchFormSearch = deepClone({
startDate: this.startDate, startDate: this.startDate,
endDate: this.endDate, endDate: this.endDate,
businessType: this.currentTab.value, businessType: this.currentTab.value,
monitorType: this.currentWatchType.value || null, warningType: this.currentWatchType.value || null,
metricTypeId: this.currentIndicatorType.value || null,
periodType: this.timeRangeType.value, periodType: this.timeRangeType.value,
}); });
}, },
...@@ -593,93 +542,38 @@ export default { ...@@ -593,93 +542,38 @@ export default {
label: item.label, label: item.label,
value: item.value !== undefined ? item.value : item.label, value: item.value !== undefined ? item.value : item.label,
}; };
if (this.currentWatchType.value != null) {
this.getWarningMetricListData();
}
// watch 会自动处理后续逻辑(重置指标类型、触发查询)
// 使用 $nextTick 确保数据更新后再更新搜索参数
this.$nextTick(() => { this.$nextTick(() => {
// 确保 searchFormSearch 参数已更新
this.searchFormSearch = deepClone({ this.searchFormSearch = deepClone({
startDate: this.startDate, startDate: this.startDate,
endDate: this.endDate, endDate: this.endDate,
businessType: this.currentTab.value, businessType: this.currentTab.value,
monitorType: this.currentWatchType.value || null, warningType: this.currentWatchType.value || null,
metricTypeId: this.currentIndicatorType.value || null,
periodType: this.timeRangeType.value, 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 { try {
const res = await getWarningTypeList(); const res = await getWarningTypeList();
if (res && res.length) { if (res && res.length) {
this.monitorTypeData = res.map(item => ({ this.monitorTypeData = res.map(item => ({
typeName: item.warningTypeName, typeName: item.warningTypeName,
typeCode: item.warningType, typeCode: item.warningType,
rules: [],
})); }));
this.currentWatchType = { label: "全部", value: null }; const first = this.monitorTypeData[0];
this.currentIndicatorType = { label: "全部", value: null }; this.currentWatchType = {
label: first.typeName,
value: first.typeCode,
};
} else { } else {
console.warn("指标类型列表接口返回为空"); 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);
} }
} catch (error) { } 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!