关注用户功能

This commit is contained in:
x ronger 2020-09-09 22:58:18 +08:00
parent ef70d21444
commit d45a583afa

View File

@ -9,11 +9,17 @@
<div class="card-body text-center"> <div class="card-body text-center">
<img v-if="user.avatarUrl" class="card-profile-img" :src="user.avatarUrl"> <img v-if="user.avatarUrl" class="card-profile-img" :src="user.avatarUrl">
<img v-else class="card-profile-img" src="https://static.rymcu.com/article/1578475481946.png"> <img v-else class="card-profile-img" src="https://static.rymcu.com/article/1578475481946.png">
<h3 class="mb-3">{{user.nickname}}</h3> <h3 class="mb-3">{{ user.nickname }}</h3>
<p class="mb-4" v-html="user.signature"></p> <p class="mb-4" v-html="user.signature"></p>
<div v-if="oauth && oauth.idUser !== user.idUser"> <div v-if="oauth && oauth.idUser !== user.idUser">
<el-button type="primary" v-if="isFollow" @click="cancelFollowUser(user.idUser)">取消关注</el-button>
<el-button type="primary" v-else @click="followUser(user.idUser)">关注</el-button>
<el-button @click="gotoChats">聊天</el-button> <el-button @click="gotoChats">聊天</el-button>
</div> </div>
<div v-else>
<el-button type="primary" @click="login">关注</el-button>
<el-button @click="login">聊天</el-button>
</div>
</div> </div>
</div> </div>
</el-col> </el-col>
@ -38,172 +44,217 @@
</template> </template>
<script> <script>
import {mapState} from 'vuex'; import {mapState} from 'vuex';
import ArticleList from "~/components/archive/list"; import ArticleList from "~/components/archive/list";
import PortfolioList from "~/components/common/portfolio/list"; import PortfolioList from "~/components/common/portfolio/list";
export default { export default {
name: "User", name: "User",
components: {ArticleList, PortfolioList}, components: {ArticleList, PortfolioList},
validate({params, store}) { validate({params, store}) {
return params.nickname return params.nickname
},
fetch({store, params, error}) {
return Promise.all([
store
.dispatch('user/fetchDetail', params)
.catch(err => error({statusCode: 404})),
store.dispatch('user/fetchArticleList', params),
store.dispatch('user/fetchPortfolioList', params)
])
},
computed: {
...mapState({
user: state => state.user.data,
articles: state => state.user.articles,
portfolios: state => state.user.portfolios,
oauth: state => state.oauth
})
},
data() {
return {
activeTab: '0',
isFollow: false
}
},
methods: {
currentChangeArticle(page) {
this.$store.dispatch('user/fetchArticleList', {page: page, nickname: this.$route.params.nickname})
}, },
fetch({store, params, error}) { currentChangePortfolio(page) {
return Promise.all([ this.$store.dispatch('user/fetchPortfolioList', {page: page, nickname: this.$route.params.nickname})
store
.dispatch('user/fetchDetail', params)
.catch(err => error({statusCode: 404})),
store.dispatch('user/fetchArticleList', params),
store.dispatch('user/fetchPortfolioList', params)
])
}, },
computed: { handleToggleTab(key) {
...mapState({ this.$set(this, 'activeTab', key);
user: state => state.user.data, },
articles: state => state.user.articles, gotoChats() {
portfolios: state => state.user.portfolios, let _ts = this;
oauth: state => state.oauth _ts.$router.push({
path: `/chats/${_ts.user.nickname}`
}) })
}, },
data() { followUser(idUser) {
return { let _ts = this;
activeTab: '0' if (_ts.oauth) {
_ts.$axios.$post('/api/follow', {
followingId: idUser,
followingType: 0
}).then(function (res) {
_ts.$set(_ts, 'isFollow', res);
})
} else {
_ts.login()
} }
}, },
methods: { cancelFollowUser(idUser) {
currentChangeArticle(page) { let _ts = this;
this.$store.dispatch('user/fetchArticleList', {page: page, nickname: this.$route.params.nickname}) if (_ts.oauth) {
}, _ts.$axios.$post('/api/follow/cancel-follow', {
currentChangePortfolio(page) { followingId: idUser,
this.$store.dispatch('user/fetchPortfolioList', {page: page, nickname: this.$route.params.nickname}) followingType: 0
}, }).then(function (res) {
handleToggleTab(key) { _ts.$set(_ts, 'isFollow', res);
this.$set(this, 'activeTab', key);
},
gotoChats() {
let _ts = this;
_ts.$router.push({
path: `/chats/${_ts.user.nickname}`
}) })
} else {
_ts.login()
} }
},
login() {
this.$router.push({
path: '/login'
})
}
},
mounted() {
let _ts = this;
if (_ts.oauth) {
_ts.$axios.$get('/api/follow/is-follow', {
params: {
followingId: _ts.user.idUser,
followingType: 0
}
}).then(function (res) {
_ts.$set(_ts, 'isFollow', res);
})
} }
} }
}
</script> </script>
<style scoped> <style scoped>
body { body {
overflow-x: hidden; overflow-x: hidden;
} }
.card { .card {
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
position: relative; position: relative;
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
width: 100%; width: 100%;
} }
.card { .card {
position: relative; position: relative;
display: -ms-flexbox; display: -ms-flexbox;
display: flex; display: flex;
-ms-flex-direction: column; -ms-flex-direction: column;
flex-direction: column; flex-direction: column;
min-width: 0; min-width: 0;
word-wrap: break-word; word-wrap: break-word;
background-color: #fff; background-color: #fff;
background-clip: border-box; background-clip: border-box;
border: 1px solid rgba(0, 40, 100, 0.12); border: 1px solid rgba(0, 40, 100, 0.12);
border-radius: 3px; border-radius: 3px;
} }
.card-profile .card-header { .card-profile .card-header {
height: 20rem; height: 20rem;
background-size: cover; background-size: cover;
} }
.card-header:first-child { .card-header:first-child {
border-radius: calc(3px - 1px) calc(3px - 1px) 0 0; border-radius: calc(3px - 1px) calc(3px - 1px) 0 0;
} }
.card-header { .card-header {
background: none; background: none;
padding: 0.5rem 1.5rem; padding: 0.5rem 1.5rem;
display: -ms-flexbox; display: -ms-flexbox;
display: flex; display: flex;
min-height: 3.5rem; min-height: 3.5rem;
-ms-flex-align: center; -ms-flex-align: center;
align-items: center; align-items: center;
} }
.card-header { .card-header {
padding: 1.5rem 1.5rem; padding: 1.5rem 1.5rem;
margin-bottom: 0; margin-bottom: 0;
background-color: rgba(0, 0, 0, 0.03); background-color: rgba(0, 0, 0, 0.03);
border-bottom: 1px solid rgba(0, 40, 100, 0.12); border-bottom: 1px solid rgba(0, 40, 100, 0.12);
} }
.card-body { .card-body {
-ms-flex: 1; -ms-flex: 1;
flex: 1; flex: 1;
margin: 0; margin: 0;
padding: 1.5rem 1.5rem; padding: 1.5rem 1.5rem;
position: relative; position: relative;
} }
.card-profile-img { .card-profile-img {
max-width: 6rem; max-width: 6rem;
margin-top: -5rem; margin-top: -5rem;
margin-bottom: 1rem; margin-bottom: 1rem;
border: 3px solid #fff; border: 3px solid #fff;
border-radius: 100%; border-radius: 100%;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
background-color: #ffffff; background-color: #ffffff;
} }
.card-img-top { .card-img-top {
border-top-left-radius: 3px; border-top-left-radius: 3px;
border-top-right-radius: 3px; border-top-right-radius: 3px;
} }
.card-img-top { .card-img-top {
width: 100%; width: 100%;
border-top-left-radius: calc(3px - 1px); border-top-left-radius: calc(3px - 1px);
border-top-right-radius: calc(3px - 1px); border-top-right-radius: calc(3px - 1px);
} }
.mb-3, .my-3 { .mb-3, .my-3 {
margin-bottom: 0.75rem !important; margin-bottom: 0.75rem !important;
} }
h3, .h3 { h3, .h3 {
font-size: 1.5rem; font-size: 1.5rem;
} }
.mb-4, .my-4 { .mb-4, .my-4 {
margin-bottom: 1rem !important; margin-bottom: 1rem !important;
} }
.article-header-md { .article-header-md {
position: relative; position: relative;
line-height: 1.4em; line-height: 1.4em;
height: 1.4em; height: 1.4em;
overflow: hidden; overflow: hidden;
} }
.article-header-md a { .article-header-md a {
font-weight: bold; font-weight: bold;
font-size: 1em; font-size: 1em;
} }
.article-summary-md { .article-summary-md {
position: relative; position: relative;
line-height: 1.4em; line-height: 1.4em;
height: 4.2em; height: 4.2em;
overflow: hidden; overflow: hidden;
} }
.el-col-6 { .el-col-6 {
padding-right: 0.75rem; padding-right: 0.75rem;
padding-left: 0.75rem; padding-left: 0.75rem;
} }
</style> </style>