提交 | 用户 | age
|
3ac5f2
|
1 |
// 创建 http 实例 |
J |
2 |
import Http from './jun_http' |
|
3 |
import config from '../config' |
|
4 |
// var switchConfig = require('../../config/jun_switchConfig') |
|
5 |
import httpEvent from './jun_httpEvent' |
|
6 |
|
|
7 |
// import Upload from './jun_upload' |
|
8 |
|
|
9 |
// baseConfig key |
|
10 |
// var keys = [ |
|
11 |
// 'baseUrl', 'testBaseUrl', 'testOnlineBaseUrl' |
|
12 |
// ] |
|
13 |
// var baseUrlkey = switchConfig.istest ? keys[1] |
|
14 |
// : switchConfig.istestonline ? keys[2] |
|
15 |
// : keys[0] |
|
16 |
|
|
17 |
// 根据配置生成 httpEvent |
|
18 |
function createHttpEvent(option){ |
|
19 |
let opt = {...httpEvent} |
|
20 |
if (!option) { |
|
21 |
return opt |
|
22 |
} else { |
|
23 |
if (option.ignores && option.ignores.length) { |
|
24 |
option.ignores.forEach((key, idx)=>{ |
|
25 |
if (opt[key]) { |
|
26 |
delete opt[key] |
|
27 |
} |
|
28 |
}) |
|
29 |
} |
|
30 |
return opt |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
var http = new Http({ |
|
35 |
baseUrl: config.domain, |
|
36 |
// 使用全部 httpEvent |
|
37 |
...createHttpEvent(), |
|
38 |
...config, |
|
39 |
}) |
|
40 |
|
|
41 |
// 静态json用 |
|
42 |
var http2 = new Http({ |
|
43 |
// 可以更改baseUrl |
|
44 |
baseUrl: config.domain, |
|
45 |
// 不使用 afterFlow |
|
46 |
...createHttpEvent({ |
|
47 |
ignores: ['afterFlow'] |
|
48 |
}), |
|
49 |
...config, |
|
50 |
}) |
|
51 |
|
|
52 |
// 登录用 |
|
53 |
var http3 = new Http({ |
|
54 |
baseUrl: config.domain, |
|
55 |
// 不使用 afterFlow |
|
56 |
...createHttpEvent({ |
|
57 |
ignores: ['beforeFlow'] |
|
58 |
}), |
|
59 |
...config, |
|
60 |
}) |
|
61 |
|
|
62 |
// vue 安装 |
|
63 |
function install(Vue){ |
|
64 |
Vue.prototype.Req = this |
|
65 |
} |
|
66 |
export default { |
|
67 |
http, |
|
68 |
http2, |
|
69 |
http3, |
|
70 |
install, |
|
71 |
} |