提交 1c13c291 authored 作者: coderBryanFu's avatar coderBryanFu

法案概览页新增图表跳转资源库

...@@ -36,6 +36,47 @@ function parseChartInterpretationArray(buffer) { ...@@ -36,6 +36,47 @@ function parseChartInterpretationArray(buffer) {
throw new Error("无法解析图表解读 JSON 数组"); throw new Error("无法解析图表解读 JSON 数组");
} }
/**
* 从数组结果中提取可展示的解读文本
* @param {unknown[]} arr
* @returns {string}
*/
function pickInterpretationText(arr) {
if (!Array.isArray(arr) || arr.length === 0) {
return "";
}
const first = arr[0] || {};
return (
first["解读"] ||
first["interpretation"] ||
first["analysis"] ||
first["content"] ||
""
);
}
/**
* 从非标准 JSON 文本中兜底提取“解读”字段(兼容单引号/双引号)
* 示例:
* [{'图表标题': '数量变化趋势', '解读': 'xxx'}]
* [{"图表标题":"数量变化趋势","解读":"xxx"}]
* @param {string} text
* @returns {string}
*/
function extractInterpretationFromLooseText(text) {
const raw = String(text || "");
if (!raw) {
return "";
}
const reg =
/["']解读["']\s*:\s*["']([\s\S]*?)["']\s*(?:[,}\]])/;
const m = raw.match(reg);
if (!m || !m[1]) {
return "";
}
return String(m[1]).replace(/\\n/g, "\n").trim();
}
/** /**
* 图表解读(SSE 流式) * 图表解读(SSE 流式)
* @param {object} data - 请求体 * @param {object} data - 请求体
...@@ -44,9 +85,15 @@ function parseChartInterpretationArray(buffer) { ...@@ -44,9 +85,15 @@ function parseChartInterpretationArray(buffer) {
* @returns {Promise<{data: unknown[]}>} * @returns {Promise<{data: unknown[]}>}
*/ */
export function getChartAnalysis(data, options = {}) { export function getChartAnalysis(data, options = {}) {
const { onChunk } = options; const onDelta =
typeof options?.onChunk === "function"
? options.onChunk
: typeof options?.onInterpretationDelta === "function"
? options.onInterpretationDelta
: null;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let buffer = ""; let buffer = "";
let latestInterpretation = "";
let settled = false; let settled = false;
const abortController = new AbortController(); const abortController = new AbortController();
...@@ -119,9 +166,18 @@ export function getChartAnalysis(data, options = {}) { ...@@ -119,9 +166,18 @@ export function getChartAnalysis(data, options = {}) {
buffer += raw; buffer += raw;
} }
// 兜底:非标准 JSON(如单引号 Python 风格)时,尝试直接从文本提取“解读”
const looseInterpretation = extractInterpretationFromLooseText(raw);
if (looseInterpretation) {
latestInterpretation = looseInterpretation;
safeResolve({ data: [{ 解读: looseInterpretation }] });
abortController.abort();
return;
}
// 每收到一条消息即回调,用于流式渲染 // 每收到一条消息即回调,用于流式渲染
if (chunk && typeof onChunk === "function") { if (chunk && onDelta) {
onChunk(chunk); onDelta(chunk);
} }
// 如果 buffer 已经拼完 markdown code fence,则提前解析并中断连接 // 如果 buffer 已经拼完 markdown code fence,则提前解析并中断连接
...@@ -129,6 +185,10 @@ export function getChartAnalysis(data, options = {}) { ...@@ -129,6 +185,10 @@ export function getChartAnalysis(data, options = {}) {
if (trimmed.endsWith("```")) { if (trimmed.endsWith("```")) {
try { try {
const arr = parseChartInterpretationArray(trimmed); const arr = parseChartInterpretationArray(trimmed);
const interpretation = pickInterpretationText(arr);
if (interpretation) {
latestInterpretation = interpretation;
}
safeResolve({ data: arr }); safeResolve({ data: arr });
abortController.abort(); abortController.abort();
} catch (_) { } } catch (_) { }
...@@ -137,8 +197,22 @@ export function getChartAnalysis(data, options = {}) { ...@@ -137,8 +197,22 @@ export function getChartAnalysis(data, options = {}) {
onclose: () => { onclose: () => {
try { try {
const arr = parseChartInterpretationArray(buffer); const arr = parseChartInterpretationArray(buffer);
const interpretation = pickInterpretationText(arr);
if (interpretation) {
latestInterpretation = interpretation;
}
safeResolve({ data: arr }); safeResolve({ data: arr });
} catch (e) { } catch (e) {
// 兜底:整体 buffer 不是标准 JSON(如单引号)时直接提取“解读”
const looseInterpretation = extractInterpretationFromLooseText(buffer);
if (looseInterpretation) {
safeResolve({ data: [{ 解读: looseInterpretation }] });
return;
}
if (latestInterpretation) {
safeResolve({ data: [{ 解读: latestInterpretation }] });
return;
}
safeReject(e); safeReject(e);
} }
}, },
......
...@@ -1156,6 +1156,15 @@ ...@@ -1156,6 +1156,15 @@
| -------- | -------- | ----- | -------- | -------- | ------ | | -------- | -------- | ----- | -------- | -------- | ------ |
|areas|区域名称列表|query|false|array|string| |areas|区域名称列表|query|false|array|string|
|researchTypeIds|研究类型ID列表|query|false|array|string| |researchTypeIds|研究类型ID列表|query|false|array|string|
|domainIds|科技领域 ID 列表(逗号分隔)|query|false|string||
|startDate|发布时间起 YYYY-MM-DD(与政策追踪发布时间逻辑一致)|query|false|string||
|endDate|发布时间止 YYYY-MM-DD|query|false|string||
|category|分类(如调查项目)|query|false|string||
|pageNum|页码|query|false|integer||
|pageSize|每页条数|query|false|integer||
|sortFun|排序|query|false|boolean||
|thinkTankId|智库 ID(详情页动态列表限定当前智库)|query|false|string||
|keyword|关键词搜索(智库动态)|query|false|string||
|token|Token Request Header|header|false|string|| |token|Token Request Header|header|false|string||
......
// 智库概览信息 // 智库概览信息
import request from "@/api/request.js"; import request, { getToken } from "@/api/request.js";
// 智库列表 // 智库列表
export function getThinkTankList() { export function getThinkTankList() {
...@@ -87,7 +87,11 @@ export function getHylyList() { ...@@ -87,7 +87,11 @@ export function getHylyList() {
} }
//获取智库报告 /**
* 智库概览/智库动态-智库报告、调查项目
* GET /api/thinkTankOverview/report
* 常用 query:pageNum, pageSize, sortFun, domainIds, startDate, endDate, category(调查项目), thinkTankId(详情页), keyword(动态搜索)
*/
export function getThinkTankReport(params) { export function getThinkTankReport(params) {
return request({ return request({
method: 'GET', method: 'GET',
...@@ -158,6 +162,7 @@ export function getThinkDynamicsReport(params) { ...@@ -158,6 +162,7 @@ export function getThinkDynamicsReport(params) {
// 智库领域观点分析(流式) // 智库领域观点分析(流式)
// [POST] 8.140.26.4:10029/report-domain-view-analysis // [POST] 8.140.26.4:10029/report-domain-view-analysis
// 每次请求体:{ domain, report_view_list }(一个 domain);多领域由前端按领域循环多次调用
export function postReportDomainViewAnalysis(data) { export function postReportDomainViewAnalysis(data) {
return request({ return request({
method: 'POST', method: 'POST',
...@@ -167,6 +172,86 @@ export function postReportDomainViewAnalysis(data) { ...@@ -167,6 +172,86 @@ export function postReportDomainViewAnalysis(data) {
}) })
} }
/**
* 智库领域观点分析(真正流式,逐 chunk 回调)
* @param {object} data
* @param {{ onReasoningChunk?: (chunk: string) => void, onMessage?: (msg: any) => void }} handlers
*/
export async function postReportDomainViewAnalysisStream(data, handlers = {}) {
const { onReasoningChunk, onMessage } = handlers
const token = getToken()
const response = await fetch('/intelligent-api/report-domain-view-analysis', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(token ? { token } : {})
},
body: JSON.stringify(data)
})
if (!response.ok) {
throw new Error(`流式分析请求失败: ${response.status}`)
}
// 兜底:非流式返回时仍可读取文本继续后续解析
if (!response.body) {
return await response.text()
}
const reader = response.body.getReader()
const decoder = new TextDecoder('utf-8')
let done = false
let pending = ''
let fullText = ''
while (!done) {
const result = await reader.read()
done = result.done
if (result.value) {
const chunkText = decoder.decode(result.value, { stream: !done })
fullText += chunkText
pending += chunkText
const lines = pending.split(/\r?\n/)
pending = lines.pop() ?? ''
for (const rawLine of lines) {
const line = String(rawLine || '').trim()
if (!line || !line.startsWith('data:')) continue
const jsonText = line.slice(5).trim()
if (!jsonText || jsonText === '[DONE]') continue
try {
const msg = JSON.parse(jsonText)
if (typeof onMessage === 'function') onMessage(msg)
if (msg?.type === 'reasoning' && msg?.chunk != null && typeof onReasoningChunk === 'function') {
const c = String(msg.chunk)
if (c) onReasoningChunk(c)
}
} catch (e) {
// 忽略非 JSON 数据行
}
}
}
}
// 处理最后一行残留
const last = String(pending || '').trim()
if (last.startsWith('data:')) {
const jsonText = last.slice(5).trim()
if (jsonText && jsonText !== '[DONE]') {
try {
const msg = JSON.parse(jsonText)
if (typeof onMessage === 'function') onMessage(msg)
if (msg?.type === 'reasoning' && msg?.chunk != null && typeof onReasoningChunk === 'function') {
const c = String(msg.chunk)
if (c) onReasoningChunk(c)
}
} catch (e) {
// ignore
}
}
}
return fullText
}
//提出建议领域分布 //提出建议领域分布
export function getThinkPolicyIndustry(params) { export function getThinkPolicyIndustry(params) {
...@@ -240,18 +325,12 @@ export function getThinkTankInfoBranch(params) { ...@@ -240,18 +325,12 @@ export function getThinkTankInfoBranch(params) {
}) })
} }
//获取经费来源统计
export function getThinkTankFundsTotal(params) {
return request({
method: 'GET',
url: `/api/thinkTankInfo/fundsTotal/${params}`,
})
}
//获取经费来源 //获取经费来源
export function getThinkTankFundsSource(params) { export function getThinkTankFundsSource(params) {
return request({ return request({
method: 'GET', method: 'GET',
url: `/api/thinkTankInfo/fundsSource/${params}`, url: `/api/thinkTankInfo/fundsStatistics/${params}`,
}) })
} }
...@@ -265,9 +344,17 @@ export function getThinkTankResearchAreae(params) { ...@@ -265,9 +344,17 @@ export function getThinkTankResearchAreae(params) {
//获取核心研究人员 //获取核心研究人员
export function getThinkTankPerson(params) { export function getThinkTankPerson(params) {
const { thinkTankId, currentPage, pageSize } = params
return request({ return request({
method: 'GET', method: 'GET',
url: `/api/thinkTankInfo/person/${params}`, url: `/api/thinkTankInfo/person/page`,
params: {
currentPage,
pageNum: currentPage,
page: currentPage,
pageSize,
thinkTankId
}
}) })
} }
......
...@@ -330,11 +330,11 @@ onMounted(async () => { ...@@ -330,11 +330,11 @@ onMounted(async () => {
.box1 { .box1 {
margin-top: 19px; margin-top: 19px;
width: 1600px; width: 1600px;
height: 1173px;
.box1-main { .box1-main {
margin-top: 8px; margin-top: 8px;
height: 1097px; min-height: 778px;
padding-left: 21px; padding-left: 21px;
padding-right: 50px; padding-right: 50px;
padding-bottom: 21px; padding-bottom: 21px;
...@@ -421,7 +421,7 @@ onMounted(async () => { ...@@ -421,7 +421,7 @@ onMounted(async () => {
.item-box { .item-box {
width: 506px; width: 506px;
height: 100%; min-height: 639.2px;
border-top: 1px solid rgb(234, 236, 238); border-top: 1px solid rgb(234, 236, 238);
.item { .item {
......
import * as echarts from 'echarts' import * as echarts from 'echarts'
/** 政策追踪「研究领域变化趋势」图例分页:每页条数(与概览数量变化趋势逻辑一致,条数按产品要求为 4) */
export const POLICY_TRACKING_LEGEND_PAGE_SIZE = 4
const colorList = [ const colorList = [
'rgba(5, 95, 194, 1)', 'rgba(5, 95, 194, 1)',
'rgba(19, 168, 168, 1)', 'rgba(19, 168, 168, 1)',
...@@ -35,22 +32,16 @@ const parseRgba = (colorStr) => { ...@@ -35,22 +32,16 @@ const parseRgba = (colorStr) => {
/** /**
* @param {{ title: unknown[], data: Array<{ name: string, value: unknown[], color?: string }> }} chartInput * @param {{ title: unknown[], data: Array<{ name: string, value: unknown[], color?: string }> }} chartInput
* @param {{ legendShowCount?: number, legendPageIndex?: number }} [options]
*/ */
const getMultiLineChart = (chartInput, options = {}) => { const getMultiLineChart = (chartInput) => {
const title = chartInput.title const title = chartInput.title
const series = chartInput.data || [] const series = chartInput.data || []
const legendShowCount =
typeof options.legendShowCount === 'number' && options.legendShowCount > 0
? options.legendShowCount
: POLICY_TRACKING_LEGEND_PAGE_SIZE
const rawPageIndex = Number(options.legendPageIndex) || 0
const allNames = series.map((item) => item.name) const allNames = series.map((item) => item.name)
const pageCount = Math.max(1, Math.ceil(allNames.length / legendShowCount)) const lineSize = Math.ceil(allNames.length / 3)
const legendPageIndex = Math.min(Math.max(0, rawPageIndex), pageCount - 1) const legendLine1 = allNames.slice(0, lineSize)
const legendStart = legendPageIndex * legendShowCount const legendLine2 = allNames.slice(lineSize, lineSize * 2)
const legendData = allNames.slice(legendStart, legendStart + legendShowCount) const legendLine3 = allNames.slice(lineSize * 2)
const xCount = Array.isArray(title) ? title.length : 0 const xCount = Array.isArray(title) ? title.length : 0
const labelFontSize = xCount > 8 ? 10 : xCount > 5 ? 11 : 12 const labelFontSize = xCount > 8 ? 10 : xCount > 5 ? 11 : 12
...@@ -91,16 +82,17 @@ const getMultiLineChart = (chartInput, options = {}) => { ...@@ -91,16 +82,17 @@ const getMultiLineChart = (chartInput, options = {}) => {
}, },
/* 贴满 #box3Chart:四边 0,由 containLabel 在网格内为轴文字留位,避免左侧/底部大块留白 */ /* 贴满 #box3Chart:四边 0,由 containLabel 在网格内为轴文字留位,避免左侧/底部大块留白 */
grid: { grid: {
top: 50, top: 92,
right: 10, right: 10,
bottom: 0, bottom: 0,
left: 20, left: 20,
containLabel: true containLabel: true
}, },
legend: { legend: [
{
show: true, show: true,
type: 'plain', type: 'plain',
data: legendData, data: legendLine1,
top: 4, top: 4,
left: 'center', left: 'center',
icon: 'circle', icon: 'circle',
...@@ -116,6 +108,45 @@ const getMultiLineChart = (chartInput, options = {}) => { ...@@ -116,6 +108,45 @@ const getMultiLineChart = (chartInput, options = {}) => {
itemWidth: 12, itemWidth: 12,
itemHeight: 12 itemHeight: 12
}, },
{
show: legendLine2.length > 0,
type: 'plain',
data: legendLine2,
top: 30,
left: 'center',
icon: 'circle',
textStyle: {
fontFamily: 'Source Han Sans CN',
fontWeight: 400,
fontSize: 14,
lineHeight: 24,
letterSpacing: 0,
align: 'left',
color: 'rgb(95, 101, 108)'
},
itemWidth: 12,
itemHeight: 12
},
{
show: legendLine3.length > 0,
type: 'plain',
data: legendLine3,
top: 56,
left: 'center',
icon: 'circle',
textStyle: {
fontFamily: 'Source Han Sans CN',
fontWeight: 400,
fontSize: 14,
lineHeight: 24,
letterSpacing: 0,
align: 'left',
color: 'rgb(95, 101, 108)'
},
itemWidth: 12,
itemHeight: 12
}
],
color: colorList, color: colorList,
xAxis: [ xAxis: [
{ {
...@@ -142,6 +173,16 @@ const getMultiLineChart = (chartInput, options = {}) => { ...@@ -142,6 +173,16 @@ const getMultiLineChart = (chartInput, options = {}) => {
yAxis: [ yAxis: [
{ {
type: 'value', type: 'value',
name: '数量',
nameLocation: 'end',
nameGap: 20,
nameTextStyle: {
color: 'rgb(132, 136, 142)',
fontFamily: 'Source Han Sans CN',
fontWeight: 400,
fontSize: 11,
padding: [0, 0, 0, -20] // 👈 这个是左移 4px(上、右、下、左)
},
splitNumber: 4, splitNumber: 4,
axisLabel: { axisLabel: {
color: 'rgb(132, 136, 142)', color: 'rgb(132, 136, 142)',
......
...@@ -21,16 +21,17 @@ ...@@ -21,16 +21,17 @@
<div class="title">{{ "科技领域" }}</div> <div class="title">{{ "科技领域" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchTypeIds)" class="checkbox-group"
@change="val => handleToggleAll(val, researchTypeIds)"> :model-value="selectedResearchIds"
全部领域 @change="handleAreaGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
{{ RESOURCE_FILTER_ALL_AREA }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchTypeList" :key="type.id" v-model="selectedResearchIds" :label="type.id" <el-checkbox v-for="type in researchTypeList" :key="type.id" class="filter-checkbox" :label="type.id">
class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
<div class="select-time-box"> <div class="select-time-box">
...@@ -39,16 +40,17 @@ ...@@ -39,16 +40,17 @@
<div class="title">{{ "发布时间" }}</div> <div class="title">{{ "发布时间" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchTimeIds)" class="checkbox-group"
@change="val => handleToggleAll(val, researchTimeIds)"> :model-value="selectedResearchTimeIds"
全部时间 @change="handleTimeGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
{{ RESOURCE_FILTER_ALL_TIME }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchTimeList" :key="type.id" v-model="selectedResearchTimeIds" <el-checkbox v-for="type in researchTimeList" :key="type.id" class="filter-checkbox" :label="type.id">
:label="type.id" class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
<!-- <div class="input-main"> <!-- <div class="input-main">
<el-input placeholder="输入作者名字" v-model="author" @input="handleGetThinkDynamicsReport()" /> <el-input placeholder="输入作者名字" v-model="author" @input="handleGetThinkDynamicsReport()" />
...@@ -63,7 +65,7 @@ ...@@ -63,7 +65,7 @@
<img :src="item.imageUrl" alt="" /> <img :src="item.imageUrl" alt="" />
</div> </div>
<div class="footer-card-title"> <div class="footer-card-title">
{{ item.name }} <span v-html="highlightText(item.name)"></span>
</div> </div>
<div class="footer-card-footer"> <div class="footer-card-footer">
<div class="time">{{ item.times }}</div> <div class="time">{{ item.times }}</div>
...@@ -84,7 +86,14 @@ ...@@ -84,7 +86,14 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { computed, ref, toRefs, watch } from "vue"; import { ref, toRefs, watch } from "vue";
import {
RESOURCE_FILTER_ALL_AREA,
RESOURCE_FILTER_ALL_TIME,
normalizeExclusiveAllOption,
stripAllAreaForRequest,
stripAllTimeForRequest
} from "../../../utils/resourceLibraryFilters";
const props = defineProps({ const props = defineProps({
researchTypeList: { researchTypeList: {
...@@ -114,6 +123,10 @@ const props = defineProps({ ...@@ -114,6 +123,10 @@ const props = defineProps({
currentPage: { currentPage: {
type: Number, type: Number,
default: 1 default: 1
},
searchKeyword: {
type: String,
default: ""
} }
}); });
...@@ -127,43 +140,58 @@ const emit = defineEmits([ ...@@ -127,43 +140,58 @@ const emit = defineEmits([
// 解构 props,保持模板里变量名不变 // 解构 props,保持模板里变量名不变
const { researchTypeList, researchTimeList, curFooterList, total, currentPage } = toRefs(props); const { researchTypeList, researchTimeList, curFooterList, total, currentPage } = toRefs(props);
const selectedResearchIds = ref([]); const selectedResearchIds = ref([RESOURCE_FILTER_ALL_AREA]);
const selectedResearchTimeIds = ref([]); const selectedResearchTimeIds = ref([RESOURCE_FILTER_ALL_TIME]);
const escapeHtml = (text) => {
return String(text ?? "")
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
};
const escapeRegExp = (text) => {
return String(text ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
};
const highlightText = (text) => {
const safeText = escapeHtml(text);
const keyword = (props.searchKeyword || "").trim();
if (!keyword) return safeText;
const pattern = new RegExp(`(${escapeRegExp(keyword)})`, "gi");
return safeText.replace(pattern, '<span class="keyword-highlight">$1</span>');
};
// 父组件更新时同步到子组件
watch( watch(
() => props.selectedFilters, () => props.selectedFilters,
val => { val => {
selectedResearchIds.value = val?.researchTypeIds ? [...val.researchTypeIds] : []; selectedResearchIds.value =
selectedResearchTimeIds.value = val?.researchTimeIds ? [...val.researchTimeIds] : []; val?.researchTypeIds?.length > 0
? [...val.researchTypeIds]
: [RESOURCE_FILTER_ALL_AREA];
selectedResearchTimeIds.value =
val?.researchTimeIds?.length > 0
? [...val.researchTimeIds]
: [RESOURCE_FILTER_ALL_TIME];
}, },
{ immediate: true, deep: true } { immediate: true, deep: true }
); );
const buildSelectedFiltersPayload = () => ({ const buildSelectedFiltersPayload = () => ({
researchTypeIds: [...selectedResearchIds.value], researchTypeIds: stripAllAreaForRequest(selectedResearchIds.value),
researchTimeIds: [...selectedResearchTimeIds.value], researchTimeIds: stripAllTimeForRequest(selectedResearchTimeIds.value),
researchHearingIds: [] researchHearingIds: []
}); });
const researchTypeIds = computed(() => (researchTypeList.value || []).map(item => item.id)); const handleAreaGroupChange = (val) => {
const researchTimeIds = computed(() => (researchTimeList.value || []).map(item => item.id)); selectedResearchIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA);
handleGetThinkDynamicsReport();
const getTargetSelection = ids => (ids === researchTypeIds.value ? selectedResearchIds : selectedResearchTimeIds); };
const isGroupAllSelected = ids =>
ids.length > 0 && ids.every(id => getTargetSelection(ids).value.includes(id));
const handleToggleAll = (checked, ids) => { const handleTimeGroupChange = (val) => {
if (!ids.length) return; selectedResearchTimeIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME);
const targetSelection = getTargetSelection(ids);
const nextSelected = new Set(targetSelection.value);
if (checked) {
ids.forEach(id => nextSelected.add(id));
} else {
ids.forEach(id => nextSelected.delete(id));
}
targetSelection.value = [...nextSelected];
handleGetThinkDynamicsReport(); handleGetThinkDynamicsReport();
}; };
...@@ -326,6 +354,10 @@ const handleToReportDetail = item => { ...@@ -326,6 +354,10 @@ const handleToReportDetail = item => {
} }
} }
:deep(.keyword-highlight) {
background-color: #fff59d;
}
.right { .right {
width: 1284px; width: 1284px;
height: 1377px; height: 1377px;
......
...@@ -21,16 +21,17 @@ ...@@ -21,16 +21,17 @@
<div class="title">{{ "科技领域" }}</div> <div class="title">{{ "科技领域" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchTypeIds)" class="checkbox-group"
@change="val => handleToggleAll(val, researchTypeIds)"> :model-value="selectedResearchIds"
全部领域 @change="handleAreaGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
{{ RESOURCE_FILTER_ALL_AREA }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchTypeList" :key="type.id" v-model="selectedResearchIds" :label="type.id" <el-checkbox v-for="type in researchTypeList" :key="type.id" class="filter-checkbox" :label="type.id">
class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
<div class="select-time-box"> <div class="select-time-box">
...@@ -39,16 +40,17 @@ ...@@ -39,16 +40,17 @@
<div class="title">{{ "发布时间" }}</div> <div class="title">{{ "发布时间" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchTimeIds)" class="checkbox-group"
@change="val => handleToggleAll(val, researchTimeIds)"> :model-value="selectedResearchTimeIds"
全部时间 @change="handleTimeGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
{{ RESOURCE_FILTER_ALL_TIME }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchTimeList" :key="type.id" v-model="selectedResearchTimeIds" <el-checkbox v-for="type in researchTimeList" :key="type.id" class="filter-checkbox" :label="type.id">
:label="type.id" class="filter-checkbox" @change="handleGetThinkDynamicsReport()">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
<!-- <div class="input-main"> <!-- <div class="input-main">
<el-input placeholder="输入作者名字" v-model="author" @input="handleGetThinkDynamicsReport()" /> <el-input placeholder="输入作者名字" v-model="author" @input="handleGetThinkDynamicsReport()" />
...@@ -63,7 +65,7 @@ ...@@ -63,7 +65,7 @@
<img :src="item.imageUrl" alt="" /> <img :src="item.imageUrl" alt="" />
</div> </div>
<div class="footer-card-title"> <div class="footer-card-title">
{{ item.name }} <span v-html="highlightText(item.name)"></span>
</div> </div>
<div class="footer-card-footer"> <div class="footer-card-footer">
<div class="time">{{ item.times }}</div> <div class="time">{{ item.times }}</div>
...@@ -84,7 +86,14 @@ ...@@ -84,7 +86,14 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { computed, ref, toRefs, watch } from "vue"; import { ref, toRefs, watch } from "vue";
import {
RESOURCE_FILTER_ALL_AREA,
RESOURCE_FILTER_ALL_TIME,
normalizeExclusiveAllOption,
stripAllAreaForRequest,
stripAllTimeForRequest
} from "../../../utils/resourceLibraryFilters";
const props = defineProps({ const props = defineProps({
researchTypeList: { researchTypeList: {
...@@ -114,6 +123,10 @@ const props = defineProps({ ...@@ -114,6 +123,10 @@ const props = defineProps({
currentPage: { currentPage: {
type: Number, type: Number,
default: 1 default: 1
},
searchKeyword: {
type: String,
default: ""
} }
}); });
...@@ -127,43 +140,59 @@ const emit = defineEmits([ ...@@ -127,43 +140,59 @@ const emit = defineEmits([
// 解构 props,保持模板里变量名不变 // 解构 props,保持模板里变量名不变
const { researchTypeList, researchTimeList, curFooterList, total, currentPage } = toRefs(props); const { researchTypeList, researchTimeList, curFooterList, total, currentPage } = toRefs(props);
const selectedResearchIds = ref([]); const selectedResearchIds = ref([RESOURCE_FILTER_ALL_AREA]);
const selectedResearchTimeIds = ref([]); const selectedResearchTimeIds = ref([RESOURCE_FILTER_ALL_TIME]);
const escapeHtml = (text) => {
return String(text ?? "")
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
};
const escapeRegExp = (text) => {
return String(text ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
};
// 父组件更新时同步到子组件 const highlightText = (text) => {
const safeText = escapeHtml(text);
const keyword = (props.searchKeyword || "").trim();
if (!keyword) return safeText;
const pattern = new RegExp(`(${escapeRegExp(keyword)})`, "gi");
return safeText.replace(pattern, '<span class="keyword-highlight">$1</span>');
};
// 父组件更新时同步到子组件(接口层无选中时为「全部」)
watch( watch(
() => props.selectedFilters, () => props.selectedFilters,
val => { val => {
selectedResearchIds.value = val?.researchTypeIds ? [...val.researchTypeIds] : []; selectedResearchIds.value =
selectedResearchTimeIds.value = val?.researchTimeIds ? [...val.researchTimeIds] : []; val?.researchTypeIds?.length > 0
? [...val.researchTypeIds]
: [RESOURCE_FILTER_ALL_AREA];
selectedResearchTimeIds.value =
val?.researchTimeIds?.length > 0
? [...val.researchTimeIds]
: [RESOURCE_FILTER_ALL_TIME];
}, },
{ immediate: true, deep: true } { immediate: true, deep: true }
); );
const buildSelectedFiltersPayload = () => ({ const buildSelectedFiltersPayload = () => ({
researchTypeIds: [...selectedResearchIds.value], researchTypeIds: stripAllAreaForRequest(selectedResearchIds.value),
researchTimeIds: [...selectedResearchTimeIds.value], researchTimeIds: stripAllTimeForRequest(selectedResearchTimeIds.value),
researchHearingIds: [] researchHearingIds: []
}); });
const researchTypeIds = computed(() => (researchTypeList.value || []).map(item => item.id)); const handleAreaGroupChange = (val) => {
const researchTimeIds = computed(() => (researchTimeList.value || []).map(item => item.id)); selectedResearchIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA);
handleGetThinkDynamicsReport();
const getTargetSelection = ids => (ids === researchTypeIds.value ? selectedResearchIds : selectedResearchTimeIds); };
const isGroupAllSelected = ids =>
ids.length > 0 && ids.every(id => getTargetSelection(ids).value.includes(id));
const handleToggleAll = (checked, ids) => { const handleTimeGroupChange = (val) => {
if (!ids.length) return; selectedResearchTimeIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME);
const targetSelection = getTargetSelection(ids);
const nextSelected = new Set(targetSelection.value);
if (checked) {
ids.forEach(id => nextSelected.add(id));
} else {
ids.forEach(id => nextSelected.delete(id));
}
targetSelection.value = [...nextSelected];
handleGetThinkDynamicsReport(); handleGetThinkDynamicsReport();
}; };
...@@ -326,6 +355,10 @@ const handleToReportDetail = item => { ...@@ -326,6 +355,10 @@ const handleToReportDetail = item => {
} }
} }
:deep(.keyword-highlight) {
background-color: #fff59d;
}
.right { .right {
width: 1284px; width: 1284px;
height: 1377px; height: 1377px;
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
}"> }">
<template #prefix> <template #prefix>
<img src="../assets/images/sort-asc.png" class="select-prefix-img" alt="" @click.stop="toggleSort()" <img src="../assets/images/sort-asc.png" class="select-prefix-img" alt="" @click.stop="toggleSort()"
:key="true" label="正序" :value="true" v-if="sort === true" /> :key="true" label="正序" :value="true" v-if="sort !== false" />
<img src="../assets/images/sort-desc.png" class="select-prefix-img" alt="" @click.stop="toggleSort()" <img src="../assets/images/sort-desc.png" class="select-prefix-img" alt="" @click.stop="toggleSort()"
:key="false" label="倒序" :value="false" v-if="sort === false" /> :key="false" label="倒序" :value="false" v-if="sort === false" />
</template> </template>
...@@ -191,7 +191,7 @@ const handleGetThinkTankList = async () => { ...@@ -191,7 +191,7 @@ const handleGetThinkTankList = async () => {
total.value = 0; total.value = 0;
} }
}; };
// 初始为 null:el-select 显示 placeholder;但排序仍按“正序”规则(见 sortedCardList) // 默认显示 placeholder「报告数量」,但前缀图标显示正序
const sort = ref(null); const sort = ref(null);
const toggleSort = () => { const toggleSort = () => {
sort.value = sort.value === false ? true : false sort.value = sort.value === false ? true : false
......
...@@ -7,15 +7,21 @@ ...@@ -7,15 +7,21 @@
<div class="title">{{ "科技领域" }}</div> <div class="title">{{ "科技领域" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox v-model="checkAllModel" class="all-checkbox" @change="emit('check-all-change', $event)"> class="checkbox-group"
全部领域 :model-value="selectedAreaList"
@change="handleAreaGroupChange">
<el-checkbox class="filter-checkbox all-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
{{ RESOURCE_FILTER_ALL_AREA }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="research in areaList" :key="research.id" v-model="selectedAreaListModel" <el-checkbox
:label="research.id" @change="emit('checked-area-change')" class="filter-checkbox"> v-for="research in areaList"
:key="research.id"
class="filter-checkbox"
:label="research.id">
{{ research.name }} {{ research.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
...@@ -25,17 +31,21 @@ ...@@ -25,17 +31,21 @@
<div class="title">{{ "发布时间" }}</div> <div class="title">{{ "发布时间" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox v-model="checkAllTimeModel" class="all-checkbox" class="checkbox-group"
@change="emit('check-all-time-change', $event)"> :model-value="selectedPubTimeList"
全部时间 @change="handleTimeGroupChange">
<el-checkbox class="filter-checkbox all-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
{{ RESOURCE_FILTER_ALL_TIME }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="time in pubTimeList" :key="time.id" v-model="selectedPubTimeListModel" :label="time.id" <el-checkbox
class="filter-checkbox" @change="emit('checked-area-time-change')"> v-for="time in pubTimeList"
:key="time.id"
class="filter-checkbox"
:label="time.id">
{{ time.name }} {{ time.name }}
</el-checkbox> </el-checkbox>
</el-checkbox-group>
</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -68,56 +78,39 @@ ...@@ -68,56 +78,39 @@
</template> </template>
<script setup> <script setup>
import { computed } from "vue"; import {
RESOURCE_FILTER_ALL_AREA,
RESOURCE_FILTER_ALL_TIME,
normalizeExclusiveAllOption
} from "../utils/resourceLibraryFilters";
const props = defineProps({ defineProps({
checkAll: { type: Boolean, default: false },
isIndeterminate: { type: Boolean, default: false },
areaList: { type: Array, default: () => [] }, areaList: { type: Array, default: () => [] },
selectedAreaList: { type: Array, default: () => [] }, selectedAreaList: { type: Array, default: () => [] },
checkAllTime: { type: Boolean, default: false },
isIndeterminateTime: { type: Boolean, default: false },
pubTimeList: { type: Array, default: () => [] }, pubTimeList: { type: Array, default: () => [] },
selectedPubTimeList: { type: Array, default: () => [] }, selectedPubTimeList: { type: Array, default: () => [] },
curFooterList: { type: Array, default: () => [] }, curFooterList: { type: Array, default: () => [] },
total: { type: Number, default: 0 }, total: { type: Number, default: 0 },
currentPage: { type: Number, default: 1 } currentPage: { type: Number, default: 1 }
}); });
const emit = defineEmits([ const emit = defineEmits([
"update:checkAll",
"update:selectedAreaList", "update:selectedAreaList",
"check-all-change",
"checked-area-change",
"update:checkAllTime",
"update:selectedPubTimeList", "update:selectedPubTimeList",
"check-all-time-change", "filter-change",
"checked-area-time-change",
"report-click", "report-click",
"page-change" "page-change"
]); ]);
const checkAllModel = computed({ const handleAreaGroupChange = (val) => {
get: () => props.checkAll, emit("update:selectedAreaList", normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA));
set: val => emit("update:checkAll", val) emit("filter-change");
}); };
const selectedAreaListModel = computed({ const handleTimeGroupChange = (val) => {
get: () => props.selectedAreaList, emit("update:selectedPubTimeList", normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME));
set: val => emit("update:selectedAreaList", val) emit("filter-change");
}); };
const checkAllTimeModel = computed({
get: () => props.checkAllTime,
set: val => emit("update:checkAllTime", val)
});
const selectedPubTimeListModel = computed({
get: () => props.selectedPubTimeList,
set: val => emit("update:selectedPubTimeList", val)
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
<template> <template>
<!-- 调查项目:结构/样式与智库报告一致,但组件独立,避免互相影响 --> <!-- 调查项目:与智库报告相同的「全部」互斥逻辑 -->
<div class="home-main-footer-main"> <div class="home-main-footer-main">
<div class="left"> <div class="left">
<div class="select-box"> <div class="select-box">
...@@ -8,15 +8,21 @@ ...@@ -8,15 +8,21 @@
<div class="title">{{ "科技领域" }}</div> <div class="title">{{ "科技领域" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox v-model="checkAllModel" class="all-checkbox" @change="emit('check-all-change', $event)"> class="checkbox-group"
全部领域 :model-value="selectedAreaList"
@change="handleAreaGroupChange">
<el-checkbox class="filter-checkbox all-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
{{ RESOURCE_FILTER_ALL_AREA }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="research in areaList" :key="research.id" v-model="selectedAreaListModel" <el-checkbox
:label="research.id" @change="emit('checked-area-change')" class="filter-checkbox"> v-for="research in areaList"
:key="research.id"
class="filter-checkbox"
:label="research.id">
{{ research.name }} {{ research.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
...@@ -26,16 +32,21 @@ ...@@ -26,16 +32,21 @@
<div class="title">{{ "发布时间" }}</div> <div class="title">{{ "发布时间" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox v-model="checkAllTimeModel" class="all-checkbox" class="checkbox-group"
@change="emit('check-all-time-change', $event)"> :model-value="selectedPubTimeList"
全部时间 @change="handleTimeGroupChange">
<el-checkbox class="filter-checkbox all-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
{{ RESOURCE_FILTER_ALL_TIME }}
</el-checkbox> </el-checkbox>
<el-checkbox v-model="selectedPubTimeListModel" v-for="time in pubTimeList" :key="time.id" :label="time.id" <el-checkbox
class="filter-checkbox" @change="emit('checked-area-time-change')"> v-for="time in pubTimeList"
:key="time.id"
class="filter-checkbox"
:label="time.id">
{{ time.name }} {{ time.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
</div> </div>
...@@ -68,56 +79,39 @@ ...@@ -68,56 +79,39 @@
</template> </template>
<script setup> <script setup>
import { computed } from "vue"; import {
RESOURCE_FILTER_ALL_AREA,
RESOURCE_FILTER_ALL_TIME,
normalizeExclusiveAllOption
} from "../utils/resourceLibraryFilters";
const props = defineProps({ defineProps({
checkAll: { type: Boolean, default: false },
isIndeterminate: { type: Boolean, default: false },
areaList: { type: Array, default: () => [] }, areaList: { type: Array, default: () => [] },
selectedAreaList: { type: Array, default: () => [] }, selectedAreaList: { type: Array, default: () => [] },
checkAllTime: { type: Boolean, default: false },
isIndeterminateTime: { type: Boolean, default: false },
pubTimeList: { type: Array, default: () => [] }, pubTimeList: { type: Array, default: () => [] },
selectedPubTimeList: { type: Array, default: () => [] }, selectedPubTimeList: { type: Array, default: () => [] },
curFooterList: { type: Array, default: () => [] }, curFooterList: { type: Array, default: () => [] },
total: { type: Number, default: 0 }, total: { type: Number, default: 0 },
currentPage: { type: Number, default: 1 } currentPage: { type: Number, default: 1 }
}); });
const emit = defineEmits([ const emit = defineEmits([
"update:checkAll",
"update:selectedAreaList", "update:selectedAreaList",
"check-all-change",
"checked-area-change",
"update:checkAllTime",
"update:selectedPubTimeList", "update:selectedPubTimeList",
"check-all-time-change", "filter-change",
"checked-area-time-change",
"report-click", "report-click",
"page-change" "page-change"
]); ]);
const checkAllModel = computed({ const handleAreaGroupChange = (val) => {
get: () => props.checkAll, emit("update:selectedAreaList", normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA));
set: val => emit("update:checkAll", val) emit("filter-change");
}); };
const selectedAreaListModel = computed({
get: () => props.selectedAreaList,
set: val => emit("update:selectedAreaList", val)
});
const checkAllTimeModel = computed({ const handleTimeGroupChange = (val) => {
get: () => props.checkAllTime, emit("update:selectedPubTimeList", normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME));
set: val => emit("update:checkAllTime", val) emit("filter-change");
}); };
const selectedPubTimeListModel = computed({
get: () => props.selectedPubTimeList,
set: val => emit("update:selectedPubTimeList", val)
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
...@@ -7,16 +7,21 @@ ...@@ -7,16 +7,21 @@
<div class="title">{{ "科技领域" }}</div> <div class="title">{{ "科技领域" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchTypeIds)" class="checkbox-group"
@change="val => handleToggleAll(val, researchTypeIds)"> :model-value="selectedResearchIds"
全部领域 @change="handleAreaGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
{{ RESOURCE_FILTER_ALL_AREA }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchTypeList" :key="type.id" v-model="selectedResearchIds" :label="type.id" <el-checkbox
class="filter-checkbox" @change="handleFilterChange"> v-for="type in researchTypeList"
:key="type.id"
class="filter-checkbox"
:label="type.id">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
...@@ -26,16 +31,21 @@ ...@@ -26,16 +31,21 @@
<div class="title">{{ "发布时间" }}</div> <div class="title">{{ "发布时间" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchTimeIds)" class="checkbox-group"
@change="val => handleToggleAll(val, researchTimeIds)"> :model-value="selectedResearchTimeIds"
全部时间 @change="handleTimeGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
{{ RESOURCE_FILTER_ALL_TIME }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchTimeList" :key="type.id" v-model="selectedResearchTimeIds" <el-checkbox
:label="type.id" class="filter-checkbox" @change="handleFilterChange"> v-for="type in researchTimeList"
:key="type.id"
class="filter-checkbox"
:label="type.id">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
...@@ -45,16 +55,21 @@ ...@@ -45,16 +55,21 @@
<div class="title">{{ "听证会部门" }}</div> <div class="title">{{ "听证会部门" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group hearing-grid"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isGroupAllSelected(researchHearingIds)" class="checkbox-group hearing-grid"
@change="val => handleToggleAll(val, researchHearingIds)"> :model-value="selectedResearchHearingIds"
全部部门 @change="handleDeptGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_DEPT">
{{ RESOURCE_FILTER_ALL_DEPT }}
</el-checkbox> </el-checkbox>
<el-checkbox v-for="type in researchHearingList" :key="type.id" v-model="selectedResearchHearingIds" <el-checkbox
:label="type.id" class="filter-checkbox" @change="handleFilterChange"> v-for="type in researchHearingList"
:key="type.id"
class="filter-checkbox"
:label="type.id">
{{ type.name }} {{ type.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
</div> </div>
...@@ -76,8 +91,7 @@ ...@@ -76,8 +91,7 @@
class="card-open-image" /> class="card-open-image" />
</div> </div>
<div class="card-item-category"> <div class="card-item-category">
<AreaTag :key="index" :tagName="item.category"> <AreaTag :key="`cat-${item.id}`" :tagName="item.category" />
</AreaTag>
</div> </div>
</div> </div>
</div> </div>
...@@ -101,6 +115,18 @@ ...@@ -101,6 +115,18 @@
<script setup> <script setup>
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import AreaTag from "@/components/base/AreaTag/index.vue";
import {
RESOURCE_FILTER_ALL_AREA,
RESOURCE_FILTER_ALL_TIME,
RESOURCE_FILTER_ALL_DEPT,
RESOURCE_FILTER_EARLIER,
normalizeExclusiveAllOption,
stripAllAreaForRequest,
stripAllTimeForRequest,
stripAllDeptForRequest,
matchesEarlierChineseDate
} from "../utils/resourceLibraryFilters";
const props = defineProps({ const props = defineProps({
researchTypeList: { type: Array, default: () => [] }, researchTypeList: { type: Array, default: () => [] },
...@@ -112,11 +138,10 @@ const emit = defineEmits(["report-click"]); ...@@ -112,11 +138,10 @@ const emit = defineEmits(["report-click"]);
const pageSize = 10; const pageSize = 10;
const currentPage = ref(1); const currentPage = ref(1);
const selectedResearchIds = ref([]); const selectedResearchIds = ref([RESOURCE_FILTER_ALL_AREA]);
const selectedResearchTimeIds = ref([]); const selectedResearchTimeIds = ref([RESOURCE_FILTER_ALL_TIME]);
const selectedResearchHearingIds = ref([]); const selectedResearchHearingIds = ref([RESOURCE_FILTER_ALL_DEPT]);
// 概览页暂无独立接口时,先使用一份静态数据(结构与智库动态保持一致)
const hearingData = ref([ const hearingData = ref([
{ id: 1, title: "美国国会听证会:人工智能与国家安全", content: "美中经济与安全审查委员会", category: "人工智能", time: "2025年7月8日" }, { id: 1, title: "美国国会听证会:人工智能与国家安全", content: "美中经济与安全审查委员会", category: "人工智能", time: "2025年7月8日" },
{ id: 2, title: "美国国会听证会:先进制造供应链韧性", content: "国会-行政部门中国委员会", category: "先进制造", time: "2025年6月15日" }, { id: 2, title: "美国国会听证会:先进制造供应链韧性", content: "国会-行政部门中国委员会", category: "先进制造", time: "2025年6月15日" },
...@@ -138,46 +163,44 @@ const researchHearingList = ref([ ...@@ -138,46 +163,44 @@ const researchHearingList = ref([
{ id: "美国商务部", name: "美国商务部" }, { id: "美国商务部", name: "美国商务部" },
]); ]);
const researchTypeIds = computed(() => (props.researchTypeList || []).map(item => item.id)); const handleAreaGroupChange = (val) => {
const researchTimeIds = computed(() => (props.researchTimeList || []).map(item => item.id)); selectedResearchIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA);
const researchHearingIds = computed(() => (researchHearingList.value || []).map(item => item.id)); currentPage.value = 1;
};
const getTargetSelection = ids => { const handleTimeGroupChange = (val) => {
if (ids === researchTypeIds.value) return selectedResearchIds; selectedResearchTimeIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME);
if (ids === researchTimeIds.value) return selectedResearchTimeIds; currentPage.value = 1;
return selectedResearchHearingIds;
}; };
const isGroupAllSelected = ids => const handleDeptGroupChange = (val) => {
ids.length > 0 && ids.every(id => getTargetSelection(ids).value.includes(id)); selectedResearchHearingIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_DEPT);
currentPage.value = 1;
const handleToggleAll = (checked, ids) => {
if (!ids.length) return;
const targetSelection = getTargetSelection(ids);
const nextSelected = new Set(targetSelection.value);
if (checked) {
ids.forEach(id => nextSelected.add(id));
} else {
ids.forEach(id => nextSelected.delete(id));
}
targetSelection.value = [...nextSelected];
handleFilterChange();
}; };
const filteredHearingData = computed(() => { const filteredHearingData = computed(() => {
const areaSel = stripAllAreaForRequest(selectedResearchIds.value);
const timeSel = stripAllTimeForRequest(selectedResearchTimeIds.value);
const deptSel = stripAllDeptForRequest(selectedResearchHearingIds.value);
return (hearingData.value || []).filter(item => { return (hearingData.value || []).filter(item => {
const matchYear = const matchYear =
selectedResearchTimeIds.value.length === 0 || timeSel.length === 0 ||
selectedResearchTimeIds.value.some(year => String(item.time || "").startsWith(year)); timeSel.some(sel => {
if (sel === RESOURCE_FILTER_EARLIER) {
return matchesEarlierChineseDate(item.time);
}
return String(item.time || "").startsWith(String(sel));
});
const matchDepartment = const matchDepartment =
selectedResearchHearingIds.value.length === 0 || deptSel.length === 0 ||
selectedResearchHearingIds.value.some(department => deptSel.some(department =>
String(item.content || "").includes(department) || String(item.title || "").includes(department) String(item.content || "").includes(department) || String(item.title || "").includes(department)
); );
const matchType = const matchType =
selectedResearchIds.value.length === 0 || areaSel.length === 0 ||
selectedResearchIds.value.some(typeId => areaSel.some(typeId =>
String(item.category || "").includes(typeId) || String(item.title || "").includes(typeId) String(item.category || "").includes(String(typeId)) || String(item.title || "").includes(String(typeId))
); );
return matchYear && matchDepartment && matchType; return matchYear && matchDepartment && matchType;
}); });
...@@ -189,10 +212,6 @@ const displayList = computed(() => { ...@@ -189,10 +212,6 @@ const displayList = computed(() => {
return list.slice(start, start + pageSize); return list.slice(start, start + pageSize);
}); });
const handleFilterChange = () => {
currentPage.value = 1;
};
const handlePageChange = page => { const handlePageChange = page => {
currentPage.value = page; currentPage.value = page;
}; };
......
...@@ -7,16 +7,21 @@ ...@@ -7,16 +7,21 @@
<div class="title">{{ "科技领域" }}</div> <div class="title">{{ "科技领域" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isAllSelected(typeIds)" class="checkbox-group"
@change="val => toggleAll(val, typeIds)"> :model-value="selectedTypeIds"
全部领域 @change="handleAreaGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_AREA">
{{ RESOURCE_FILTER_ALL_AREA }}
</el-checkbox> </el-checkbox>
<el-checkbox class="filter-checkbox" v-for="t in (researchTypeList || [])" :key="t.id" <el-checkbox
v-model="selectedTypeIds" :label="t.id" @change="emitChange"> class="filter-checkbox"
v-for="t in (researchTypeList || [])"
:key="t.id"
:label="t.id">
{{ t.name }} {{ t.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
...@@ -26,16 +31,21 @@ ...@@ -26,16 +31,21 @@
<div class="title">{{ "发布时间" }}</div> <div class="title">{{ "发布时间" }}</div>
</div> </div>
<div class="select-main"> <div class="select-main">
<div class="checkbox-group"> <el-checkbox-group
<el-checkbox class="filter-checkbox" :model-value="isAllSelected(yearIds)" class="checkbox-group"
@change="val => toggleAll(val, yearIds)"> :model-value="selectedYearIds"
全部时间 @change="handleYearGroupChange">
<el-checkbox class="filter-checkbox" :label="RESOURCE_FILTER_ALL_TIME">
{{ RESOURCE_FILTER_ALL_TIME }}
</el-checkbox> </el-checkbox>
<el-checkbox class="filter-checkbox" v-for="y in (researchTimeList || [])" :key="y.id" <el-checkbox
v-model="selectedYearIds" :label="y.id" @change="emitChange"> class="filter-checkbox"
v-for="y in (researchTimeList || [])"
:key="y.id"
:label="y.id">
{{ y.name }} {{ y.name }}
</el-checkbox> </el-checkbox>
</div> </el-checkbox-group>
</div> </div>
</div> </div>
</div> </div>
...@@ -95,10 +105,17 @@ ...@@ -95,10 +105,17 @@
</template> </template>
<script setup> <script setup>
import { computed, ref } from "vue"; import { ref } from "vue";
import AreaTag from "@/components/base/AreaTag/index.vue"; import AreaTag from "@/components/base/AreaTag/index.vue";
import {
const props = defineProps({ RESOURCE_FILTER_ALL_AREA,
RESOURCE_FILTER_ALL_TIME,
normalizeExclusiveAllOption,
stripAllAreaForRequest,
stripAllTimeForRequest
} from "../utils/resourceLibraryFilters";
defineProps({
researchTypeList: { type: Array, default: () => [] }, researchTypeList: { type: Array, default: () => [] },
researchTimeList: { type: Array, default: () => [] }, researchTimeList: { type: Array, default: () => [] },
list: { type: Array, default: () => [] }, list: { type: Array, default: () => [] },
...@@ -109,29 +126,25 @@ const props = defineProps({ ...@@ -109,29 +126,25 @@ const props = defineProps({
const emit = defineEmits(["filter-change", "page-change", "item-click"]); const emit = defineEmits(["filter-change", "page-change", "item-click"]);
const selectedTypeIds = ref([]); const selectedTypeIds = ref([RESOURCE_FILTER_ALL_AREA]);
const selectedYearIds = ref([]); const selectedYearIds = ref([RESOURCE_FILTER_ALL_TIME]);
const typeIds = computed(() => (props.researchTypeList || []).map(i => i.id)); const emitFilterToParent = () => {
const yearIds = computed(() => (props.researchTimeList || []).map(i => i.id));
const isAllSelected = ids => ids.length > 0 && ids.every(id => {
const target = ids === typeIds.value ? selectedTypeIds.value : selectedYearIds.value
return target.includes(id)
});
const toggleAll = (checked, ids) => {
const target = ids === typeIds.value ? selectedTypeIds : selectedYearIds
target.value = checked ? [...ids] : []
emitChange()
}
const emitChange = () => {
emit("filter-change", { emit("filter-change", {
researchTypeIds: [...selectedTypeIds.value], researchTypeIds: stripAllAreaForRequest(selectedTypeIds.value),
researchTimeIds: [...selectedYearIds.value], researchTimeIds: stripAllTimeForRequest(selectedYearIds.value),
}) });
} };
const handleAreaGroupChange = (val) => {
selectedTypeIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_AREA);
emitFilterToParent();
};
const handleYearGroupChange = (val) => {
selectedYearIds.value = normalizeExclusiveAllOption(val, RESOURCE_FILTER_ALL_TIME);
emitFilterToParent();
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论