@conecli/cone-render 0.8.25-beta.0 → 0.8.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.ts +1 -1
- package/dist/common/token/const.ts +1 -1
- package/dist/common/token/index.h5.ts +1 -1
- package/dist/common/token/index.ts +1 -1
- package/dist/common/token/token.jd.ts +1 -1
- package/dist/common/token/token.ts +1 -1
- package/dist/common/token/token.wxapp.ts +1 -1
- package/dist/open/api/index.ts +1 -1
- package/dist/open/api/userToken.ts +1 -0
- package/dist/service/fetchGateway.ts +1 -0
- package/dist/service/fetchJsonp.ts +1 -0
- package/dist/service/http/http.ts +1 -1
- package/dist/service/http/httpInterceptors.jd.ts +1 -1
- package/dist/service/http/httpInterceptors.ts +1 -1
- package/package.json +1 -1
package/dist/api/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const TokenPlatform = {
|
|
2
1
|
TYPE_JDAPP: '01',
|
|
3
2
|
TYPE_WQ: '02',
|
|
4
3
|
TYPE_M: '03',
|
|
5
4
|
TYPE_OTHER: '-1',
|
|
5
|
+
export const TokenPlatform = {
|
|
6
6
|
TYPE_JDAPP: '01',
|
|
7
7
|
TYPE_WQ: '02',
|
|
8
8
|
TYPE_M: '03',
|
|
9
9
|
TYPE_OTHER: '-1',
|
|
10
10
|
TYPE_ISVDEV: 'isvdev',
|
|
11
11
|
TYPE_ISV_PACK_SAMPLE: 'isvPackSample',
|
|
12
12
|
TYPE_ZXDESIGNER: 'zxdesigner',
|
|
13
13
|
TYPE_JSHOPX: 'jshopx',
|
|
14
14
|
TYPE_PAGES: 'pages',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import { isApp } from '../../utils/jm-common'
|
|
2
1
|
return new Promise((resolve, reject) => {
|
|
3
2
|
let platform: string = getPlatform()
|
|
4
3
|
console.log('isSDKM:', window?.page_data?.isSDKM)
|
|
5
4
|
if (platform === TokenPlatform.TYPE_JDAPP) {
|
|
6
5
|
import('./token.jd')
|
|
7
6
|
.then((data) => {
|
|
8
7
|
console.log('data:', data)
|
|
9
8
|
resolve(data)
|
|
10
9
|
})
|
|
11
10
|
.catch((err) => {
|
|
12
11
|
reject(err)
|
|
13
12
|
})
|
|
14
13
|
}
|
|
15
14
|
else if (platform === TokenPlatform.TYPE_WQ) {
|
|
16
15
|
import('./token.wxapp')
|
|
17
16
|
.then((data) => {
|
|
18
17
|
console.log('data:', data)
|
|
19
18
|
resolve(data)
|
|
20
19
|
})
|
|
21
20
|
.catch((err) => {
|
|
22
21
|
reject(err)
|
|
23
22
|
})
|
|
24
23
|
} else {
|
|
25
24
|
import('./token')
|
|
26
25
|
.then((data) => {
|
|
27
26
|
console.log('data:', data)
|
|
28
27
|
resolve(data)
|
|
29
28
|
})
|
|
30
29
|
.catch((err) => {
|
|
31
30
|
reject(err)
|
|
32
31
|
})
|
|
33
32
|
}
|
|
34
33
|
})
|
|
35
34
|
return new Promise((resolve) => {
|
|
36
35
|
loadTokenPromise.then((proxy: any) => {
|
|
37
36
|
if (proxy?.isLogin) {
|
|
38
37
|
proxy?.isLogin().then((data: boolean) => {
|
|
39
38
|
resolve(data)
|
|
40
39
|
})
|
|
41
40
|
} else {
|
|
42
41
|
resolve(false)
|
|
43
42
|
}
|
|
44
43
|
})
|
|
45
44
|
})
|
|
46
45
|
return new Promise((resolve) => {
|
|
47
46
|
loadTokenPromise.then((proxy: any) => {
|
|
48
47
|
if (proxy?.getIsvToken) {
|
|
49
48
|
proxy?.getIsvToken().then((data: string) => {
|
|
50
49
|
resolve(data)
|
|
51
50
|
})
|
|
52
51
|
} else {
|
|
53
52
|
resolve('')
|
|
54
53
|
}
|
|
55
54
|
})
|
|
56
55
|
})
|
|
57
56
|
return new Promise((resolve) => {
|
|
58
57
|
loadTokenPromise.then((proxy: any) => {
|
|
59
58
|
if (proxy?.toLogin) {
|
|
60
59
|
proxy?.toLogin(options)
|
|
61
60
|
resolve(true)
|
|
62
61
|
} else {
|
|
63
62
|
resolve(false)
|
|
64
63
|
}
|
|
65
64
|
})
|
|
66
65
|
})
|
|
67
66
|
let platform = TokenPlatform.TYPE_M
|
|
68
67
|
if (isApp('jd')) {
|
|
69
68
|
platform = TokenPlatform.TYPE_JDAPP
|
|
70
69
|
}
|
|
71
70
|
else if ((isApp('wx') && isApp('mp')) || window?.page_data?.isSDKM) {
|
|
72
71
|
platform = TokenPlatform.TYPE_WQ
|
|
73
72
|
}
|
|
74
73
|
return platform
|
|
74
|
+
import { isApp } from '../../utils/jm-common'
|
|
75
75
|
return new Promise((resolve, reject) => {
|
|
76
76
|
let platform: string = getPlatform()
|
|
77
77
|
if (platform === TokenPlatform.TYPE_JDAPP) {
|
|
78
78
|
import('./token.jd')
|
|
79
79
|
.then((data) => {
|
|
80
80
|
console.log('data:', data)
|
|
81
81
|
resolve(data)
|
|
82
82
|
})
|
|
83
83
|
.catch((err) => {
|
|
84
84
|
reject(err)
|
|
85
85
|
})
|
|
86
86
|
}
|
|
87
87
|
else if (platform === TokenPlatform.TYPE_WQ) {
|
|
88
88
|
import('./token.wxapp')
|
|
89
89
|
.then((data) => {
|
|
90
90
|
console.log('data:', data)
|
|
91
91
|
resolve(data)
|
|
92
92
|
})
|
|
93
93
|
.catch((err) => {
|
|
94
94
|
reject(err)
|
|
95
95
|
})
|
|
96
96
|
} else {
|
|
97
97
|
import('./token')
|
|
98
98
|
.then((data) => {
|
|
99
99
|
console.log('data:', data)
|
|
100
100
|
resolve(data)
|
|
101
101
|
})
|
|
102
102
|
.catch((err) => {
|
|
103
103
|
reject(err)
|
|
104
104
|
})
|
|
105
105
|
}
|
|
106
106
|
})
|
|
107
107
|
return new Promise((resolve) => {
|
|
108
108
|
loadTokenPromise.then((proxy: any) => {
|
|
109
109
|
if (proxy?.isLogin) {
|
|
110
110
|
proxy?.isLogin().then((data: boolean) => {
|
|
111
111
|
resolve(data)
|
|
112
112
|
})
|
|
113
113
|
} else {
|
|
114
114
|
resolve(false)
|
|
115
115
|
}
|
|
116
116
|
})
|
|
117
117
|
})
|
|
118
118
|
return new Promise((resolve) => {
|
|
119
119
|
loadTokenPromise.then((proxy: any) => {
|
|
120
120
|
if (proxy?.getIsvToken) {
|
|
121
121
|
proxy?.getIsvToken().then((data: string) => {
|
|
122
122
|
resolve(data)
|
|
123
123
|
})
|
|
124
124
|
} else {
|
|
125
125
|
resolve('')
|
|
126
126
|
}
|
|
127
127
|
})
|
|
128
128
|
})
|
|
129
129
|
return new Promise((resolve) => {
|
|
130
130
|
loadTokenPromise.then((proxy: any) => {
|
|
131
131
|
if (proxy?.toLogin) {
|
|
132
132
|
proxy?.toLogin(options)
|
|
133
133
|
resolve(true)
|
|
134
134
|
} else {
|
|
135
135
|
resolve(false)
|
|
136
136
|
}
|
|
137
137
|
})
|
|
138
138
|
})
|
|
139
139
|
let platform = TokenPlatform.TYPE_M
|
|
140
140
|
if (isApp('jd')) {
|
|
141
141
|
platform = TokenPlatform.TYPE_JDAPP
|
|
142
142
|
}
|
|
143
143
|
else if (isApp('wx') && isApp('mp')) {
|
|
144
144
|
platform = TokenPlatform.TYPE_WQ
|
|
145
145
|
}
|
|
146
146
|
return platform
|
|
147
147
|
let platform = getPlatform()
|
|
148
148
|
let source = platform
|
|
149
149
|
if (platform === TokenPlatform.TYPE_M || platform === TokenPlatform.TYPE_WQ) {
|
|
150
150
|
source = TokenPlatform.TYPE_JDAPP
|
|
151
151
|
}
|
|
152
152
|
return source
|
|
153
153
|
return window?.page_data?.pageChannel || ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import { TokenPlatform } from './const'
|
|
2
1
|
return new Promise((resolve) => {
|
|
3
2
|
console.log('isLogin暂未实现')
|
|
4
3
|
resolve(false)
|
|
5
4
|
})
|
|
6
5
|
return new Promise((resolve) => {
|
|
7
6
|
console.log('getIsvToken暂未实现')
|
|
8
7
|
resolve('')
|
|
9
8
|
})
|
|
10
9
|
return new Promise((resolve) => {
|
|
11
10
|
console.log('toLogin暂未实现')
|
|
12
11
|
resolve(false)
|
|
13
12
|
})
|
|
14
13
|
let platform = TokenPlatform.TYPE_OTHER
|
|
15
14
|
return platform
|
|
15
|
+
import { TokenPlatform } from './const'
|
|
16
16
|
return new Promise((resolve) => {
|
|
17
17
|
console.log('isLogin暂未实现')
|
|
18
18
|
resolve(false)
|
|
19
19
|
})
|
|
20
20
|
return new Promise((resolve) => {
|
|
21
21
|
console.log('getIsvToken暂未实现')
|
|
22
22
|
resolve('')
|
|
23
23
|
})
|
|
24
24
|
return new Promise((resolve) => {
|
|
25
25
|
console.log('toLogin暂未实现')
|
|
26
26
|
resolve(false)
|
|
27
27
|
})
|
|
28
28
|
return TokenPlatform.TYPE_OTHER
|
|
29
29
|
return ''
|
|
30
30
|
return ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
console.log('load token.jd')
|
|
2
1
|
return new Promise((resolve) => {
|
|
3
2
|
if (jmfe) {
|
|
4
3
|
jmfe.isJDAppLogin().then(({ data }) => {
|
|
5
4
|
if (data === '1') {
|
|
6
5
|
resolve(true)
|
|
7
6
|
} else if (data === '0') {
|
|
8
7
|
resolve(false)
|
|
9
8
|
}
|
|
10
9
|
})
|
|
11
10
|
} else {
|
|
12
11
|
console.warn('jmfe对象不存在,可能没有提前动态引入jd-jssdk.js')
|
|
13
12
|
resolve(false)
|
|
14
13
|
}
|
|
15
14
|
})
|
|
16
15
|
return requestIsvToken(window.location.href)
|
|
17
16
|
if (jmfe) {
|
|
18
17
|
jmfe.toLogin(options)
|
|
19
18
|
} else {
|
|
20
19
|
console.warn('jmfe对象不存在,可能没有提前动态引入jd-jssdk.js')
|
|
21
20
|
}
|
|
22
21
|
return new Promise((resolve) => {
|
|
23
22
|
console.log('requestIsvToken:', url)
|
|
24
23
|
if (jmfe) {
|
|
25
24
|
jmfe.requestIsvToken(url).then(({ status, data, msg }) => {
|
|
26
25
|
if (status === '0') {
|
|
27
26
|
resolve(data || '')
|
|
28
27
|
} else {
|
|
29
28
|
resolve('')
|
|
30
29
|
}
|
|
31
30
|
})
|
|
32
31
|
} else {
|
|
33
32
|
console.warn('jmfe对象不存在,可能没有提前动态引入jd-jssdk.js')
|
|
34
33
|
resolve('')
|
|
35
34
|
}
|
|
36
35
|
})
|
|
36
|
+
console.log('load token.jd')
|
|
37
37
|
return new Promise((resolve) => {
|
|
38
38
|
if (jmfe) {
|
|
39
39
|
jmfe.isJDAppLogin().then(({ data }) => {
|
|
40
40
|
if (data === '1') {
|
|
41
41
|
resolve(true)
|
|
42
42
|
} else if (data === '0') {
|
|
43
43
|
resolve(false)
|
|
44
44
|
}
|
|
45
45
|
})
|
|
46
46
|
} else {
|
|
47
47
|
console.warn('jmfe对象不存在,可能没有提前动态引入jd-jssdk.js')
|
|
48
48
|
resolve(false)
|
|
49
49
|
}
|
|
50
50
|
})
|
|
51
51
|
return requestIsvToken(window.location.href)
|
|
52
52
|
if (jmfe) {
|
|
53
53
|
jmfe.toLogin(options)
|
|
54
54
|
} else {
|
|
55
55
|
console.warn('jmfe对象不存在,可能没有提前动态引入jd-jssdk.js')
|
|
56
56
|
}
|
|
57
57
|
if (jmfe) {
|
|
58
58
|
console.log('registerCode:', code)
|
|
59
59
|
jmfe.registerCode(code)
|
|
60
60
|
} else {
|
|
61
61
|
console.warn('jmfe对象不存在,可能没有提前引入jd-jssdk.js')
|
|
62
62
|
}
|
|
63
63
|
return new Promise((resolve) => {
|
|
64
64
|
console.log('requestIsvToken:', url)
|
|
65
65
|
if (jmfe) {
|
|
66
66
|
jmfe
|
|
67
67
|
.requestIsvToken(url)
|
|
68
68
|
.then((result: any) => {
|
|
69
69
|
console.log('requestIsvToken result:' + JSON.stringify(result))
|
|
70
70
|
const { status, data, msg } = result
|
|
71
71
|
if (status === '0') {
|
|
72
72
|
resolve(data || '')
|
|
73
73
|
} else {
|
|
74
74
|
resolve('')
|
|
75
75
|
}
|
|
76
76
|
})
|
|
77
77
|
.catch((e: any) => {
|
|
78
78
|
console.log('requestIsvToken error:' + JSON.stringify(e))
|
|
79
79
|
resolve('')
|
|
80
80
|
})
|
|
81
81
|
} else {
|
|
82
82
|
console.warn('jmfe对象不存在,可能没有提前引入jd-jssdk.js')
|
|
83
83
|
resolve('')
|
|
84
84
|
}
|
|
85
85
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
console.log('load token')
|
|
2
1
|
return new Promise((resolve) => {
|
|
3
2
|
console.log('isLogin暂未实现')
|
|
4
3
|
resolve(false)
|
|
5
4
|
})
|
|
6
5
|
return new Promise((resolve) => {
|
|
7
6
|
console.log('getIsvToken暂未实现')
|
|
8
7
|
resolve('')
|
|
9
8
|
})
|
|
10
9
|
console.log('toLogin暂未实现')
|
|
10
|
+
import { domain } from '../../api'
|
|
11
11
|
return window?.page_data?.pageChannel || ''
|
|
12
12
|
return new Promise((resolve) => {
|
|
13
13
|
const channel = getPageChannel()
|
|
14
14
|
if (
|
|
15
15
|
channel === PageChannel.TYPE_ISVDEV ||
|
|
16
16
|
channel === PageChannel.TYPE_ISV_PACK_SAMPLE
|
|
17
17
|
) {
|
|
18
18
|
getIsvToken().then((token) => {
|
|
19
19
|
console.log('isLogin token:' + token)
|
|
20
20
|
if (token) {
|
|
21
21
|
resolve(true)
|
|
22
22
|
} else {
|
|
23
23
|
resolve(false)
|
|
24
24
|
}
|
|
25
25
|
})
|
|
26
26
|
} else {
|
|
27
27
|
const isLogin: string = `${domain.mobileLogin}/cgi-bin/ml/islogin`
|
|
28
28
|
fetchJsonp(isLogin)
|
|
29
29
|
.then((response: any) => {
|
|
30
30
|
return response.json()
|
|
31
31
|
})
|
|
32
32
|
.then((data) => {
|
|
33
33
|
console.log('data:', data)
|
|
34
34
|
if (data?.islogin === '1') {
|
|
35
35
|
resolve(true)
|
|
36
36
|
} else {
|
|
37
37
|
resolve(false)
|
|
38
38
|
}
|
|
39
39
|
})
|
|
40
40
|
.catch((e) => {
|
|
41
41
|
console.log('fetchJsonp cgi-bin/ml/islogin error:', e.message)
|
|
42
42
|
resolve(false)
|
|
43
43
|
})
|
|
44
44
|
}
|
|
45
45
|
})
|
|
46
46
|
return new Promise((resolve) => {
|
|
47
47
|
fetchGateway(
|
|
48
48
|
'isvObfuscator',
|
|
49
49
|
{
|
|
50
50
|
url: window.location.href,
|
|
51
51
|
id: 'shopisv',
|
|
52
52
|
},
|
|
53
53
|
{},
|
|
54
54
|
)
|
|
55
55
|
.then((data: any) => {
|
|
56
56
|
console.log('fetchGateway isvObfuscator data:' + JSON.stringify(data))
|
|
57
57
|
if (
|
|
58
58
|
data?.statusCode == 200 &&
|
|
59
59
|
data?.data?.errcode === 0 &&
|
|
60
60
|
data?.data?.token
|
|
61
61
|
) {
|
|
62
62
|
resolve(data?.data?.token)
|
|
63
63
|
} else {
|
|
64
64
|
resolve('')
|
|
65
65
|
}
|
|
66
66
|
})
|
|
67
67
|
.catch((e: { message: any }) => {
|
|
68
68
|
console.log('fetchGateway isvObfuscator error:' + e.message)
|
|
69
69
|
resolve('')
|
|
70
70
|
})
|
|
71
71
|
})
|
|
72
72
|
const defaultParams = {
|
|
73
73
|
appid: '100',
|
|
74
74
|
returnurl: window.location.href,
|
|
75
75
|
}
|
|
76
76
|
const params = Object.assign({}, defaultParams, options)
|
|
77
77
|
params.returnurl = encodeURIComponent(params.returnurl)
|
|
78
78
|
const loginUrl = `${domain.mobileLogin}/user/login.action?${serialize(
|
|
79
79
|
params,
|
|
80
80
|
)}`
|
|
81
81
|
console.log('loginUrl:', loginUrl)
|
|
82
82
|
window.location.href = loginUrl
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import cookie from '../../utils/jm-cookie'
|
|
2
1
|
return new Promise((resolve) => {
|
|
3
2
|
const token = cookie.get('wq_auth_token')
|
|
4
3
|
resolve(!!token)
|
|
5
4
|
})
|
|
6
5
|
return new Promise((resolve) => {
|
|
7
6
|
const token = cookie.get('wq_auth_token') || ''
|
|
8
7
|
resolve(token)
|
|
9
8
|
})
|
|
10
9
|
const returnurl = options?.returnurl || window.location.href
|
|
11
10
|
pinTokenRedirect(WXAPP_BIZ_KEY, returnurl)
|
|
12
11
|
const url = `
|
|
13
12
|
${domain.wq}/pinbind/pintokenredirect?biz=${biz}&url=${encodeURIComponent(
|
|
14
13
|
targetUrl,
|
|
15
14
|
)}`
|
|
16
15
|
console.log('pinTokenRedirect:', url)
|
|
17
16
|
window.location.href = url
|
|
17
|
+
import cookie from '../../utils/jm-cookie'
|
|
18
18
|
return new Promise((resolve) => {
|
|
19
19
|
const token = cookie.get('wq_auth_token')
|
|
20
20
|
resolve(!!token)
|
|
21
21
|
})
|
|
22
22
|
return new Promise((resolve) => {
|
|
23
23
|
const token = cookie.get('wq_auth_token') || ''
|
|
24
24
|
resolve(token)
|
|
25
25
|
})
|
|
26
26
|
return new Promise((resolve) => {
|
|
27
27
|
fetchGateway(
|
|
28
28
|
'isvObfuscator',
|
|
29
29
|
{
|
|
30
30
|
url: window.location.href,
|
|
31
31
|
id: 'shopisv',
|
|
32
32
|
},
|
|
33
33
|
{ loginType: 1, loginWQBiz: WXAPP_BIZ_KEY },
|
|
34
34
|
)
|
|
35
35
|
.then((data: any) => {
|
|
36
36
|
console.warn('fetchGateway isvObfuscator data:' + JSON.stringify(data))
|
|
37
37
|
if (
|
|
38
38
|
data?.statusCode == 200 &&
|
|
39
39
|
data?.data?.errcode === 0 &&
|
|
40
40
|
data?.data?.token
|
|
41
41
|
) {
|
|
42
42
|
resolve(data?.data?.token)
|
|
43
43
|
} else {
|
|
44
44
|
resolve('')
|
|
45
45
|
}
|
|
46
46
|
})
|
|
47
47
|
.catch((e: { message: any }) => {
|
|
48
48
|
console.warn('fetchGateway isvObfuscator error:' + e.message)
|
|
49
49
|
resolve('')
|
|
50
50
|
})
|
|
51
51
|
})
|
|
52
52
|
const returnurl = options?.returnurl || window.location.href
|
|
53
53
|
pinTokenRedirect(WXAPP_BIZ_KEY, returnurl)
|
|
54
54
|
const url = `
|
|
55
55
|
${domain.wq}/pinbind/pintokenredirect?biz=${biz}&url=${encodeURIComponent(
|
|
56
56
|
targetUrl,
|
|
57
57
|
)}`
|
|
58
58
|
console.log('pinTokenRedirect:', url)
|
|
59
59
|
window.location.href = url
|
package/dist/open/api/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import * as device from './device'
|
|
2
1
|
device,
|
|
3
2
|
environment,
|
|
4
3
|
jump,
|
|
5
4
|
storage,
|
|
6
5
|
util,
|
|
7
6
|
moduleUtil,
|
|
8
7
|
track,
|
|
9
8
|
trackPromise,
|
|
10
9
|
global,
|
|
11
10
|
http,
|
|
12
11
|
shopMember,
|
|
13
12
|
userToken,
|
|
14
13
|
TokenPlatform,
|
|
14
|
+
import * as device from './device'
|
|
15
15
|
device,
|
|
16
16
|
environment,
|
|
17
17
|
jump,
|
|
18
18
|
storage,
|
|
19
19
|
util,
|
|
20
20
|
moduleUtil,
|
|
21
21
|
track,
|
|
22
22
|
trackPromise,
|
|
23
23
|
global,
|
|
24
24
|
http,
|
|
25
25
|
shopMember,
|
|
26
26
|
userToken,
|
|
27
27
|
TokenPlatform,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { api } from '../api'
|
|
2
|
clientVersion: '11.0.0',
|
|
1
3
|
client: 'wh5',
|
|
2
4
|
area: '1_72_2799_0',
|
|
3
5
|
loginType: '2',
|
|
4
6
|
uuid: UUID,
|
|
5
7
|
functionId: string,
|
|
6
8
|
body = {},
|
|
7
9
|
options = {},
|
|
8
10
|
requestOptions = {},
|
|
9
11
|
const params = Object.assign(
|
|
10
12
|
{},
|
|
11
13
|
{
|
|
12
14
|
t: Date.now(),
|
|
13
15
|
functionId,
|
|
14
16
|
appid: 'shop_m_jd_com',
|
|
15
17
|
body: JSON.stringify(body),
|
|
16
18
|
},
|
|
17
19
|
clientParams,
|
|
18
20
|
options,
|
|
19
21
|
)
|
|
20
22
|
console.warn(
|
|
21
23
|
'fetchGateway url:' + api.apiFunc + ',functionId:' + params.functionId,
|
|
22
24
|
)
|
|
23
25
|
return http.post(api.apiFunc, params, requestOptions)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const defaultOptions = {
|
|
2
|
timeout: 5000,
|
|
1
3
|
jsonpCallback: 'callback',
|
|
2
4
|
return `jsonp_${Date.now()}_${Math.ceil(Math.random() * 100000)}`
|
|
3
5
|
try {
|
|
4
6
|
delete window[functionName]
|
|
5
7
|
} catch (e) {
|
|
6
8
|
window[functionName] = undefined
|
|
7
9
|
}
|
|
8
10
|
const script = document.getElementById(scriptId)
|
|
9
11
|
document.getElementsByTagName('head')[0].removeChild(script)
|
|
10
12
|
const timeout =
|
|
11
13
|
|
|
12
14
|
options.timeout != null ? options.timeout : defaultOptions.timeout
|
|
13
15
|
const jsonpCallback =
|
|
14
16
|
|
|
15
17
|
options.jsonpCallback != null
|
|
16
18
|
? options.jsonpCallback
|
|
17
19
|
: defaultOptions.jsonpCallback
|
|
18
20
|
let timeoutId: string | number | NodeJS.Timeout | undefined
|
|
19
21
|
return new Promise((resolve, reject) => {
|
|
20
22
|
const callbackFunction = generateCallbackFunction()
|
|
21
23
|
window[callbackFunction] = function (response: any) {
|
|
22
24
|
resolve({
|
|
23
25
|
ok: true,
|
|
24
26
|
json: function () {
|
|
25
27
|
return Promise.resolve(response)
|
|
26
28
|
},
|
|
27
29
|
})
|
|
28
30
|
if (timeoutId) clearTimeout(timeoutId)
|
|
29
31
|
removeScript(jsonpCallback + '_' + callbackFunction)
|
|
30
32
|
clearFunction(callbackFunction)
|
|
31
33
|
}
|
|
32
34
|
url += url.indexOf('?') === -1 ? '?' : '&'
|
|
33
35
|
const jsonpScript = document.createElement('script')
|
|
34
36
|
jsonpScript.setAttribute(
|
|
35
37
|
'src',
|
|
36
38
|
url + jsonpCallback + '=' + callbackFunction,
|
|
37
39
|
)
|
|
38
40
|
jsonpScript.id = jsonpCallback + '_' + callbackFunction
|
|
39
41
|
document.getElementsByTagName('head')[0].appendChild(jsonpScript)
|
|
40
42
|
timeoutId = setTimeout(() => {
|
|
41
43
|
reject(new Error(`JSONP request to ${url} timed out`))
|
|
42
44
|
clearFunction(callbackFunction)
|
|
43
45
|
removeScript(jsonpCallback + '_' + callbackFunction)
|
|
44
46
|
}, timeout)
|
|
45
47
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro, { RequestTask } from "@tarojs/taro";
|
|
2
1
|
jsonHeader = "application/json;charset=utf-8",
|
|
3
2
|
formDataHeader = "application/x-www-form-urlencoded"
|
|
4
3
|
constructor() {
|
|
5
4
|
this._init()
|
|
6
5
|
}
|
|
7
6
|
_init(): void {
|
|
8
7
|
httpInterceptors.forEach((item) => {
|
|
9
8
|
Taro.addInterceptor((chain) => item(chain))
|
|
10
9
|
})
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
get(url: string, data: any = null, otherOptions = {}): Taro.RequestTask<any> {
|
|
14
13
|
return this.request({url, data, method:"GET", ...otherOptions})
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
post(
|
|
18
17
|
url: string,
|
|
19
18
|
data: any = null,
|
|
20
19
|
otherOptions = {}
|
|
21
20
|
): Taro.RequestTask<any> {
|
|
22
21
|
return this.request({url, data, method:"POST", ...otherOptions})
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
request({url, method = "POST", timeout = 7000, ...otherOptions}): RequestTask<any> {
|
|
26
25
|
const header = {
|
|
27
26
|
"content-type": method === "POST" ? RequestHeaderContentType.formDataHeader : RequestHeaderContentType.jsonHeader
|
|
28
27
|
}
|
|
29
28
|
const requestTask = Taro.request({
|
|
30
29
|
url,
|
|
31
30
|
method,
|
|
32
31
|
timeout,
|
|
33
32
|
header,
|
|
34
33
|
credentials: 'include',
|
|
35
34
|
...otherOptions,
|
|
36
35
|
})
|
|
37
36
|
const requestTimeoutPromise =
|
|
38
37
|
new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
|
|
39
38
|
setTimeout(() => {
|
|
40
39
|
resolve({
|
|
41
40
|
statusCode: 500,
|
|
42
41
|
resTimeoutState: true,
|
|
43
42
|
errMsg: 'request timeout',
|
|
44
43
|
})
|
|
45
44
|
}, timeout)
|
|
46
45
|
})
|
|
47
46
|
return Promise.race([requestTask, requestTimeoutPromise]).then(
|
|
48
47
|
(res: any) => {
|
|
49
48
|
if (res && res.statusCode === 500 && res.resTimeoutState) {
|
|
50
49
|
console.log('request 请求超时 url:' + url)
|
|
51
50
|
requestTask.abort && requestTask.abort()
|
|
52
51
|
}
|
|
53
52
|
return res
|
|
54
53
|
}
|
|
55
54
|
)
|
|
56
55
|
}
|
|
56
|
+
import Taro, { RequestTask } from '@tarojs/taro'
|
|
57
57
|
jsonHeader = 'application/json;charset=utf-8',
|
|
58
58
|
formDataHeader = 'application/x-www-form-urlencoded',
|
|
59
59
|
constructor() {
|
|
60
60
|
this._init()
|
|
61
61
|
}
|
|
62
62
|
_init(): void {
|
|
63
63
|
httpInterceptors.forEach((item) => {
|
|
64
64
|
Taro.addInterceptor((chain) => item(chain))
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
get(url: string, data: any = null, otherOptions = {}): Taro.RequestTask<any> {
|
|
69
69
|
return this.request({ url, data, method: 'GET', ...otherOptions })
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
post(
|
|
73
73
|
url: string,
|
|
74
74
|
data: any = null,
|
|
75
75
|
otherOptions = {},
|
|
76
76
|
): Taro.RequestTask<any> {
|
|
77
77
|
return this.request({ url, data, method: 'POST', ...otherOptions })
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
request({
|
|
81
81
|
url,
|
|
82
82
|
method = 'POST',
|
|
83
83
|
timeout = 7000,
|
|
84
84
|
...otherOptions
|
|
85
85
|
}): RequestTask<any> {
|
|
86
86
|
const { header: otherHeader, ...otherOpts } = otherOptions
|
|
87
87
|
const header = {
|
|
88
88
|
'content-type':
|
|
89
89
|
method === 'POST'
|
|
90
90
|
? RequestHeaderContentType.formDataHeader
|
|
91
91
|
: RequestHeaderContentType.jsonHeader,
|
|
92
92
|
...otherHeader,
|
|
93
93
|
}
|
|
94
94
|
const param: any = {
|
|
95
95
|
url,
|
|
96
96
|
method,
|
|
97
97
|
timeout,
|
|
98
98
|
header,
|
|
99
99
|
credentials: 'include',
|
|
100
100
|
...otherOpts,
|
|
101
101
|
}
|
|
102
102
|
const requestTask = Taro.request(param)
|
|
103
103
|
const requestTimeoutPromise =
|
|
104
104
|
new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
|
|
105
105
|
setTimeout(() => {
|
|
106
106
|
resolve({
|
|
107
107
|
statusCode: 500,
|
|
108
108
|
resTimeoutState: true,
|
|
109
109
|
errMsg: 'request timeout',
|
|
110
110
|
})
|
|
111
111
|
}, timeout)
|
|
112
112
|
})
|
|
113
113
|
return Promise.race([requestTask, requestTimeoutPromise]).then(
|
|
114
114
|
(res: any) => {
|
|
115
115
|
if (res && res.statusCode === 500 && res.resTimeoutState) {
|
|
116
116
|
console.warn('request 请求超时 url:' + url)
|
|
117
117
|
requestTask.abort && requestTask.abort()
|
|
118
118
|
}
|
|
119
119
|
return res
|
|
120
120
|
},
|
|
121
121
|
)
|
|
122
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
2
|
const requestParams = chain.requestParams
|
|
3
3
|
const { header } = requestParams
|
|
4
4
|
const userInfo = global?.info?.userInfo
|
|
5
5
|
console.log('获取用户信息', userInfo)
|
|
6
6
|
if (userInfo) {
|
|
7
7
|
header[
|
|
8
8
|
'Cookie'
|
|
9
9
|
] = `pin=${userInfo.encodePin};ticket=${userInfo.ptkey};pt_pin=${userInfo.encodePin};pt_key=${userInfo.ptkey};${global.info.cookiesStr}`
|
|
10
10
|
}
|
|
11
11
|
return chain.proceed(requestParams).then((res) => {
|
|
12
12
|
if (res.statusCode === HttpStatus.SUCCESS) {
|
|
13
13
|
return res
|
|
14
14
|
} else {
|
|
15
15
|
return {
|
|
16
16
|
statusCode: res.statusCode,
|
|
17
17
|
msg: httpStatusMsg[res.statusCode] || defaultHttpStatusMsg,
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Taro from '@tarojs/taro'
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
2
|
const requestParams = chain.requestParams
|
|
3
3
|
return chain.proceed(requestParams).then((res) => {
|
|
4
4
|
if (res.statusCode === HttpStatus.SUCCESS) {
|
|
5
5
|
return res
|
|
6
6
|
} else {
|
|
7
7
|
return {
|
|
8
8
|
statusCode: res.statusCode,
|
|
9
9
|
msg: httpStatusMsg[res.statusCode] || defaultHttpStatusMsg,
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
})
|