main.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import common from '../utils/util';
  2. import constant from '../utils/constant';
  3. var app = getApp();
  4. var dataSendTimeout = 0;
  5. function getData(url, callback) {
  6. if (!app.globalData.IsProduction)
  7. console.log("加密前的结果为===", url);
  8. var url = common.Encrypt(url);
  9. //console.log("加密后的结果为===",url);
  10. wx.request({
  11. url: app.globalData.serverUrl + url,
  12. success: function (res) {
  13. if (res.statusCode)
  14. common.checkError(res.statusCode);
  15. var data = res.data.result;
  16. callback(data);
  17. },
  18. fail: function () {
  19. wx.showToast({
  20. title: '系统忙请稍候',
  21. // image: "../images/universalpic_warning_white_126x120.png",
  22. duration: 3000
  23. });
  24. var err={};
  25. err.errCode=100;
  26. err.errMsg="网络错误";
  27. callback(null,err);
  28. },
  29. });
  30. }
  31. function postData(url, postData, callback) {
  32. console.log("加密前的结果为===", url);
  33. var url = common.Encrypt(url);
  34. //console.log("加密后的结果为===",url);
  35. wx.request({
  36. url: app.globalData.serverUrl + url,
  37. method: "POST",
  38. data: postData,
  39. success: function (res) {
  40. if (res.statusCode)
  41. common.checkError(res.statusCode);
  42. var data = res.data.result;
  43. callback(data);
  44. },
  45. fail: function () {
  46. wx.showToast({
  47. title: '系统忙请稍候',
  48. duration: 3000
  49. });
  50. },
  51. });
  52. }
  53. function getLocalHost(callback) {
  54. if (!app.globalData.IsProduction) {
  55. var url = common.Encrypt("Ping");
  56. wx.request({
  57. url: app.globalData.serverUrlLocalhost + url,
  58. success: function (res) {
  59. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  60. callback();
  61. },
  62. fail: function () {
  63. app.globalData.serverUrl = app.globalData.serverUrlServer;
  64. callback();
  65. },
  66. });
  67. } else {
  68. app.globalData.serverUrl = app.globalData.serverUrlServer;
  69. callback();
  70. }
  71. }
  72. function getWindowHeight() {
  73. var height = app.globalData.systemInfo.windowHeight;
  74. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  75. if (app.globalData.systemInfo.model) {
  76. if (height == 504 && (
  77. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 ||
  78. app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 ||
  79. app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 ||
  80. app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 ||
  81. app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  82. )) {
  83. height = 596;
  84. } else if (app.globalData.systemInfo.model.indexOf("iPad") >= 0) {
  85. height = 470;
  86. }
  87. }
  88. height = height * 2;
  89. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  90. height = height + 168;
  91. } else {
  92. height = height + 50;
  93. }
  94. //console.log("height:" + height);
  95. //var height = app.globalData.systemInfo.screenHeight * 2;
  96. return height;
  97. }
  98. module.exports = {
  99. getData: getData,
  100. postData: postData,
  101. getLocalHost: getLocalHost,
  102. getWindowHeight: getWindowHeight,
  103. }