SidebarRecommend.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div>
  3. <div class="recommend-container">
  4. <div style="display: flex; align-items: center; margin-bottom: 20px">
  5. <a-image :src="Frame" style="width: 20px; height: 20px"></a-image>
  6. <span style="font-size: 18px; font-weight: bold; margin-left: 10px">资源</span><span
  7. style="color: #165dff;font-size: 18px; font-weight: bold;">推荐</span>
  8. </div>
  9. <div v-for="(item, index) in recommendations" :key="index" class="recommend-item"
  10. @click="handlerItem(item)">
  11. <div style="display: flex; flex-direction: column">
  12. <div style="display: flex;">
  13. <div
  14. class="item"
  15. :style="{
  16. backgroundSize: 'cover',
  17. backgroundPosition: 'center',
  18. backgroundImage: item.coverImagePath && sysConfig.FILE_URL + item.coverImagePath
  19. ? 'url(' + sysConfig.FILE_URL + item.coverImagePath + ')'
  20. : 'none',
  21. backgroundColor: item.coverImagePath && sysConfig.FILE_URL + item.coverImagePath
  22. ? 'transparent'
  23. : '#7f8c8d55'
  24. }"
  25. ></div>
  26. <div
  27. style="display: flex; flex-direction: column; justify-content: space-between; width: 100%; padding-left: 7px">
  28. <a-tooltip>
  29. <template #title>{{ item.fileName }}</template>
  30. <span style="font-size: 15px; font-weight: bold">{{
  31. tool.truncateString(item.fileName, 20)
  32. }}</span>
  33. </a-tooltip>
  34. <!-- <span style="font-weight: bold; font-size: 12px; margin-top: 5px">{{ item.fileName }}</span>-->
  35. <div style="display: flex; justify-content: space-between; align-items: center">
  36. <div style="display: flex; justify-content: center; align-items: center">
  37. <FieldTimeOutlined/>
  38. <div style="width: 5px"></div>
  39. <span style="font-size: 10px">{{ item.uploadTime }}</span>
  40. </div>
  41. <div style="width: 20px"></div>
  42. <div style="display: flex; justify-content: center; align-items: center">
  43. <EyeOutlined/>
  44. <div style="width: 5px"></div>
  45. <span style="font-size: 12px">{{ item.viewCount }}</span>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <div v-if="index<recommendations.length-1"
  51. style="height: 1px; width: 100%; margin-top: 10px; background: #7f8c8d22"></div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script setup>
  58. const emit = defineEmits(['handlerItem'])
  59. import {list} from '@/api/portal'
  60. import tool from '@/utils/tool'
  61. import Frame from '@/assets/images/Frame.png'
  62. import sysConfig from '@/config/index'
  63. import EventBus from '@/utils/EventBus'
  64. const currentPage = reactive({
  65. funcType: 1,
  66. current: 1,
  67. size: 6
  68. })
  69. const recommendations = ref([
  70. // { id: '1', title: '资源名称', time: '05-22', look: '10000' },
  71. // { id: '2', title: '资源名称', time: '05-22', look: '10000' },
  72. // { id: '3', title: '资源名称', time: '05-22', look: '10000' },
  73. // { id: '4', title: '资源名称', time: '05-22', look: '10000' },
  74. // { id: '5', title: '资源名称', time: '05-22', look: '10000' },
  75. // { id: '6', title: '资源名称', time: '05-22', look: '10000' }
  76. ])
  77. // 更多数据...
  78. const getList = () => {
  79. list(currentPage)
  80. .then((res) => {
  81. console.log('下面列表获取', res)
  82. if (res.code == 200) {
  83. recommendations.value = res.data.records
  84. currentPage.current = res.data.current
  85. // "size": 20,
  86. // "current": 1,
  87. // "pages": 1
  88. }
  89. })
  90. .catch((err) => {
  91. console.log(err)
  92. })
  93. }
  94. onMounted(() => {
  95. getList()
  96. })
  97. const upLoadList = (data) => {
  98. let queryData = data
  99. list({...currentPage, ...queryData})
  100. .then((res) => {
  101. if (res.code == 200) {
  102. recommendations.value = res.data.records
  103. currentPage.current = res.data.current
  104. }
  105. })
  106. .catch((err) => {
  107. console.log(err)
  108. })
  109. }
  110. const handlerItem = (item) => {
  111. // emit('handlerItem', item)
  112. EventBus.emit('openResourceDetails', {id: item.id})
  113. }
  114. EventBus.off('upLoadList', upLoadList)
  115. EventBus.on('upLoadList', upLoadList)
  116. </script>
  117. <style scoped>
  118. .recommend-container {
  119. background: white;
  120. display: flex;
  121. flex-direction: column;
  122. margin-bottom: 10px;
  123. border-radius: 4px;
  124. padding: 20px;
  125. }
  126. .recommend-item {
  127. display: flex;
  128. margin-bottom: 10px;
  129. cursor: pointer;
  130. }
  131. .recommend-avatar {
  132. margin-right: 15px;
  133. }
  134. .recommend-content {
  135. flex: 1;
  136. }
  137. .recommend-title {
  138. font-size: 16px;
  139. color: #1890ff;
  140. margin-bottom: 5px;
  141. }
  142. .recommend-description {
  143. font-size: 14px;
  144. color: #666;
  145. }
  146. .item {
  147. min-width: 150px;
  148. height: 90px;
  149. }
  150. </style>