ChunkList.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="chunk-list">
  3. <a-spin v-if="loading" dot :loading="loading" />
  4. <div v-else>
  5. <div v-for="(item, index) in chunks" :key="index">
  6. <div class="card">
  7. <AsideImage v-if="item.image_url" :src="item.image_url" />
  8. <div class="document-reference">
  9. <a-popover trigger="hover">
  10. <template #content>
  11. <div class="popup-markdown">
  12. <div v-html="highlightText(item.content_with_weight)" />
  13. </div>
  14. </template>
  15. <div v-html="highlightText(item.highlight)" class="highlight-content" />
  16. </a-popover>
  17. <div class="file-btn" @click="fileClick(item)">
  18. <a-space>
  19. <FileIcon :name="item.docnm_kwd" />
  20. <div>{{ item.docnm_kwd }}</div>
  21. </a-space>
  22. </div>
  23. </div>
  24. </div>
  25. <a-divider :margin="12" v-if="index < chunks.length - 1" />
  26. </div>
  27. <div v-if="chunks.length > 1">
  28. <a-divider />
  29. <a-pagination
  30. :current="current_page"
  31. :total="total"
  32. :page-size="page_size"
  33. show-total
  34. show-page-size
  35. @change="handlePageChange"
  36. @page-size-change="handlePageSizeChange"
  37. />
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script setup>
  43. import { ref } from 'vue';
  44. import FileIcon from './FileIcon.vue';
  45. import AsideImage from './PopoverImage.vue';
  46. const props = defineProps({
  47. chunks: Array,
  48. total: {
  49. type: Number,
  50. required: true
  51. },
  52. highlight_word: String,
  53. page_size: {
  54. type: Number,
  55. default: 10
  56. },
  57. loading: Boolean
  58. });
  59. const emit = defineEmits(['clickDocumentButton', 'pageChange', 'pageSizeChange']);
  60. const fileClick = (item) => {
  61. emit('clickDocumentButton', item);
  62. };
  63. const highlightText = (text) => {
  64. if (!props.highlight_word) return text;
  65. const regex = new RegExp(`(${props.highlight_word})`, 'gi');
  66. return text.replace(regex, `<span class="highlighted">$1</span>`);
  67. };
  68. const current_page = ref(1);
  69. const page_size = ref(10);
  70. const handlePageChange = (page) => {
  71. current_page.value = page;
  72. emit('pageChange', page);
  73. };
  74. const handlePageSizeChange = (page_size) => {
  75. page_size.value = page_size;
  76. emit('pageSizeChange', page_size);
  77. };
  78. </script>
  79. <style scoped>
  80. .chunk-list {
  81. text-align: center;
  82. }
  83. .card {
  84. display: flex;
  85. align-items: center;
  86. box-sizing: border-box;
  87. text-align: left;
  88. padding: 14px;
  89. padding-bottom: 8px;
  90. color: var(--color-text-1);
  91. font-size: 14px;
  92. list-style: none;
  93. position: relative;
  94. background: var(--color-bg-1);
  95. border: 1px solid var(--color-neutral-3);
  96. border-radius: 8px;
  97. }
  98. .popup-markdown {
  99. color: var(--color-text-1);
  100. width: 60vw;
  101. max-height: 40vh;
  102. overflow: auto;
  103. }
  104. .highlight-content {
  105. display: -webkit-box;
  106. -webkit-box-orient: vertical;
  107. -webkit-line-clamp: 2;
  108. overflow: hidden;
  109. text-overflow: ellipsis;
  110. }
  111. .file-btn {
  112. font-weight: 600;
  113. cursor: pointer;
  114. }
  115. .document-reference {
  116. margin-left: 8px;
  117. display: flex;
  118. flex-direction: column;
  119. gap: 16px;
  120. }
  121. /* 新增高亮样式 */
  122. :deep(.highlighted) {
  123. color: red; /* 设置高亮文本为链接颜色 */
  124. }
  125. :deep(.arco-pagination) {
  126. justify-content: end;
  127. }
  128. :deep(.arco-pagination-item-active) {
  129. border-radius: 8px;
  130. font-weight: 600;
  131. background-color: var(--color-bg-1);
  132. }
  133. :deep(.arco-select-view-single) {
  134. border-radius: 8px;
  135. background-color: var(--color-bg-1);
  136. }
  137. </style>