ImagePage.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div>
  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 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 data.imageUrls" :key="image.thumbnailUrl" :md="6" :sm="12" :xs="12">
  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. </el-image>
  57. </div>
  58. <div style="padding: 14px;">
  59. <span>
  60. <i v-if="collected" class="el-icon-star-on"/>
  61. <i v-else class="el-icon-star-off" @click="collectImage"/>
  62. </span>
  63. </div>
  64. </el-card>
  65. </el-col>
  66. </div>
  67. </el-col>
  68. </el-row>
  69. </div>
  70. </template>
  71. <script>
  72. import { getUserAlbums, getUserAlbum } from "@/api/image";
  73. import {followUser, getUserInfo, unfollowUser} from "@/api/user";
  74. export default {
  75. name: 'ImagePage',
  76. data() {
  77. return {
  78. // 屏幕宽度, 为了控制分页条的大小
  79. screenWidth: document.body.clientWidth,
  80. currentPage: 1,
  81. viewerOptions:{
  82. movable: true,
  83. fullscreen: false,
  84. keyboard: true
  85. },
  86. user: null,
  87. data: null,
  88. followButton: {
  89. icon: 'el-icon-plus',
  90. text: '关注'
  91. },
  92. collected: false
  93. }
  94. },
  95. created() {
  96. const albumId = this.$route.params.albumId
  97. getUserAlbum(albumId).then(res => {
  98. if (res.code === 0) {
  99. const resData = res.data
  100. this.data = resData
  101. document.title = '相册 - ' + resData.albumName
  102. this.userId = resData.userId
  103. getUserInfo(this.userId).then(res => {
  104. if (res.code === 0) {
  105. this.user = res.data
  106. }
  107. })
  108. }
  109. })
  110. },
  111. mounted() {
  112. // 当窗口宽度改变时获取屏幕宽度
  113. window.onresize = () => {
  114. return () => {
  115. window.screenWidth = document.body.clientWidth
  116. this.screenWidth = window.screenWidth
  117. }
  118. }
  119. },
  120. methods: {
  121. showImages(index) {
  122. const imageUrls = []
  123. for (const i of this.data.imageUrls) {
  124. imageUrls.push(i.originalUrl)
  125. }
  126. this.$viewerApi({
  127. images: imageUrls,
  128. options: {
  129. initialViewIndex: index,
  130. movable: true,
  131. fullscreen: false,
  132. keyboard: true
  133. }
  134. })
  135. },
  136. followUser(userId) {
  137. if (this.followButton.text === '关注') {
  138. followUser(userId).then(res => {
  139. if (res.code === 0) {
  140. this.followButton.text = '已关注'
  141. this.followButton.icon = 'el-icon-check'
  142. }
  143. })
  144. } else {
  145. unfollowUser(userId).then(res => {
  146. if (res.code === 0) {
  147. this.followButton.text = '关注'
  148. this.followButton.icon = 'el-icon-plus'
  149. }
  150. })
  151. }
  152. },
  153. sendMessage(userId) {
  154. console.log('发送消息')
  155. },
  156. collectImage() {
  157. console.log('收藏图片')
  158. this.collected = true
  159. }
  160. }
  161. }
  162. </script>
  163. <style scoped>
  164. .movie-list {
  165. padding-top: 15px;
  166. padding-left: 6%;
  167. padding-right: 6%;
  168. }
  169. /*处于手机屏幕时*/
  170. @media screen and (max-width: 768px){
  171. .movie-list {
  172. padding-top: 8px;
  173. padding-left: 0.5%;
  174. padding-right: 0.5%;
  175. }
  176. .coverImg {
  177. height: 120px !important;
  178. }
  179. }
  180. .coverImg {
  181. width: 100%;
  182. height: 320px;
  183. display: block;
  184. }
  185. .card {
  186. margin-bottom: 20px;
  187. transition: all 0.6s; /*所有属性变化在0.6秒内执行动画*/
  188. }
  189. .imgs {
  190. position: relative;
  191. }
  192. </style>