long
2024-06-26 911e0ed72a790ba054385ffe594262e123948691
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
// 创建 http 实例
import Http from './jun_http'
import config from '../config'
// var switchConfig = require('../../config/jun_switchConfig')
import httpEvent from './jun_httpEvent'
 
// import Upload from './jun_upload'
 
// baseConfig key
// var keys = [
//     'baseUrl', 'testBaseUrl', 'testOnlineBaseUrl'
// ]
// var baseUrlkey = switchConfig.istest ? keys[1]
//             : switchConfig.istestonline ? keys[2]
//             : keys[0]
 
// 根据配置生成 httpEvent
function createHttpEvent(option){
    let opt = {...httpEvent}
    if (!option) {
        return opt
    } else {
        if (option.ignores && option.ignores.length) {
            option.ignores.forEach((key, idx)=>{
                if (opt[key]) {
                    delete opt[key]
                }
            })
        }
        return opt
    }
}
 
var http = new Http({
    baseUrl: config.domain,
    // 使用全部 httpEvent
    ...createHttpEvent(),
    ...config,
})
 
// 静态json用
var http2 = new Http({
    // 可以更改baseUrl
    baseUrl: config.domain,
    // 不使用 afterFlow
    ...createHttpEvent({
        ignores: ['afterFlow']
    }),
    ...config,
})
 
// 登录用
var http3 = new Http({
    baseUrl: config.domain,
    // 不使用 afterFlow
    ...createHttpEvent({
        ignores: ['beforeFlow']
    }),
    ...config,
})
 
// vue 安装
function install(Vue){
    Vue.prototype.Req = this
}
export default {
    http,
    http2,
    http3,
    install,
}