You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
9.0 KiB

4 weeks ago
  1. <template>
  2. <div id="aCoursesList" class="bg-fa of">
  3. <section class="container">
  4. <section class="i-article">
  5. <div class="fl col-7">
  6. <section class="mr30">
  7. <header class="comm-title all-article-title">
  8. <h2 class="fl tac">
  9. <span class="c-333" style="font-weight: bold;">推荐</span>
  10. </h2>
  11. <section class="c-tab-title">
  12. <!-- <a href="javascript: void(0)">&nbsp;</a> -->
  13. </section>
  14. </header>
  15. <!-- / -->
  16. <!-- / -->
  17. <article class="i-article-list">
  18. <!-- / -->
  19. <ul>
  20. <li v-for="(recommendation,index) in recommendationList" :key="recommendation.id">
  21. <aside class="i-article-pic">
  22. <img :src="recommendation.imageUrl" :alt="1">
  23. </aside>
  24. <h3 class="hLh30 txtOf">
  25. <a :title="recommendation.title" href="/home/1" class="i-art-title">{{ recommendation.title }}</a>
  26. </h3>
  27. <section class="i-q-txt mt5 i-q-txt2"/>
  28. <section class="hLh30 txtOf mt5 a-list-extrainfo">
  29. <div class="fl">
  30. <img :src="recommendation.head" alt="" width="23px" height="23px" style="border-radius: 13px;">
  31. <span class="c-999 f-fM">{{ recommendation.author }}</span>&nbsp;
  32. <span class="c-999 f-fM">{{ formatDateTime(recommendation.publishTime) }}</span>&nbsp;
  33. <span class="el-icon-view">&nbsp;{{ recommendation.shares }}</span>&nbsp;&nbsp;
  34. <span class="el-icon-chat-dot-square">&nbsp;{{ recommendation.comments }}</span>&nbsp;&nbsp;
  35. <!-- <span> -->
  36. <!-- <a class="noter-dy vam" title="回答" href="http://127.0.0.1:81/front/articleinfo/23.html">
  37. <em class="icon18">&nbsp;</em>
  38. <span>{{ recommendation.comments }}</span>
  39. </a> -->
  40. <!-- <a href="#" class=""><span class="el-icon-chat-dot-square">{{ recommendation.comments }}</span></a> -->
  41. <!-- <tt title="赞一下" class=" vam ml10 f-fM" @click="addPraise(recommendation.id)">
  42. <img src="/assets/img/pic/YES.png" alt="" style="color: aqua;">
  43. <span>{{ recommendation.likes }}</span>
  44. </tt> -->
  45. <!-- </span> -->
  46. <!-- <span class="" @click="praise(index,recommendation.id)">
  47. <img v-if="recommendation.isLikd==0" src="/assets/img/pic/NO.png" alt=""></i>
  48. <img src="/assets/img/pic/YES.png" alt="">
  49. </span>
  50. <span>{{ recommendation.likes }}</span> -->
  51. <span>
  52. <i
  53. :id="'like-count'+recommendation.id"
  54. :style="{color: recommendation.isLiked==0 ? '#f56c6c' : '#c0c4cc'}"
  55. class="el-icon-thumb "
  56. @click="praise(recommendation.id,recommendation.isLiked,index)"
  57. >&nbsp;{{ recommendation.likes }}</i>
  58. <!-- <i v-if="recommendation.isLiked==0" class="el-icon-thumb">&nbsp;{{ recommendation.likes }}</i>&nbsp;&nbsp;
  59. <i class="el-icon-thumb" style="color: aqua;">&nbsp;{{ recommendation.likes }}</i> -->
  60. </span>
  61. </div>
  62. </section>
  63. </li>
  64. </ul>
  65. <!-- / -->
  66. </article>
  67. <!-- 公共分页 开始 -->
  68. <!-- <div>
  69. <div class="paging">
  70. <a class="undisable" title></a>
  71. <a id="backpage" class="undisable" href="#" title>&lt;</a>
  72. <a href="#" title class="current undisable">1</a>
  73. <a href="#" title>2</a>
  74. <a id="nextpage" href="#" title>&gt;</a>
  75. <a href="#" title></a>
  76. <div class="clear"/>
  77. </div>
  78. </div> -->
  79. <!-- 公共分页 结束 -->
  80. </section>
  81. </div>
  82. <!-- 精选视频 -->
  83. <aside class="fl col-3 articleRecommend">
  84. <div>
  85. <header class="comm-title all-article-title">
  86. <h2 class="fl tac">
  87. <span class="c-333 " style="font-weight: bold;">精选视频</span>
  88. </h2>
  89. <section class="c-tab-title">
  90. <!-- <a href="javascript: void(0)">&nbsp;</a> -->
  91. </section>
  92. </header>
  93. <article class="i-article-list">
  94. <!-- / -->
  95. <ul>
  96. <li v-for="featured in featuredList" :key="featured.id">
  97. <aside class="i-article-pic">
  98. <img :src="featured.imageUrl" :alt="1">
  99. </aside>
  100. <h3 class="hLh30 txtOf">
  101. <a :title="featured.title" href="/home/1" class="i-art-title">{{ featured.title }}</a>
  102. </h3>
  103. <section class="i-q-txt mt5 i-q-txt2"/>
  104. <section class="hLh30 txtOf mt5 pr10 a-list-extrainfo">
  105. <div class="fl">
  106. <span class="el-icon-view">&nbsp;{{ featured.views }}</span>&nbsp;&nbsp;
  107. <span class="c-999 f-fM">{{ formatDateTime(featured.publishTime) }}</span>&nbsp;
  108. </div>
  109. </section>
  110. </li>
  111. </ul>
  112. <!-- / -->
  113. </article>
  114. </div>
  115. </aside></section></section></div></template>
  116. <!-- <script>
  117. </script> -->
  118. <script>
  119. import indexApi from '~/api/home'
  120. import service from '../../utils/request'
  121. // import service from '../../utils/request'
  122. export default {
  123. async asyncData() {
  124. // 获取直播和专题数据
  125. const RecommendationResponse = await indexApi.RecommendationList()
  126. const recommendationList = RecommendationResponse.data
  127. const FeaturedResponse = await indexApi.FeaturedList()
  128. const featuredList = FeaturedResponse.data
  129. // var time = recommendationList.publishTime
  130. // var d = new Date(time)
  131. // var times = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()
  132. return {
  133. recommendationList,
  134. featuredList
  135. // currentMonth: new Date().getMonth() + 1
  136. }
  137. },
  138. methods: {
  139. praise(id, index) {
  140. service.post('recommendation/api/addLike/' + id)
  141. // .then(response => response.json())
  142. .then(Response => {
  143. // console.log(id)
  144. // console.log(status)
  145. // console.log(response)
  146. // window.location.reload()
  147. // console.log(this.RecommendationResponse)
  148. // console.log(id)
  149. // document.getElementById(`like-count`).textContent = data.data.likes
  150. // document.getElementById(`like-isLiked`).className = data.isLiked ? 'liked' : ''
  151. service.post('recommendation/api/selectRecommendation')
  152. .then(Response => {
  153. const data = Response.data
  154. // console.log(data)
  155. for (var i = 0; i < data.length; i++) {
  156. // console.log(data[i])
  157. if (data[i].id === id) {
  158. // console.log(data[i].id)
  159. // console.log(id)
  160. document.getElementById(`like-count` + id).textContent = data[i].likes
  161. if (data[i].isLiked === 0) {
  162. // console.log(data[i].isLiked)
  163. document.getElementById(`like-count` + id).style.color = '#f56c6c'
  164. } else {
  165. document.getElementById(`like-count` + id).style.color = '#c0c4cc'
  166. }
  167. }
  168. }
  169. // const isLikd = data.isLiked
  170. // document.getElementById(`like-count`).textContent = data.likes
  171. // const i = document.getElementById(`like-count`)
  172. // // '#f56c6c' : '#c0c4cc'
  173. // if (isLikd) {
  174. // i.style.color = '#f56c6c'
  175. // } else {
  176. // i.style.color = '#c0c4cc'
  177. // }
  178. // console.log(Response)
  179. })
  180. // console.log(data)
  181. })
  182. .catch(error => {
  183. console.log(error)
  184. console.log('error')
  185. })
  186. },
  187. formatDateTime(isoString) {
  188. const date = new Date(isoString)
  189. const month = (date.getMonth() + 1).toString().padStart(2, 0)
  190. const day = date.getDate().toString().padStart(2, 0)
  191. const hours = date.getHours().toString().padStart(2, 0)
  192. const minutes = date.getMinutes().toString().padStart(2, '0')
  193. return `${month}-${day} ${hours}:${minutes}`
  194. }
  195. }
  196. }
  197. </script>