| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import { baseUrl } from "./config.js" |
| | | export const http = function (options) { |
| | | { |
| | | return new Promise((resolve, reject) => { |
| | | let token = uni.getStorageSync('token') |
| | | // å¨ç»å½çæ¶åéè¦å¨å token uni.setStorageSync("authorization","è¿éæ¯ç»å½è·åçtokenå¼") |
| | | |
| | | // uni.showLoading({ |
| | | // title:"å è½½ä¸..." |
| | | // }) |
| | | uni.showLoading({ |
| | | title: 'å è½½ä¸', |
| | | mask: true |
| | | }) |
| | | uni.request({ |
| | | url: baseUrl + options.url, |
| | | data: options.data || {}, |
| | | method: options.method || 'GET', |
| | | header: options.header || { |
| | | // æ ¹æ®å®é
æ¥å£è®¾è®¡ key å token æè
authorization |
| | | token: token, |
| | | "content-type": 'application/json' |
| | | }, |
| | | success: (res) => { |
| | | let data = res.data |
| | | // æ§å¶å°æ¾ç¤ºæ°æ®ä¿¡æ¯ |
| | | uni.hideLoading() |
| | | // ç»å½è¿æ |
| | | if (data.code === 401) { |
| | | uni.navigateTo({ |
| | | url: '/packageA/loginAgain/loginAgain' |
| | | }) |
| | | } |
| | | if (data.code !== 200) { |
| | | uni.showToast({ |
| | | title: data.message, |
| | | icon: "none", |
| | | duration: 2000 |
| | | }) |
| | | } |
| | | resolve(data) |
| | | // return response.data |
| | | }, |
| | | fail: (err) => { |
| | | // 页é¢ä¸å¼¹æ¡æ¾ç¤ºå¤±è´¥ |
| | | uni.showToast({ |
| | | title: 'è¯·æ±æ¥å£å¤±è´¥' |
| | | }) |
| | | // è¿åéè¯¯æ¶æ¯ |
| | | reject(err) |
| | | uni.hideLoading() |
| | | return Promise.reject(err) |
| | | }, |
| | | catch: (e) => { |
| | | console.log(e) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | } |