| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- export default function request(config = {}) {
- let {
- url,
- data = {},
- method = "GET",
- header = {}
- } = config
- // 拼接url TODO 这里要修改,改成不同环境取不同的url
- // url = '/api' + url;
- url = 'http://localhost:8080' + 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)
- }
- })
- })
- }
|