| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <template>
- <div>
- <el-row class="movie-list">
- <el-col :md="24">
- <el-card :if="!user" :body-style="{ padding: '0px' }" class="card">
- <div slot="header" class="clearfix">
- <el-row>
- <el-col :md="1">
- <el-avatar>
- <el-image :src="user.avatarUrl"/>
- </el-avatar>
- </el-col>
- <el-col :md="23">
- <router-link target="_blank" :to="`/user/${user.userId}/image`">
- <span>{{ user.screenName }}的相册</span>
- </router-link>
- <span v-html="' '" />
- <el-button
- type="danger"
- size="mini"
- :icon="followButton.icon"
- @click="followUser(user.userId)"
- >
- <span>{{followButton.text}}</span>
- </el-button>
- <el-button
- type="danger"
- size="mini"
- icon="el-icon-message"
- @click="sendMessage(user.userId)"
- >
- <span>发消息</span>
- </el-button>
- </el-col>
- </el-row>
- <el-row>
- <br>
- <span>{{data.albumName}}</span>
- </el-row>
- </div>
- </el-card>
- </el-col>
- </el-row>
- <el-row>
- <el-col :md="24" class="movie-list">
- <div>
- <el-col v-for="(image, index) in data.imageUrls" :key="image.thumbnailUrl" :md="6" :sm="12" :xs="12">
- <el-card :body-style="{ padding: '0px' }" class="card">
- <div class="imgs">
- <el-image
- lazy
- fit="cover"
- class="coverImg"
- :src="image.thumbnailUrl"
- @click="showImages(index)">
- </el-image>
- </div>
- <div style="padding: 14px;">
- <span>
- <i v-if="collected" class="el-icon-star-on"/>
- <i v-else class="el-icon-star-off" @click="collectImage"/>
- </span>
- </div>
- </el-card>
- </el-col>
- </div>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import { getUserAlbums, getUserAlbum } from "@/api/image";
- import {followUser, getUserInfo, unfollowUser} from "@/api/user";
- export default {
- name: 'ImagePage',
- data() {
- return {
- // 屏幕宽度, 为了控制分页条的大小
- screenWidth: document.body.clientWidth,
- currentPage: 1,
- viewerOptions:{
- movable: true,
- fullscreen: false,
- keyboard: true
- },
- user: null,
- data: null,
- followButton: {
- icon: 'el-icon-plus',
- text: '关注'
- },
- collected: false
- }
- },
- created() {
- const albumId = this.$route.params.albumId
- getUserAlbum(albumId).then(res => {
- if (res.code === 0) {
- const resData = res.data
- this.data = resData
- document.title = '相册 - ' + resData.albumName
- this.userId = resData.userId
- getUserInfo(this.userId).then(res => {
- if (res.code === 0) {
- this.user = res.data
- }
- })
- }
- })
- },
- mounted() {
- // 当窗口宽度改变时获取屏幕宽度
- window.onresize = () => {
- return () => {
- window.screenWidth = document.body.clientWidth
- this.screenWidth = window.screenWidth
- }
- }
- },
- methods: {
- showImages(index) {
- const imageUrls = []
- for (const i of this.data.imageUrls) {
- imageUrls.push(i.originalUrl)
- }
- this.$viewerApi({
- images: imageUrls,
- options: {
- initialViewIndex: index,
- movable: true,
- fullscreen: false,
- keyboard: true
- }
- })
- },
- followUser(userId) {
- if (this.followButton.text === '关注') {
- followUser(userId).then(res => {
- if (res.code === 0) {
- this.followButton.text = '已关注'
- this.followButton.icon = 'el-icon-check'
- }
- })
- } else {
- unfollowUser(userId).then(res => {
- if (res.code === 0) {
- this.followButton.text = '关注'
- this.followButton.icon = 'el-icon-plus'
- }
- })
- }
- },
- sendMessage(userId) {
- console.log('发送消息')
- },
- collectImage() {
- console.log('收藏图片')
- this.collected = true
- }
- }
- }
- </script>
- <style scoped>
- .movie-list {
- padding-top: 15px;
- padding-left: 6%;
- padding-right: 6%;
- }
- /*处于手机屏幕时*/
- @media screen and (max-width: 768px){
- .movie-list {
- padding-top: 8px;
- padding-left: 0.5%;
- padding-right: 0.5%;
- }
- .coverImg {
- height: 120px !important;
- }
- }
- .coverImg {
- width: 100%;
- height: 320px;
- display: block;
- }
- .card {
- margin-bottom: 20px;
- transition: all 0.6s; /*所有属性变化在0.6秒内执行动画*/
- }
- .imgs {
- position: relative;
- }
- </style>
|