DiskAlbumView.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div v-loading="loading" style="height: 80vh;">
  3. <el-scrollbar ref="myScrollbar" style="width: 100%; height: 100%;">
  4. <el-row v-if="dataList.length !== 0">
  5. <el-col
  6. v-for="(album, index) in dataList"
  7. :key="index"
  8. :md="6"
  9. :sm="12"
  10. :xs="12"
  11. style="padding: 5px"
  12. >
  13. <el-image
  14. lazy
  15. fit="cover"
  16. class="coverImg"
  17. :src="album.url"
  18. @click="showImages(index)"
  19. />
  20. </el-col>
  21. </el-row>
  22. <el-row v-if="!loading && dataList.length === 0" style="display: flex; justify-content: center;">
  23. <span style="color: #007bff">
  24. 这是一个空相册, 快去
  25. <router-link style="text-decoration-line: none; color: red" :to="`/disk/album/edit/${albumId}`">
  26. 添加
  27. </router-link>
  28. 点照片到相册中吧!
  29. </span>
  30. </el-row>
  31. <el-row>
  32. <div v-if="hasMore" style="display: flex; justify-content: center;">
  33. <el-button link size="mini" type="text" icon="el-icon-bottom" @click="loadMore">
  34. 加载更多
  35. </el-button>
  36. </div>
  37. </el-row>
  38. </el-scrollbar>
  39. </div>
  40. </template>
  41. <script>
  42. import { getAlbumDetail } from '@/api/disk'
  43. export default {
  44. name: 'DiskAlbumView',
  45. data() {
  46. return {
  47. albumId: null,
  48. currentPage: 1,
  49. dataList: [],
  50. loading: false,
  51. hasMore: false
  52. }
  53. },
  54. created() {
  55. document.title = '查看相册'
  56. const albumId = this.$route.params.albumId
  57. if (albumId === undefined) {
  58. return
  59. }
  60. this.albumId = albumId
  61. this.getData()
  62. },
  63. methods: {
  64. getData() {
  65. this.loading = true
  66. getAlbumDetail(this.albumId, this.currentPage).then(resp => {
  67. if (resp.code === 0) {
  68. const respData = resp.data
  69. document.title = '查看相册 ' + respData.albumName
  70. this.dataList = this.dataList.concat(respData.pageList.list)
  71. this.hasMore = respData.pageList.hasNext
  72. } else {
  73. this.$message.error(resp.msg)
  74. }
  75. }).catch(error => {
  76. this.$message.error(error.message)
  77. }).finally(() => {
  78. this.loading = false
  79. // 滚动条始终保持在底部
  80. this.$nextTick(() => {
  81. this.$refs['myScrollbar'].wrap.scrollTop = this.$refs['myScrollbar'].wrap.scrollHeight
  82. })
  83. })
  84. },
  85. loadMore() {
  86. this.currentPage += 1
  87. this.getData()
  88. },
  89. showImages(index) {
  90. const imageUrls = []
  91. for (const item of this.dataList) {
  92. imageUrls.push(item.url)
  93. }
  94. this.$viewerApi({
  95. images: imageUrls,
  96. options: {
  97. initialViewIndex: index,
  98. movable: true,
  99. fullscreen: false,
  100. keyboard: true
  101. }
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. /*处于手机屏幕时*/
  109. @media screen and (max-width: 768px){
  110. .coverImg {
  111. height: 120px !important;
  112. }
  113. }
  114. .coverImg {
  115. width: 100%;
  116. height: 320px;
  117. display: block;
  118. }
  119. </style>