ImagePage.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <el-row v-if="!permissionDenied" class="movie-list">
  3. <el-row class="movie-list">
  4. <el-col :md="24">
  5. <el-card :if="!user" :body-style="{ padding: '0px' }" class="card">
  6. <div slot="header" class="clearfix">
  7. <el-row>
  8. <el-col :md="1">
  9. <el-avatar>
  10. <el-image :src="user.avatarUrl" />
  11. </el-avatar>
  12. </el-col>
  13. <el-col :md="23">
  14. <router-link style="text-decoration-line: none" target="_blank" :to="`/user/${user.userId}/image`">
  15. <span>{{ user.screenName }}的相册</span>
  16. </router-link>
  17. <span v-html="'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'" />
  18. <el-button
  19. type="danger"
  20. size="mini"
  21. :icon="followButton.icon"
  22. @click="followUser(user.userId)"
  23. >
  24. <span>{{ followButton.text }}</span>
  25. </el-button>
  26. <el-button
  27. type="danger"
  28. size="mini"
  29. icon="el-icon-message"
  30. @click="sendMessage(user.userId)"
  31. >
  32. <span>发消息</span>
  33. </el-button>
  34. </el-col>
  35. </el-row>
  36. <el-row>
  37. <br>
  38. <span>{{ data.albumName }}</span>
  39. </el-row>
  40. </div>
  41. </el-card>
  42. </el-col>
  43. </el-row>
  44. <el-row>
  45. <el-col :md="24" class="movie-list">
  46. <div>
  47. <el-col v-for="(image, index) in dataList" :key="image.thumbnailUrl" :md="6" :sm="12" :xs="12" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  48. <el-card :body-style="{ padding: '0px' }" class="card">
  49. <div class="imgs">
  50. <el-image
  51. lazy
  52. fit="cover"
  53. class="coverImg"
  54. :src="image.thumbnailUrl"
  55. @click="showImages(index)"
  56. />
  57. </div>
  58. </el-card>
  59. </el-col>
  60. </div>
  61. </el-col>
  62. </el-row>
  63. <el-row class="movie-list">
  64. <el-pagination
  65. :small="screenWidth <= 768"
  66. hide-on-single-page
  67. layout="prev, pager, next"
  68. :page-size="pageSize"
  69. :current-page="currentPage"
  70. :total="totalSize"
  71. @current-change="handleCurrentChange"
  72. @prev-click="handleCurrentChange"
  73. @next-click="handleCurrentChange"
  74. />
  75. </el-row>
  76. </el-row>
  77. <div v-else>
  78. <permission-denied-card :text-object="textObject" />
  79. </div>
  80. </template>
  81. <script>
  82. import PermissionDeniedCard from '@/components/card/PermissionDeniedCard'
  83. import { followUser, getUserInfo, unfollowUser } from '@/api/user'
  84. import { getImageItems } from '@/api/image'
  85. export default {
  86. name: 'ImagePage',
  87. components: { PermissionDeniedCard },
  88. data() {
  89. return {
  90. // 屏幕宽度, 为了控制分页条的大小
  91. screenWidth: document.body.clientWidth,
  92. currentPage: 1,
  93. pageSize: 12,
  94. totalSize: 0,
  95. dataList: [],
  96. albumId: null,
  97. user: null,
  98. followButton: {
  99. icon: 'el-icon-plus',
  100. text: '关注'
  101. },
  102. permissionDenied: false,
  103. textObject: {
  104. content: '相册',
  105. route: '/image'
  106. }
  107. }
  108. },
  109. created() {
  110. this.albumId = this.$route.params.albumId
  111. this.getAlbumItemsWrapper()
  112. },
  113. mounted() {
  114. // 当窗口宽度改变时获取屏幕宽度
  115. window.onresize = () => {
  116. return () => {
  117. window.screenWidth = document.body.clientWidth
  118. this.screenWidth = window.screenWidth
  119. }
  120. }
  121. },
  122. methods: {
  123. handleCurrentChange(pageNumber) {
  124. this.currentPage = pageNumber
  125. this.dataList = []
  126. this.getAlbumItemsWrapper()
  127. // 回到顶部
  128. scrollTo(0, 0)
  129. },
  130. getAlbumItemsWrapper() {
  131. getImageItems(this.albumId, this.currentPage).then(resp => {
  132. if (resp.code === 0) {
  133. this.data = resp.data
  134. document.title = '相册 - ' + this.data.albumName
  135. const images = this.data.images
  136. this.dataList = images.list
  137. this.totalSize = images.totalSize
  138. this.userId = this.data.userId
  139. getUserInfo(this.userId).then(resp => {
  140. if (resp.code === 0) {
  141. this.user = resp.data
  142. } else {
  143. this.$notify.error({
  144. message: resp.msg,
  145. type: 'warning',
  146. duration: 3000
  147. })
  148. }
  149. })
  150. } else if (resp.code === 2) {
  151. this.$router.push('/404')
  152. } else {
  153. this.permissionDenied = true
  154. }
  155. }).catch(error => {
  156. this.$notify.error({
  157. message: error.message,
  158. type: 'error',
  159. duration: 3000
  160. })
  161. })
  162. },
  163. followUser(userId) {
  164. if (this.followButton.text === '关注') {
  165. followUser(userId).then(resp => {
  166. if (resp.code === 0) {
  167. this.followButton.text = '已关注'
  168. this.followButton.icon = 'el-icon-check'
  169. }
  170. })
  171. } else {
  172. unfollowUser(userId).then(resp => {
  173. if (resp.code === 0) {
  174. this.followButton.text = '关注'
  175. this.followButton.icon = 'el-icon-plus'
  176. }
  177. })
  178. }
  179. },
  180. sendMessage(userId) {
  181. console.log('发送消息')
  182. },
  183. showImages(index) {
  184. const imageUrls = []
  185. for (const i of this.dataList) {
  186. imageUrls.push(i.originalUrl)
  187. }
  188. this.$viewerApi({
  189. images: imageUrls,
  190. options: {
  191. initialViewIndex: index,
  192. movable: true,
  193. fullscreen: false,
  194. keyboard: true
  195. }
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style scoped>
  202. /*处于手机屏幕时*/
  203. @media screen and (max-width: 768px){
  204. .movie-list {
  205. padding-top: 8px;
  206. padding-left: 0.5%;
  207. padding-right: 0.5%;
  208. }
  209. .coverImg {
  210. height: 120px !important;
  211. }
  212. }
  213. .movie-list {
  214. padding-top: 15px;
  215. padding-left: 6%;
  216. padding-right: 6%;
  217. }
  218. .coverImg {
  219. width: 100%;
  220. height: 320px;
  221. display: block;
  222. }
  223. .card {
  224. margin-bottom: 20px;
  225. transition: all 0.6s; /*所有属性变化在0.6秒内执行动画*/
  226. }
  227. .imgs {
  228. position: relative;
  229. }
  230. </style>