@@ -6,7 +6,7 @@ import createService from '../service';
6
6
import { IOptions } from '../types' ;
7
7
import useAsync from './useAsync' ;
8
8
import { ApiType } from '../const/index' ;
9
- import globalConfig from '../configuration/config'
9
+ import globalConfig from '../configuration/config' ;
10
10
import { getOssDownloadUrl , genOssUploadSignature } from '../oss' ;
11
11
import { DownloadSignatureParam , DownloadSignatureResponse , OssSignatureParam , OssSignatureResponse } from '../oss/types' ;
12
12
import createError from '../utils/createError' ;
@@ -33,7 +33,7 @@ export const useService = <R = any, P extends IParams = {}>(
33
33
service : ( p : P ) => Promise < R > ,
34
34
params ?: P ,
35
35
opt : IProps < R > = { } ,
36
- deps : DependencyList = [ ]
36
+ deps : DependencyList = [ ] ,
37
37
) => {
38
38
return useAsync < P , R > (
39
39
async ( runParams : P ) => {
@@ -49,7 +49,7 @@ export const useService = <R = any, P extends IParams = {}>(
49
49
opt . onError && opt . onError ( error ) ;
50
50
} ,
51
51
onSuccess : opt . onSuccess ,
52
- }
52
+ } ,
53
53
) ;
54
54
} ;
55
55
@@ -61,6 +61,8 @@ const useXconsoleService = <R = any, P extends IParams = {}>(
61
61
apiType = ApiType . open ,
62
62
useFetcher = false ,
63
63
) => {
64
+ let requestService ;
65
+
64
66
if ( useFetcher ) {
65
67
const { region : userRegion , useNewRisk, useFetcherProxy, ignoreError, disableThrowResponseError } = opt || { } ;
66
68
const fetcher = useFetcherProxy ? createFetcherProxy ( { } , { } , useNewRisk ) : createFetcher ( { } , { } , useNewRisk ) ;
@@ -80,32 +82,32 @@ const useXconsoleService = <R = any, P extends IParams = {}>(
80
82
return json . data ;
81
83
} ;
82
84
83
- const requestInstance = ( params : P ) => {
84
- const { RegionId } = params ;
85
+ // eslint-disable-next-line @typescript-eslint/no-shadow
86
+ requestService = ( params : P ) => {
87
+ const { RegionId, content } = params ;
85
88
const region = userRegion || RegionId || getActiveRegionId ( ) ;
86
89
87
-
88
90
switch ( apiType ) {
89
91
case ApiType . open :
90
92
return fetcher . callOpenApi < R , P > ( code , action , params , { region, getData } ) . catch ( handleError ) ;
91
93
case ApiType . inner :
92
94
return fetcher . callInnerApi < R , P > ( code , action , params , { region, getData } ) . catch ( handleError ) ;
93
95
case ApiType . roa :
94
- return fetcher . callOpenApi < R , P > ( code , action , params , { region, roa : params . content , getData } ) . catch ( handleError ) ;
96
+ // roa 的参数格式特殊
97
+ return fetcher . callOpenApi < R , P > ( code , action , params . params || params , { region, roa : content , getData } ) . catch ( handleError ) ;
95
98
case ApiType . app :
96
99
return fetcher . callContainerApi < R , P > ( code , action , params , { getData } ) . catch ( handleError ) ;
100
+ default :
101
+ return fetcher . callOpenApi < R , P > ( code , action , params , { region, getData } ) . catch ( handleError ) ;
97
102
}
98
-
99
- return fetcher . callOpenApi < R , P > ( code , action , params , { region, getData } ) . catch ( handleError ) ;
100
- }
101
-
102
- return useService < R , P > ( requestInstance , params , opt , [ code , action ] ) ;
103
+ } ;
104
+ } else {
105
+ requestService = createService < R , P > ( code , action , {
106
+ ...opt ,
107
+ apiType,
108
+ } ) ;
103
109
}
104
110
105
- const requestService = createService < R , P > ( code , action , {
106
- ...opt ,
107
- apiType,
108
- } ) ;
109
111
return useService < R , P > ( requestService , params , opt , [ code , action ] ) ;
110
112
} ;
111
113
@@ -170,14 +172,14 @@ export const useHttpApi = <R = any, P extends IParams = {}>(
170
172
171
173
export const useOssDownloadUrl = (
172
174
params : DownloadSignatureParam ,
173
- opt : IProps < DownloadSignatureResponse > = { }
175
+ opt : IProps < DownloadSignatureResponse > = { } ,
174
176
) => {
175
177
return useService < DownloadSignatureResponse , DownloadSignatureParam > ( getOssDownloadUrl , params , opt ) ;
176
178
} ;
177
179
178
180
export const useOssUploadSignature = (
179
181
params : OssSignatureParam ,
180
- opt : IProps < OssSignatureResponse > = { }
182
+ opt : IProps < OssSignatureResponse > = { } ,
181
183
) => {
182
184
return useService < OssSignatureResponse , OssSignatureParam > ( genOssUploadSignature , params , opt ) ;
183
185
} ;
0 commit comments