main.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. function onSelect(obj,event,callback){
  97. var result=false;
  98. var str=event.currentTarget.dataset.object;
  99. var index=event.currentTarget.dataset.index;
  100. var clickType=event.currentTarget.dataset.clicktype;
  101. if (clickType=="checkbox"){
  102. if (obj.data[str][index].CSS)
  103. obj.data[str][index].CSS="";
  104. else{
  105. obj.data[str][index].CSS="Selected";
  106. result=true;
  107. }
  108. }
  109. else{
  110. for(var i=0;i<obj.data[str].length;i++){
  111. if (i==index){
  112. obj.data[str][i].CSS="Selected";
  113. }
  114. else{
  115. obj.data[str][i].CSS="";
  116. }
  117. }
  118. }
  119. obj.setData(obj.data);
  120. callback(obj,event,result);
  121. }
  122. function returnTop() {
  123. if (wx.canIUse('pageScrollTo')) {
  124. wx.pageScrollTo({
  125. scrollTop: 0
  126. });
  127. }
  128. }
  129. function getBaiduToken() {
  130. var that = this
  131. //调用登录接口
  132. wx.login({
  133. success: function (res0) {
  134. getData('GetBaiduToken20220922?ProgramID='+app.globalData.ProgramID+'&Code='+res0.code, function (data) {
  135. if (data) {
  136. app.globalData.BaiduToken = data;
  137. //console.log(app.globalData.BaiduToken);
  138. }
  139. });
  140. }
  141. });
  142. }
  143. function getCollect(callback) {
  144. var that = this;
  145. var list=wx.getStorageSync("CollectList");
  146. if (list){
  147. if (callback)
  148. callback(list);
  149. }
  150. else{
  151. var id=app.globalData.userInfo.UserID;
  152. getData("GetMPSSchoolCollect?UserID="+id, function (data) {
  153. if (data) {
  154. wx.setStorageSync('CollectList', data);
  155. if (callback)
  156. callback(data);
  157. }
  158. else
  159. if (callback)
  160. callback(null);
  161. });
  162. }
  163. }
  164. function gotoMiniprogram(SourceID){
  165. wx.navigateToMiniProgram({
  166. appId: "wx84b3feac6069eec3",
  167. path: "pages/index/index?SourceID="+SourceID,
  168. extraData: {
  169. },
  170. success(res) {
  171. // 打开成功
  172. }
  173. });
  174. }
  175. function goto(e) {
  176. if (app.globalData.IsGoto){
  177. app.globalData.IsGoto=false;
  178. setTimeout(function(){
  179. app.globalData.IsGoto=true;
  180. },1000);
  181. var url = e.currentTarget.dataset.url;
  182. wx.navigateTo({
  183. url: './' + url,
  184. });
  185. }
  186. }
  187. module.exports = {
  188. getData: getData,
  189. postData: postData,
  190. getLocalHost: getLocalHost,
  191. getWindowHeight: getWindowHeight,
  192. onSelect: onSelect,
  193. returnTop:returnTop,
  194. getBaiduToken: getBaiduToken,
  195. getCollect: getCollect,
  196. gotoMiniprogram:gotoMiniprogram,
  197. goto:goto,
  198. }