SelectedRecommend.vue 5.6 KB

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