12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import $ from "../utils/Tool.js"
- // const test = "http://192.168.12.20:50009"; //192.168.12.20 172.16.36.245
- const API_BASE_URL = "https://duoduoenv.sagacloud.cn";
- function get(url, data = {},testenv){
- let _url;
- if(testenv){
- _url = test + url.replace('/server','');
- }else{
- _url = API_BASE_URL + url;
- }
- data = Object.assign(data, {
- pubname: "sagacare",
- openid:$.storage.get('openId')
- });
- return new Promise(function (resolve, reject) {
- wx.request({
- url: _url,
- method: 'GET',
- data: data,
- header: {
- 'content-type': 'application/json'
- },
- success: function success(request) {
- resolve(request.data);
- },
- fail: function fail(error) {
- wx.showModal({
- title: '网络错误',
- content: '网络出错,请刷新重试',
- showCancel: false
- })
- reject(error);
- },
- complete: function complete() {
- }
- });
- });
- }
- function post(url, data = {},testenv) {
- let _url;
- if(testenv){
- _url = test + url.replace('/server','');
- }else{
- _url = API_BASE_URL + url;
- }
- data = Object.assign(data, {
- openid:$.storage.get('openId')
- })
- _url = _url + `?pubname=sagacare&openid=${$.storage.get('openId')}`
- if (data.flag) {
- _url = _url + `&flag=${data.flag}`
- }
- return new Promise(function (resolve, reject) {
- wx.request({
- url: _url,
- method: 'POST',
- data: data,
- header: {
- 'content-type': 'application/json'
- },
- success: function success(request) {
- resolve(request.data);
- },
- fail: function fail(error) {
- wx.showModal({
- title: '网络错误',
- content: '网络出错,请刷新重试',
- showCancel: false
- })
- reject(error);
- },
- complete: function complete() {
- }
- });
- });
- };
- module.exports = {
- http:{get,post}
- }
|