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