提交 bd2621da authored 作者: coderBryanFu's avatar coderBryanFu

feat:更新数据资源库

上级 f23aec00
// 使用 day.js(推荐,轻量级)
import dayjs from 'dayjs';
// 获取日期范围
const getDateRange = (type) => {
const endDate = dayjs(); // 当前日期
let startDate;
switch(type) {
case '近一月':
startDate = dayjs().subtract(1, 'month');
break;
case '近三月':
startDate = dayjs().subtract(3, 'month');
break;
case '近半年':
startDate = dayjs().subtract(6, 'month');
break;
case '近一年':
startDate = dayjs().subtract(1, 'year');
break;
default:
return null;
}
return [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD')
];
}
export default getDateRange
// 使用示例
// console.log(getDateRange('近一个月')); // ['2026-02-25', '2026-03-25']
// console.log(getDateRange('近三个月')); // ['2025-12-25', '2026-03-25']
// console.log(getDateRange('近半年')); // ['2025-09-25', '2026-03-25']
// console.log(getDateRange('近一年')); // ['2025-03-25', '2026-03-25']
\ No newline at end of file
const getMonthRange = (yearMonth) => {
// yearMonth 格式:'2026-03'
const [year, month] = yearMonth.split('-');
// 当月第一天
const firstDay = `${year}-${month}-01`;
// 当月最后一天:先获取下个月的第0天,即当月的最后一天
const lastDay = new Date(Number(year), Number(month), 0);
const lastDayStr = `${year}-${month}-${lastDay.getDate()}`;
return [firstDay, lastDayStr];
}
export default getMonthRange
// 绘制echarts图表
import getMonthRange from './getMonthRange'
import * as echarts from 'echarts'
import 'echarts-wordcloud';
import router from '@/router/index'
......@@ -14,6 +15,9 @@ const setChart = (option, chartId, allowClick, selectParam) => {
chart.on('click', function (params) {
switch (selectParam.moduleType) {
case '国会法案':
if(selectParam.selectedDate && selectParam.length === 4) {
selectParam.selectedDate = JSON.stringify([selectParam.selectedDate+'-01-01',selectParam.selectedDate+'-12-31'])
}
// 判断点击的是否为饼图的数据项
if (params.componentType === 'series' && params.seriesType === 'pie') {
console.log('点击的扇形名称:', params.name);
......@@ -49,7 +53,7 @@ const setChart = (option, chartId, allowClick, selectParam) => {
console.log('当前点击', selectParam, params.seriesName, params.name);
if (params.seriesName !== '通过率') {
selectParam = {
selectedDate: params.name,
selectedDate: JSON.stringify(getMonthRange(params.name)),
status: params.seriesName === '通过法案' ? 1 : 0,
...selectParam
}
......
......@@ -34,7 +34,8 @@
@close="handleCloseCurTag(tag, index)" />
</div>
<div class="header-footer-right">
<HeaderBtnBox :isShowAll="isFolderAll" @show-all="handleSwitchFolderAll" @clear="handleClear" @confirm="handleConfirm" />
<HeaderBtnBox :isShowAll="isFolderAll" @show-all="handleSwitchFolderAll" @clear="handleClear"
@confirm="handleConfirm" />
</div>
</div>
</div>
......@@ -163,6 +164,7 @@ import { useRoute } from "vue-router";
import { getPostOrgList, getPostMemberList } from '@/api/bill/billHome'
import { search } from '@/api/comprehensiveSearch'
import { ElMessage } from 'element-plus'
import getDateRange from '@/utils/getDateRange'
const route = useRoute();
// 图表/数据
......@@ -263,8 +265,8 @@ const activeTagList = computed(() => {
if (selectedArea.value && selectedArea.value !== '全部领域') {
arr.push(selectedArea.value)
}
if (selectedDate.value) {
arr.push(selectedDate.value)
if (selectedDate.value === '自定义') {
arr.push(customTime.value.join('至'))
}
if (selectedParty.value && selectedParty.value !== '全部党派') {
arr.push(selectedParty.value)
......@@ -449,27 +451,23 @@ const dateList = ref([
id: '自定义'
},
{
name: '2026',
id: '2026'
name: '近一年',
id: '近一年'
},
{
name: '2025',
id: '2025'
name: '近半年',
id: '近半年'
},
{
name: '2024',
id: '2024'
name: '近三月',
id: '近三月'
},
{
name: '2023',
id: '2023'
},
{
name: '2022',
id: '2022'
},
name: '近一月',
id: '近一月'
}
])
const customTime = ref('') // 自定义时间
const customTime = ref([]) // 自定义时间
const handleCustomDate = value => {
// console.log('value', value);
customTime.value = value
......@@ -477,6 +475,9 @@ const handleCustomDate = value => {
const handleSelectDate = (value) => {
selectedDate.value = value
if (selectedDate.value !== '自定义') {
customTime.value = getDateRange(selectedDate.value)
}
}
// 所属党派
......@@ -660,7 +661,7 @@ const isSort = ref(true); // true 倒序 false 升序
// isSort.value = !isSort.value;
// };
const handlePxChange = val => {
fetchTableData()
};
const currentPage = ref(1);
......@@ -681,15 +682,15 @@ const fetchTableData = async () => {
keyword: '',
type: 1, // type 1= 法案 2= 政令 3 =智库 4=智库报告 5=实体清单【制裁记录】 6= 人物 7= 机构 8=新闻 9= 社媒
domains: selectedArea.value === '全部领域' ? null : [selectedArea.value],
proposedDateStart: null,
proposedDateEnd: selectedDate.value ? selectedDate.value : null,
proposedDateStart: customTime.value[0],
proposedDateEnd: customTime.value[1],
affiliation: selectedParty.value === '全部党派' ? null : selectedParty.value,
originChamber: selectedCongress.value === '全部议院' ? null : selectedCongress.value,
originDepart: selectedOrg.value === '全部委员会' ? null : selectedOrg.value,
sponsorPersonName: selectedmember.value === '全部议员' ? null : selectedmember.value,
status: selectedStauts.value === '通过' ? 1 : 0,
sleStatus: isInvolveCn ? 1 : 0,
description: isSort.value ? 0 : 1 // 0 先按分数降序 后按时间降序 1 先按分数降序,再按时间升序
sort: isSort.value ? 0 : 1 // 0 先按分数降序 后按时间降序 1 先按分数降序,再按时间升序
}
try {
const res = await search(params)
......@@ -697,8 +698,6 @@ const fetchTableData = async () => {
if (res.code === 200 && res.data) {
tableData.value = res.data.records
totalNum.value = res.data.total
staticsDemensionList.value[0].data = {
dataX: Object.keys(res.data.aggregationsDate),
dataY: Object.values(res.data.aggregationsDate).map(value => Number(value))
......@@ -726,6 +725,20 @@ const fetchTableData = async () => {
}
const curDemensionItem = staticsDemensionList.value.filter(item => {
return item.name === curDemension.value
})[0]
setTimeout(() => {
activeChart.value = curDemensionItem.chartTypeList[0]
curChartData.value = curDemensionItem.data
})
} catch (error) {
}
......@@ -854,10 +867,15 @@ const curChartData = ref(null)
// 跳转到当前页 初始化筛选条件
const initParam = () => {
selectedArea.value = route.query.domains ? route.query.domains : '全部领域'
selectedDate.value = route.query.selectedDate,
isInvolveCn.value = route.query.isInvolveCn ? true : false
if (Array.isArray(JSON.parse(route.query.selectedDate)) && JSON.parse(route.query.selectedDate).length) {
selectedDate.value = '自定义'
customTime.value = JSON.parse(route.query.selectedDate)
// console.log('customTime', customTime.value);
}
isInvolveCn.value = route.query.isInvolveCn ? true : false
if (route.query.status) {
selectedStauts.value = route.query.status === '1' ? '通过' : '提出'
} else {
......@@ -879,9 +897,6 @@ onMounted(async () => {
await fetchTableData()
activeChart.value = staticsDemensionList.value[0].chartTypeList[0]
curChartData.value = staticsDemensionList.value[0].data
})
</script>
......
<template>
<div class="select-wrapper" :class="{'select-wrapper-custom': selectValue === '自定义'}">
<div class="select-wrapper" :class="{ 'select-wrapper-custom': selectValue === '自定义' }">
<div class="select-left text-tip-1">{{ selectTitle + ':' }}</div>
<div class="select-right" :class="{'select-right-custom': selectValue === '自定义'}">
<div class="select-right" :class="{ 'select-right-custom': selectValue === '自定义' }">
<el-select v-model="selectValue" :placeholder="placeholderName" style="width: 240px">
<!-- <el-option label="全部领域" value="全部领域" /> -->
<el-option v-for="item in selectList" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-date-picker style="width: 300px" v-if="selectValue === '自定义'" v-model="customTimeValue" type="daterange"
<el-date-picker style="width: 300px" v-if="selectValue==='自定义'" v-model="customTimeValue" type="daterange" value-format="YYYY-MM-DD"
range-separator="--" start-placeholder="开始日期" end-placeholder="结束日期" size="default" />
<!-- <el-date-picker v-model="customTimeValue" type="daterange" value-format="YYYY-MM-DD">
</el-date-picker> -->
</div>
</div>
</template>
......@@ -61,6 +63,7 @@ const customTimeValue = computed({
justify-content: space-between;
align-items: center;
gap: 8px;
.select-left {
width: 100px;
height: 24px;
......@@ -72,15 +75,18 @@ const customTimeValue = computed({
display: flex;
gap: 8px;
justify-content: space-between;
:deep(.el-input__wrapper) {
border-radius: 4px;
}
}
.select-right-custom{
.select-right-custom {
width: 630px;
}
}
.select-wrapper-custom{
.select-wrapper-custom {
width: 738px;
}
</style>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论