main.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. timeout:120000,
  13. success: function (res) {
  14. if (res.statusCode)
  15. common.checkError(res.statusCode);
  16. var data = res.data.result;
  17. callback(data);
  18. },
  19. fail: function () {
  20. wx.showToast({
  21. title: '系统忙请稍候',
  22. // image: "../images/universalpic_warning_white_126x120.png",
  23. duration: 3000
  24. });
  25. var err={};
  26. err.errCode=100;
  27. err.errMsg="网络错误";
  28. callback(null,err);
  29. },
  30. });
  31. }
  32. function postData(url, postData, callback) {
  33. console.log("加密前的结果为===", url);
  34. var url = common.Encrypt(url);
  35. //console.log("加密后的结果为===",url);
  36. wx.request({
  37. url: app.globalData.serverUrl + url,
  38. method: "POST",
  39. timeout:120000,
  40. data: postData,
  41. success: function (res) {
  42. if (res.statusCode)
  43. common.checkError(res.statusCode);
  44. var data = res.data.result;
  45. callback(data);
  46. },
  47. fail: function () {
  48. wx.showToast({
  49. title: '系统忙请稍候',
  50. duration: 3000
  51. });
  52. },
  53. });
  54. }
  55. function getLocalHost(callback) {
  56. if (!app.globalData.IsProduction) {
  57. var url = common.Encrypt("Ping");
  58. wx.request({
  59. url: app.globalData.serverUrlLocalhost + url,
  60. success: function (res) {
  61. app.globalData.serverUrl = app.globalData.serverUrlLocalhost;
  62. callback();
  63. },
  64. fail: function () {
  65. app.globalData.serverUrl = app.globalData.serverUrlServer;
  66. callback();
  67. },
  68. });
  69. } else {
  70. app.globalData.serverUrl = app.globalData.serverUrlServer;
  71. callback();
  72. }
  73. }
  74. function getWindowHeight() {
  75. var height = app.globalData.systemInfo.windowHeight;
  76. //console.log("app.globalData.systemInfo.windowHeight:" + app.globalData.systemInfo.windowHeight * 2);
  77. if (app.globalData.systemInfo.model) {
  78. if (height == 504 && (
  79. app.globalData.systemInfo.model.indexOf("iPhone 6<") >= 0 ||
  80. app.globalData.systemInfo.model.indexOf("iPhone 7<") >= 0 ||
  81. app.globalData.systemInfo.model.indexOf("iPhone 6s<") >= 0 ||
  82. app.globalData.systemInfo.model.indexOf("iPhone 5") >= 0 ||
  83. app.globalData.systemInfo.model.indexOf("iPhone SE") >= 0
  84. )) {
  85. height = 596;
  86. } else if (app.globalData.systemInfo.model.indexOf("iPad") >= 0) {
  87. height = 470;
  88. }
  89. }
  90. height = height * 2;
  91. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0) {
  92. height = height + 168;
  93. } else {
  94. height = height + 50;
  95. }
  96. //console.log("height:" + height);
  97. //var height = app.globalData.systemInfo.screenHeight * 2;
  98. return height;
  99. }
  100. function onSelect(obj,event,callback){
  101. var result=false;
  102. var str=event.currentTarget.dataset.object;
  103. var index=event.currentTarget.dataset.index;
  104. var clickType=event.currentTarget.dataset.clicktype;
  105. if (clickType=="checkbox"){
  106. if (obj.data[str][index].CSS)
  107. obj.data[str][index].CSS="";
  108. else{
  109. obj.data[str][index].CSS="Selected";
  110. result=true;
  111. }
  112. }
  113. else{
  114. for(var i=0;i<obj.data[str].length;i++){
  115. if (i==index){
  116. obj.data[str][i].CSS="Selected";
  117. }
  118. else{
  119. obj.data[str][i].CSS="";
  120. }
  121. }
  122. }
  123. obj.setData(obj.data);
  124. callback(obj,event,result);
  125. }
  126. module.exports = {
  127. getData: getData,
  128. postData: postData,
  129. getLocalHost: getLocalHost,
  130. getWindowHeight: getWindowHeight,
  131. onSelect:onSelect,
  132. }