mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-08 10:13:44 +08:00
opt: optimize the formula show styles
This commit is contained in:
@@ -82,6 +82,7 @@ import {useRouter} from 'vue-router';
|
||||
import {ArrowDown, ArrowRight, Expand, Fold} from "@element-plus/icons-vue";
|
||||
import {httpGet} from "@/utils/http";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {removeAdminToken} from "@/store/session";
|
||||
|
||||
const message = ref(5);
|
||||
const sysTitle = ref(process.env.VUE_APP_TITLE)
|
||||
@@ -153,6 +154,7 @@ onMounted(() => {
|
||||
|
||||
const logout = function () {
|
||||
httpGet("/api/admin/logout").then(() => {
|
||||
removeAdminToken()
|
||||
router.replace('/admin/login')
|
||||
}).catch((e) => {
|
||||
ElMessage.error("注销失败: " + e.message);
|
||||
|
||||
@@ -39,7 +39,7 @@ export function removeUserToken() {
|
||||
}
|
||||
|
||||
export function getAdminToken() {
|
||||
return Storage.get(AdminTokenKey)
|
||||
return Storage.get(AdminTokenKey) ?? ""
|
||||
}
|
||||
|
||||
export function setAdminToken(token) {
|
||||
|
||||
@@ -167,7 +167,7 @@ export function isImage(url) {
|
||||
}
|
||||
|
||||
export function processContent(content) {
|
||||
//process img url
|
||||
// 如果是图片链接地址,则直接替换成图片标签
|
||||
const linkRegex = /(https?:\/\/\S+)/g;
|
||||
const links = content.match(linkRegex);
|
||||
if (links) {
|
||||
@@ -181,20 +181,31 @@ export function processContent(content) {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理引用块
|
||||
if (content.indexOf("\n") === -1) {
|
||||
const lines = content.split("\n")
|
||||
if (lines.length <= 1) {
|
||||
return content
|
||||
}
|
||||
|
||||
const texts = content.split("\n")
|
||||
const lines = []
|
||||
for (let txt of texts) {
|
||||
lines.push(txt)
|
||||
if (txt.startsWith(">")) {
|
||||
lines.push("\n")
|
||||
const texts = []
|
||||
// 定义匹配数学公式的正则表达式
|
||||
const formulaRegex = /^\s*[a-z|A-Z]+[^=]+\s*=\s*[^=]+$/;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
// 处理引用块换行
|
||||
if (lines[i].startsWith(">")) {
|
||||
texts.push(lines[i])
|
||||
texts.push("\n")
|
||||
continue
|
||||
}
|
||||
console.log(formulaRegex.test(lines[i]))
|
||||
// 识别并处理数学公式,需要排除那些已经被识别出来的公式
|
||||
if (i > 0 && formulaRegex.test(lines[i]) && lines[i - 1].indexOf("$$") === -1) {
|
||||
texts.push("$$")
|
||||
texts.push(lines[i])
|
||||
texts.push("$$")
|
||||
continue
|
||||
}
|
||||
texts.push(lines[i])
|
||||
}
|
||||
return lines.join("\n")
|
||||
return texts.join("\n")
|
||||
}
|
||||
|
||||
export function escapeHTML(html) {
|
||||
@@ -203,3 +214,23 @@ export function escapeHTML(html) {
|
||||
.replace(/>/g, ">");
|
||||
}
|
||||
|
||||
// 处理数学公式
|
||||
export function processMathFormula(input) {
|
||||
const arr = []
|
||||
const lines = input.split("\n")
|
||||
if (lines.length <= 1) {
|
||||
return input
|
||||
}
|
||||
// 定义匹配数学公式的正则表达式
|
||||
const mathFormulaRegex = /[+\-*/^()\d.]/;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (i > 0 && mathFormulaRegex.test(lines) && lines[i - 1].indexOf("$$") === -1) {
|
||||
arr.push("$$")
|
||||
arr.push(lines[i])
|
||||
arr.push("$$")
|
||||
} else {
|
||||
arr.push(lines[i])
|
||||
}
|
||||
}
|
||||
return arr.join("\n")
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ const logout = function () {
|
||||
activelyClose.value = true;
|
||||
httpGet('/api/user/logout').then(() => {
|
||||
removeUserToken()
|
||||
location.reload()
|
||||
router.push("/login")
|
||||
}).catch(() => {
|
||||
ElMessage.error('注销失败!');
|
||||
})
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<el-image v-if="scope.row.vip" :src="vipImg" style="height: 20px;position: relative; top:5px; left: 5px"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="nickname" label="昵称"/>
|
||||
<el-table-column prop="power" label="剩余算力"/>
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="scope">
|
||||
|
||||
Reference in New Issue
Block a user