request.js 3.13 KB
Newer Older
1
import store from '../store/index'
程智春 committed
2 3 4

console.log(store.state.mixid,'store.state')
let shopMixid = store.state.mixid;
程默 committed
5

程默 committed
6 7 8
// wx.getStore
export async function requestGET(url, options) {

程默 committed
9 10 11 12 13 14
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            data: options,
            method: "GET",
            header: {
程默 committed
15
                "Shop-Mixid": store.state.mixid,
李嘉林 committed
16
                "Offline-Shop-Code": store.state.offlineShopCode,
程智春 committed
17
                "Authorization": wx.getStorageSync('sessionid') || "",
程智春 committed
18 19
                "Region-id" : wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).systemRegionId : '',
              "Area-Id": wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).id : '',
程智春 committed
20
                // "dubbo-tag": "ljx"
程默 committed
21 22 23 24 25 26 27 28 29 30
            },
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            }
        })
    })
}
程默 committed
31

程默 committed
32
export async function requestPOST(url, options) {
程默 committed
33 34 35 36 37 38
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            data: options,
            method: "POST",
            header: {
程默 committed
39
                "Shop-Mixid": store.state.mixid,
40
                "Authorization": wx.getStorageSync('sessionid') || "",
李嘉林 committed
41
                "Offline-Shop-Code": store.state.offlineShopCode,
42
                "openId": wx.getStorageSync("openid") || '',
程智春 committed
43 44
              "Region-id": wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).systemRegionId : '',
              "Area-Id": wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).id : '',
程智春 committed
45
                // "dubbo-tag": "ljx"
程默 committed
46 47 48 49 50 51 52 53 54 55 56
            },
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            }
        })
    })
}

程默 committed
57
export function requestPOST1(url, options) {
程默 committed
58 59 60 61 62
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            data: options,
            method: "POST",
程默 committed
63 64
            header: {
                "Content-Type": "application/x-www-form-urlencoded",
程默 committed
65
                "Shop-Mixid": store.state.mixid,
66
                Authorization: wx.getStorageSync('sessionid') || "",
李嘉林 committed
67
                "Offline-Shop-Code": store.state.offlineShopCode,
程智春 committed
68 69
              "Region-id": wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).systemRegionId : '',
              "Area-Id": wx.getStorageSync('location') ? JSON.parse(wx.getStorageSync('location')).id : '',
程智春 committed
70
                // "dubbo-tag": "ljx"
程默 committed
71
            },
程默 committed
72 73 74 75 76 77 78 79
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            }
        })
    })
程默 committed
80 81
}

程默 committed
82 83 84 85 86 87 88 89 90 91 92 93
// function getHeader() {
//     let sessionid = wx.getStorageSync('sessionid');
//     let header = {
//         "Content-Type": "application/x-www-form-urlencoded",
//         "Shop-Mixid": shopMixid,
//         Authorization: sessionid
//     };
//     // if (!sessionid) {
//     //     delete header.Authorization
//     // }
//     return header
// }