init commit
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, defineEmits, onMounted, defineProps, defineExpose } from "vue";
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
|
||||
import { onBeforeRouteUpdate } from 'vue-router';
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
let { cardList, total, getKnowled } = useKnowledgeBase()
|
||||
let query = ref("");
|
||||
const props = defineProps({
|
||||
isReplying: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
}
|
||||
});
|
||||
onMounted(() => {
|
||||
getKnowled()
|
||||
})
|
||||
const emit = defineEmits(['send-msg']);
|
||||
const createSession = (val: string) => {
|
||||
if (!val.trim()) {
|
||||
MessagePlugin.info("请先输入内容!");
|
||||
return
|
||||
}
|
||||
if (!query.value && cardList.value.length == 0) {
|
||||
MessagePlugin.info("请先上传知识库!");
|
||||
return;
|
||||
}
|
||||
if (props.isReplying) {
|
||||
return MessagePlugin.error("正在回复中,请稍后再试!");
|
||||
}
|
||||
emit('send-msg', val);
|
||||
clearvalue();
|
||||
}
|
||||
const clearvalue = () => {
|
||||
query.value = "";
|
||||
}
|
||||
const onKeydown = (val: string, event: { e: { preventDefault(): unknown; keyCode: number; shiftKey: any; ctrlKey: any; }; }) => {
|
||||
if ((event.e.keyCode == 13 && event.e.shiftKey) || (event.e.keyCode == 13 && event.e.ctrlKey)) {
|
||||
return;
|
||||
}
|
||||
if (event.e.keyCode == 13) {
|
||||
event.e.preventDefault();
|
||||
createSession(val)
|
||||
}
|
||||
}
|
||||
onBeforeRouteUpdate((to, from, next) => {
|
||||
clearvalue()
|
||||
next()
|
||||
})
|
||||
|
||||
</script>
|
||||
<template>
|
||||
<div class="answers-input">
|
||||
<t-textarea v-model="query" placeholder="基于知识库提问" name="description" :autosize="true" @keydown="onKeydown" />
|
||||
<div class="answers-input-source">
|
||||
<span>{{ total }}个来源</span>
|
||||
</div>
|
||||
<div @click="createSession(query)" class="answers-input-send"
|
||||
:class="[query.length && total ? '' : 'grey-out']">
|
||||
<img src="../assets/img/sending-aircraft.svg" alt="">
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped lang="less">
|
||||
.answers-input {
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
bottom: 60px;
|
||||
left: 50%;
|
||||
transform: translateX(-400px);
|
||||
}
|
||||
|
||||
:deep(.t-textarea__inner) {
|
||||
width: 100%;
|
||||
width: 800px;
|
||||
max-height: 250px !important;
|
||||
min-height: 112px !important;
|
||||
resize: none;
|
||||
color: #000000e6;
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
padding: 16px 12px 12px 16px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #E7E7E7;
|
||||
box-sizing: border-box;
|
||||
background: #FFF;
|
||||
box-shadow: 0 6px 6px 0 #0000000a, 0 12px 12px -1px #00000014;
|
||||
|
||||
&:focus {
|
||||
border: 1px solid #07C05F;
|
||||
}
|
||||
|
||||
&:placeholder {
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.answers-input-send {
|
||||
background-color: #07C05F;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
right: 12px;
|
||||
cursor: pointer;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.answers-input-source {
|
||||
position: absolute;
|
||||
bottom: 12px;
|
||||
right: 64px;
|
||||
line-height: 32px;
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.grey-out {
|
||||
background-color: #b5eccf !important;
|
||||
cursor: no-drop !important;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,426 @@
|
||||
:deep(.md-content) {
|
||||
box-sizing: border-box !important;
|
||||
|
||||
img {
|
||||
max-width: 444px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
margin-top: 5px;
|
||||
font-weight: bold;
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC", "Cascadia Code";
|
||||
transition: all 0.2s ease-out;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.hljs-title,
|
||||
.hljs-title.class_,
|
||||
.hljs-title.class_.inherited__,
|
||||
.hljs-title.function_ {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.proto {
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
h1 tt,
|
||||
h1 code {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
h2 tt,
|
||||
h2 code {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
h3 tt,
|
||||
h3 code {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
h4 tt,
|
||||
h4 code {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
h5 tt,
|
||||
h5 code {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
h6 tt,
|
||||
h6 code {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
h2 a,
|
||||
h3 a {
|
||||
color: #34495e;
|
||||
}
|
||||
|
||||
p,
|
||||
blockquote,
|
||||
ul,
|
||||
ol,
|
||||
dl,
|
||||
table {
|
||||
font-size: 14px;
|
||||
margin: 10px 0;
|
||||
font-family: "PingFang SC", "Cascadia Code";
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
summary {
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
li>ol,
|
||||
li>ul {
|
||||
margin: 0 0;
|
||||
}
|
||||
|
||||
hr {
|
||||
padding: 0;
|
||||
margin: 32px 0;
|
||||
border-top: 0.5rem dotted #0590ff57;
|
||||
overflow: hidden;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
body>h2:first-child {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
body>h1:first-child {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
body>h1:first-child+h2 {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
body>h3:first-child,
|
||||
body>h4:first-child,
|
||||
body>h5:first-child,
|
||||
body>h6:first-child {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
a:first-child h1,
|
||||
a:first-child h2,
|
||||
a:first-child h3,
|
||||
a:first-child h4,
|
||||
a:first-child h5,
|
||||
a:first-child h6 {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
h1 p,
|
||||
h2 p,
|
||||
h3 p,
|
||||
h4 p,
|
||||
h5 p,
|
||||
h6 p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
li p.first {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
ul:first-child,
|
||||
ol:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
ul:last-child,
|
||||
ol:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
padding: 0.8em 1.4rem;
|
||||
margin: 1em 0;
|
||||
font-weight: 400;
|
||||
border-left: 4px solid #2196f3;
|
||||
background-color: #2196f321;
|
||||
border-radius: 0px 8px 8px 0px;
|
||||
box-shadow: rgb(149 149 149 / 13%) 0px 5px 10px;
|
||||
}
|
||||
|
||||
table {
|
||||
padding: 0;
|
||||
word-break: initial;
|
||||
/* border-radius: 4px; */
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table tr {
|
||||
border-top: 1px solid #2196f31f;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table tr:nth-child(2n),
|
||||
thead {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
table tr th {
|
||||
font-weight: bold;
|
||||
border: 1px solid #9b9b9b3b;
|
||||
border-bottom: 0;
|
||||
text-align: left;
|
||||
margin: 0;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
|
||||
table tr td {
|
||||
border: 1px solid #9b9b9b3b;
|
||||
text-align: left;
|
||||
margin: 0;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
|
||||
table tr th:first-child,
|
||||
table tr td:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
table tr th:last-child,
|
||||
table tr td:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
tt {
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
figure {
|
||||
border-radius: 8px;
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.md-task-list-item>input {
|
||||
margin-left: -1.3em;
|
||||
}
|
||||
|
||||
@media print {
|
||||
html {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
table,
|
||||
pre {
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
pre {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
.md-fences {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.md-diagram-panel {
|
||||
position: static !important;
|
||||
}
|
||||
|
||||
|
||||
.mathjax-block>.code-tooltip {
|
||||
bottom: 0.375rem;
|
||||
}
|
||||
|
||||
h3.md-focus:before,
|
||||
h4.md-focus:before,
|
||||
h5.md-focus:before,
|
||||
h6.md-focus:before {
|
||||
border: 0px;
|
||||
position: unset;
|
||||
padding: 0px;
|
||||
font-size: unset;
|
||||
line-height: unset;
|
||||
float: unset;
|
||||
}
|
||||
|
||||
.md-image>.md-meta {
|
||||
border-radius: 3px;
|
||||
font-family: var(--font-monospace);
|
||||
padding: 2px 0 0 4px;
|
||||
font-size: 0.9em;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.md-tag {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.md-toc {
|
||||
margin-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.sidebar-tabs {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
|
||||
/** focus mode */
|
||||
|
||||
.on-focus-mode blockquote {
|
||||
border-left-color: rgba(85, 85, 85, 0.12);
|
||||
}
|
||||
|
||||
header,
|
||||
.context-menu,
|
||||
.megamenu-content,
|
||||
footer {
|
||||
font-family: var(--font-sans-serif);
|
||||
}
|
||||
|
||||
.file-node-content:hover .file-node-icon,
|
||||
.file-node-content:hover .file-node-open-state {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.mac-seamless-mode #typora-sidebar {
|
||||
background-color: var(--side-bar-bg-color);
|
||||
}
|
||||
|
||||
.md-lang {
|
||||
color: #b4654d;
|
||||
}
|
||||
|
||||
.html-for-mac .context-menu {
|
||||
--item-hover-bg-color: #e6f0fe;
|
||||
}
|
||||
|
||||
.pin-outline #outline-content .outline-active strong,
|
||||
.pin-outline .outline-active {
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.code-tooltip {
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ededed;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.cm-s-inner .cm-comment,
|
||||
.cm-s-inner.cm-comment {
|
||||
color: #57a64a;
|
||||
font-style: italic;
|
||||
/* font-family: 'PingFang'; */
|
||||
}
|
||||
|
||||
h1.md-end-block.md-heading:after,
|
||||
h2.md-end-block.md-heading:after,
|
||||
h3.md-end-block.md-heading:after,
|
||||
h4.md-end-block.md-heading:after,
|
||||
h5.md-end-block.md-heading:after,
|
||||
h6.md-end-block.md-heading:after {
|
||||
color: #bfbfbf !important;
|
||||
border: 1px solid;
|
||||
border-radius: 4px;
|
||||
position: absolute;
|
||||
left: -2.5rem;
|
||||
float: left;
|
||||
font-size: 14px;
|
||||
padding-left: 4px;
|
||||
padding-right: 5px;
|
||||
vertical-align: bottom;
|
||||
font-weight: 400;
|
||||
line-height: normal;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
h1.md-end-block.md-heading:hover:after,
|
||||
h2.md-end-block.md-heading:hover:after,
|
||||
h3.md-end-block.md-heading:hover:after,
|
||||
h4.md-end-block.md-heading:hover:after,
|
||||
h5.md-end-block.md-heading:hover:after,
|
||||
h6.md-end-block.md-heading:hover:after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
h1.md-end-block.md-heading:hover:after {
|
||||
content: "h1";
|
||||
top: 1.1rem;
|
||||
}
|
||||
|
||||
h2.md-end-block.md-heading:hover:after {
|
||||
content: "h2";
|
||||
top: 0.63rem;
|
||||
}
|
||||
|
||||
h3.md-end-block.md-heading:hover:after {
|
||||
content: "h3";
|
||||
top: 0.55rem;
|
||||
}
|
||||
|
||||
h4.md-end-block.md-heading:hover:after {
|
||||
content: "h4";
|
||||
top: 0.3rem;
|
||||
}
|
||||
|
||||
h5.md-end-block.md-heading:hover:after {
|
||||
content: "h5";
|
||||
top: 0.18rem;
|
||||
}
|
||||
|
||||
h6.md-end-block.md-heading:hover:after {
|
||||
content: "h6";
|
||||
top: 0.16rem;
|
||||
}
|
||||
|
||||
.outline-label {
|
||||
font-family: "Cascadia Code", "PingFang SC";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<script setup lang="ts">
|
||||
import { marked } from "marked";
|
||||
import { onMounted, ref, nextTick, onUnmounted, onUpdated, watch } from "vue";
|
||||
import { downKnowledgeDetails } from "@/api/knowledge-base/index";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import picturePreview from '@/components/picture-preview.vue';
|
||||
marked.use({
|
||||
mangle: false,
|
||||
headerIds: false,
|
||||
});
|
||||
const renderer = new marked.Renderer();
|
||||
let page = 1;
|
||||
let doc = null;
|
||||
let down = ref()
|
||||
let mdContentWrap = ref()
|
||||
let url = ref('')
|
||||
let reviewUrl = ref('')
|
||||
let reviewImg = ref(false)
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
doc = document.getElementsByClassName('t-drawer__body')[0]
|
||||
doc.addEventListener('scroll', handleDetailsScroll);
|
||||
})
|
||||
})
|
||||
onUpdated(() => {
|
||||
page = 1
|
||||
})
|
||||
onUnmounted(() => {
|
||||
doc.removeEventListener('scroll', handleDetailsScroll);
|
||||
})
|
||||
const checkImage = (url) => {
|
||||
return new Promise((resolve) => {
|
||||
const img = new Image();
|
||||
img.onload = () => resolve(true);
|
||||
img.onerror = () => resolve(false);
|
||||
img.src = url;
|
||||
});
|
||||
};
|
||||
renderer.image = function (href, title, text) {
|
||||
// 自定义HTML结构,图片展示带标题
|
||||
return `<figure>
|
||||
<img class="markdown-image" src="${href}" alt="${title}" title="${text}">
|
||||
<figcaption style="text-align: left;">${text}</figcaption>
|
||||
</figure>`;
|
||||
};
|
||||
const props = defineProps(["visible", "details"]);
|
||||
const emit = defineEmits(["closeDoc", "getDoc"]);
|
||||
watch(() => props.details.md, (newVal) => {
|
||||
nextTick(async () => {
|
||||
const images = mdContentWrap.value.querySelectorAll('img.markdown-image');
|
||||
if (images) {
|
||||
images.forEach(async item => {
|
||||
item.addEventListener('click', function (event) {
|
||||
reviewUrl.value = event.target.src;
|
||||
reviewImg.value = true
|
||||
})
|
||||
const isValid = await checkImage(item.src);
|
||||
if (!isValid) {
|
||||
item.remove();
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}, {
|
||||
immediate: true,
|
||||
deep: true
|
||||
})
|
||||
|
||||
// 处理 Markdown 中的图片
|
||||
const processMarkdown = (markdownText) => {
|
||||
// 自定义渲染器处理图片
|
||||
marked.use({ renderer });
|
||||
let html = marked.parse(markdownText);
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
return doc.body.innerHTML;
|
||||
};
|
||||
const closePreImg = () => {
|
||||
reviewImg.value = false
|
||||
reviewUrl.value = '';
|
||||
}
|
||||
const handleClose = () => {
|
||||
emit("closeDoc", false);
|
||||
doc.scrollTop = 0;
|
||||
};
|
||||
const downloadFile = () => {
|
||||
downKnowledgeDetails(props.details.id)
|
||||
.then((result) => {
|
||||
if (result) {
|
||||
url.value = URL.createObjectURL(result);
|
||||
down.value.click();
|
||||
// const link = document.createElement("a");
|
||||
// link.style.display = "none";
|
||||
// link.setAttribute("href", url);
|
||||
// link.setAttribute("download", props.details.title);
|
||||
// link.click();
|
||||
// document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
MessagePlugin.error("获取文件失败!");
|
||||
});
|
||||
};
|
||||
const handleDetailsScroll = () => {
|
||||
if (doc) {
|
||||
let pageNum = Math.ceil(props.details.total / 20);
|
||||
const { scrollTop, scrollHeight, clientHeight } = doc;
|
||||
if (scrollTop + clientHeight >= scrollHeight) {
|
||||
page++;
|
||||
if (props.details.md.length < props.details.total && page <= pageNum) {
|
||||
emit("getDoc", page);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<div class="doc_content" ref="mdContentWrap">
|
||||
<t-drawer :visible="visible" :zIndex="2000" :closeBtn="true" @close="handleClose">
|
||||
<template #header>{{
|
||||
details.title.substring(0, details.title.lastIndexOf("."))
|
||||
}}</template>
|
||||
<div class="doc_box">
|
||||
<a :href="url" style="display: none" ref="down" :download="details.title"></a>
|
||||
<span class="label">文档标题</span>
|
||||
<div class="download_box">
|
||||
<span class="doc_t">{{ details.title }}</span>
|
||||
<div class="icon_box" @click="downloadFile()">
|
||||
<img class="download_box" src="@/assets/img/download.svg" alt="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content_header">
|
||||
<span class="label">文档内容</span>
|
||||
<span class="time"> 更新时间:{{ details.time }} </span>
|
||||
</div>
|
||||
<div v-if="details.md.length == 0" class="no_content">暂无数据</div>
|
||||
<div v-else class="content" v-for="(item, index) in details.md" :key="index" :style="index % 2 !== 0
|
||||
? 'background: #07c05f26;'
|
||||
: 'background: #3032360f;'
|
||||
">
|
||||
<div class="md-content" v-html="processMarkdown(item.content)"></div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button @click="handleClose">确定</t-button>
|
||||
<t-button theme="default" @click="handleClose">取消</t-button>
|
||||
</template>
|
||||
</t-drawer>
|
||||
<picturePreview :reviewImg="reviewImg" :reviewUrl="reviewUrl" @closePreImg="closePreImg"></picturePreview>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped lang="less">
|
||||
@import "./css/markdown.less";
|
||||
|
||||
:deep(.t-drawer .t-drawer__content-wrapper) {
|
||||
width: 654px !important;
|
||||
}
|
||||
|
||||
:deep(.t-drawer__header) {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
:deep(.t-drawer__body.narrow-scrollbar) {
|
||||
padding: 16px 24px;
|
||||
}
|
||||
|
||||
.content {
|
||||
word-break: break-word;
|
||||
padding: 4px;
|
||||
gap: 4px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.doc_box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: #000000e6;
|
||||
font-size: 14px;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
line-height: 22px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.download_box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.doc_t {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
padding: 5px 8px;
|
||||
align-items: center;
|
||||
border-radius: 3px;
|
||||
border: 1px solid #dcdcdc;
|
||||
background: #30323605;
|
||||
word-break: break-all;
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
.icon_box {
|
||||
margin-left: 18px;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
color: #07c05f;
|
||||
|
||||
.download_box {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
fill: currentColor;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.content_header {
|
||||
margin-top: 22px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.time {
|
||||
margin-left: 12px;
|
||||
color: #00000066;
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.no_content {
|
||||
margin-top: 12px;
|
||||
color: #00000066;
|
||||
font-size: 12px;
|
||||
padding: 16px;
|
||||
background: #fbfbfb;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
<template>
|
||||
<div class="empty">
|
||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||
<span class="empty-txt">知识为空,拖放上传</span>
|
||||
<span class="empty-type-txt">pdf、doc 格式文件,不超过10M</span>
|
||||
<span class="empty-type-txt">text、markdown格式文件,不超过200K</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped lang="less">
|
||||
.empty {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-txt {
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 26px;
|
||||
margin: 12px 0 16px 0;
|
||||
}
|
||||
|
||||
.empty-type-txt {
|
||||
color: #00000066;
|
||||
text-align: center;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
width: 217px;
|
||||
}
|
||||
|
||||
.empty-img {
|
||||
width: 162px;
|
||||
height: 162px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,453 @@
|
||||
<template>
|
||||
<div class="aside_box">
|
||||
<div class="logo_box">
|
||||
<img class="logo" src="@/assets/img/weknora.png" alt="">
|
||||
</div>
|
||||
<div class="menu_box" v-for="(item, index) in menuArr" :key="index">
|
||||
<div @click="gotopage(item.path)"
|
||||
@mouseenter="mouseenteMenu(item.path)" @mouseleave="mouseleaveMenu(item.path)"
|
||||
:class="['menu_item', item.childrenPath && item.childrenPath == currentpath ? 'menu_item_c_active' : item.path == currentpath ? 'menu_item_active' : '']">
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
<img class="icon" :src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'setting' ? settingIcon : prefixIcon)" alt="">
|
||||
</div>
|
||||
<span class="menu_title">{{ item.title }}</span>
|
||||
</div>
|
||||
<t-popup overlayInnerClassName="upload-popup" class="placement top center" content="上传知识"
|
||||
placement="top" show-arrow destroy-on-close>
|
||||
<div class="upload-file-wrap" @click="uploadFile" variant="outline"
|
||||
v-if="item.path == 'knowledgeBase'">
|
||||
<img class="upload-file-icon" :class="[item.path == currentpath ? 'active-upload' : '']"
|
||||
:src="getImgSrc(fileAddIcon)" alt="">
|
||||
</div>
|
||||
</t-popup>
|
||||
</div>
|
||||
<div ref="submenuscrollContainer" @scroll="handleScroll" class="submenu" v-if="item.children">
|
||||
<div class="submenu_item_p" v-for="(subitem, subindex) in item.children" :key="subindex"
|
||||
@click="gotopage(subitem.path)">
|
||||
<div :class="['submenu_item', currentSecondpath == subitem.path ? 'submenu_item_active' : '']"
|
||||
@mouseenter="mouseenteBotDownr(subindex)" @mouseleave="mouseleaveBotDown">
|
||||
<i v-if="currentSecondpath == subitem.path" class="dot"></i>
|
||||
<span class="submenu_title"
|
||||
:style="currentSecondpath == subitem.path ? 'margin-left:14px;max-width:160px;' : 'margin-left:18px;max-width:173px;'">
|
||||
{{ subitem.title }}
|
||||
</span>
|
||||
<t-popup v-model:visible="subitem.isMore" @overlay-click="delCard(subindex, subitem)"
|
||||
@visible-change="onVisibleChange" overlayClassName="del-menu-popup" trigger="click"
|
||||
destroy-on-close placement="top-left">
|
||||
<div v-if="(activeSubmenu == subindex) || (currentSecondpath == subitem.path) || subitem.isMore"
|
||||
@click.stop="openMore(subindex)" variant="outline" class="menu-more-wrap">
|
||||
<t-icon name="ellipsis" class="menu-more" />
|
||||
</div>
|
||||
<template #content>
|
||||
<span class="del_submenu">删除记录</span>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" @change="upload" style="display: none" ref="uploadInput"
|
||||
accept=".pdf,.docx,.doc,.txt,.md,.jpg,.jpeg,.png" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onMounted, watch, computed, ref, reactive } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getSessionsList, delSession } from "@/api/chat/index";
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase';
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
let { requestMethod } = useKnowledgeBase()
|
||||
let uploadInput = ref();
|
||||
const usemenuStore = useMenuStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const currentpath = ref('');
|
||||
const currentPage = ref(1);
|
||||
const page_size = ref(30);
|
||||
const total = ref(0);
|
||||
const currentSecondpath = ref('');
|
||||
const submenuscrollContainer = ref(null);
|
||||
// 计算总页数
|
||||
const totalPages = computed(() => Math.ceil(total.value / page_size.value));
|
||||
const hasMore = computed(() => currentPage.value < totalPages.value);
|
||||
const { menuArr } = storeToRefs(usemenuStore);
|
||||
let activeSubmenu = ref(-1);
|
||||
const loading = ref(false)
|
||||
const uploadFile = () => {
|
||||
uploadInput.value.click()
|
||||
}
|
||||
const upload = (e) => {
|
||||
requestMethod(e.target.files[0], uploadInput)
|
||||
}
|
||||
const mouseenteBotDownr = (val) => {
|
||||
activeSubmenu.value = val;
|
||||
}
|
||||
const mouseleaveBotDown = () => {
|
||||
activeSubmenu.value = -1;
|
||||
}
|
||||
const onVisibleChange = (e) => {
|
||||
}
|
||||
|
||||
const delCard = (index, item) => {
|
||||
delSession(item.id).then(res => {
|
||||
if (res && res.success) {
|
||||
menuArr.value[1].children.splice(index, 1);
|
||||
if (item.id == route.params.chatid) {
|
||||
router.push('/platform/creatChat');
|
||||
}
|
||||
} else {
|
||||
MessagePlugin.error("删除失败,请稍后再试!");
|
||||
}
|
||||
})
|
||||
}
|
||||
const debounce = (fn, delay) => {
|
||||
let timer
|
||||
return (...args) => {
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => fn(...args), delay)
|
||||
}
|
||||
}
|
||||
// 滚动处理
|
||||
const checkScrollBottom = () => {
|
||||
const container = submenuscrollContainer.value
|
||||
if (!container) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container[0]
|
||||
const isBottom = scrollHeight - (scrollTop + clientHeight) < 100 // 触底阈值
|
||||
if (isBottom && hasMore.value) {
|
||||
currentPage.value++;
|
||||
getMessageList();
|
||||
}
|
||||
}
|
||||
const handleScroll = debounce(checkScrollBottom, 200)
|
||||
const getMessageList = () => {
|
||||
if (loading.value) return;
|
||||
loading.value = true;
|
||||
getSessionsList(currentPage.value, page_size.value).then(res => {
|
||||
if (res.data && res.data.length) {
|
||||
res.data.forEach(item => {
|
||||
let obj = { title: item.title ? item.title : "新会话", path: `chat/${item.id}`, id: item.id, isMore: false, isNoTitle: item.title ? false : true }
|
||||
usemenuStore.updatemenuArr(obj)
|
||||
});
|
||||
loading.value = false;
|
||||
}
|
||||
if (res.total) {
|
||||
total.value = res.total;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const openMore = (e) => { }
|
||||
onMounted(() => {
|
||||
currentpath.value = route.name;
|
||||
if (route.params.chatid) {
|
||||
currentSecondpath.value = `${route.name}/${route.params.chatid}`;
|
||||
}
|
||||
getMessageList();
|
||||
});
|
||||
|
||||
watch([() => route.name, () => route.params], (newvalue) => {
|
||||
currentpath.value = newvalue[0];
|
||||
if (newvalue[1].chatid) {
|
||||
currentSecondpath.value = `${newvalue[0]}/${newvalue[1].chatid}`;
|
||||
} else {
|
||||
currentSecondpath.value = "";
|
||||
}
|
||||
|
||||
});
|
||||
let fileAddIcon = ref('file-add-green.svg');
|
||||
let knowledgeIcon = ref('zhishiku-green.svg');
|
||||
let prefixIcon = ref('prefixIcon.svg');
|
||||
let settingIcon = ref('setting.svg');
|
||||
let pathPrefix = ref(route.name)
|
||||
const getIcon = (path) => {
|
||||
fileAddIcon.value = path == 'knowledgeBase' ? 'file-add-green.svg' : 'file-add.svg';
|
||||
knowledgeIcon.value = path == 'knowledgeBase' ? 'zhishiku-green.svg' : 'zhishiku.svg';
|
||||
prefixIcon.value = path == 'creatChat' ? 'prefixIcon-green.svg' : path == 'knowledgeBase' ? 'prefixIcon-grey.svg' : 'prefixIcon.svg';
|
||||
settingIcon.value = path == 'settings' ? 'setting-green.svg' : 'setting.svg';
|
||||
}
|
||||
getIcon(route.name)
|
||||
const gotopage = (path) => {
|
||||
pathPrefix.value = path;
|
||||
router.push(`/platform/${path}`);
|
||||
getIcon(path)
|
||||
}
|
||||
|
||||
const getImgSrc = (url) => {
|
||||
return new URL(`/src/assets/img/${url}`, import.meta.url).href;
|
||||
}
|
||||
|
||||
const mouseenteMenu = (path) => {
|
||||
if (pathPrefix.value != 'knowledgeBase' && pathPrefix.value != 'creatChat' && path != 'knowledgeBase') {
|
||||
prefixIcon.value = 'prefixIcon-grey.svg';
|
||||
}
|
||||
}
|
||||
const mouseleaveMenu = (path) => {
|
||||
if (pathPrefix.value != 'knowledgeBase' && pathPrefix.value != 'creatChat' && path != 'knowledgeBase') {
|
||||
getIcon(route.name)
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.del_submenu {
|
||||
color: #fa5151;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.aside_box {
|
||||
min-width: 260px;
|
||||
padding: 8px;
|
||||
background: #fff;
|
||||
box-sizing: border-box;
|
||||
|
||||
.logo_box {
|
||||
height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.logo{
|
||||
width: 134px;
|
||||
height: auto;
|
||||
margin-left: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.logo_img {
|
||||
margin-left: 24px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin-right: 7.25px;
|
||||
}
|
||||
|
||||
.logo_txt {
|
||||
transform: rotate(0.049deg);
|
||||
color: #000000;
|
||||
font-family: "TencentSans";
|
||||
font-size: 24.12px;
|
||||
font-style: normal;
|
||||
font-weight: W7;
|
||||
line-height: 21.7px;
|
||||
}
|
||||
|
||||
.menu_box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
||||
.upload-file-wrap {
|
||||
padding: 6px;
|
||||
border-radius: 3px;
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.upload-file-wrap:hover {
|
||||
background-color: #dbede4;
|
||||
color: #07C05F;
|
||||
|
||||
}
|
||||
|
||||
.upload-file-icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.active-upload {
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
.menu_item_active {
|
||||
border-radius: 4px;
|
||||
background: #07c05f1a !important;
|
||||
|
||||
.menu_icon,
|
||||
.menu_title {
|
||||
color: #07c05f !important;
|
||||
}
|
||||
}
|
||||
|
||||
.menu_item_c_active {
|
||||
|
||||
.menu_icon,
|
||||
.menu_title {
|
||||
color: #000000e6;
|
||||
}
|
||||
}
|
||||
|
||||
.menu_p {
|
||||
height: 56px;
|
||||
padding: 6px 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.menu_item {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 48px;
|
||||
padding: 13px 8px 13px 16px;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 4px;
|
||||
|
||||
.menu_item-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-radius: 4px;
|
||||
background: #30323605;
|
||||
color: #00000099;
|
||||
|
||||
.menu_icon,
|
||||
.menu_title {
|
||||
color: #00000099;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.menu_icon {
|
||||
display: flex;
|
||||
margin-right: 10px;
|
||||
color: #00000099;
|
||||
|
||||
.icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
fill: currentColor;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.menu_title {
|
||||
color: #00000099;
|
||||
text-overflow: ellipsis;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.submenu {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-style: normal;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-style: normal;
|
||||
overflow-y: scroll;
|
||||
scrollbar-width: none;
|
||||
height: calc(98vh - 276px);
|
||||
}
|
||||
|
||||
.submenu_item_p {
|
||||
height: 44px;
|
||||
padding: 4px 8px 4px 12px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
|
||||
.submenu_item {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #00000099;
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
height: 36px;
|
||||
padding-left: 18px;
|
||||
padding-right: 14px;
|
||||
position: relative;
|
||||
|
||||
.submenu_title {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.menu-more-wrap {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.menu-more {
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
color: #07C05F;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
border-radius: 50%;
|
||||
background: #07C05F;
|
||||
}
|
||||
|
||||
.sub_title {
|
||||
margin-left: 14px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #30323605;
|
||||
color: #00000099;
|
||||
border-radius: 3px;
|
||||
|
||||
.menu-more {
|
||||
color: #00000099;
|
||||
}
|
||||
|
||||
.submenu_title {
|
||||
max-width: 160px !important;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.submenu_item_active {
|
||||
background: #07c05f1a !important;
|
||||
color: #07c05f !important;
|
||||
border-radius: 3px;
|
||||
|
||||
.menu-more {
|
||||
color: #07c05f !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<style lang="less">
|
||||
.upload-popup {
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
color: #FFFFFF;
|
||||
border-color: rgba(0, 0, 0, 0.9) !important;
|
||||
box-shadow: none;
|
||||
margin-bottom: 10px !important;
|
||||
|
||||
.t-popup__arrow::before {
|
||||
border-color: rgba(0, 0, 0, 0.9) !important;
|
||||
background-color: rgba(0, 0, 0, 0.9) !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.del-menu-popup {
|
||||
z-index: 99 !important;
|
||||
|
||||
.t-popup__content {
|
||||
width: 100px;
|
||||
height: 40px;
|
||||
line-height: 30px;
|
||||
padding-left: 14px;
|
||||
cursor: pointer;
|
||||
margin-top: 4px !important;
|
||||
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { watch } from "vue"
|
||||
|
||||
const props = defineProps(['reviewImg', 'reviewUrl'])
|
||||
const emit = defineEmits(['closePreImg'])
|
||||
const close = () => {
|
||||
emit('closePreImg')
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<t-image-viewer :visible="reviewImg" closeOnOverlay closeOnEscKeydown @close="close"
|
||||
:images="[{
|
||||
mainImage: reviewUrl,
|
||||
download: false
|
||||
}]">
|
||||
</t-image-viewer>
|
||||
</template>
|
||||
<style scoped lang="less"></style>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
<template>
|
||||
<div class="mask">
|
||||
<img class="upload-mask-img" src="@/assets/img/upload-mask.svg" alt="">
|
||||
<span class="drag-txt">将文件拖放到此处</span>
|
||||
<span class="drag-type-txt">pdf、doc 格式文件,不超过30M</span>
|
||||
<span class="drag-type-txt">text、markdown格式文件,不超过30M</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped lang="less">
|
||||
.mask{
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.drag-txt {
|
||||
color: #07c05f;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
line-height: 26px;
|
||||
display: inline-block;
|
||||
margin: 12px 0 16px 0;
|
||||
}
|
||||
|
||||
.drag-type-txt {
|
||||
width: 217px;
|
||||
color: #00000066;
|
||||
text-align: center;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.upload-img{
|
||||
width: 162px;
|
||||
height: 162px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user