network.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // method OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  2. function request(dever, url, param, callback, method, header)
  3. {
  4. if (!header) {
  5. var header = {};
  6. header['content-type'] = 'application/x-www-form-urlencoded';
  7. }
  8. for (var i in dever.config.host) {
  9. if (url.indexOf(i + '.') != -1) {
  10. url = url.replace(i + '.', dever.config.host[i]);
  11. break;
  12. }
  13. }
  14. wx.request(
  15. {
  16. url: url,
  17. data: param,
  18. method: method.toUpperCase(),
  19. header: header,
  20. success: function (res) {
  21. if (res.data.status == 1) {
  22. if (res.data.data.config) {
  23. dever.setSetting(res.data.data.config);
  24. }
  25. dever.stopPullDown();
  26. callback.success(res.data.data, res);
  27. } else {
  28. dever.alert(res.msg);
  29. }
  30. },
  31. fail: function () {
  32. //callback.fail();
  33. },
  34. complete: function () {
  35. //callback.complete();
  36. }
  37. })
  38. }
  39. module.exports = {
  40. request:request
  41. }