api.js
4.83 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import axios from 'axios';
import {
Message
} from 'element-ui'
import router from './../router/index';
import {
HTTP_CODE
} from './../global/const-data';
import {
COOKIES_EX
} from './../global/const-data';
let base = "/ocadminapi";
if (process.env.NODE_ENV == "development") {
base = 'http://admin.k.wxpai.cn/ocadminapi';
}
//获取session
function getApiSession() {
return sessionStorage.getItem(COOKIES_EX + 'sid');
}
//formDataHeaders设置
let formDataHeaders = {
headers: {
"Content-Type": "multipart/form-data"
}
}
// 超时时间
axios.defaults.timeout = 30000;
// http request 拦截器
axios.interceptors.request.use(
config => {
if (config.params) {
config.params.adminSessionId = getApiSession();
}
//从data中传
// if (config.data) {
// config.data.adminSessionId = getApiSession();
// }
return config;
},
err => {
Message.error({
message: '请求超时'
})
return Promise.reject(err);
}
);
// http response 拦截器
axios.interceptors.response.use(
response => {
// 这个重复代码较多, 在状态码齐全后重新写判断
if (response.data.code == HTTP_CODE.IDENTITY_FAILURE) {
// 身份失效
router.replace({
path: '/login',
query: {
redirect: router.currentRoute.fullPath
}
});
Message.error({
message: '身份过期,请重新登录'
})
return Promise.reject(response.data);
} else if (response.data.code == HTTP_CODE.UNAUTHORIZED) {
Message.error({
message: '没有操作权限'
})
return Promise.reject(response.data);
} else {
return response;
}
},
error => {
// if (error.response) {
// switch (error.response.status) {
// case 401:
// // 返回 401 清除token信息并跳转到登录页面
// // store.commit(types.LOGOUT);
// router.replace({
// path: '/login',
// query: {
// redirect: router.currentRoute.fullPath
// }
// })
// }
// }
// return Promise.reject(error.response.data) // 返回接口返回的错误信息
return Promise.reject(); // 返回接口返回的错误信息
}
);
// get方法demo
export const getDemo = params => {
return axios.get(`${base}/path1/path2/getdemo`, {
params: params
}).then(res => res.data);
};
// post方法demo
export const postDemo = params => {
return axios.post(`${base}/path1/path2/postdemo`, params).then(res => res.data);
};
// postformdata
export const updatePostformdata = params => {
return axios.post(`${base}/path1/path2/postformdata`, params, formDataHeaders).then(res => res.data);
};
// 登陆
export const requestLogin = params => {
return axios.post(`${base}/admin/kd/login`, params).then(res => res.data);
};
// 检索应用列表
export const getApplicationList = params => {
// params.adminSessionId = getApiSession();
return axios.get(`${base}/admin/kd/application/list`, {
params: params
}).then(res => res.data);
};
// 整体报告
export const getStatView = params => {
// params.adminSessionId = getApiSession();
return axios.get(`${base}/admin/kd/application/stat/view`, {
params: params
}).then(res => res.data);
};
// 趋势列表
export const getStatDashboardList = params => {
// params.adminSessionId = getApiSession();
return axios.get(`${base}/admin/kd/application/stat/dashboard/list`, {
params: params
}).then(res => res.data);
};
// 导出报表
export const getStatViewDump = params => {
return new Promise((resolve, reject) => {
params.adminSessionId = getApiSession();
let url = `${base}/admin/kd/application/stat/view/dump?adminSessionId=${params.adminSessionId}&appCode=${params.appCode}&start=${params.start}&end=${params.end}`;
window.open(url);
resolve();
});
};
// 查码
export const getDrawsnQuery = params => {
// params.adminSessionId = getApiSession();
return axios.get(`${base}/admin/kd/drawsn/query`, {
params: params
}).then(res => res.data);
};
// ---- 分割线 ----
export const getUserList = params => {
return axios.get(`${base}/user/list`, {
params: params
}).then(res => res.data);
};
export const getUserListPage = params => {
return axios.get(`${base}/user/listpage`, {
params: params
}).then(res => res.data);;
};
export const removeUser = params => {
return axios.get(`${base}/user/remove`, {
params: params
}).then(res => res.data);;
};
export const batchRemoveUser = params => {
return axios.get(`${base}/user/batchremove`, {
params: params
}).then(res => res.data);
};
export const editUser = params => {
return axios.get(`${base}/user/edit`, {
params: params
}).then(res => res.data);
};
export const addUser = params => {
return axios.get(`${base}/user/add`, {
params: params
}).then(res => res.data);
};