You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.1 KiB
72 lines
1.1 KiB
import functions from "@/utils/functions.js"; |
|
import { |
|
setToken, |
|
getToken, |
|
getRefreshToken |
|
} from "@/utils/auth.js"; |
|
|
|
const service = (params) => { |
|
|
|
return new Promise((relove, reject) => { |
|
|
|
if (!params.hideLoading) { |
|
functions.showWaiting(); |
|
} |
|
|
|
uni.request({ |
|
url: params.url, |
|
data: params.data, |
|
method: params.method, |
|
dataType: "json", |
|
header: { |
|
"content-type": "application/json;charset=utf-8", |
|
"token": getToken() |
|
} |
|
}).then(res => { |
|
|
|
functions.closeWaiting(); |
|
|
|
//停止下拉刷新 |
|
uni.stopPullDownRefresh(); |
|
|
|
let [err, success] = res; |
|
|
|
if (!err) { |
|
|
|
if (success.statusCode == 200) { |
|
|
|
let data = success.data; |
|
|
|
switch (data.code) { |
|
|
|
case 200: |
|
relove(data.data); |
|
break; |
|
case 203: |
|
functions.logout(); |
|
break; |
|
default: |
|
reject(data); |
|
functions.error(data.msg); |
|
} |
|
|
|
} else { |
|
|
|
//请求失败 |
|
functions.error("服务器请求失败"); |
|
} |
|
|
|
} else { |
|
|
|
//请求失败 |
|
functions.error("服务器请求失败"); |
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
export default service;
|
|
|