main.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 getCollect(callback) {
  130. var that = this;
  131. var list=wx.getStorageSync("CollectList");
  132. if (list){
  133. if (callback)
  134. callback(list);
  135. }
  136. else{
  137. var id=app.globalData.userInfo.UserID;
  138. getData("GetMPSSchoolCollect?UserID="+id, function (data) {
  139. if (data) {
  140. wx.setStorageSync('CollectList', data);
  141. if (callback)
  142. callback(data);
  143. }
  144. else
  145. if (callback)
  146. callback(null);
  147. });
  148. }
  149. }
  150. function gotoMiniprogram(AppID,Path){
  151. wx.navigateToMiniProgram({
  152. appId: AppID,
  153. path: Path,
  154. extraData: {
  155. },
  156. success(res) {
  157. // 打开成功
  158. }
  159. });
  160. }
  161. function getProgramList() {
  162. return [
  163. {
  164. ID: 166,
  165. Name: "秒过",
  166. ImageUrl:"../images/ad_01.png",
  167. AppID: 'wx84b3feac6069eec3',
  168. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  169. },
  170. {
  171. ID: 164,
  172. Name: "口算",
  173. ImageUrl:"../images/ad_03.png",
  174. AppID: 'wxa5441bbf344692ba',
  175. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  176. },
  177. {
  178. ID: 105,
  179. Name: "计算题",
  180. ImageUrl:"../images/ad_04.png",
  181. AppID: 'wx1fef080f74481cbd',
  182. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  183. },
  184. {
  185. ID: 98,
  186. Name: "拼音",
  187. ImageUrl:"../images/ad_05.png",
  188. AppID: 'wx331e8dd070f01d0e',
  189. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  190. },
  191. {
  192. ID: 106,
  193. Name: "识字",
  194. ImageUrl:"../images/ad_06.png",
  195. AppID: 'wx313a8f2c0741efe1',
  196. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  197. },
  198. {
  199. ID: 99,
  200. Name: "自然拼读",
  201. ImageUrl:"../images/ad_07.png",
  202. AppID: 'wxb54a6d5aff836ee3',
  203. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  204. },
  205. {
  206. id: 90,
  207. Name: "注意力游戏",
  208. ImageUrl:"../images/ad_08.png",
  209. AppID: 'wxa5e33c61fe37dd01',
  210. Path: 'pages/index/index?SourceID=' + app.globalData.ProgramID,
  211. },
  212. ];
  213. }
  214. function goto(e) {
  215. if (app.globalData.IsGoto){
  216. app.globalData.IsGoto=false;
  217. setTimeout(function(){
  218. app.globalData.IsGoto=true;
  219. },1000);
  220. var url = e.currentTarget.dataset.url;
  221. wx.navigateTo({
  222. url: './' + url,
  223. });
  224. }
  225. }
  226. module.exports = {
  227. getData: getData,
  228. postData: postData,
  229. getLocalHost: getLocalHost,
  230. getWindowHeight: getWindowHeight,
  231. onSelect: onSelect,
  232. returnTop:returnTop,
  233. getCollect: getCollect,
  234. gotoMiniprogram:gotoMiniprogram,
  235. getProgramList:getProgramList,
  236. goto:goto,
  237. }