SelectedRecommend.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div class="keep-group">
  3. <div class="flex-r-c">
  4. <div class="title-group flex-r-c center left">
  5. <h5>{{ title }}</h5>
  6. </div>
  7. </div>
  8. <div class="hot-keep-group flex-r-c wrap">
  9. <div class="card-item flex-r-c" v-for="item in options" :key="item.id" @click="goContent(item)">
  10. <div class="mini-img-group">
  11. <img :src="item.img" alt="" @error="handleError">
  12. <i :class="'el-icon-jy-' + item.type" />
  13. </div>
  14. <div class="flex-c-c">
  15. <div class="flex">
  16. <div class="title-text van-multi-ellipsis--l2">{{ item.title }}</div>
  17. </div>
  18. <div class="money-group center left">
  19. {{ item.docTags }}
  20. </div>
  21. <div class="flex-c-c info-text">
  22. <span v-if="item.contribution">贡献者: {{ item.contribution }}</span>
  23. <div class="info-text-group flex-r-c center left">
  24. <span v-if="item.viewTimes">{{ SetViewUnit(item.viewTimes) }}浏览</span>
  25. <span v-if="item.page">共{{ item.page }}页</span>
  26. <span v-if="item.size">{{ item.size | sizeFormatter }}</span>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'SelectedRecommend',
  37. props: {
  38. title: {
  39. type: String,
  40. default: '精选推荐'
  41. },
  42. options: {
  43. type: Array,
  44. default: () => []
  45. }
  46. },
  47. data () {
  48. return {}
  49. },
  50. mounted () {
  51. this.setItemwidth()
  52. },
  53. methods: {
  54. handleError (img) {
  55. img.target.src = require('../assets/images/error.png')
  56. },
  57. SetViewUnit (num) {
  58. let newNum = 0
  59. if (!num) return 0
  60. if (num > 10000) {
  61. newNum = (num / 10000).toFixed(1) + 'w'
  62. } else {
  63. newNum = num
  64. }
  65. return newNum
  66. },
  67. goContent (item) {
  68. this.$emit('click', item)
  69. },
  70. setItemwidth () { // 适配嵌入工作台内
  71. const bodyWidth = document.body.clientWidth
  72. if (window.goTemplateData && window.goTemplateData.inIframe && bodyWidth > 1248) {
  73. const element = document.getElementsByClassName('card-item')[0]
  74. const itemwidth = element.offsetWidth + 104 // 104是margin
  75. const num = Math.floor(bodyWidth / itemwidth)
  76. const newwidth = (Math.floor((bodyWidth - (itemwidth * num)) / num)) + itemwidth
  77. var elements = document.querySelectorAll('.card-item')
  78. elements.forEach(function (ele) {
  79. ele.style.width = newwidth + 'px' // 设置新的宽度
  80. })
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. .keep-group {
  88. margin-top: 38px;
  89. padding-bottom: 50px;
  90. @include diy-icon('iconJianYu', 24, 24);
  91. @include diy-icon('pdf', 24);
  92. @include diy-icon('word', 24);
  93. @include diy-icon('excel', 24);
  94. @include diy-icon('ppt', 24);
  95. .title-group {
  96. margin-bottom: 16px;
  97. h5 {
  98. color: #1D1D1D;
  99. font-family: Microsoft YaHei;
  100. font-size: 18px;
  101. font-weight: 400;
  102. line-height: 28px;
  103. letter-spacing: 0px;
  104. text-align: left;
  105. margin-right: 9px;
  106. }
  107. }
  108. .card-item {
  109. cursor: pointer;
  110. justify-content: flex-start;
  111. padding: 8px 0 12px;
  112. box-sizing: border-box;
  113. &:hover {
  114. .title-text {
  115. color: #2ABED1;
  116. }
  117. }
  118. .money-group {
  119. display: block;
  120. margin-top: 18px;
  121. width: 180px;
  122. overflow: hidden;
  123. white-space: nowrap;
  124. text-overflow: ellipsis;
  125. font-size: 13px;
  126. line-height: 22px;
  127. color: #999999;
  128. }
  129. .mini-img-group {
  130. flex-shrink: 0;
  131. position: relative;
  132. border-radius: 4px;
  133. border: 1px solid #ececec;
  134. width: 80px;
  135. height: 112px;
  136. margin-right: 16px;
  137. overflow: hidden;
  138. display: flex;
  139. flex-direction: row;
  140. align-items: center;
  141. justify-content: center;
  142. img {
  143. width: 100%;
  144. }
  145. i {
  146. position: absolute;
  147. right: 0;
  148. bottom: 0;
  149. }
  150. }
  151. .info-text-group {
  152. span {
  153. display: inline-block;
  154. &:last-child {
  155. &::after {
  156. content: unset;
  157. }
  158. }
  159. &::after {
  160. content: "|";
  161. padding: 0 4px;
  162. color: #ececec;
  163. }
  164. }
  165. }
  166. .info-text {
  167. font-family: Microsoft YaHei;
  168. font-style: normal;
  169. font-weight: normal;
  170. font-size: 13px;
  171. line-height: 24px;
  172. color: #999999;
  173. }
  174. .red-text {
  175. color: #FF3A20;
  176. font-family: Microsoft YaHei;
  177. font-style: normal;
  178. font-weight: normal;
  179. font-size: 18px;
  180. line-height: 28px;
  181. }
  182. .title-text {
  183. width: 183px;
  184. font-family: Microsoft YaHei;
  185. font-style: normal;
  186. font-weight: normal;
  187. font-size: 16px;
  188. line-height: 24px;
  189. color: #1D1D1D;
  190. word-wrap: break-word;
  191. }
  192. }
  193. .van-ellipsis {
  194. overflow: hidden;
  195. white-space: nowrap;
  196. text-overflow: ellipsis;
  197. }
  198. .van-multi-ellipsis--l2 {
  199. display: -webkit-box;
  200. overflow: hidden;
  201. text-overflow: ellipsis;
  202. -webkit-line-clamp: 2;
  203. -webkit-box-orient: vertical;
  204. }
  205. .hot-keep-group {
  206. .card-item {
  207. width: 279px;
  208. overflow: hidden;
  209. }
  210. }
  211. }
  212. .in-app {
  213. // 工作台内适配
  214. .hot-keep-group {
  215. justify-content: flex-start !important;
  216. @media screen and (max-width: 1248px) {
  217. .card-item {
  218. margin-right: 41px;
  219. }
  220. }
  221. @media screen and (min-width: 1248px) {
  222. .card-item {
  223. margin-right: 104px;
  224. }
  225. }
  226. }
  227. }
  228. </style>