detail.js
1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const FETCH_DETAIL_INFO = 'FETCH_DETAIL_INFO';
const UPDATE_ARTICLE_PRAISE_INFO = 'UPDATE_ARTICLE_PRAISE_INFO';
export default function() {
return {
namespaced: true,
state: {
// sort: 1 笔记 4 视频
detailInfo: {}
},
actions: {
async fetchDetailInfo({commit}, {articleId}) {
const res = await this.$api.get('/api/grass/columnArticleDetail', {
articleId,
singleDetail: 'Y',
fromXianyu: 'Y'
});
if (res.code === 200) {
// 历史原因返回为List
commit(FETCH_DETAIL_INFO, res.data.detailList[0] || {});
}
},
async updatePraiseStatus({commit}, {articleId, status}) {
const res = await this.$api.get('/api/grass/updateArticlePraise', {
articleId,
status
});
if (res.code === 200) {
commit(UPDATE_ARTICLE_PRAISE_INFO);
}
}
},
mutations: {
// 获取详情
[FETCH_DETAIL_INFO](state, detailInfo) {
state.detailInfo = detailInfo;
},
[UPDATE_ARTICLE_PRAISE_INFO](state) {
let {hasPraise, praiseCount} = state.detailInfo;
state.detailInfo = {
...state.detailInfo,
hasPraise: hasPraise === 'Y' ? 'N' : 'Y',
praiseCount: hasPraise === 'Y' ? praiseCount - 1 : praiseCount + 1
};
}
},
getters: {
authorInfo({detailInfo}) {
const {authorHeadIco, authorName, authorType, authorUid} = detailInfo;
return {authorHeadIco, authorName, authorType, authorUid};
}
}
};
}