opt: refactor chat session page for mobile device

This commit is contained in:
RockYang
2024-01-25 14:07:10 +08:00
parent a39ed9764c
commit a1d1fe7763
10 changed files with 324 additions and 104 deletions

View File

@@ -266,7 +266,7 @@ import {
VideoPause
} from '@element-plus/icons-vue'
import 'highlight.js/styles/a11y-dark.css'
import {dateFormat, isImage, isMobile, randString, removeArrayItem, UUID} from "@/utils/libs";
import {dateFormat, isImage, isMobile, processContent, randString, removeArrayItem, UUID} from "@/utils/libs";
import {ElMessage, ElMessageBox} from "element-plus";
import hl from "highlight.js";
import {getSessionId, getUserToken, removeUserToken} from "@/store/session";
@@ -803,37 +803,6 @@ const loadChatHistory = function (chatId) {
})
}
const processContent = (content) => {
//process img url
const linkRegex = /(https?:\/\/\S+)/g;
const links = content.match(linkRegex);
if (links) {
for (let link of links) {
if (isImage(link)) {
const index = content.indexOf(link)
if (content.substring(index - 1, 2) !== "]") {
content = content.replace(link, "\n![](" + link + ")\n")
}
}
}
}
// 处理引用块
if (content.indexOf("\n") === -1) {
return content
}
const texts = content.split("\n")
const lines = []
for (let txt of texts) {
lines.push(txt)
if (txt.startsWith(">")) {
lines.push("\n")
}
}
return lines.join("\n")
}
const stopGenerate = function () {
showStopGenerate.value = false;
httpGet("/api/chat/stop?session_id=" + getSessionId()).then(() => {