提交 769dfe68 authored 作者: 张伊明's avatar 张伊明

bug修复

上级 88a85d8a
流水线 #392 已通过 于阶段
in 1 分 42 秒
......@@ -16,7 +16,7 @@ export function getBillIndustry(params) {
return request({
method: 'GET',
url: `/api/BillOverview/billIndustry/${params.year}`,
params: { status: params.status }
params: { stageName: params.stageName }
})
}
......
<template>
<p class="p-regular-rereg">
<span class="text-regular" v-for="(segment, index) in processedText" :key="index">
<span v-if="segment.isEntity" @click="$emit('onEntityClick', segment.entity)" class="entity-link">
<span
v-if="segment.isEntity"
@click="$emit('onEntityClick', segment.entity)"
:class="['entity-link', { 'keyword-highlight': segment.isKeywordHit }]"
>
{{ segment.entity?.text_span }}
<img :src="SearchIcon" :width="10" :height="10" alt="search" />
</span>
<span v-else>
{{ segment.text }}
<span :class="{ 'keyword-highlight': segment.isKeywordHit }">{{ segment.text }}</span>
</span>
</span>
</p>
......@@ -20,6 +24,7 @@ export interface ProcessedTextSegment {
text: string;
isEntity: boolean;
entity?: TextEntity;
isKeywordHit?: boolean;
}
const props = defineProps({
text: {
......@@ -29,15 +34,42 @@ const props = defineProps({
entities: {
type: Array<TextEntity>,
default: () => []
},
highlight: {
type: String,
default: ""
}
});
const emit = defineEmits(["onEntityClick"]);
// 处理后的文本段
const processedText = ref<ProcessedTextSegment[]>([]);
const normalizeKeyword = (value: unknown) => String(value ?? "").trim();
const getKeywordMatches = (text: string, keyword: string) => {
if (!keyword) return [{ text, isKeywordHit: false }];
const lowerText = text.toLowerCase();
const lowerKeyword = keyword.toLowerCase();
if (!lowerKeyword) return [{ text, isKeywordHit: false }];
const parts: Array<{ text: string; isKeywordHit: boolean }> = [];
let start = 0;
while (start < text.length) {
const index = lowerText.indexOf(lowerKeyword, start);
if (index === -1) {
parts.push({ text: text.slice(start), isKeywordHit: false });
break;
}
if (index > start) {
parts.push({ text: text.slice(start, index), isKeywordHit: false });
}
parts.push({ text: text.slice(index, index + keyword.length), isKeywordHit: true });
start = index + keyword.length;
}
return parts.filter(part => part.text);
};
// 处理文本,识别并替换实体
const processText = () => {
console.log("props.entities.length", props.entities.length);
if (!props.text || !props.entities) {
// console.log('props.text', props.entities.length)
processedText.value = [{ text: "", isEntity: false }];
......@@ -46,6 +78,7 @@ const processText = () => {
const result = [];
let currentPosition = 0;
const keyword = normalizeKeyword(props.highlight);
// 按实体文本长度排序,优先匹配长文本
const sortedEntities = [...props.entities].sort((a, b) => b.text_span.length - a.text_span.length);
......@@ -61,7 +94,8 @@ const processText = () => {
// 如果当前位置是实体,添加到结果
result.push({
isEntity: true,
entity: { ...entity }
entity: { ...entity },
isKeywordHit: keyword ? entityText.toLowerCase().includes(keyword.toLowerCase()) : false
});
currentPosition = endPosition;
matched = true;
......@@ -82,18 +116,26 @@ const processText = () => {
if (nextEntityStart > currentPosition) {
const plainText = props.text.substring(currentPosition, nextEntityStart);
result.push({
text: plainText,
isEntity: false
const parts = getKeywordMatches(plainText, keyword);
parts.forEach(part => {
result.push({
text: part.text,
isEntity: false,
isKeywordHit: part.isKeywordHit
});
});
currentPosition = nextEntityStart;
} else {
// 没有更多实体,添加剩余文本
const remainingText = props.text.substring(currentPosition);
if (remainingText) {
result.push({
text: remainingText,
isEntity: false
const parts = getKeywordMatches(remainingText, keyword);
parts.forEach(part => {
result.push({
text: part.text,
isEntity: false,
isKeywordHit: part.isKeywordHit
});
});
}
currentPosition = props.text.length;
......@@ -106,6 +148,7 @@ const processText = () => {
// 监听文本和实体变化
watch(() => props.text, processText);
watch(() => props.entities, processText, { deep: true });
watch(() => props.highlight, processText);
// 初始化处理
onMounted(processText);
......@@ -113,6 +156,11 @@ onMounted(processText);
<style lang="scss" scoped>
@use "@/styles/common.scss";
.keyword-highlight {
background: rgba(255, 199, 0, 0.35);
border-radius: 2px;
}
.entity-link {
color: var(--color-primary-100);
&:hover {
......
......@@ -1030,14 +1030,15 @@ const handleBox6 = async () => {
// 涉华领域分布
const box9ChartData = ref([]);
const box9selectetedTime = ref("2025");
// 立法状态下拉:提出法案、众议院通过、参议院通过、解决分歧、完成立法
// v-model 存储的是接口需要的 status 值
const box9LegislativeStatus = ref("提案");
// 立法状态下拉:提出法案、众议院通过、参议院通过、解决分歧、呈交总统、完成立法
// v-model 存储的是接口需要的 status 值(直接作为接口参数)
const box9LegislativeStatus = ref("提出法案");
const box9LegislativeStatusList = ref([
{ label: "提出法案", value: "提案" },
{ label: "提出法案", value: "提出法案" },
{ label: "众议院通过", value: "众议院通过" },
{ label: "参议院通过", value: "参议院通过" },
{ label: "解决分歧", value: "分歧已解决" },
{ label: "解决分歧", value: "解决分歧" },
{ label: "呈交总统", value: "呈交总统" },
{ label: "完成立法", value: "完成立法" }
]);
const box9YearList = ref([
......@@ -1089,7 +1090,7 @@ const getBox9Data = async () => {
chartLoading.value = { ...chartLoading.value, box6: true };
const params = {
year: box9selectetedTime.value,
status: box9LegislativeStatus.value
stageName: box9LegislativeStatus.value
};
try {
const res = await getBillIndustry(params);
......@@ -1126,16 +1127,9 @@ const handleBox9Data = async () => {
const selectedIndex = box9LegislativeStatusList.value.findIndex(
item => item.value === box9LegislativeStatus.value
);
const arr = [
{ label: "提出法案", value: "提案" },
{ label: "众议院通过", value: "众议院通过" },
{ label: "参议院通过", value: "参议院通过" },
{ label: "解决分歧", value: "分歧已解决" },
{ label: "完成立法", value: "完成立法" }
]
const status = arr.filter(item => {
return item.value === box9LegislativeStatus.value
})[0].label
// 当前选中的立法状态中文名(直接等于接口传参值)
const statusItem = box9LegislativeStatusList.value[selectedIndex];
const status = statusItem ? statusItem.label : "";
const selectParam = {
moduleType: '国会法案',
key: 2,
......@@ -1294,13 +1288,14 @@ const getBox8ChartOption = stageList => {
const handleBox8Data = async () => {
chartLoading.value = { ...chartLoading.value, box8: true };
// 进展分布显示顺序:提出法案(对应进度“提案”)、众议院通过、参议院通过、分歧已解决(解决分歧)、完成立法
const stageOrder = ["提案", "众议院通过", "参议院通过", "分歧已解决", "完成立法"];
// 进展分布显示顺序:提出法案(对应进度“提案”)、众议院通过、参议院通过、解决分歧(对应进度“分歧已解决”)、呈交总统、完成立法
const stageOrder = ["提案", "众议院通过", "参议院通过", "分歧已解决", "呈交总统", "完成立法"];
const stageNameMap = {
提案: "提出法案",
众议院通过: "众议院通过",
参议院通过: "参议院通过",
分歧已解决: "解决分歧",
呈交总统: "呈交总统",
完成立法: "完成立法"
};
......
......@@ -1169,6 +1169,10 @@ onMounted(async () => {
<style lang="scss" scoped>
.wrap {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
direction: ltr;
justify-content: flex-start;
margin-bottom: 30px;
......@@ -1254,6 +1258,8 @@ onMounted(async () => {
.left {
margin-top: 16px;
width: 792px;
flex: 0 0 792px;
.box1 {
width: 792px;
......@@ -1651,6 +1657,7 @@ onMounted(async () => {
margin-left: 16px;
margin-top: 16px;
width: 792px;
flex: 0 0 792px;
height: 847px;
.box3 {
......
......@@ -131,6 +131,7 @@
<IntelligentEntityText
:text="term?.fynr || ''"
:entities="termsHighlight ? getTermEntities(term, 'cn') : []"
:highlight="searchKeyword"
@on-entity-click="e => gotoSearchResults(e.text_span, '')"
/>
</div>
......@@ -141,6 +142,7 @@
<IntelligentEntityText
:text="term?.ywnr || ''"
:entities="termsHighlight ? getTermEntities(term, 'en') : []"
:highlight="searchKeyword"
@on-entity-click="e => gotoSearchResults(e.text_span, '')"
/>
</div>
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论