108 lines
2.4 KiB
JavaScript
108 lines
2.4 KiB
JavaScript
let app = getApp()
|
|
const websiteUrl = 'https://passport.gter.net';
|
|
|
|
const wxpost = function (url, data = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
var authorization = wx.getStorageSync('Authorization');
|
|
wx.request({
|
|
url: websiteUrl + url,
|
|
method: 'POST',
|
|
data: data,
|
|
header: {
|
|
'content-type': 'application/json;charset=utf-8',
|
|
Authorization: authorization,
|
|
envVersion: getApp().globalData['envVersion'],
|
|
},
|
|
success: (res) => {
|
|
|
|
if (res.data.code == 200) {
|
|
resolve(res.data)
|
|
} else if (res.data.code == 401) {
|
|
// 需要授权
|
|
// console.log(app)
|
|
app.globalData.user.uid = 0;
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: res.data.message,
|
|
})
|
|
reject(res.data)
|
|
} else {
|
|
|
|
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: res.data.message,
|
|
complete: function (res) {
|
|
if (url == '/peer/topical/subjectDetails') {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
reject(res.data)
|
|
}
|
|
|
|
},
|
|
fail(res) {
|
|
reject(res)
|
|
}
|
|
});
|
|
})
|
|
|
|
}
|
|
|
|
const wxget = function (url, data = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
var authorization = wx.getStorageSync('authorization');
|
|
wx.request({
|
|
url: websiteUrl + url,
|
|
method: 'GET',
|
|
data: data,
|
|
header: {
|
|
authorization: authorization,
|
|
envVersion: getApp().globalData['envVersion'],
|
|
},
|
|
success: (res) => {
|
|
if (res.data.code == 200) {
|
|
resolve(res.data)
|
|
} else if (res.data.code == 401) {
|
|
// 需要授权
|
|
// console.log(app)
|
|
app.globalData.user.uid = 0;
|
|
wx.showToast({
|
|
icon: 'none',
|
|
title: res.data.message
|
|
})
|
|
|
|
// authorize().then(res => {
|
|
|
|
// })
|
|
reject(res)
|
|
} else {
|
|
wx.hideLoading()
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: res.data.message,
|
|
})
|
|
reject(res.data)
|
|
}
|
|
|
|
},
|
|
fail(res) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: res,
|
|
})
|
|
reject(res)
|
|
}
|
|
});
|
|
})
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
wxpost,
|
|
wxget
|
|
} |