接入结果总览风险真实接口
This commit is contained in:
@@ -22,7 +22,16 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mockOverviewData, mockOverviewStateData } from "./preliminaryCheck.mock";
|
||||
import {
|
||||
createOverviewLoadedData,
|
||||
mockOverviewData,
|
||||
mockOverviewStateData,
|
||||
} from "./preliminaryCheck.mock";
|
||||
import {
|
||||
getOverviewDashboard,
|
||||
getOverviewRiskPeople,
|
||||
getOverviewTopRiskPeople,
|
||||
} from "@/api/ccdi/projectOverview";
|
||||
import OverviewStats from "./OverviewStats";
|
||||
import RiskPeopleSection from "./RiskPeopleSection";
|
||||
import RiskModelSection from "./RiskModelSection";
|
||||
@@ -52,14 +61,75 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
pageState: "loaded",
|
||||
pageState: "loading",
|
||||
mockData: mockOverviewData,
|
||||
stateDataMap: mockOverviewStateData,
|
||||
realData: mockOverviewData,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
currentData() {
|
||||
return this.stateDataMap[this.pageState] || this.mockData;
|
||||
if (this.pageState === "loaded") {
|
||||
return this.realData;
|
||||
}
|
||||
return this.stateDataMap[this.pageState] || this.realData;
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
projectId(newVal) {
|
||||
if (newVal) {
|
||||
this.loadOverviewData();
|
||||
return;
|
||||
}
|
||||
this.realData = this.stateDataMap.empty;
|
||||
this.pageState = "empty";
|
||||
},
|
||||
},
|
||||
created() {
|
||||
if (this.projectId) {
|
||||
this.loadOverviewData();
|
||||
return;
|
||||
}
|
||||
this.realData = this.stateDataMap.empty;
|
||||
this.pageState = "empty";
|
||||
},
|
||||
methods: {
|
||||
async loadOverviewData() {
|
||||
if (!this.projectId) {
|
||||
this.realData = this.stateDataMap.empty;
|
||||
this.pageState = "empty";
|
||||
return;
|
||||
}
|
||||
|
||||
this.pageState = "loading";
|
||||
try {
|
||||
const [dashboardRes, riskPeopleRes, topRiskPeopleRes] = await Promise.all([
|
||||
getOverviewDashboard(this.projectId),
|
||||
getOverviewRiskPeople(this.projectId),
|
||||
getOverviewTopRiskPeople(this.projectId),
|
||||
]);
|
||||
const dashboardData = (dashboardRes && dashboardRes.data) || {};
|
||||
const riskPeopleData = (riskPeopleRes && riskPeopleRes.data) || {};
|
||||
const topRiskPeopleData = (topRiskPeopleRes && topRiskPeopleRes.data) || {};
|
||||
|
||||
this.realData = createOverviewLoadedData({
|
||||
dashboardData,
|
||||
riskPeopleData,
|
||||
topRiskPeopleData,
|
||||
});
|
||||
|
||||
const hasOverviewData = Boolean(
|
||||
(Array.isArray(dashboardData.stats) && dashboardData.stats.length) ||
|
||||
(Array.isArray(riskPeopleData.overviewList) && riskPeopleData.overviewList.length) ||
|
||||
(Array.isArray(topRiskPeopleData.topRiskList) && topRiskPeopleData.topRiskList.length)
|
||||
);
|
||||
|
||||
this.pageState = hasOverviewData ? "loaded" : "empty";
|
||||
} catch (error) {
|
||||
this.realData = this.stateDataMap.empty;
|
||||
this.pageState = "empty";
|
||||
console.error("加载结果总览失败", error);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -140,6 +140,45 @@ export const mockOverviewData = {
|
||||
},
|
||||
};
|
||||
|
||||
const summaryStatMetaMap = mockOverviewData.summary.stats.reduce((acc, item) => {
|
||||
acc[item.key] = {
|
||||
icon: item.icon,
|
||||
tone: item.tone,
|
||||
};
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
function normalizeSummaryStats(stats) {
|
||||
if (!Array.isArray(stats)) {
|
||||
return [];
|
||||
}
|
||||
return stats.map((item) => ({
|
||||
...summaryStatMetaMap[item.key],
|
||||
...item,
|
||||
}));
|
||||
}
|
||||
|
||||
export function createOverviewLoadedData({ dashboardData, riskPeopleData, topRiskPeopleData } = {}) {
|
||||
return {
|
||||
...mockOverviewData,
|
||||
summary: {
|
||||
...mockOverviewData.summary,
|
||||
...(dashboardData || {}),
|
||||
actions: mockOverviewData.summary.actions,
|
||||
stats: normalizeSummaryStats(dashboardData && dashboardData.stats),
|
||||
},
|
||||
riskPeople: {
|
||||
...mockOverviewData.riskPeople,
|
||||
overviewList: Array.isArray(riskPeopleData && riskPeopleData.overviewList)
|
||||
? riskPeopleData.overviewList
|
||||
: [],
|
||||
topRiskList: Array.isArray(topRiskPeopleData && topRiskPeopleData.topRiskList)
|
||||
? topRiskPeopleData.topRiskList
|
||||
: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const mockOverviewStateData = {
|
||||
loaded: mockOverviewData,
|
||||
empty: {
|
||||
|
||||
Reference in New Issue
Block a user