提交 63fa7533 authored 作者: 朱政's avatar 朱政

feat:资助体系图表切换时间或经费项目时,重新调用ai

上级 cb0a0e8a
流水线 #330 已通过 于阶段
in 1 分 32 秒
...@@ -243,6 +243,7 @@ const handleLeft1YearChange = () => { ...@@ -243,6 +243,7 @@ const handleLeft1YearChange = () => {
}; };
// 资助体系v2.0:资助领域分布情况:资助经费 // 资助体系v2.0:资助领域分布情况:资助经费
const handleGetFundField = async () => { const handleGetFundField = async () => {
invalidateAiContent(aiContentLeft1, isAiLoadingLeft1, left1AiSeq);
const seq = ++left1FundReqSeq; const seq = ++left1FundReqSeq;
left1FundLoading.value = true; left1FundLoading.value = true;
try { try {
...@@ -286,6 +287,7 @@ const handleGetFundField = async () => { ...@@ -286,6 +287,7 @@ const handleGetFundField = async () => {
//资助体系v2.0:资助领域分布情况:资助项目 //资助体系v2.0:资助领域分布情况:资助项目
const handleFindCountryProjectAreaList = async () => { const handleFindCountryProjectAreaList = async () => {
invalidateAiContent(aiContentLeft1, isAiLoadingLeft1, left1AiSeq);
const seq = ++left1ProjReqSeq; const seq = ++left1ProjReqSeq;
left1ProjLoading.value = true; left1ProjLoading.value = true;
try { try {
...@@ -444,6 +446,7 @@ const setRadio2 = (val) => { ...@@ -444,6 +446,7 @@ const setRadio2 = (val) => {
}; };
// 资助体系v2.0:资助经费变化情况:资助经费 // 资助体系v2.0:资助经费变化情况:资助经费
const handlegetCountryFundingChange = async () => { const handlegetCountryFundingChange = async () => {
invalidateAiContent(aiContentRight1, isAiLoadingRight1, right1AiSeq);
try { try {
right1FundLoading.value = true; right1FundLoading.value = true;
let params = { let params = {
...@@ -481,6 +484,7 @@ const handlegetCountryFundingChange = async () => { ...@@ -481,6 +484,7 @@ const handlegetCountryFundingChange = async () => {
}; };
//资助体系v2.0:资助经费变化情况:资助项目 //资助体系v2.0:资助经费变化情况:资助项目
const handlegetCountryFundProjectChange = async () => { const handlegetCountryFundProjectChange = async () => {
invalidateAiContent(aiContentRight1, isAiLoadingRight1, right1AiSeq);
try { try {
right1ProjLoading.value = true; right1ProjLoading.value = true;
let params = { let params = {
...@@ -526,6 +530,7 @@ const handleRight2YearChange = () => { ...@@ -526,6 +530,7 @@ const handleRight2YearChange = () => {
handlegetOrgFundStrength(); handlegetOrgFundStrength();
}; };
const handlegetOrgFundStrength = async () => { const handlegetOrgFundStrength = async () => {
invalidateAiContent(aiContentRight2, isAiLoadingRight2, right2AiSeq);
try { try {
let params = { let params = {
year: normalizeYearParam(value3.value) year: normalizeYearParam(value3.value)
...@@ -727,6 +732,19 @@ const isAiLoadingLeft2 = ref(false); ...@@ -727,6 +732,19 @@ const isAiLoadingLeft2 = ref(false);
const isAiLoadingRight1 = ref(false); const isAiLoadingRight1 = ref(false);
const isAiLoadingRight2 = ref(false); const isAiLoadingRight2 = ref(false);
const AI_LOADING_TEXT = "解读生成中…";
// 用于保证“切换筛选后只写入最新一次解读结果”
const left1AiSeq = ref(0);
const left2AiSeq = ref(0);
const right1AiSeq = ref(0);
const right2AiSeq = ref(0);
const invalidateAiContent = (targetRef, loadingRef, aiSeqRef) => {
aiSeqRef.value += 1;
loadingRef.value = false;
targetRef.value = AI_LOADING_TEXT;
};
const appendAiInterpretationChunk = (targetRef, chunk, loadingText = "解读生成中…") => { const appendAiInterpretationChunk = (targetRef, chunk, loadingText = "解读生成中…") => {
if (!chunk) return; if (!chunk) return;
const current = String(targetRef.value || ""); const current = String(targetRef.value || "");
...@@ -746,31 +764,39 @@ const getInterpretationTextFromChartResponse = (res) => { ...@@ -746,31 +764,39 @@ const getInterpretationTextFromChartResponse = (res) => {
); );
}; };
const fetchChartInterpretationOnce = async (payload, targetRef, loadingRef) => { const fetchChartInterpretationOnce = async (payload, targetRef, loadingRef, aiSeqRef) => {
if (loadingRef.value) return; if (loadingRef.value) return;
const hasValidContent = const hasValidContent =
targetRef.value && targetRef.value &&
targetRef.value !== "解读生成中…" && targetRef.value !== AI_LOADING_TEXT &&
targetRef.value !== "解读加载失败" && targetRef.value !== "解读加载失败" &&
targetRef.value !== "暂无图表数据"; targetRef.value !== "暂无图表数据";
if (hasValidContent) return; if (hasValidContent) return;
const localSeq = aiSeqRef.value;
loadingRef.value = true; loadingRef.value = true;
targetRef.value = "解读生成中…"; targetRef.value = AI_LOADING_TEXT;
try { try {
const res = await getChartAnalysis( const res = await getChartAnalysis(
{ text: JSON.stringify(payload) }, { text: JSON.stringify(payload) },
{ {
onChunk: (chunk) => appendAiInterpretationChunk(targetRef, chunk) onChunk: (chunk) => {
if (aiSeqRef.value !== localSeq) return;
appendAiInterpretationChunk(targetRef, chunk, AI_LOADING_TEXT);
}
} }
); );
if (aiSeqRef.value !== localSeq) return;
const text = getInterpretationTextFromChartResponse(res); const text = getInterpretationTextFromChartResponse(res);
targetRef.value = text || targetRef.value || "未返回有效解读内容"; targetRef.value = text || targetRef.value || "未返回有效解读内容";
} catch (e) { } catch (e) {
if (aiSeqRef.value !== localSeq) return;
console.error("图表解读请求失败", e); console.error("图表解读请求失败", e);
targetRef.value = "解读加载失败"; targetRef.value = "解读加载失败";
} finally { } finally {
loadingRef.value = false; if (aiSeqRef.value === localSeq) loadingRef.value = false;
} }
}; };
...@@ -819,7 +845,7 @@ const handleSwitchAiLeft1 = async (val) => { ...@@ -819,7 +845,7 @@ const handleSwitchAiLeft1 = async (val) => {
aiContentLeft1.value = "暂无图表数据"; aiContentLeft1.value = "暂无图表数据";
return; return;
} }
await fetchChartInterpretationOnce(payload, aiContentLeft1, isAiLoadingLeft1); await fetchChartInterpretationOnce(payload, aiContentLeft1, isAiLoadingLeft1, left1AiSeq);
}; };
const handleSwitchAiLeft2 = async (val) => { const handleSwitchAiLeft2 = async (val) => {
isShowAiContentLeft2.value = val; isShowAiContentLeft2.value = val;
...@@ -829,7 +855,7 @@ const handleSwitchAiLeft2 = async (val) => { ...@@ -829,7 +855,7 @@ const handleSwitchAiLeft2 = async (val) => {
aiContentLeft2.value = "暂无图表数据"; aiContentLeft2.value = "暂无图表数据";
return; return;
} }
await fetchChartInterpretationOnce(payload, aiContentLeft2, isAiLoadingLeft2); await fetchChartInterpretationOnce(payload, aiContentLeft2, isAiLoadingLeft2, left2AiSeq);
}; };
const handleSwitchAiRight1 = async (val) => { const handleSwitchAiRight1 = async (val) => {
isShowAiContentRight1.value = val; isShowAiContentRight1.value = val;
...@@ -839,7 +865,7 @@ const handleSwitchAiRight1 = async (val) => { ...@@ -839,7 +865,7 @@ const handleSwitchAiRight1 = async (val) => {
aiContentRight1.value = "暂无图表数据"; aiContentRight1.value = "暂无图表数据";
return; return;
} }
await fetchChartInterpretationOnce(payload, aiContentRight1, isAiLoadingRight1); await fetchChartInterpretationOnce(payload, aiContentRight1, isAiLoadingRight1, right1AiSeq);
}; };
const handleSwitchAiRight2 = async (val) => { const handleSwitchAiRight2 = async (val) => {
isShowAiContentRight2.value = val; isShowAiContentRight2.value = val;
...@@ -849,7 +875,7 @@ const handleSwitchAiRight2 = async (val) => { ...@@ -849,7 +875,7 @@ const handleSwitchAiRight2 = async (val) => {
aiContentRight2.value = "暂无图表数据"; aiContentRight2.value = "暂无图表数据";
return; return;
} }
await fetchChartInterpretationOnce(payload, aiContentRight2, isAiLoadingRight2); await fetchChartInterpretationOnce(payload, aiContentRight2, isAiLoadingRight2, right2AiSeq);
}; };
...@@ -970,6 +996,7 @@ const left2RawSankey = ref([]); ...@@ -970,6 +996,7 @@ const left2RawSankey = ref([]);
const hasLeft2ChartData = computed(() => isNonEmptyArray(left2RawSankey.value)); const hasLeft2ChartData = computed(() => isNonEmptyArray(left2RawSankey.value));
// 机构资助领域情况 // 机构资助领域情况
const handleGetOrgFundsArea = async () => { const handleGetOrgFundsArea = async () => {
invalidateAiContent(aiContentLeft2, isAiLoadingLeft2, left2AiSeq);
try { try {
let params = { let params = {
year: normalizeYearParam(value2.value) year: normalizeYearParam(value2.value)
......
...@@ -459,6 +459,10 @@ onMounted(async () => { ...@@ -459,6 +459,10 @@ onMounted(async () => {
height: 24px; height: 24px;
margin-right: 0 !important; margin-right: 0 !important;
} }
:deep(.el-checkbox__label) {
font-size: 16px;
}
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论