Skip to content

Commit 534e03b

Browse files
committed
Merge branch 'master' of gitee.com:ChanWahFung/nuxt-juejin-project
2 parents 4012606 + 0c27e70 commit 534e03b

File tree

15 files changed

+53
-52
lines changed

15 files changed

+53
-52
lines changed

components/business/book/bookCategory.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export default {
2727
},
2828
methods: {
2929
...mapMutations([
30-
'updateTopbarBlock'
30+
'UPDATE_TOPBAR_BLOCK'
3131
]),
3232
navItemClick(item) {
3333
if (this.paramsAlias != item.alias) {
34-
this.isTopbarBlock === false && this.updateTopbarBlock(true)
34+
this.isTopbarBlock === false && this.UPDATE_TOPBAR_BLOCK(true)
3535
window.scrollTo({ top: 0 })
3636
if (item.alias) {
3737
this.$router.push({

components/business/recommendation/recommendCategory.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export default {
2727
},
2828
methods: {
2929
...mapMutations([
30-
'updateTopbarBlock'
30+
'UPDATE_TOPBAR_BLOCK'
3131
]),
3232
navItemClick(item) {
3333
if (this.paramsName != item.name) {
34-
this.isTopbarBlock === false && this.updateTopbarBlock(true)
34+
this.isTopbarBlock === false && this.UPDATE_TOPBAR_BLOCK(true)
3535
window.scrollTo({ top: 0 })
3636
this.$router.push({
3737
name: 'recommendation-authors-name',

components/business/timeline/timelineCategory.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
},
3232
methods: {
3333
...mapMutations([
34-
'updateTopbarBlock'
34+
'UPDATE_TOPBAR_BLOCK'
3535
]),
3636
async getTagByCategories(categoryId) {
3737
await this.$api.getTagByCategories({
@@ -41,7 +41,7 @@ export default {
4141
},
4242
navItemClick(item) {
4343
if (this.paramsTitle != item.title) {
44-
this.isTopbarBlock === false && this.updateTopbarBlock(true)
44+
this.isTopbarBlock === false && this.UPDATE_TOPBAR_BLOCK(true)
4545
window.scrollTo({ top: 0 })
4646
this.$router.push({
4747
name: 'timeline-title',

components/common/backTop.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { mapMutations } from 'vuex'
1010
export default {
1111
methods: {
1212
...mapMutations([
13-
'updateTopbarBlock'
13+
'UPDATE_TOPBAR_BLOCK'
1414
]),
1515
backTop() {
1616
window.scrollTo({
1717
top: 0
1818
})
1919
// 解决置顶后导航栏不显示
20-
this.updateTopbarBlock(true)
20+
this.UPDATE_TOPBAR_BLOCK(true)
2121
}
2222
}
2323
}

components/common/topBar.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ export default {
8080
let scrollTop = 0
8181
window.addEventListener('scroll', () => {
8282
if (scrollingElement.scrollTop < 300) {
83-
this.isTopbarBlock === false && this.updateTopbarBlock(true)
83+
this.isTopbarBlock === false && this.UPDATE_TOPBAR_BLOCK(true)
8484
return
8585
}
8686
if (scrollingElement.scrollTop > scrollTop) {
87-
this.updateTopbarBlock(false)
87+
this.UPDATE_TOPBAR_BLOCK(false)
8888
} else if (scrollingElement.scrollTop < scrollTop) {
89-
this.updateTopbarBlock(true)
89+
this.UPDATE_TOPBAR_BLOCK(true)
9090
}
9191
scrollTop = scrollingElement.scrollTop
9292
})
@@ -112,15 +112,15 @@ export default {
112112
this.$api.setUserNotificationNum()
113113
this.getUserNotificationNum()
114114
}
115-
this.updateTopbarBlock(true)
115+
this.UPDATE_TOPBAR_BLOCK(true)
116116
}
117117
},
118118
immediate: true
119119
}
120120
},
121121
methods: {
122122
...mapMutations([
123-
'updateTopbarBlock'
123+
'UPDATE_TOPBAR_BLOCK'
124124
]),
125125
sreachHandler () {
126126
this.$router.push({

middleware/auth.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ export default function (context) {
33
const cookiesToken = app.$cookies.get('token')
44
if (cookiesToken) {
55
// 每次跳转路由 验证登录状态是否过期
6-
app.$api.isAuth().then(res => {
6+
return app.$api.isAuth().then(res => {
77
if (res.s === 1) {
88
if (res.d.isExpired) { // 过期 移除登陆验证信息
99
app.$utils.removeAuthInfo(context)
1010
} else { // 未过期 重新设置存储
1111
const stateToken = store.state.auth.token
1212
if (cookiesToken && stateToken === '') {
13-
store.commit('auth/updateUserInfo', app.$cookies.get('userInfo'))
14-
store.commit('auth/updateUserId', app.$cookies.get('userId'))
15-
store.commit('auth/updateClientId', app.$cookies.get('clientId'))
16-
store.commit('auth/updateToken', app.$cookies.get('token'))
13+
store.commit('auth/UPDATE_USERINFO', app.$cookies.get('userInfo'))
14+
store.commit('auth/UPDATE_USERID', app.$cookies.get('userId'))
15+
store.commit('auth/UPDATE_CLIENTID', app.$cookies.get('clientId'))
16+
store.commit('auth/UPDATE_TOKEN', app.$cookies.get('token'))
1717
}
1818
}
1919
}
2020
})
2121
}
22+
return Promise.resolve()
2223
}

pages/book/_alias.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default {
3838
} else {
3939
bookCategoryList = await app.$api.getBookChannel()
4040
.then(res => res.s === 1 ? initBookCategoryList.concat(res.d) : initBookCategoryList)
41-
store.commit('category/updateBookCategoryList', bookCategoryList)
41+
store.commit('category/UPDATE_BOOK_CATEGORY_LIST', bookCategoryList)
4242
}
4343
return params.alias === undefined || bookCategoryList.includes(params.alias)
4444
},

pages/recommendation/authors/_name.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default {
2121
categoryList = store.state.category.recommendCategoryList
2222
} else {
2323
categoryList = await app.$api.getAuthorChannel().then(res => res.s === 1 ? res.d : [])
24-
store.commit('category/updateRecommendCategoryList', categoryList)
24+
store.commit('category/UPDATE_RECOMMEND_CATEGORY_LIST', categoryList)
2525
}
2626
// 作者榜单
2727
let res = await app.$api.getAuthorRank({

pages/search/index.vue

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@
1616
import reachBottom from '~/mixins/reachBottom'
1717
1818
export default {
19-
head () {
20-
return {
21-
title: `${this.$route.query.keyword} - 搜索 - 掘金`
22-
}
23-
},
24-
watchQuery: ['keyword', 'type', 'period'],
25-
validate ({ query }) {
26-
let types = [undefined, 'all', 'article', 'tag', 'user']
27-
let periods = [undefined, 'all', 'd1', 'w1', 'm3']
28-
if (types.includes(query.type) && periods.includes(query.period)) {
29-
return true
30-
}
31-
return false
32-
},
3319
async asyncData({ app, query }) {
3420
let res = await app.$api.searchList({
3521
after: 0,
@@ -43,6 +29,20 @@ export default {
4329
searchList: res.edges || []
4430
}
4531
},
32+
head () {
33+
return {
34+
title: `${this.$route.query.keyword} - 搜索 - 掘金`
35+
}
36+
},
37+
validate ({ query }) {
38+
let types = [undefined, 'all', 'article', 'tag', 'user']
39+
let periods = [undefined, 'all', 'd1', 'w1', 'm3']
40+
if (types.includes(query.type) && periods.includes(query.period)) {
41+
return true
42+
}
43+
return false
44+
},
45+
watchQuery: ['keyword', 'type', 'period'],
4646
mixins: [reachBottom],
4747
data() {
4848
return {

pages/timeline/_title.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171
categoryList = store.state.category.timelineCategoryList
7272
} else {
7373
categoryList = await app.$api.getCategories().then(res => res.s === 1 ? initCategoryList.concat(res.d.categoryList) : initCategoryList)
74-
store.commit('category/updateTimelineCategoryList', categoryList)
74+
store.commit('category/UPDATE_TIMELINE_CATEGORY_LIST', categoryList)
7575
}
7676
return params.title === undefined || categoryList.filter(item => item.title === params.title).length
7777
},

pages/user/_id.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<span>{{ userInfo.selfDescription }}</span>
2323
</div>
2424
</div>
25-
<div class="user-block__action">
25+
<div class="user-block__action" v-if="$store.state.auth.userId != userInfo.uid">
2626
<follow-btn :is-follow.sync="isFollowed" type="user" :followee-id="userInfo.uid"></follow-btn>
2727
</div>
2828
</div>

store/auth.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export const state = () => ({
77
})
88

99
export const mutations = {
10-
updateUserInfo(state, payload){
10+
UPDATE_USERINFO(state, payload){
1111
state.userInfo = payload
1212
},
13-
updateUserId(state, payload){
13+
UPDATE_USERID(state, payload){
1414
state.userId = payload
1515
},
16-
updateClientId(state, payload){
16+
UPDATE_CLIENTID(state, payload){
1717
state.clientId = payload
1818
},
19-
updateToken(state, payload){
19+
UPDATE_TOKEN(state, payload){
2020
state.token = payload
2121
}
2222
}

store/category.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ export const state = () => ({
5757
})
5858

5959
export const mutations = {
60-
updateTimelineCategoryList(state, payload){
60+
UPDATE_TIMELINE_CATEGORY_LIST(state, payload){
6161
state.timelineCategoryList = payload
6262
},
63-
updateRecommendCategoryList(state, payload){
63+
UPDATE_RECOMMEND_CATEGORY_LIST(state, payload){
6464
state.recommendCategoryList = payload
6565
},
66-
updateBookCategoryList(state, payload){
66+
UPDATE_BOOK_CATEGORY_LIST(state, payload){
6767
state.bookCategoryList = payload
6868
}
6969
}

store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const state = () => ({
33
})
44

55
export const mutations = {
6-
updateTopbarBlock(state, payload){
6+
UPDATE_TOPBAR_BLOCK(state, payload){
77
state.isTopbarBlock = payload
88
}
99
}

utils/utils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ export default {
8989
$cookies.set('clientId', res.clientId, { expires })
9090
$cookies.set('token', res.token, { expires })
9191
$cookies.set('userInfo', res.user, { expires })
92-
$store.commit('auth/updateUserInfo', res.user)
93-
$store.commit('auth/updateClientId', res.clientId)
94-
$store.commit('auth/updateToken', res.token)
95-
$store.commit('auth/updateUserId', res.userId)
92+
$store.commit('auth/UPDATE_USERINFO', res.user)
93+
$store.commit('auth/UPDATE_CLIENTID', res.clientId)
94+
$store.commit('auth/UPDATE_TOKEN', res.token)
95+
$store.commit('auth/UPDATE_USERID', res.userId)
9696
}
9797
},
9898
/**
@@ -116,10 +116,10 @@ export default {
116116
$cookies.remove('clientId')
117117
$cookies.remove('token')
118118
$cookies.remove('userId')
119-
$store.commit('auth/updateUserInfo', null)
120-
$store.commit('auth/updateClientId', '')
121-
$store.commit('auth/updateToken', '')
122-
$store.commit('auth/updateUserId', '')
119+
$store.commit('auth/UPDATE_USERINFO', null)
120+
$store.commit('auth/UPDATE_CLIENTID', '')
121+
$store.commit('auth/UPDATE_TOKEN', '')
122+
$store.commit('auth/UPDATE_USERID', '')
123123
}
124124
}
125125
}

0 commit comments

Comments
 (0)