| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- export default function request(config = {}) {
- let {
- url,
- data = {},
- method = "GET",
- header = {}
- } = config
- // 拼接url TODO 这里要修改,改成不同环境取不同的url
- url = process.env.BASE_API_URL + url;
- // 添加token
- header['Authorization'] = uni.getStorageSync('token');
- return new Promise((resolve, reject) => {
- uni.request({
- url,
- data,
- method,
- header,
- withCredentials: true,
- success: res => {
- if (res.data.code === '0') {
- resolve(res.data.data)
- } else if (res.data.errCode === '999') {
- uni.showModal({
- title: "错误提示",
- content: res.data.msg,
- showCancel: false
- })
- reject(res.data)
- } else {
- uni.showToast({
- title: res.data.msg,
- icon: "none"
- })
- reject(res.data)
- }
- },
- fail: err => {
- reject(err)
- }
- })
- })
- }
|