-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
api.js
46 lines (44 loc) · 1.4 KB
/
api.js
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
import axios from 'axios';
export default {
send: (options) => {
axios
.post(options.url, options.data)
.then((response) => {
const data = response.data;
if (!data || data.code !== 0) {
options.error && options.error(data && data.msg);
return;
}
options.success && options.success(data);
})
.catch((e) => {
console.error(e);
options.error && options.error();
});
},
read: (options) => {
axios
.get(options.url)
.then((response) => {
const data = response.data;
if (!data || data.code !== 0) {
options.error && options.error(data && data.msg);
return;
}
options.success &&
options.success(
data.data.map((item) => ({
time: item[0],
type: item[1],
color: item[2],
author: item[3],
text: item[4],
}))
);
})
.catch((e) => {
console.error(e);
options.error && options.error();
});
},
};