center.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. seajs.use(['arale/switchable/1.0.2/slide','arale/dialog/1.3.1/dialog'], function(Slide,Dialog) {
  2. var M = {
  3. ver : 1,
  4. os : 5,
  5. channel : "web",
  6. domain : "http://ms-api.duowan.com",
  7. recommendCache : {},
  8. typeId : 1,
  9. sortType : 1,
  10. //banner图
  11. getBanner : function(){
  12. var url = M.domain+"/home/banner.do";
  13. var data = {
  14. channel: M.channel,
  15. ver: M.ver,
  16. os: M.os
  17. };
  18. $.ajax({
  19. url: url,
  20. dataType: 'jsonp',
  21. data: data,
  22. success: function(ret){
  23. V.renderBanner(ret);
  24. },
  25. error: function(ret){
  26. M.getBanner();
  27. }
  28. });
  29. },
  30. //获取推荐类型
  31. getRecommenderType : function(){
  32. var url = M.domain+"/home/recommenderType.do";
  33. var data = {
  34. channel: M.channel,
  35. ver: M.ver,
  36. os: M.os,
  37. uid: M.uid,
  38. token: M.token
  39. };
  40. $.ajax({
  41. url: url,
  42. dataType: 'jsonp',
  43. data: data,
  44. success: function(ret){
  45. M.typeId = ret.data.list[0]["id"];
  46. // V.renderRecommenderType(ret);
  47. },
  48. error: function(ret){
  49. M.getRecommenderType();
  50. }
  51. });
  52. },
  53. //由推荐类型获取推荐游戏列表
  54. getRecommendByCT : function(){
  55. var url = M.domain+"/mobileGame/byCommonType.do";
  56. var data = {
  57. typeId: M.typeId,
  58. channel: M.channel,
  59. ver: M.ver,
  60. os: M.os,
  61. uid: M.uid,
  62. token: M.token,
  63. sortType : M.sortType
  64. };
  65. var gamaFlag = "type"+M.typeId+M.sortType;
  66. if (M.recommendCache.hasOwnProperty(gamaFlag)) {
  67. V.renderRecommender(M.recommendCache[gamaFlag]);
  68. return;
  69. }
  70. $.ajax({
  71. url: url,
  72. dataType: 'jsonp',
  73. data: data,
  74. success: function(ret){
  75. M.recommendCache[gamaFlag] = ret;
  76. V.renderRecommender(ret);
  77. },
  78. error: function(ret){
  79. M.getRecommendByCT();
  80. }
  81. });
  82. },
  83. //获取游戏下载排行
  84. getDownloadRank : function(){
  85. var url = M.domain+"/home/downloadRank.do";
  86. var data = {
  87. channel: M.channel,
  88. ver: M.ver,
  89. os: M.os,
  90. uid: M.uid,
  91. token: M.token
  92. };
  93. $.ajax({
  94. url: url,
  95. dataType: 'jsonp',
  96. data: data,
  97. success: function(ret){
  98. V.renderDownloadRank(ret);
  99. },
  100. error: function(ret){
  101. M.getDownloadRank();
  102. }
  103. });
  104. }
  105. }
  106. var V = {
  107. init : function(){
  108. M.os = commonUtil.checkPlatform();
  109. M.getBanner();
  110. // M.getRecommenderType();
  111. M.getRecommendByCT(1);
  112. M.getDownloadRank();
  113. },
  114. renderBanner : function(ret){
  115. var bannerTpl = __inline('../../tpl/simulatorBannar.tmpl');
  116. var dom = bannerTpl({
  117. data : ret.data.list
  118. });
  119. $("#bannerWrap").html(dom);
  120. if(!ret.data.list){
  121. return;
  122. }
  123. var slide1 = new Slide({
  124. element: '[data-role="slide-banner"]',
  125. classPrefix: null,
  126. activeTriggerClass: 'is-active',
  127. autoplay: true,
  128. effect: 'scrollx'
  129. }).render();
  130. },
  131. renderRecommenderType : function(ret){
  132. var list = ret.data.list;
  133. var len = list.length;
  134. var dom = "";
  135. for (var i=0; i<len; i++){
  136. dom += '<option value="'+list[i]["id"]+'">'+list[i]["typeName"]+'</option>';
  137. }
  138. $("#recommendTypeWrap").html(dom);
  139. M.getRecommendByCT($("#recommendTypeWrap").val());
  140. },
  141. renderRecommender : function(ret){
  142. var recommendTpl = __inline('../../tpl/simulatorRecommend.tmpl');
  143. var dom = recommendTpl({
  144. data : ret.data.list
  145. });
  146. $("#recommendWrap").html(dom);
  147. },
  148. renderDownloadRank : function(ret){
  149. var rankTpl = __inline('../../tpl/simulatorDlRank.tmpl');
  150. var dom = rankTpl({
  151. data : ret.data.list
  152. });
  153. $("#dlRankWrap").html(dom);
  154. },
  155. initBanner : function(){
  156. var slide = new Slide({
  157. element: '[data-role="slide-banner"]',
  158. classPrefix: null,
  159. activeTriggerClass: 'is-active',
  160. autoplay: false,
  161. effect: 'scrollx'
  162. }).render();
  163. },
  164. popUp : function(){
  165. var popTpl = __inline('../../tpl/simulatorDialog.tmpl');
  166. var dom = popTpl();
  167. var pop = new Dialog({
  168. contentType:4,
  169. content: dom,
  170. width:520,
  171. height: 320,
  172. classPrefix:"pop-center"
  173. }).show();
  174. //弹框
  175. $(".pop-center .btn-go").click(function(){
  176. $(this).parent().fadeOut().siblings().fadeIn();
  177. });
  178. $(".pop-center .btn-open").click(function(){
  179. pop.hide();
  180. });
  181. }
  182. }
  183. var C = {
  184. init : function(){
  185. //排行榜
  186. $("#dlRankWrap").on("mousemove",".item-rank",function(){
  187. $(this).addClass("active").siblings().removeClass("active");
  188. });
  189. //推荐位游戏
  190. var select = new commonUtil.Select({
  191. element : ".select-wrap",
  192. callback : function(val){
  193. M.sortType = val;
  194. M.getRecommendByCT();
  195. }
  196. });
  197. }
  198. }
  199. function initPop() {
  200. var timeout = setTimeout(function(){
  201. if(window.doneFlag) {
  202. if (window.popStatus==1) {
  203. V.popUp();
  204. }
  205. } else {
  206. initPop();
  207. }
  208. },200);
  209. }
  210. C.init();
  211. V.init();
  212. initPop();
  213. });