Przeglądaj źródła

feat:添加markdown

AmandaG 6 miesięcy temu
rodzic
commit
61b94b6e58

+ 1 - 2
src/auto-imports.d.ts

@@ -3,7 +3,6 @@
 // @ts-nocheck
 // noinspection JSUnusedGlobalSymbols
 // Generated by unplugin-auto-import
-// biome-ignore lint: disable
 export {}
 declare global {
   const $api: typeof import('@/api/index')['default']
@@ -69,6 +68,6 @@ declare global {
 // for type re-export
 declare global {
   // @ts-ignore
-  export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
+  export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
   import('vue')
 }

+ 10 - 1
src/styles/reset.scss

@@ -150,7 +150,6 @@ div {
   margin: 1em 0 0.5em;
   font-weight: bold;
 }
-
 .markdown-body p {
   margin: 1em 0;
 }
@@ -199,3 +198,13 @@ div {
   background: #f6f8fa;
   overflow-x: auto;
 }
+
+.markdown-test b, .markdown-test strong,.markdown-test p,.markdown-test code,.markdown-test blockquote,.markdown-test ul,
+.markdown-test ol,.markdown-test li,.markdown-test h1,
+.markdown-test h2,
+.markdown-test h3,
+.markdown-test h4,
+.markdown-test h5,
+.markdown-test h6 {
+  color: #FFF;
+}

+ 21 - 3
src/views/PromptConfiguration/src/components/PreviewTesting.vue

@@ -2,6 +2,8 @@
 import icon from '../images/icon_ai_test@2x.png'
 import CodeBlock from './CodeBlock.vue'
 import moment from 'moment'
+import MarkdownIt from 'markdown-it'
+import 'github-markdown-css/github-markdown.css'
 
 const PromptdialogVisible = ref(false)
 const testquestionvalue = ref('')
@@ -21,6 +23,17 @@ const props = defineProps({
   
 })
 
+const md = new MarkdownIt({
+  html: true,
+  linkify: true,
+  typographer: true,
+  breaks: true
+})
+
+const renderedMessage = (content) => {
+  return md.render(content)
+}
+
 const prompttext = ref(props.prompttext)
 const testquestion = ref(props.testquestion)
 watch(
@@ -59,6 +72,7 @@ const exporttxt = () => {
 }
 
 const unformattedJson = ref({})
+const testtype = ref('')
 
 const PromptAITest = (val:any) => {
   if(testquestion.value == false) {
@@ -71,7 +85,8 @@ const PromptAITest = (val:any) => {
     }).then((res) => {
       if (res.code === 200) {
         previewLoading.value = false
-        unformattedJson.value = res.data
+        unformattedJson.value = res.data.data
+        testtype.value = res.data.type
       }
     })
   }
@@ -133,8 +148,11 @@ const PromptAITest = (val:any) => {
       </div>
       <div class="test_result"  v-vloading="previewLoading">
         <div v-if="Object.keys(unformattedJson).length == 0" class="test_result_text">暂无数据</div>
-        <CodeBlock v-else language="json" :raw-code="JSON.stringify(unformattedJson)">
-        </CodeBlock>
+        <div v-else style="width: 100%;">
+          <div style="padding: 8px;" v-if="testtype == 'markdown'" v-html="renderedMessage(unformattedJson)" class="markdown-body markdown-test"></div>
+          <CodeBlock v-else language="json" :raw-code="JSON.stringify(unformattedJson)">
+          </CodeBlock>
+        </div>
       </div>
     </div>
   </div>