MessageBody.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="body-container" ref="body_container">
  3. <CardItem v-for="item in moke_data" :key="item.name" :name="item.name" :img_src="item.img_src">
  4. <template #bottom>
  5. <div class="bottom">
  6. <div>{{ item.count }}{{ $t('management.document') }}</div>
  7. <div>|</div>
  8. <div>{{ item.time }}</div>
  9. </div>
  10. </template>
  11. <template #settings>
  12. <a-dropdown trigger="hover" @select="handleSelect">
  13. <icon-more :style="{ fontSize: '20px' }" />
  14. <template #content>
  15. <a-doption :value="{ value: 'edit' }">{{ $t('management.edit') }}</a-doption>
  16. <a-doption :value="{ value: 'delete' }">{{ $t('management.delete') }}</a-doption>
  17. </template>
  18. </a-dropdown>
  19. </template>
  20. </CardItem>
  21. <div class="loading-tips">
  22. <a-spin v-if="scroll_bottom && pages.current < total_pages" :tip="$t('management.loadingData')" />
  23. <div v-if="scroll_bottom && pages.current >= total_pages">{{ $t('management.noMoreData') }}</div>
  24. </div>
  25. </div>
  26. </template>
  27. <script setup>
  28. import { ref, reactive, onMounted, onBeforeUnmount } from 'vue';
  29. import CardItem from '../../views/manage/CardItem.vue';
  30. import { getImageKnowLedge } from '../../views/manage/common';
  31. import { getKnowledgeList } from '../../apis/knowledge';
  32. import { bus_knowledgeSearch } from '../../base/event-bus';
  33. const moke_data = ref([
  34. // {
  35. // name: '知识库1',
  36. // img_src: knowledgeFrame1,
  37. // count: 292,
  38. // time: '2024:11:11 12:00:00'
  39. // }
  40. ]);
  41. const pages = reactive({
  42. current: 1,
  43. pageSize: 25
  44. });
  45. // 总页码
  46. const total_pages = ref(5);
  47. const body_container = ref(null);
  48. const scroll_bottom = ref(false);
  49. // 搜索文本
  50. const search_text = ref('');
  51. const handleSelect = ({ value }) => {
  52. if (value === 'edit') {
  53. } else {
  54. }
  55. };
  56. const getKnowledge = async () => {
  57. // TODO: 等待接口修改后,需要将searchText传到接口中
  58. try {
  59. const res = await getKnowledgeList(pages.current, pages.pageSize);
  60. if (res.code == 200) {
  61. const data = res.data.rows.map((item) => {
  62. return {
  63. ...item,
  64. time: new Date(item.update_time).toLocaleString('zh-CN'),
  65. img_src: getImageKnowLedge(item.avatar),
  66. count: item.count ? item.count : 292
  67. };
  68. });
  69. moke_data.value.push(...data);
  70. }
  71. } catch (err) {
  72. console.log(err, 'flag');
  73. }
  74. };
  75. const scrollHandler = (e) => {
  76. if (e.target.scrollTop + e.target.clientHeight >= e.target.scrollHeight) {
  77. scroll_bottom.value = true;
  78. // 调用函数加载更多数据
  79. if (pages.current < total_pages.value) {
  80. pages.current += 1;
  81. getKnowledge();
  82. } else {
  83. }
  84. }
  85. };
  86. bus_knowledgeSearch.on((text) => {
  87. search_text.value = text;
  88. getKnowledge();
  89. });
  90. onMounted(() => {
  91. getKnowledge();
  92. body_container.value.addEventListener('scroll', scrollHandler);
  93. });
  94. onBeforeUnmount(() => {
  95. bus_knowledgeSearch.off();
  96. body_container.value.removeEventListener('scroll', scrollHandler);
  97. });
  98. </script>
  99. <style scoped lang="css">
  100. .body-container {
  101. display: grid;
  102. grid-template-columns: repeat(6, 1fr);
  103. gap: 20px;
  104. overflow-y: scroll;
  105. height: calc(100% - 80px);
  106. }
  107. .body-container::-webkit-scrollbar {
  108. display: none;
  109. }
  110. .bottom {
  111. display: flex;
  112. gap: 10px;
  113. }
  114. .loading-tips {
  115. grid-column: 1/-1;
  116. grid-row-start: auto;
  117. text-align: center;
  118. }
  119. </style>