Commit 4e1ec2bb authored by mhw's avatar mhw

预览修改

parent 2f94e54a
...@@ -55,10 +55,14 @@ export default { ...@@ -55,10 +55,14 @@ export default {
// 遍历并输出链接的 href 属性 // 遍历并输出链接的 href 属性
anchorTags.forEach((aTag) => { anchorTags.forEach((aTag) => {
let tagUrl = aTag.getAttribute('href') console.log(aTag);
let tagUrl = aTag.getAttribute('href') || ''
let isFile = ['pdf', 'jpg', 'gif', 'jpeg', 'png', 'docx', 'doc', 'xlsx', 'xls', 'mp4', 'webm', 'ogg', 'ogv', 'txt'].indexOf(tagUrl.split('.').pop().toLowerCase()) !== -1 let isFile = ['pdf', 'jpg', 'gif', 'jpeg', 'png', 'docx', 'doc', 'xlsx', 'xls', 'mp4', 'webm', 'ogg', 'ogv', 'txt'].indexOf(tagUrl.split('.').pop().toLowerCase()) !== -1
let isFile2 = ['html', 'md', 'json', 'jsonl', 'csv', 'pdf', 'png', 'jpg', 'jpeg', 'bmp', 'eml', 'msg', 'epub', 'xlsx', 'xlsd', 'ipynb', 'odt', 'py', 'rst', 'rtf', 'srt', 'toml', 'tsv', 'docx', 'doc', 'xml', 'ppt', 'pptx', 'txt', 'htm'] console.log(isFile);
if (isFile2 || aTag.id === 'show_detail') { // 判断知识库以及文件对话 的文件类型,并添加dom以及样式 let isFile2 = ['html', 'md', 'json', 'jsonl', 'csv', 'pdf', 'png', 'jpg', 'jpeg', 'bmp', 'eml', 'msg', 'epub', 'xlsx', 'xlsd', 'ipynb', 'odt', 'py', 'rst', 'rtf', 'srt', 'toml', 'tsv', 'docx', 'doc', 'xml', 'ppt', 'pptx', 'txt', 'htm'].indexOf(tagUrl.split('.').pop().toLowerCase()) !== -1
if (isFile2 || aTag.id === 'show_detail') { // 判断知识库以及文件对话 的文件类型,并添加dom以及样式 || 添加特殊a标签展示详情内容
console.log(aTag);
this.setDescribeStyle(aTag) this.setDescribeStyle(aTag)
} }
aTag.addEventListener('click', function (event) { aTag.addEventListener('click', function (event) {
...@@ -75,19 +79,47 @@ export default { ...@@ -75,19 +79,47 @@ export default {
}); });
}, },
setDescribeStyle (aTag) { setDescribeStyle (aTag) {
let describeDom = aTag.parentNode.nextElementSibling // let describeDom = aTag.nextElementSibling
// 在当前元素前插入新的 HTML 内容 // 在当前元素前插入新的 HTML 内容
describeDom.insertAdjacentHTML('beforebegin', ` aTag.insertAdjacentHTML('afterend', `
<button style="margin-bottom:10px" type="button" class="el-button el-button--primary el-button--mini is-round"> <button style="margin-bottom:10px" type="button" class="el-button el-button--primary el-button--mini is-round">
<span style="margin-right:5px">详情</span> <span style="margin-right:5px">详情</span>
<i class="el-icon-arrow-down"></i> <i class="el-icon-arrow-down"></i>
</button> </button>
`); `);
// 获取当前元素的父元素
var parentElement = aTag.parentNode;
// 获取当前元素在父元素中的索引
// var currentIndex = Array.from(parentElement.children).indexOf(aTag);
// 获取当前元素的同级后面的所有内容(包括文本节点)
var siblingNodesAfter = [];
var twoSibling = aTag.nextElementSibling;
var nextSibling = twoSibling.nextSibling;
while (nextSibling) {
if (nextSibling.nodeType === 1 || nextSibling.nodeType === 3) {
// 添加元素节点和文本节点
siblingNodesAfter.push(nextSibling);
}
nextSibling = nextSibling.nextSibling;
}
// 创建外层的 <div> 元素
var wrapperDiv = document.createElement('div');
wrapperDiv.classList.add('describe-view')
// 将获取的同级元素放入外层的 <div>
siblingNodesAfter.forEach(function (node) {
wrapperDiv.appendChild(node);
});
describeDom.classList.add('describe-view') parentElement.appendChild(wrapperDiv);
// describeDom.classList.add('describe-view')
let describeDom = aTag.nextElementSibling.nextElementSibling
let height = describeDom.scrollHeight let height = describeDom.scrollHeight
describeDom.setAttribute('style', 'height:0px;') describeDom.setAttribute('style', 'height:0px;')
describeDom.previousElementSibling.addEventListener('click', function (event) { twoSibling.addEventListener('click', function (event) {
if (height > 0 && (describeDom.style.height !== '0px' && describeDom.style.height !== '')) { if (height > 0 && (describeDom.style.height !== '0px' && describeDom.style.height !== '')) {
describeDom.setAttribute('style', 'height:0px;') describeDom.setAttribute('style', 'height:0px;')
} else { } else {
...@@ -111,7 +143,7 @@ export default { ...@@ -111,7 +143,7 @@ export default {
</style> </style>
<style> <style>
.describe-view { .describe-view {
overflow: hidden; overflow: hidden !important;
transition: 0.5s all; transition: 0.5s all;
color: #000; color: #000;
font-size: 14px; font-size: 14px;
......
...@@ -165,8 +165,9 @@ export default { ...@@ -165,8 +165,9 @@ export default {
}) })
} else if (this.chatForm.pattern === '知识图谱问答') { } else if (this.chatForm.pattern === '知识图谱问答') {
let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{')) let temporary = JSON.parse(`[${data}]`.replace(/}{/g, '},{'))
console.log(temporary);
temporary.forEach((item) => { temporary.forEach((item) => {
this.modifyContent(item)// 修改返回内容
nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容 nowChat.excludeReferenceAnswer += item.answer || '' // 排除回答中的引用内容
nowChat.answer += item.answer || '\n' + item.docs nowChat.answer += item.answer || '\n' + item.docs
}) })
...@@ -179,8 +180,10 @@ export default { ...@@ -179,8 +180,10 @@ export default {
modifyContent (item) { // 修改返回内容 modifyContent (item) { // 修改返回内容
if (item.docs) { if (item.docs) {
item.docs = item.docs.map((item2) => { item.docs = item.docs.map((item2) => {
let tagUrl = item2?.match(/\]\((.*?)\)/g)[0].slice(2, -1) let tagUrl = ((item2?.match(/\]\((.*?)\)/g) || [])[0] || '').slice(2, -1)
console.log(tagUrl);
let url = '' let url = ''
item2 = item2.replace(/\n/g, '<br>')
if (tagUrl.indexOf('https') !== -1) { if (tagUrl.indexOf('https') !== -1) {
url = tagUrl.replace(/^https:\/\/[^/]+\//, `https://${window.location.hostname}:${window.location.port}/`); url = tagUrl.replace(/^https:\/\/[^/]+\//, `https://${window.location.hostname}:${window.location.port}/`);
item2 = item2.replace(/\]\((.*?)\)/g, `](${url})`) item2 = item2.replace(/\]\((.*?)\)/g, `](${url})`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment