12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const request = function (url = "", options) {
- const baseUrl = getApp().globalData.http.baseUrl + "/yos/rest/index" + url;
- options.data.accesstoken = wx.getStorageSync('userMsg').token;
- return new Promise((resolve, reject) => {
- wx.request({
- url: baseUrl,
- method: options.method,
- data: options.method == "GET" ? options.data : JSON.stringify(options.data),
- // header这里根据业务情况自行选择需要还是不需要
- header: {
- "Content-Type": 'application/json;charset=UTF-8'
- },
- success: (res) => {
- if (res.data.code == -1) {
- wx.showToast({
- title: res.data.msg,
- icon: 'none'
- })
- resolve(res.data)
- } else if (res.data.code == 0) {
- wx.showToast({
- title: res.data.msg,
- duration: 3000,
- icon: 'none'
- })
- resolve(res.data)
- } else {
- resolve(res.data)
- }
- },
- fail: (err) => {
- reject(err)
- }
- })
- })
- }
- module.exports = {
- get(url, data) {
- return request(url, {
- method: "GET",
- data
- })
- },
- //封装post方法
- post(url, data) {
- return request(url, {
- method: "POST",
- data
- })
- }
- }
|