feat: view sql in chat

This commit is contained in:
ulleo
2025-07-21 14:27:49 +08:00
parent 9c23895fc6
commit 707bde759a
5 changed files with 42 additions and 4 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ const md = new MarkdownIt({
if (lang && hljs.getLanguage(lang)) {
try {
return `<pre class="hljs">
<code>${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}</code>
<div>${hljs.highlight(str, { language: lang, ignoreIllegals: true }).value}</div>
</pre>`
} catch (e) {
console.error(e)
@@ -15,7 +15,7 @@ import icon_into_item_outlined from '@/assets/svg/icon_into-item_outlined.svg'
import icon_window_max_outlined from '@/assets/svg/icon_window-max_outlined.svg'
import icon_window_mini_outlined from '@/assets/svg/icon_window-mini_outlined.svg'
import { useI18n } from 'vue-i18n'
import MdComponent from '@/views/chat/component/MdComponent.vue'
import SQLComponent from '@/views/chat/component/SQLComponent.vue'
const props = withDefaults(
defineProps<{
@@ -324,8 +324,9 @@ function addToDashboard() {
body-class="chart-sql-drawer-body"
>
<div>
<MdComponent
:message="'```sql\n' + message.record?.sql + '\n```'"
<SQLComponent
v-if="message.record?.sql"
:sql="message.record?.sql"
style="margin-top: 12px"
/>
</div>
@@ -0,0 +1,29 @@
<script setup lang="ts">
import 'highlight.js/styles/github.min.css'
import 'github-markdown-css/github-markdown-light.css'
import hljs from 'highlight.js'
defineProps<{
sql: string
}>()
</script>
<template>
<pre class="hljs">
<div
v-dompurify-html="hljs.highlight(sql, { language: 'sql', ignoreIllegals: true }).value"
></div>
</pre>
</template>
<style lang="less">
.hljs {
overflow: auto;
padding: 1rem;
display: block;
background: rgba(245, 246, 247, 1);
border: 1px solid rgba(222, 224, 227, 1);
border-radius: 6px;
}
</style>