1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- let baseUrl = null
- let oldUrl = null
- const {
- miniProgram: {
- envVersion
- }
- } = wx.getAccountInfoSync();
- if (envVersion == 'develop') {
- baseUrl = 'https://reader-api.efunbox.cn/wx'
- oldUrl = 'https://reader-api.efunbox.cn'
- } else {
- baseUrl = 'https://reader-api.ai160.com/wx'
- oldUrl = 'https://reader-api.ai160.com'
- }
- function request(url, method, data, oldBaseUrl = false) {
- let header = {
- 'uid': wx.getStorageSync('uid') || ''
- }
- if (getApp() && getApp().globalData.requestTasks) {
- try {
- //getApp() 获取全局app对象内容
- getApp().globalData.requestTasks.abort()
- } catch (e) {
- console.error(e)
- }
- }
- return new Promise((reslove, reject) => {
- wx.request({
- url: oldBaseUrl ? oldUrl + url : baseUrl + url,
- method: method,
- data: data,
- header: header,
- success: (result) => {
- let {
- data: {
- code,
- data = {},
- message
- }
- } = result
- if (code == '200') {
- reslove(data)
- } else if (code == '1102' || code == '1204') {
- wx.clearStorage()
- } else {
- console.log(message);
- // reject(message)
- }
- },
- fail: (res) => {
- console.error(res)
- reject(res)
- },
- })
- })
- }
- module.exports = {
- request,
- }
|