diff --git a/miniprogram/app.js b/miniprogram/app.js index 5b0b455..33494b1 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -25,7 +25,7 @@ App({ globalData: { paramDeptId:'', userProjectId:'', - appId: "wxc44b5d588f599758", + appId: "wxc44b5d588f599758", // 智慧工地后台接口访问域名 // reqUrl:"http://wxw.ngrok.makalu.cc", //reqUrl:'https://jaapplets.makalu.cc', @@ -95,6 +95,7 @@ App({ "appId":"wxc44b5d588f599758", }, success:(res)=>{ + wx.setStorageSync("token","eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImRjYzEwMTI5LWM0Y2ItNDAyMS1iNzEzLTFlOTMzODdmOWEwYyJ9.zpE5EZ7Zz0yj8Z7lJTUUnASBy7wXqVG2eZlxOu7rTHz0oeDyJY8FO5uSkWMwkQvK_Uk3tc9qt5jbtc46BCN1vQ"); wx.setStorageSync('openId', res.data.openid) } }) diff --git a/miniprogram/utils/api.js b/miniprogram/utils/api.js new file mode 100644 index 0000000..4e9e9f7 --- /dev/null +++ b/miniprogram/utils/api.js @@ -0,0 +1,40 @@ +function request (url, method, data, header = {}) { + wx.showLoading({ + title: '加载中' + }) + return new Promise((resolve, reject) => { + wx.request({ + url: app.globalData.reqUrl+ url, + method: method, + data: data, + header: { + 'content-type': 'application/json', + 'Authorization': 'Bearer '+wx.getStorageSync('cookie').toString(), + ...header + }, + success: function (res) { + wx.hideLoading() + resolve(res.data) + }, + fail: function (error) { + wx.hideLoading() + reject(error) + }, + complete: function () { + wx.hideLoading() + } + }) + }) + } + function get (obj) { + return request(obj.url, 'GET', obj.data) + } + function post (obj) { + return request(obj.url, 'POST', obj.data) + } + + export default { + request, + get, + post + } \ No newline at end of file