Prechádzať zdrojové kódy

Merge branch 'dev' of United_Software/k_online_ui into test

Jack Zhou 6 mesiacov pred
rodič
commit
181df75179

+ 9 - 0
src/styles/index.scss

@@ -56,3 +56,12 @@
 .icon_dark {
   fill: var(--color-neutral-1);
 }
+div.markdown-body {
+  background: transparent;
+  table {
+    th,
+    td {
+      white-space: nowrap;
+    }
+  }
+}

+ 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;
+}

+ 17 - 17
src/views/AIRobotChat/src/AIRobotChat.vue

@@ -18,7 +18,11 @@ const md = new MarkdownIt({
 })
 
 const renderedMessage = (content) => {
-  return md.render(content)
+  const normalized = content
+    .replace(/\\n/g, '\n') // 粘贴带来的 \\n 处理
+    .replace(/\r\n/g, '\n') // Windows 换行标准化
+    .trim()
+  return md.render(normalized)
 }
 
 const themeStore = useThemeStore()
@@ -57,7 +61,8 @@ const messages = ref<MessageItem[]>([
   },
   {
     type: 'user',
-    content: 'Hi! I am your Freight Assistant. How can I help you?'
+    content:
+      'Hi! I am your Freight Assistant. How can I help you?Of course! Please provide me with the details of your shipment.Of course! Please provide me with the details of your shipment.'
   },
   {
     type: 'robot',
@@ -68,7 +73,8 @@ const messages = ref<MessageItem[]>([
   },
   {
     type: 'user',
-    content: 'Of course! Please provide me with the details of your shipment.'
+    content:
+      'Of course! Please provide me with the details of your shipment.Of course! Please provide me with the details of your shipment.'
   }
 ])
 messages.value = JSON.parse(sessionStorage.getItem('AIChat')) || messages.value
@@ -177,15 +183,7 @@ function scrollToBottom() {
 
 const simulateStreamingMarkdown = () => {
   loadingAnswer.value = true
-  const chunks = [
-    '# 欢迎使用这是一个用于测试的 Markdown 文本 Markdown\n\n',
-    '这是一个用于测试的这是一个用于测试的 Markdown 文本 **Markdown** 文本。\n\n',
-    '你可以使用这是一个用于测试的 Markdown 文本 *斜体* 来强调重点。\n\n',
-    '也可以使用这是一个用于测试的 Markdown 文本 [链接](https://example.com) 引导用户跳转。\n\n',
-    '- 支持无这是一个用于测试的 Markdown 文本这是一个用于测试的 Markdown 文本序列表\n',
-    '- 非常适合这是一个用于测试的 Markdown 文本这是一个用于测试的 Markdown 文本这是一个用于测试的 Markdown 文本逐行流式显示\n\n',
-    '这是一段这是一个用于测试的 Markdown 文本这是一个用于测试的 Markdown 文本这是一个用于测试的 Markdown 文本测试!\n'
-  ]
+  const chunks: any = [userQuestion.value]
 
   messages.value.push({
     type: 'robot',
@@ -211,6 +209,7 @@ const simulateStreamingMarkdown = () => {
       }
     } else {
       clearInterval(interval)
+      userQuestion.value = ''
     }
   }, 200) // 每500ms追加一段
 }
@@ -271,6 +270,9 @@ defineExpose({
             ? 'query-style'
             : ''
         ]"
+        :style="{
+          maxWidth: modalSize === 'large' ? 'calc(100% - 20px)' : 'calc(100% - 16px)'
+        }"
         v-for="(msg, index) in messages"
         :key="index"
         @mouseenter="msg.isShowFeedback = true"
@@ -287,8 +289,8 @@ defineExpose({
           src="./image/icon_loading.png"
           alt=""
         />
-        <span v-if="!msg.isAnswer">{{ msg.content }}</span>
-        <div v-else>
+        <!-- <span v-if="!msg.isAnswer">{{ msg.content }}</span> -->
+        <div>
           <div v-html="renderedMessage(msg.content)" class="markdown-body"></div>
           <LoadingDots
             v-if="index === messages.length - 1 && msg.isAnswer && loadingAnswer"
@@ -520,9 +522,7 @@ defineExpose({
         margin-right: 4px;
         animation: loading-rotate 2s linear infinite;
       }
-      .markdown-body {
-        background: transparent;
-      }
+
       .pause-btn {
         position: absolute;
         right: -22px;

+ 1 - 1
src/views/Dashboard/src/DashboardView.vue

@@ -1320,7 +1320,7 @@ const ClickParams = (val: any) => {
 }
 .filters_left {
   border-radius: var(--border-radius-6);
-  flex: 1 48%;
+  flex: 1 40%;
 }
 .KPI_title {
   border-bottom: 1px solid var(--color-border);

+ 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>