network.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. var log = param;
  21. log.url = url;
  22. self.set('url', log);
  23. wx.request(
  24. {
  25. url: url,
  26. data: param,
  27. method: method.toUpperCase(),
  28. header: header,
  29. success: function (res) {
  30. if (res.data.status == 1) {
  31. if (res.data.data.setting) {
  32. self.dever.setSetting(self, res.data.data.setting);
  33. }
  34. self.set('loading', false);
  35. callback.success(res.data.data, res);
  36. } else {
  37. self.dever.alert(res.msg);
  38. }
  39. },
  40. fail: function () {
  41. //callback.fail();
  42. },
  43. complete: function () {
  44. //callback.complete();
  45. }
  46. })
  47. }
  48. module.exports = {
  49. request:request
  50. }