ImagePage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div v-if="!permissionDenied">
  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 data.images" :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. </div>
  64. <div v-else>
  65. <permission-denied-card :text-object="textObject" />
  66. </div>
  67. </template>
  68. <script>
  69. import PermissionDeniedCard from '@/components/card/PermissionDeniedCard'
  70. import { followUser, getUserInfo, unfollowUser } from '@/api/user'
  71. import { getImageItems } from '@/api/image'
  72. export default {
  73. name: 'ImagePage',
  74. components: { PermissionDeniedCard },
  75. data() {
  76. return {
  77. // 屏幕宽度, 为了控制分页条的大小
  78. screenWidth: document.body.clientWidth,
  79. currentPage: 1,
  80. user: null,
  81. followButton: {
  82. icon: 'el-icon-plus',
  83. text: '关注'
  84. },
  85. data: null,
  86. dataList: [],
  87. permissionDenied: false,
  88. textObject: {
  89. content: '相册',
  90. route: '/image'
  91. }
  92. }
  93. },
  94. created() {
  95. const albumId = this.$route.params.albumId
  96. getImageItems(albumId).then(resp => {
  97. if (resp.code === 0) {
  98. const respData = resp.data
  99. document.title = '相册 - ' + respData.albumName
  100. this.data = respData
  101. this.userId = respData.userId
  102. getUserInfo(this.userId).then(resp => {
  103. if (resp.code === 0) {
  104. this.user = resp.data
  105. } else {
  106. this.$notify.error({
  107. message: resp.msg,
  108. type: 'warning',
  109. duration: 3000
  110. })
  111. }
  112. })
  113. } else if (resp.code === 2) {
  114. this.$router.push('/404')
  115. } else {
  116. this.permissionDenied = true
  117. }
  118. }).catch(error => {
  119. this.$notify.error({
  120. message: error.message,
  121. type: 'error',
  122. duration: 3000
  123. })
  124. })
  125. },
  126. mounted() {
  127. // 当窗口宽度改变时获取屏幕宽度
  128. window.onresize = () => {
  129. return () => {
  130. window.screenWidth = document.body.clientWidth
  131. this.screenWidth = window.screenWidth
  132. }
  133. }
  134. },
  135. methods: {
  136. followUser(userId) {
  137. if (this.followButton.text === '关注') {
  138. followUser(userId).then(resp => {
  139. if (resp.code === 0) {
  140. this.followButton.text = '已关注'
  141. this.followButton.icon = 'el-icon-check'
  142. }
  143. })
  144. } else {
  145. unfollowUser(userId).then(resp => {
  146. if (resp.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. showImages(index) {
  157. const imageUrls = []
  158. for (const i of this.data.images) {
  159. imageUrls.push(i.originalUrl)
  160. }
  161. this.$viewerApi({
  162. images: imageUrls,
  163. options: {
  164. initialViewIndex: index,
  165. movable: true,
  166. fullscreen: false,
  167. keyboard: true
  168. }
  169. })
  170. }
  171. }
  172. }
  173. </script>
  174. <style scoped>
  175. /*处于手机屏幕时*/
  176. @media screen and (max-width: 768px){
  177. .movie-list {
  178. padding-top: 8px;
  179. padding-left: 0.5%;
  180. padding-right: 0.5%;
  181. }
  182. .coverImg {
  183. height: 120px !important;
  184. }
  185. }
  186. .movie-list {
  187. padding-top: 15px;
  188. padding-left: 6%;
  189. padding-right: 6%;
  190. }
  191. .coverImg {
  192. width: 100%;
  193. height: 320px;
  194. display: block;
  195. }
  196. .card {
  197. margin-bottom: 20px;
  198. transition: all 0.6s; /*所有属性变化在0.6秒内执行动画*/
  199. }
  200. .imgs {
  201. position: relative;
  202. }
  203. </style>