service.js
1.01 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
import { GET, POST } from '../../../libs/request';
import { API_HOST} from '../../../libs/config';
class Service {
constructor(url = '') {
this.url = url;
}
_get(path, data) {
let method = path ? this.url + path : API_HOST;
console.log(`request => ${data.method || method} =>`, data);
return GET(method, data).then(result => {
if (result.code !== 200) {
console.error(`response => ${data.method || method} =>`, result);
} else {
console.log(`response => ${data.method || method} =>`, result);
}
return result
});
}
_post(path, data) {
let method = path ? this.url + path : API_HOST;
console.log(`request => ${data.method || method} =>`, data);
return POST(method, data).then(result => {
if (result.code !== 200) {
console.error(`response => ${data.method || method} =>`, result);
} else {
console.log(`response => ${data.method || method} =>`, result);
}
return result;
});
}
}
export default Service;