DialogZnwsContent.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="dialog-chat-answer-content">
  3. <div v-if="is_loading && type == 'znws'" class="loading"><a-spin></a-spin> <span>正在思考中...</span></div>
  4. <div class="answer-content-text answer-content-report" v-for="(item, index) in result_list" :key="index">
  5. <div class="answer-content" v-if="typeof item === 'string'" v-html="renderHtml(item)"></div>
  6. <HomeChart v-if="typeof item === 'object'" :data="item">
  7. <template #insertBtn>
  8. <a-button @click="toInsert(item)" :loading="loading" :disabled="loading">
  9. <img :src="InsertIcon" alt="" v-if="!loading" />
  10. <span>插入</span>
  11. </a-button>
  12. </template>
  13. </HomeChart>
  14. </div>
  15. <!-- <div class="answer-content-text answer-content-report" v-if="result_list && !result_list.length" :key="index">
  16. <div class="answer-content" v-html="暂无内容"></div>
  17. </div> -->
  18. <slot></slot>
  19. <div class="report-loading" v-if="answer_status === 1">
  20. <img src="../../../assets/chat-report/report-ing.png" alt="" />
  21. <!-- <span>报告生成中...</span> -->
  22. </div>
  23. </div>
  24. <!-- <div v-html="html_1"></div> -->
  25. </template>
  26. <script setup>
  27. import { ref, computed, onMounted } from 'vue';
  28. import HomeChart from '../../chat_echart/HomeChart.vue';
  29. import marked from '../../../3rd-libs/marked';
  30. import InsertIcon from '../../../assets/ai-editor/insert-icon.svg';
  31. import { createChartPic } from '../../../modules/conversation-dialog/api-dialog';
  32. // 接收markdown数据,进行一些转换
  33. const props = defineProps({
  34. /**
  35. * 内容类型
  36. */
  37. type: String,
  38. /**
  39. * 文本内容数组
  40. */
  41. result_list: Array,
  42. /**
  43. * 状态值
  44. */
  45. is_loading: Boolean,
  46. /**
  47. * 会话状态
  48. * */
  49. answer_status: Boolean
  50. });
  51. const emit = defineEmits(['insertEchart']);
  52. const loading = ref(false);
  53. const content_style = computed(() => {
  54. if (props.type === 'q') {
  55. return {
  56. background: 'var(--primary-default)',
  57. color: '#fff'
  58. };
  59. }
  60. });
  61. const renderHtml = (item) => {
  62. let renderContent = marked.parse(item);
  63. // renderContent = renderContent.replace(/^ {2}/gm, '&nbsp;&nbsp;&nbsp;&nbsp;');
  64. // renderContent = renderContent
  65. // .replace(/<p>(.*?)<\/p>/gs, (match, content) => {
  66. // return `<p class="indented" style="text-indent: 2em;">${content}</p>`;
  67. // // return `<p>${content}</p>`
  68. // })
  69. // .replace(/<br\s*\/?>([^<]*)/g, (match, content) => {
  70. // if (content.trim() === '') return match;
  71. // return `<br/><span style="display:inline-block;text-indent:2em;">${content}</span>`;
  72. // });
  73. // renderContent = renderContent
  74. // .replace(/<pre><code>/gs, '<p style="text-indent: 2em;">')
  75. // .replace(/<\/code><\/pre>/gs, '</p>');
  76. return renderContent;
  77. };
  78. const toInsert = async (item) => {
  79. loading.value = true;
  80. const params = {
  81. type: 'table',
  82. data: item.origin_chart
  83. };
  84. const res = await createChartPic(params);
  85. // console.log(res.data.chart_buf);
  86. emit('insertEchart', res.data.chart_buf);
  87. loading.value = false;
  88. };
  89. onMounted(() => {});
  90. </script>
  91. <style lang="css" scoped>
  92. .dialog-chat-answer-content {
  93. position: relative;
  94. background-color: var(--color-bg-1);
  95. color: var(--color-text-1);
  96. border-radius: 12px;
  97. /* padding-top: 15px;
  98. padding-bottom: 15px;
  99. padding-left: 30px;
  100. padding-right: 30px; */
  101. }
  102. .answer-content-report .answer-content * p {
  103. text-indent: 2em !important;
  104. }
  105. .answer-content * p {
  106. text-indent: 2em !important;
  107. }
  108. p {
  109. text-indent: 2em !important;
  110. }
  111. .dialog-chat-answer-content code {
  112. overflow-x: auto;
  113. }
  114. .answer-content-text {
  115. line-height: 24px;
  116. }
  117. .loading {
  118. margin-top: 20px;
  119. display: flex;
  120. align-items: center;
  121. gap: 10px;
  122. }
  123. </style>
  124. <style>
  125. .answer-content-text table {
  126. border-collapse: collapse;
  127. }
  128. .answer-content-text table,
  129. .answer-content-text th,
  130. .answer-content-text td {
  131. border: 1px solid rgb(184, 179, 179);
  132. }
  133. .answer-content-text th,
  134. .answer-content-text td {
  135. padding: 8px;
  136. text-align: left;
  137. }
  138. .refferences {
  139. background: rgb(238, 243, 254);
  140. border: 1px solid rgb(255, 255, 255);
  141. box-shadow: rgba(29, 48, 91, 0.2) 0px 1px 1px 0px;
  142. padding: 2px 6px;
  143. cursor: pointer;
  144. }
  145. .refferences:hover {
  146. background-color: var(--primary-default);
  147. color: #fff;
  148. }
  149. .indented br + * {
  150. display: inline-block;
  151. text-indent: 2em;
  152. }
  153. .report-loading {
  154. margin-top: 10px;
  155. }
  156. .report-loading img {
  157. width: 32px;
  158. }
  159. </style>