|
@@ -0,0 +1,47 @@
|
|
|
+import WdRequest from './request'
|
|
|
+import { platform } from '@/utils/platform'
|
|
|
+import { BASE_URL, TIME_OUT } from './config/index'
|
|
|
+
|
|
|
+const request = new WdRequest({
|
|
|
+ baseUrl: BASE_URL,
|
|
|
+ timeout: TIME_OUT,
|
|
|
+ interceptor: {
|
|
|
+ requestSuccessFn: (config) => {
|
|
|
+
|
|
|
+ config.header = {
|
|
|
+ platform,
|
|
|
+ ...config.header,
|
|
|
+ }
|
|
|
+
|
|
|
+ return config
|
|
|
+ },
|
|
|
+
|
|
|
+ responseSuccessFn: (res) => {
|
|
|
+
|
|
|
+ if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
|
+
|
|
|
+ return res.data
|
|
|
+ } else if (res.statusCode === 401) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return Promise.reject(res)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: res?.data?.msg || '请求错误',
|
|
|
+ })
|
|
|
+ return Promise.reject(res)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ responseErrorFn: (err) => {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '网络错误,换个网络试试',
|
|
|
+ })
|
|
|
+ return err
|
|
|
+ },
|
|
|
+ },
|
|
|
+})
|
|
|
+export default request
|