DialogAnswer.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="dialog-item dialog-anwser" :class="anwser_klass">
  3. <BtnSelectItem v-if="select_btn_visible" @change="handleSelectChange" />
  4. <div class="dialog-main answer-main">
  5. <div class="dialog-icon answer-icon">
  6. <img :src="answer.client_custom_icon" />
  7. </div>
  8. <div class="dialog-content answer-content">
  9. <div>
  10. <DialogContent :content="answer_html" :is_loading="is_content_loading">
  11. <DialogActions
  12. v-if="answer_status === 2"
  13. class="answer-actions-btns"
  14. @copy="handleAnswerCopy"
  15. @share="handleAnswerShare"
  16. @retry="handleAnswerRetry"
  17. />
  18. </DialogContent>
  19. <BtnStopChat v-if="answer_status === 1" @stop="handleStopChat" />
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. /**
  27. * 智能体的回答内容,可能需要包括下面一些功能
  28. *
  29. * 4. 回答反馈:分享、点赞、复制
  30. */
  31. import { computed, onMounted } from 'vue';
  32. import { Message } from '@arco-design/web-vue';
  33. import BtnSelectItem from './BtnSelectItem.vue';
  34. import DialogActions from './DialogActions.vue';
  35. import BtnStopChat from './BtnStopChat.vue';
  36. import DialogContent from '../conversation-content/DialogContent.vue';
  37. import formatAnwserString from '../conversation-dialog/format-anwser-string';
  38. import { formatFileDownloadStr } from '../conversation-dialog/format-dialog-answer-custom-markdown-str';
  39. import { getIconIntelligent } from '../common/icon-map';
  40. import { formatStaticAssetsUrl } from '../../utils/utils';
  41. import applyRefferencePopover4RefFlag from '../answer-refference/apply-refference-popover-4-ref-flag';
  42. import applyRefferencePopover4FileName from '../answer-refference/apply-refference-popover-4-filename';
  43. import { applyCodeHighLight } from '../conversation-dialog/format-code-string';
  44. import copyText from '../../3rd-libs/clipboard';
  45. const props = defineProps({
  46. /**
  47. * 是否显示选择按钮
  48. * 仿照kimi,当用户选择分享时,选择按钮会展示
  49. */
  50. show_select: true,
  51. /**
  52. * 答案内容数据
  53. */
  54. answer: Object
  55. });
  56. const emit = defineEmits(['stop', 'retry', 'select']);
  57. const select_btn_visible = computed(() => {
  58. return props.show_select === true;
  59. });
  60. /**
  61. * 当前对话的状态
  62. * 0 加载中
  63. * 1 正在对话
  64. * 2 已结束
  65. */
  66. const answer_status = computed(() => {
  67. const answer = props.answer;
  68. return answer.client_custom_chat_status;
  69. });
  70. /**
  71. * 内容是否正在加载中
  72. */
  73. const is_content_loading = computed(() => {
  74. return answer_status.value === 0;
  75. });
  76. /**
  77. * 智能体回答的内容的html字符串
  78. * 是markdown格式
  79. * 需要使用markdown解析器进行解析
  80. */
  81. const answer_html = computed(() => {
  82. const answer = props.answer;
  83. const str = answer.content;
  84. let answer_string = formatAnwserString(str);
  85. // 由于SQL和代码不能通过markdown解析,所以此处进行字符串的拼接
  86. // 在markdown转换结束后,添加拼接字符串
  87. if (answer.client_custom_linked_code) {
  88. answer_string = answer_string + answer.client_custom_linked_code;
  89. }
  90. if (answer.client_custom_linked_sql) {
  91. answer_string = answer_string + answer.client_custom_linked_sql;
  92. }
  93. if (answer.client_custom_linked_image) {
  94. const img_url = formatStaticAssetsUrl(answer.client_custom_linked_image);
  95. answer_string = answer_string + `<img src="${img_url}" />`;
  96. }
  97. // 处理下载链接
  98. if (answer.client_custom_linked_download_files) {
  99. const file_name = answer.client_custom_linked_download_files.file_name;
  100. const file_url = answer.client_custom_linked_download_files.file_url;
  101. const download_file_str = formatFileDownloadStr(file_name, file_url);
  102. answer_string = answer_string + download_file_str;
  103. }
  104. return answer_string;
  105. });
  106. const anwser_klass = computed(() => {
  107. const answer = props.answer;
  108. // console.log(answer, '答案数据');
  109. return `klass-${answer.client_custom_unique_id}-answer-content`;
  110. });
  111. const handleSelectChange = () => {
  112. emit('select');
  113. };
  114. /**
  115. * 停止答案的生成
  116. */
  117. const handleStopChat = () => {
  118. emit('stop');
  119. };
  120. /**
  121. * copy
  122. */
  123. const handleAnswerCopy = () => {
  124. copyText(answer_html.value);
  125. Message.success('已复制');
  126. };
  127. /**
  128. * 分享答案
  129. */
  130. const handleAnswerShare = () => {};
  131. /**
  132. * 重新生成答案
  133. */
  134. const handleAnswerRetry = () => {
  135. emit('retry');
  136. };
  137. onMounted(() => {
  138. const container_klass = anwser_klass.value;
  139. const answer = props.answer;
  140. /**
  141. * 文档引用效果
  142. */
  143. applyRefferencePopover4RefFlag(container_klass, answer.client_custom_linked_refference_full_content);
  144. applyRefferencePopover4FileName(container_klass, answer.client_custom_linked_refference_full_content);
  145. /**
  146. * 处理代码样式
  147. */
  148. applyCodeHighLight(container_klass);
  149. });
  150. </script>
  151. <style src="./dialog-item-common.css" />
  152. <style lang="css" scoped>
  153. .dialog-anwser {
  154. color: var(--color-text-1);
  155. display: flex;
  156. justify-content: space-between;
  157. }
  158. .answer-main {
  159. }
  160. .answer-content {
  161. display: flex;
  162. justify-content: flex-start;
  163. }
  164. .answer-icon {
  165. margin-right: 5px;
  166. }
  167. .answer-icon img {
  168. width: 100%;
  169. }
  170. .answer-actions-btns {
  171. margin-top: 5px;
  172. }
  173. </style>