@jetlinks-web/core 2.1.3 → 2.1.5
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/package.json +4 -4
- package/src/axios.ts +13 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetlinks-web/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"keywords": [
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"axios": "^1.7.4",
|
|
23
23
|
"rxjs": "^7.8.1",
|
|
24
|
-
"@jetlinks-web/
|
|
25
|
-
"@jetlinks-web/
|
|
26
|
-
"@jetlinks-web/
|
|
24
|
+
"@jetlinks-web/constants": "^1.0.9",
|
|
25
|
+
"@jetlinks-web/utils": "^1.2.8",
|
|
26
|
+
"@jetlinks-web/types": "^1.0.2"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"registry": "https://registry.npmjs.org/",
|
package/src/axios.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TOKEN_KEY, BASE_API } from '@jetlinks-web/constants'
|
|
1
|
+
import { TOKEN_KEY, BASE_API, LOCAL_BASE_API } from '@jetlinks-web/constants'
|
|
2
2
|
import { getToken } from '@jetlinks-web/utils'
|
|
3
3
|
import axios from 'axios'
|
|
4
4
|
import type {
|
|
@@ -66,11 +66,17 @@ const controller = new AbortController();
|
|
|
66
66
|
const handleRequest = (config: InternalAxiosRequestConfig) => {
|
|
67
67
|
const token = getToken()
|
|
68
68
|
const lang = localStorage.getItem(_options.langKey)
|
|
69
|
+
const env = localStorage.getItem(LOCAL_BASE_API)
|
|
69
70
|
|
|
70
71
|
if (lang) {
|
|
71
72
|
config.headers[_options.langKey] = lang
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
if (!config.url.startsWith(env)) {
|
|
76
|
+
const _url = config.url.startsWith('/') ? config.url : `/${config.url}`
|
|
77
|
+
config.url = env + _url
|
|
78
|
+
}
|
|
79
|
+
|
|
74
80
|
// 没有token,并且该接口需要token校验
|
|
75
81
|
if (!token && !_options.filter_url?.some((url) => config.url?.includes(url))) {
|
|
76
82
|
// 跳转登录页
|
|
@@ -244,7 +250,7 @@ export class Request {
|
|
|
244
250
|
* @param {object} options 请求配置
|
|
245
251
|
* @returns {Promise<AxiosResponse<any>>} 分页查询结果
|
|
246
252
|
*/
|
|
247
|
-
page(data: any, options: RequestOptions= {
|
|
253
|
+
page(data: any={}, options: RequestOptions= {
|
|
248
254
|
url: undefined,
|
|
249
255
|
method: undefined,
|
|
250
256
|
}) {
|
|
@@ -258,7 +264,7 @@ export class Request {
|
|
|
258
264
|
* @param {object} options 请求配置
|
|
259
265
|
* @returns {Promise<AxiosResponse<any>>} 不分页查询结果
|
|
260
266
|
*/
|
|
261
|
-
noPage(data
|
|
267
|
+
noPage(data: any={}, options: RequestOptions = {
|
|
262
268
|
url: undefined,
|
|
263
269
|
method: undefined,
|
|
264
270
|
}) {
|
|
@@ -287,25 +293,25 @@ export class Request {
|
|
|
287
293
|
* @param {object} options 请求配置
|
|
288
294
|
* @returns {Promise<AxiosResponse<any>>} 保存结果
|
|
289
295
|
*/
|
|
290
|
-
save(data: any, options: RequestOptions = {
|
|
296
|
+
save(data: any={}, options: RequestOptions = {
|
|
291
297
|
url: undefined,
|
|
292
298
|
method: undefined,
|
|
293
299
|
}) {
|
|
294
300
|
const { url=``, method = 'post', ...rest } = options
|
|
295
301
|
return request[method](`${this.modulePath}${url}`, data, rest)
|
|
296
302
|
}
|
|
297
|
-
|
|
303
|
+
|
|
298
304
|
/**
|
|
299
305
|
* 更新
|
|
300
306
|
* @param {object} data 更新参数
|
|
301
307
|
* @param {object} options 请求配置
|
|
302
308
|
* @returns {Promise<AxiosResponse<any>>} 更新结果
|
|
303
309
|
*/
|
|
304
|
-
update(data: any, options: RequestOptions = {
|
|
310
|
+
update(data: any={}, options: RequestOptions = {
|
|
305
311
|
url: undefined,
|
|
306
312
|
method: undefined,
|
|
307
313
|
}) {
|
|
308
|
-
const { url=``, method = '
|
|
314
|
+
const { url=``, method = 'patch', ...rest } = options
|
|
309
315
|
return patch(`${this.modulePath}${url}`, data, rest)
|
|
310
316
|
}
|
|
311
317
|
|