提交 80811a1a authored 作者: 张烨's avatar 张烨

fix:政令-修复数量变化趋势和领域分布情况加载异常问题

上级 0c40bb2d
...@@ -17,7 +17,14 @@ ...@@ -17,7 +17,14 @@
</template> </template>
<script setup> <script setup>
import {ref} from 'vue' import {onMounted, ref} from 'vue'
const props = defineProps({
activeTime: {
typeof: String,
default: '近一周'
}
})
const timeList = ref([ const timeList = ref([
{ {
...@@ -34,6 +41,10 @@ const timeList = ref([ ...@@ -34,6 +41,10 @@ const timeList = ref([
}, },
]) ])
onMounted(() => {
timeList.value.forEach(item => { item.active = item.time === props.activeTime })
})
const handleTimeClick = (item, index) => { const handleTimeClick = (item, index) => {
timeList.value.forEach(time => { timeList.value.forEach(time => {
time.active = false time.active = false
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<img :src="tipsTcon" alt=""> <img :src="tipsTcon" alt="">
</div> </div>
<div class="date-text">近期美国各联邦政府机构发布涉华政令数量汇总</div> <div class="date-text">近期美国各联邦政府机构发布涉华政令数量汇总</div>
<TimeTabPane @time-click="onKeyOrganization" /> <TimeTabPane @time-click="onKeyOrganization" activeTime="近一年" />
</div> </div>
<div class="home-main-header-item-box" v-if="keyOrganizationList.length"> <div class="home-main-header-item-box" v-if="keyOrganizationList.length">
<div class="organization-item" v-for="(item, index) in keyOrganizationList" :key="index" @click="handleToInstitution(item)"> <div class="organization-item" v-for="(item, index) in keyOrganizationList" :key="index" @click="handleToInstitution(item)">
...@@ -767,7 +767,7 @@ const handleGetDecreeYearOrder = async () => { ...@@ -767,7 +767,7 @@ const handleGetDecreeYearOrder = async () => {
chart1Data.value.dataY = res.data.map(item => { chart1Data.value.dataY = res.data.map(item => {
return item.count; return item.count;
}); });
summarize1.value = await onChartInterpretation({type:"柱状图",name:"数量变化趋势",data:res.data}) onChartInterpretation({type:"柱状图",name:"数量变化趋势",data:res.data}, summarize1)
} }
} catch (error) { } catch (error) {
console.error("行政令发布频度error", error); console.error("行政令发布频度error", error);
...@@ -775,15 +775,25 @@ const handleGetDecreeYearOrder = async () => { ...@@ -775,15 +775,25 @@ const handleGetDecreeYearOrder = async () => {
box5Params.loading = false box5Params.loading = false
}; };
// AI智能总结 // AI智能总结
const onChartInterpretation = async (text) => { const onChartInterpretation = async (text, param) => {
param.value = "正在生成..."
// 👇 新增:超时 + 终止请求(只加这一段)
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 10000); // 10秒超时
try {
const response = await fetch('/aiAnalysis/chart_interpretation', { const response = await fetch('/aiAnalysis/chart_interpretation', {
method: 'POST', method: 'POST',
headers: { headers: {
"X-API-Key": "aircasKEY19491001", "X-API-Key": "aircasKEY19491001",
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({text}) // 把参数转为JSON字符串 body: JSON.stringify({text}),
signal: controller.signal // 👇 新增:绑定中断信号
}); });
clearTimeout(timeout); // 👇 新增:请求成功清除定时器
const reader = response.body.getReader(); const reader = response.body.getReader();
const decoder = new TextDecoder(); const decoder = new TextDecoder();
...@@ -806,7 +816,15 @@ const onChartInterpretation = async (text) => { ...@@ -806,7 +816,15 @@ const onChartInterpretation = async (text) => {
} }
} }
} }
return summarize param.value = summarize
} catch (err) {
// 👇 新增:超时处理
if (err.name === 'AbortError') {
param.value = "请求超时,请重试";
} else {
param.value = "生成失败,请重试";
}
}
} }
const handleBox5 = async () => { const handleBox5 = async () => {
...@@ -870,7 +888,7 @@ const handleGetDecreeArea = async () => { ...@@ -870,7 +888,7 @@ const handleGetDecreeArea = async () => {
value: item.count value: item.count
}; };
}); });
summarize2.value = await onChartInterpretation({type:"环形图",name:"领域分布情况",data:res.data}) onChartInterpretation({type:"环形图",name:"领域分布情况",data:res.data}, summarize2)
} }
} catch (error) { } catch (error) {
console.error("政令科技领域error", error); console.error("政令科技领域error", error);
...@@ -1194,7 +1212,7 @@ const handleSearch = () => { ...@@ -1194,7 +1212,7 @@ const handleSearch = () => {
// 关键机构 // 关键机构
const keyOrganizationList = ref([]); const keyOrganizationList = ref([]);
const onKeyOrganization = async (event) => { const onKeyOrganization = async (event) => {
let day = 7 let day = 365
if (event?.time === '近一周') day = 7 if (event?.time === '近一周') day = 7
if (event?.time === '近一月') day = 30 if (event?.time === '近一月') day = 30
if (event?.time === '近一年') day = 365 if (event?.time === '近一年') day = 365
......
...@@ -79,8 +79,9 @@ ...@@ -79,8 +79,9 @@
<div class="graph-box" v-if="contentType==1"> <div class="graph-box" v-if="contentType==1">
<ChartChain :listData="fishbone.list" :baseData="fishbone.base" /> <ChartChain :listData="fishbone.list" :baseData="fishbone.base" />
</div> </div>
<div class="graph-box" v-if="contentType==2 && graphInfo.nodes.length"> <div class="graph-box" v-if="contentType==2">
<GraphChart :nodes="graphInfo.nodes" :links="graphInfo.links" layoutType="force" /> <GraphChart v-if="graphInfo.nodes?.length" :nodes="graphInfo.nodes" :links="graphInfo.links" layoutType="force" />
<el-empty v-else style="padding: 60px 0" description="暂无数据" :image-size="100" />
</div> </div>
</div> </div>
</AnalysisBox> </AnalysisBox>
...@@ -168,6 +169,7 @@ const onDecreeEntities = async (page=1) => { ...@@ -168,6 +169,7 @@ const onDecreeEntities = async (page=1) => {
const contentType = ref(1); const contentType = ref(1);
const headerContentType = (type) => { const headerContentType = (type) => {
contentType.value = type; contentType.value = type;
if (!entityInfo.total) return;
headerChartData(entityInfo.node) headerChartData(entityInfo.node)
}; };
const headerChartData = (row) => { const headerChartData = (row) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论