Image.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div>
  3. <!--电影列表,与推荐列表-->
  4. <el-row id="movie-list">
  5. <!--电影列表-->
  6. <el-col :md="24">
  7. <div>
  8. <el-col v-for="(image, index) in dataList"
  9. :key="image.thumbnailUrl"
  10. :md="6" :sm="12" :xs="12"
  11. style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  12. <el-card :body-style="{ padding: '0px' }" class="card">
  13. <div class="imgs">
  14. <el-image
  15. lazy
  16. fit="cover"
  17. class="coverImg"
  18. :src="image.thumbnailUrl"
  19. @click="showImages(index)">
  20. </el-image>
  21. </div>
  22. <div style="padding: 14px;">
  23. <span style="position: relative; bottom: 0; left: 0%; color:green">
  24. <i v-if="image.collected" class='el-icon-star-on' @click="collectItem(image)"/>
  25. <i v-else class='el-icon-star-off' @click="collectItem(image)"/>
  26. </span>
  27. <span style="position: relative; bottom: 0; left: 0; color:blue">
  28. 来自相册:
  29. </span>
  30. <router-link target="_blank" :to="`/image/album/${image.albumId}`">
  31. <span style="position: relative; bottom: 0; left: 0; color:blue">
  32. {{ image.albumName | ellipsis }}
  33. </span>
  34. </router-link>
  35. </div>
  36. </el-card>
  37. </el-col>
  38. </div>
  39. <!--
  40. 分页按钮:
  41. page-size:每页显示条数
  42. total:总条数
  43. hide-on-single-page: 页数为一时隐藏
  44. -->
  45. <el-col :span="24" class="pagination">
  46. <el-pagination
  47. background
  48. :small="screenWidth <= 768"
  49. layout="prev, pager, next"
  50. :page-size="pageSize"
  51. :current-page="currentPage"
  52. :total="totalSize"
  53. @current-change="handleCurrentChange"
  54. />
  55. </el-col>
  56. </el-col>
  57. </el-row>
  58. <el-row v-if="dataList.length === 0" class="not-result">
  59. <el-col :span="12" :offset="6">
  60. <img src="@/assets/img/icon/not-result.png">
  61. <div>没有图片数据</div>
  62. </el-col>
  63. </el-row>
  64. </div>
  65. </template>
  66. <script>
  67. import {getImages} from '@/api/image'
  68. import {collectItem} from "@/api/collect";
  69. export default {
  70. name: 'Image',
  71. components: {},
  72. filters: {
  73. ellipsis(value) {
  74. if (!value) return ''
  75. const max = 10
  76. if (value.length > max) {
  77. return value.slice(0, max) + '...'
  78. }
  79. return value
  80. }
  81. },
  82. data() {
  83. return {
  84. // 屏幕宽度, 为了控制分页条的大小
  85. screenWidth: document.body.clientWidth,
  86. currentPage: 1,
  87. pageSize: 12,
  88. totalPages: 0,
  89. totalSize: 0,
  90. showEmpty: true,
  91. dataList: [],
  92. }
  93. },
  94. created() {
  95. document.title = '图片主页'
  96. this.getImagesWrapper(this.currentPage)
  97. },
  98. mounted() {
  99. // 当窗口宽度改变时获取屏幕宽度
  100. window.onresize = () => {
  101. return () => {
  102. window.screenWidth = document.body.clientWidth
  103. this.screenWidth = window.screenWidth
  104. }
  105. }
  106. },
  107. methods: {
  108. handleCurrentChange(currentPage) {
  109. this.currentPage = currentPage
  110. this.getImagesWrapper(this.currentPage)
  111. // 回到顶部
  112. scrollTo(0, 0)
  113. },
  114. getImagesWrapper(page) {
  115. getImages(page).then(resp => {
  116. if (resp.code === 0) {
  117. this.dataList = resp.data.list
  118. this.totalPages = resp.totalPages
  119. this.totalSize = resp.totalSize
  120. } else {
  121. this.$notify({
  122. title: '获取数据失败',
  123. message: res.msg,
  124. type: 'warning',
  125. duration: 3000
  126. })
  127. }
  128. }).catch(error => {
  129. this.$notify({
  130. title: '获取数据错误',
  131. message: error.message,
  132. type: 'error',
  133. duration: 3000
  134. })
  135. })
  136. },
  137. showImages(index) {
  138. const imageUrls = []
  139. for (const i of this.dataList) {
  140. imageUrls.push(i.originalUrl)
  141. }
  142. this.$viewerApi({
  143. images: imageUrls,
  144. options: {
  145. initialViewIndex: index,
  146. movable: true,
  147. fullscreen: false,
  148. keyboard: true
  149. }
  150. })
  151. },
  152. collectItem(image) {
  153. const jsonData = {}
  154. jsonData.contentType = 1001
  155. jsonData.contentId = image.imageFileId
  156. if (image.collected) {
  157. jsonData.collected = false
  158. collectItem(jsonData).then(res => {
  159. if (res.code === 0) {
  160. this.$notify({
  161. title: '取消收藏图片',
  162. type: 'info',
  163. duration: 3000
  164. })
  165. image.collected = false
  166. }
  167. })
  168. } else {
  169. jsonData.collected = true
  170. collectItem(jsonData).then(res => {
  171. if (res.code === 0) {
  172. this.$notify({
  173. title: '图片已收藏',
  174. type: 'info',
  175. duration: 3000
  176. })
  177. image.collected = true
  178. }
  179. })
  180. }
  181. }
  182. }
  183. }
  184. </script>
  185. <style scoped>
  186. /*处于手机屏幕时*/
  187. @media screen and (max-width: 768px){
  188. #movie-list {
  189. padding-top: 8px;
  190. padding-left: 0.5%;
  191. padding-right: 0.5%;
  192. }
  193. .coverImg {
  194. height: 120px !important;
  195. }
  196. }
  197. #movie-list {
  198. padding-top: 15px;
  199. padding-left: 6%;
  200. padding-right: 6%;
  201. }
  202. .coverImg {
  203. width: 100%;
  204. height: 320px;
  205. display: block;
  206. }
  207. .not-result {
  208. padding-top: 100px;
  209. padding-bottom: 100px;
  210. text-align: center;
  211. }
  212. .pagination {
  213. text-align: center;
  214. padding: 10px;
  215. }
  216. </style>