network.js 1.4 KB

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