-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
132 lines (131 loc) · 3.93 KB
/
Copy pathapi.js
File metadata and controls
132 lines (131 loc) · 3.93 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const axios = require('axios');
axios.interceptors.request.use(res => {
if (/^\/api\//.test(res.url)) {
// res.url = `https://www.doinblog.com${res.url}`;
res.url = `http://127.0.0.1:3001${res.url.replace('/api', '')}`;
return res;
}
});
axios.interceptors.response.use(res => {
return res.data
});
module.exports = {
// 公共个性化数据
async getIndividuationData() {
let individuation = {};
let {code, data} = await axios.get('/api/individuation/getIndividuation');
if (code === 200) {
individuation = data;
}
return individuation;
},
// banner数据
async getBannerData() {
let banner = [];
let {code, data} = await axios.get('/api/article/getArticleList', {params: {isOnlyTop: true}});
if (code === 200) {
banner = data;
}
return banner;
},
// 获取文章列表数据
async getArticleList(params) {
let articleList = {};
let {code, data, pageIndex, pageTotal} = await axios.get('/api/article/getArticleList', {params});
if (code === 200) {
articleList = {
data,
pageIndex,
pageTotal
};
}
return articleList;
},
// 获取文章总数
async getArticleTotal() {
let articleTotal = 0;
let {code, data} = await axios.get('/api/article/getArticleTotal');
if (code === 200) {
articleTotal = data;
}
return articleTotal;
},
// 获取标签对应文章列表数据
async getArticleListByLabelId(params) {
let articleList = {};
let {code, data, pageIndex, pageTotal} = await axios.get('/api/article/getArticleListByLabelId', {params});
if (code === 200) {
articleList = {
data,
pageIndex,
pageTotal
};
}
return articleList;
},
// 获取标签名
async getLabelById(params) {
let label = {};
let {code, data} = await axios.post('/api/label/getLabelById', params);
if (code === 200) {
label = data;
}
return label;
},
// 获取标签总数
async getLabelTotal() {
let labelTotal = 0;
let {code, data} = await axios.get('/api/label/getLabelTotal');
if (code === 200) {
labelTotal = data;
}
return labelTotal;
},
// 获取文章按月归档数据
async getArticleArchive(params) {
let archiveList = [];
let {code, data, pageIndex, pageTotal} = await axios.get('/api/article/archiveByMonth', {params});
if (code === 200) {
archiveList = {
data,
pageIndex,
pageTotal
};
}
return archiveList;
},
// 获取标签列表数据
async getLabelList() {
let labelList = [];
let {code, data} = await axios.get('/api/label/getLabelList');
if (code === 200) {
labelList = data;
}
return labelList;
},
// 获取月份随记列表数据
async getDiaryList(params) {
let labelTotal = [];
let {code, data} = await axios.get('/api/diary/getDiaryByMonth', {params});
if (code === 200) {
labelTotal = data;
}
return labelTotal;
},
// 增加文章阅读量
async updateArticleHits(params) {
await axios.post('/api/article/updateArticleHits', params);
},
// 获取文章详情数据
async getArticleDetail(params) {
let articleDetail = {};
let {code, data} = await axios.get('/api/article/getArticleById', {params});
if (code === 200) {
if (data.label_id) {
data.label = await this.getLabelById({id: data.label_id});
}
articleDetail = data;
}
return articleDetail;
}
};