@@ -17,13 +17,14 @@ export const baseClient = axios.create({
17
17
18
18
export class AxiosWrapper {
19
19
// eslint-disable-next-line camelcase
20
- constructor ( { name = 'default' , loading_name, responseType = 'json' , headers, dispatch, router, successMsg, failMsg, successCallback, failCallback, customRequest } ) {
20
+ constructor ( { name = 'default' , loading_name, responseType = 'json' , headers, dispatch, commit , router, successMsg, failMsg, successCallback, failCallback, customRequest } ) {
21
21
this . name = name
22
22
// eslint-disable-next-line camelcase
23
23
this . loading_name = loading_name
24
24
// eslint-disable-next-line camelcase
25
25
this . responseType = responseType
26
26
this . dispatch = dispatch
27
+ this . commit = commit
27
28
this . router = router
28
29
this . successMsg = successMsg
29
30
this . failMsg = failMsg
@@ -80,7 +81,7 @@ export class AxiosWrapper {
80
81
return this . customRequest ( ...args )
81
82
. then ( data => {
82
83
const handler = this . getCommonResponseHandler ( { failMsg : 'Save Failed.' } )
83
- handler . call ( this , { data : { status : 200 , data } } )
84
+ handler . call ( this , { status : 200 , data : { data } } )
84
85
} )
85
86
. finally ( ( ) => this . setLoadingValue ( false ) )
86
87
}
@@ -112,7 +113,8 @@ export class AxiosWrapper {
112
113
}
113
114
114
115
setLoadingValue ( payload ) {
115
- this . dispatch ( 'loading/update' , { type : this . loading_name , payload } , { root : true } )
116
+ // this.dispatch('loading/update', { type: this.loading_name, payload }, { root: true })
117
+ this . commit ( 'loading/update' , { type : this . loading_name , payload } , { root : true } )
116
118
}
117
119
118
120
setDefaultLoadingName ( ...args ) {
@@ -134,16 +136,16 @@ export class AxiosWrapper {
134
136
return ( response ) => {
135
137
if ( ! response . data ) {
136
138
myMessage . warn ( this . failMsg || failMsg )
137
- } else if ( response . data . status === 200 ) {
139
+ } else if ( response . status === 200 ) {
138
140
this . successMsg && myMessage . success ( this . successMsg )
139
141
if ( this . successCallback ) {
140
142
this . successCallback ( response )
141
143
} else {
142
- // this.dispatch ({ type: this.name, payload : response.data.data })
144
+ this . commit ( { type : this . name , value : response . data } , { root : true } )
143
145
}
144
146
} else if ( this . responseType === 'json' ) {
145
147
myMessage . error ( response . data . msg )
146
- if ( response . data . status === 401 ) {
148
+ if ( response . status === 401 ) {
147
149
if ( this . router ) {
148
150
this . router . push ( '/login' )
149
151
}
0 commit comments