main.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. function onSelect(obj,event,callback){
  99. var result=false;
  100. var str=event.currentTarget.dataset.object;
  101. var index=event.currentTarget.dataset.index;
  102. var clickType=event.currentTarget.dataset.clicktype;
  103. if (clickType=="checkbox"){
  104. if (obj.data[str][index].CSS)
  105. obj.data[str][index].CSS="";
  106. else{
  107. obj.data[str][index].CSS="Selected";
  108. result=true;
  109. }
  110. }
  111. else{
  112. for(var i=0;i<obj.data[str].length;i++){
  113. if (i==index){
  114. obj.data[str][i].CSS="Selected";
  115. }
  116. else{
  117. obj.data[str][i].CSS="";
  118. }
  119. }
  120. }
  121. obj.setData(obj.data);
  122. callback(obj,event,result);
  123. }
  124. module.exports = {
  125. getData: getData,
  126. postData: postData,
  127. getLocalHost: getLocalHost,
  128. getWindowHeight: getWindowHeight,
  129. onSelect:onSelect,
  130. }