main.js 3.0 KB

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