ImagePage.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. metaInfo: {
  88. meta: [
  89. { name: 'referrer', content: 'no-referrer' }
  90. ]
  91. },
  92. components: { PermissionDeniedCard },
  93. data() {
  94. return {
  95. // 屏幕宽度, 为了控制分页条的大小
  96. screenWidth: document.body.clientWidth,
  97. currentPage: 1,
  98. pageSize: 12,
  99. totalSize: 0,
  100. dataList: [],
  101. albumId: null,
  102. user: null,
  103. followButton: {
  104. icon: 'el-icon-plus',
  105. text: '关注'
  106. },
  107. permissionDenied: false,
  108. textObject: {
  109. content: '相册',
  110. route: '/image'
  111. }
  112. }
  113. },
  114. created() {
  115. this.albumId = this.$route.params.albumId
  116. this.getAlbumItemsWrapper()
  117. },
  118. mounted() {
  119. // 当窗口宽度改变时获取屏幕宽度
  120. window.onresize = () => {
  121. return () => {
  122. window.screenWidth = document.body.clientWidth
  123. this.screenWidth = window.screenWidth
  124. }
  125. }
  126. },
  127. methods: {
  128. handleCurrentChange(pageNumber) {
  129. this.currentPage = pageNumber
  130. this.dataList = []
  131. this.getAlbumItemsWrapper()
  132. // 回到顶部
  133. scrollTo(0, 0)
  134. },
  135. getAlbumItemsWrapper() {
  136. getImageItems(this.albumId, this.currentPage).then(resp => {
  137. if (resp.code === 0) {
  138. this.data = resp.data
  139. document.title = '相册 - ' + this.data.albumName
  140. const images = this.data.images
  141. this.dataList = images.list
  142. this.totalSize = images.totalSize
  143. this.userId = this.data.userId
  144. getUserInfo(this.userId).then(resp => {
  145. if (resp.code === 0) {
  146. this.user = resp.data
  147. } else {
  148. this.$notify.error({
  149. message: resp.msg,
  150. type: 'warning',
  151. duration: 3000
  152. })
  153. }
  154. })
  155. } else if (resp.code === 2) {
  156. this.$router.push('/404')
  157. } else {
  158. this.permissionDenied = true
  159. }
  160. }).catch(error => {
  161. this.$notify.error({
  162. message: error.message,
  163. type: 'error',
  164. duration: 3000
  165. })
  166. })
  167. },
  168. followUser(userId) {
  169. if (this.followButton.text === '关注') {
  170. followUser(userId).then(resp => {
  171. if (resp.code === 0) {
  172. this.followButton.text = '已关注'
  173. this.followButton.icon = 'el-icon-check'
  174. }
  175. })
  176. } else {
  177. unfollowUser(userId).then(resp => {
  178. if (resp.code === 0) {
  179. this.followButton.text = '关注'
  180. this.followButton.icon = 'el-icon-plus'
  181. }
  182. })
  183. }
  184. },
  185. sendMessage(userId) {
  186. console.log('发送消息')
  187. },
  188. showImages(index) {
  189. const imageUrls = []
  190. for (const i of this.dataList) {
  191. imageUrls.push(i.originalUrl)
  192. }
  193. this.$viewerApi({
  194. images: imageUrls,
  195. options: {
  196. initialViewIndex: index,
  197. movable: true,
  198. fullscreen: false,
  199. keyboard: true
  200. }
  201. })
  202. }
  203. }
  204. }
  205. </script>
  206. <style scoped>
  207. /*处于手机屏幕时*/
  208. @media screen and (max-width: 768px){
  209. .movie-list {
  210. padding-top: 8px;
  211. padding-left: 0.5%;
  212. padding-right: 0.5%;
  213. }
  214. .coverImg {
  215. height: 120px !important;
  216. }
  217. }
  218. .movie-list {
  219. padding-top: 15px;
  220. padding-left: 6%;
  221. padding-right: 6%;
  222. }
  223. .coverImg {
  224. width: 100%;
  225. height: 320px;
  226. display: block;
  227. }
  228. .card {
  229. margin-bottom: 20px;
  230. transition: all 0.6s; /*所有属性变化在0.6秒内执行动画*/
  231. }
  232. .imgs {
  233. position: relative;
  234. }
  235. </style>