|
|
|
@ -26,22 +26,19 @@ class Proxy { |
|
|
|
|
() => Axios.get(url, { params, ...opt }), |
|
|
|
|
data || params |
|
|
|
|
); |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
post = (url, params, opt, data) => { |
|
|
|
|
try { |
|
|
|
|
this.check(url, opt, () => Axios.post(url, params, opt), data || params); |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
put = (url, params, opt, data) => { |
|
|
|
|
try { |
|
|
|
|
this.check(url, opt, () => Axios.put(url, params, opt), data || params); |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
delete = (url, params, opt, data) => { |
|
|
|
@ -52,8 +49,7 @@ class Proxy { |
|
|
|
|
() => Axios.delete(url, { ...opt, data: params }), |
|
|
|
|
data || params |
|
|
|
|
); |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
check = async (url, { dispatch }, fetch, params) => { |
|
|
|
@ -70,8 +66,16 @@ class Proxy { |
|
|
|
|
let response = fetch(); |
|
|
|
|
dispatch({ type: url, data: response.data.data, params }); |
|
|
|
|
return response.data.data; |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
break; |
|
|
|
|
case 403: |
|
|
|
|
console.log(url.split("/")[0] + "/" + "error"), |
|
|
|
|
dispatch({ |
|
|
|
|
type: url.split("/")[0] + "/" + "error", |
|
|
|
|
// data: response.data,
|
|
|
|
|
// params,
|
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
default: |
|
|
|
|
dispatch({ |
|
|
|
|
type: url.split("/")[0] + "/" + "error", |
|
|
|
@ -80,8 +84,7 @@ class Proxy { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
refresh = () => { |
|
|
|
@ -95,8 +98,7 @@ class Proxy { |
|
|
|
|
{ headers: { Authorization: `Bearer ${refresh}` } } |
|
|
|
|
); |
|
|
|
|
return login ? true : false; |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
login = (url, params, { dispatch }) => { |
|
|
|
@ -104,9 +106,9 @@ class Proxy { |
|
|
|
|
this.post(url, params, { |
|
|
|
|
dispatch: (obj) => { |
|
|
|
|
let login = obj.data; |
|
|
|
|
if (!login || !login.refreshToken){ |
|
|
|
|
if (!login || !login.refreshToken) { |
|
|
|
|
return false; |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
const refresh = ["refresh", login.refreshToken]; |
|
|
|
|
const access = ["access", login.accessToken]; |
|
|
|
|
const userData = ["userData", JSON.stringify(login.profile)]; |
|
|
|
@ -116,8 +118,7 @@ class Proxy { |
|
|
|
|
dispatch(obj); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
logout = (url, params, { dispatch }) => { |
|
|
|
@ -129,8 +130,7 @@ class Proxy { |
|
|
|
|
dispatch(obj); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
} catch (error) {} |
|
|
|
|
}; |
|
|
|
|
status = async () => { |
|
|
|
|
try { |
|
|
|
@ -149,8 +149,8 @@ class Proxy { |
|
|
|
|
}; |
|
|
|
|
getStatus = async ({ dispatch }) => { |
|
|
|
|
let status = await this.status(); |
|
|
|
|
dispatch({ type: "user/getStatus", data: {status}}) |
|
|
|
|
} |
|
|
|
|
dispatch({ type: "user/getStatus", data: { status } }); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
const _proxy = new Proxy(); |
|
|
|
|
export default _proxy; |
|
|
|
|