request.js
853 Bytes
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
import { util } from 'utils'
const urlObj = {
supervisorUrl: '/rop-dj-supervisor-mini/router',
clueUrl: '/rop-scrm-clue/router'
}
const httpObj = {
djHttp: '$DJ_HTTP',
scrmHttp: '$SCRM_HTTP'
}
/**
* 通用的 POST 请求方法
* 封装了针对特定业务格式的数据提交
*
* @param {String} method - 接口调用的 method 参数
* @param {Object} data - 请求负载数据
* @param {String} url - 请求的 URL 地址
* @param {Object} options - 额外的请求配置项
* @returns {Promise}
*/
function post(method, data = {}, url = 'supervisorUrl', options = {}, httpType = 'djHttp') {
// 合并 method 到 data 中,适应后端要求的格式
const payload = {
method,
...data
}
return window[httpObj[httpType]]({
url: urlObj[url],
data: payload,
...options
})
}
export default {
post
}