| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import app from '../../App.vue';
- // http://117.ci2.cn:8080/
- //http://api.order.ci2.cn/ //98
- //http://api.test.order.ci2.cn/
- const baseurl="http://api.order.ci2.cn/";
- console.log(app.globalData)
- const request = (url, options) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: `${baseurl}${url}`,
- method: options.method,
- // data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
- data:options.data,
- header: {
- 'content-Type': 'application/json',
- "Authorization": uni.getStorageSync('userInfo').Authorization ? uni.getStorageSync('userInfo').Authorization:''
- },
- success(res) {
- if (res.data.code === "success"||res.data.status) {
- // 返回data
- resolve(res.data)
- } else {
- if(res.data.code=='U204'){
- uni.reLaunch({
- url:'/pages/login/newlogin'
- })
- }
- reject(res.data)
- }
- },
- fail(err) {
-
- console.log(err)
- reject(err.data)
- }
- })
- })
- }
- const get = (url, options = {}) => {
- return request(url, { method: 'GET', data: options })
- }
- const post = (url, options) => {
- return request(url, { method: 'POST', data: options })
- }
- const put = (url, options) => {
- return request(url, { method: 'PUT', data: options })
- }
- // 不能声明DELETE(关键字)
- const remove = (url, options) => {
- return request(url, { method: 'DELETE', data: options })
- }
- module.exports = {
- get,
- post,
- put,
- remove
- }
|