resolver-egretimp-plus 0.0.21 → 0.0.28
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/h5/index.js +1 -1
- package/dist/theme/element/index.css +1 -1
- package/dist/theme/element/src/components/form.scss +4 -0
- package/dist/web/index.js +1 -1
- package/package.json +3 -1
- package/scripts/webpack.config.js +3 -1
- package/src/api/builtIn.js +3 -1
- package/src/components/icons/question-filled.vue +3 -2
- package/src/components/loading/loading.vue +3 -5
- package/src/components/packages-H5/CmiCell.vue +4 -3
- package/src/enums/index.js +10 -3
- package/src/hooks/pageConfig.js +49 -71
- package/src/index.jsx +2 -2
- package/src/resolver-H5.vue +18 -2
- package/src/resolver-common.vue +45 -0
- package/src/resolver-web.vue +17 -2
- package/src/theme/element/components/form.scss +4 -0
- package/src/utils/cipher.js +141 -0
- package/src/utils/render.jsx +6 -11
- package/src/utils/request.js +98 -8
package/src/utils/request.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
+
import qs from 'qs'
|
|
3
|
+
import { AUTH_CODE, NOT_AUTH_APIS, PASSWORD, USER_NAME, USER_TYPE } from '../enums'
|
|
4
|
+
import { LCP_LOGIN, REFRESH_TOKEN } from '../api/builtIn'
|
|
5
|
+
import { HashingFactory } from './cipher'
|
|
6
|
+
import dayjs from 'dayjs'
|
|
2
7
|
|
|
3
8
|
export function generateRequester(config) {
|
|
4
9
|
const interceptors = config?.interceptors || {}
|
|
@@ -9,35 +14,120 @@ export function generateRequester(config) {
|
|
|
9
14
|
return service
|
|
10
15
|
}
|
|
11
16
|
|
|
17
|
+
const THRESHOLD_TIME = 1000 * 60 * 10
|
|
18
|
+
let loginToken = ''
|
|
19
|
+
let EXPIRATION_Time = null
|
|
12
20
|
const service = axios.create({
|
|
13
21
|
timeout: 60000 // request timeout
|
|
14
22
|
})
|
|
15
23
|
service.interceptors.request.use(
|
|
16
24
|
config => {
|
|
17
|
-
|
|
25
|
+
let data = config.data
|
|
26
|
+
const url = config.url
|
|
27
|
+
if (
|
|
28
|
+
config && config.headers &&
|
|
29
|
+
(
|
|
30
|
+
config.headers['Content-type']?.includes('application/x-www-form-urlencoded')
|
|
31
|
+
)
|
|
32
|
+
) {
|
|
33
|
+
data = qs.stringify(data)
|
|
34
|
+
}
|
|
35
|
+
const reqConfig = {
|
|
18
36
|
...config,
|
|
37
|
+
data
|
|
19
38
|
}
|
|
39
|
+
return new Promise(async (resolve, reject) => {
|
|
40
|
+
try {
|
|
41
|
+
if ((!NOT_AUTH_APIS.includes(url) && !loginToken)) {
|
|
42
|
+
await simulatelogin()
|
|
43
|
+
reqConfig.headers = {
|
|
44
|
+
...(reqConfig.headers || {}),
|
|
45
|
+
Authorization: `Bearer ${loginToken}`
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
if (!NOT_AUTH_APIS.includes(url)) {
|
|
49
|
+
if ((EXPIRATION_Time.getTime() - new Date().getTime()) < THRESHOLD_TIME && REFRESH_TOKEN !== url) {
|
|
50
|
+
await refreshToken()
|
|
51
|
+
reqConfig.headers = {
|
|
52
|
+
...(reqConfig.headers || {}),
|
|
53
|
+
Authorization: `Bearer ${loginToken}`
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
reqConfig.headers = {
|
|
57
|
+
...(reqConfig.headers || {}),
|
|
58
|
+
Authorization: `Bearer ${loginToken}`
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
resolve(reqConfig)
|
|
64
|
+
} catch (error) {
|
|
65
|
+
reject()
|
|
66
|
+
}
|
|
67
|
+
})
|
|
20
68
|
},
|
|
21
69
|
error => {
|
|
22
|
-
|
|
70
|
+
return Promise.reject(error)
|
|
23
71
|
}
|
|
24
72
|
)
|
|
25
73
|
|
|
26
74
|
// response interceptor
|
|
27
75
|
service.interceptors.response.use(
|
|
28
76
|
response => {
|
|
29
|
-
const { config } = response
|
|
77
|
+
// const { config } = response
|
|
30
78
|
return response
|
|
31
79
|
},
|
|
32
80
|
error => {
|
|
33
|
-
|
|
81
|
+
return error
|
|
34
82
|
}
|
|
35
83
|
)
|
|
36
84
|
|
|
37
|
-
export function buildInRequest(url,
|
|
38
|
-
|
|
85
|
+
export function buildInRequest(url, data, config = {}) {
|
|
86
|
+
const reqConfig = {
|
|
39
87
|
url,
|
|
40
|
-
|
|
41
|
-
|
|
88
|
+
...config
|
|
89
|
+
}
|
|
90
|
+
const method = String.prototype.toLocaleUpperCase.call((reqConfig.method || (reqConfig.method = 'POST')))
|
|
91
|
+
if (method === 'POST') {
|
|
92
|
+
reqConfig.data = data
|
|
93
|
+
}
|
|
94
|
+
if (method === 'GET') {
|
|
95
|
+
result.params = data
|
|
96
|
+
}
|
|
97
|
+
return service(reqConfig)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function simulatelogin() {
|
|
101
|
+
const MD5HashingInstance = HashingFactory.createMD5Hashing()
|
|
102
|
+
return buildInRequest(LCP_LOGIN, {
|
|
103
|
+
username: USER_NAME,
|
|
104
|
+
password: MD5HashingInstance.hash(PASSWORD),
|
|
105
|
+
userType: USER_TYPE,
|
|
106
|
+
onecode: AUTH_CODE,
|
|
107
|
+
}, {
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
110
|
+
},
|
|
111
|
+
}).then(res => {
|
|
112
|
+
if (res.data && res.data.resultCode === '000000') {
|
|
113
|
+
loginToken = res.data.result.token
|
|
114
|
+
EXPIRATION_Time = dayjs(new Date()).add(2, 'hours').toDate()
|
|
115
|
+
return Promise.resolve(res)
|
|
116
|
+
} else {
|
|
117
|
+
return Promise.reject(res?.data?.resultMessage)
|
|
118
|
+
}
|
|
42
119
|
})
|
|
43
120
|
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
function refreshToken() {
|
|
124
|
+
return buildInRequest(REFRESH_TOKEN).then(res => {
|
|
125
|
+
if (res.data && res.data.resultCode === '000000') {
|
|
126
|
+
loginToken = res.data.result
|
|
127
|
+
EXPIRATION_Time = dayjs(new Date()).add(2, 'hours').toDate()
|
|
128
|
+
return Promise.resolve(res)
|
|
129
|
+
} else {
|
|
130
|
+
return Promise.reject(res?.data?.resultMessage)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
}
|