feat(article): 更新内容处理逻辑,插入来源信息并优化文本节点获取
This commit is contained in:
parent
cf2b692c84
commit
b71bc19188
|
|
@ -64,7 +64,7 @@
|
||||||
class="articleDes"
|
class="articleDes"
|
||||||
:class="props?.data?.needpay && 'needpay'"
|
:class="props?.data?.needpay && 'needpay'"
|
||||||
style="white-space: pre-wrap"
|
style="white-space: pre-wrap"
|
||||||
v-html="props.data.content"
|
v-html="content"
|
||||||
>
|
>
|
||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -175,7 +175,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref, toRefs } from "vue";
|
||||||
import {
|
import {
|
||||||
onLaunch,
|
onLaunch,
|
||||||
onShow,
|
onShow,
|
||||||
|
|
@ -188,6 +188,7 @@ import LoginDialog from "@/pages/realtimeInfo/components/LoginPopup/index.vue";
|
||||||
import { Session } from "@/utils/storage";
|
import { Session } from "@/utils/storage";
|
||||||
import zhaiyaoImg from "../../assets/zixun/zhaiyao_icon.png";
|
import zhaiyaoImg from "../../assets/zixun/zhaiyao_icon.png";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const emit = defineEmits(["getFurtherReadData"]);
|
const emit = defineEmits(["getFurtherReadData"]);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
@ -215,6 +216,40 @@ const tagList1 = ref([
|
||||||
name: "医药生物-医疗服务",
|
name: "医药生物-医疗服务",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
// 匹配第一个文本node
|
||||||
|
function getFirstTextNode(node: any): any {
|
||||||
|
// 文本节点
|
||||||
|
if (node.nodeType === 3) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < node.childNodes.length; i++) {
|
||||||
|
const child = node.childNodes[i];
|
||||||
|
const textNode = getFirstTextNode(child);
|
||||||
|
if (textNode) {
|
||||||
|
return textNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = computed(() => {
|
||||||
|
const content = props.data.content;
|
||||||
|
const insertText = `中证参考海外资讯${dayjs(props.data.publishTime).format('MM月DD日')}援引${props.data.source}`;
|
||||||
|
if (!content) return;
|
||||||
|
const dom = new DOMParser().parseFromString(content, "text/html");
|
||||||
|
const body = dom.querySelector("body");
|
||||||
|
const p = body?.childNodes;
|
||||||
|
for(let i = 0; i < p.length; i++){
|
||||||
|
const textNode = getFirstTextNode(p[i]);
|
||||||
|
console.log(textNode)
|
||||||
|
if(textNode){
|
||||||
|
textNode.textContent = insertText + textNode.textContent;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return body?.innerHTML;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
// 未登录|试用,显示蒙层
|
// 未登录|试用,显示蒙层
|
||||||
|
|
@ -679,4 +714,11 @@ const getMoreNews = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.aaa{
|
||||||
|
float: left;
|
||||||
|
margin-top: 36rpx;
|
||||||
|
font-size: var(--h2-font-size);
|
||||||
|
color: #333;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue