actions.js
1.94 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
59
60
61
62
import * as Types from './types';
export default {
/**
* 获取社区文章瀑布流列表
* @param commit
* @param page
* @param limit
* @returns {Promise<void>}
*/
async fetchArticleList({commit}, {page = 1, limit = 20, reload = false, lastedTime = null}) {
commit(Types.FETCH_ARTICLE_LIST_REQUEST);
let result = await this.$api.get('/api/grass/article/list', {
page,
limit,
columnType: 1001,
lastedTime
}).catch(() => {
commit(Types.FETCH_ARTICLE_LIST_FAILED);
});
if (result.code === 200 && result.data.list && result.data.list.length) {
result.data.list.forEach((item) => {
let imageHeight = item.imageHeight;
let imageWidth = item.imageWidth;
if (imageWidth > 350) {
imageWidth = 350;
imageHeight = parseInt(350 * item.imageHeight / item.imageWidth, 10);
}
if (item.dataType === 1) {
item.authorHeadIco = item.authorHeadIco.replace(/{mode}/, 2).replace(/{width}/, 40).replace(/{height}/, 40);
item.coverImage = item.coverImage.replace(/{mode}/, 2).replace(/{width}/, imageWidth).replace(/{height}/, imageHeight).replace(/\/format\/webp/, '');
} else if (item.dataType === 2) {
item.resourceSrc = item.resourceSrc.replace(/{mode}/, 2).replace(/{width}/, imageWidth).replace(/{height}/, imageHeight).replace(/\/format\/webp/, '');
}
item.imageNewWidth = imageWidth;
item.imageNewHeight = imageHeight;
});
commit(Types.FETCH_ARTICLE_LIST_SUCCESS, {result, reload});
} else {
commit(Types.FETCH_ARTICLE_LIST_FAILED);
}
},
// 点赞
async updateArticlePraise({commit}, {articleId, status, index}) {
let result = await this.$api.get('/api/grass/updateArticlePraise', {
articleId,
status
});
if (result.code === 200) {
commit(Types.UPDATE_ARTICLE_PRAISE, {articleId, status, index});
}
return result;
}
};