record_v3.0.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. window.staticImg = "http://static.lolbox.duowan.com/images";
  2. $(function() {
  3. var recordDetailTpl = __inline("../tpl/recordDetail.tmpl");
  4. var recordDataLayerTpl = __inline("../tpl/recordDataLayer.tmpl");
  5. var boxContentTpl = __inline("../tpl/boxContent.tmpl");
  6. jQuery.cookie = function (name, value, options) {
  7. if (typeof value != 'undefined') { // name and value given, set cookie
  8. options = options || {};
  9. if (value === null) {
  10. value = '';
  11. options.expires = -1;
  12. }
  13. var expires = '';
  14. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  15. var date;
  16. if (typeof options.expires == 'number') {
  17. date = new Date();
  18. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  19. } else {
  20. date = options.expires;
  21. }
  22. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  23. }
  24. var path = options.path ? '; path=' + options.path : '';
  25. var domain = options.domain ? '; domain=' + options.domain : '';
  26. var secure = options.secure ? '; secure' : '';
  27. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  28. } else { // only name given, get cookie
  29. var cookieValue = '';
  30. if (document.cookie && document.cookie != '') {
  31. var cookies = document.cookie.split(';');
  32. for (var i = 0; i < cookies.length; i++) {
  33. var cookie = jQuery.trim(cookies[i]);
  34. // Does this cookie string begin with the name we want?
  35. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  36. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  37. break;
  38. }
  39. }
  40. }
  41. return cookieValue;
  42. }
  43. };
  44. var Record = function() {
  45. this.baseUrl = "http://api.lolbox.duowan.com/api/v3/player/";
  46. this.boxServerName = encodeURIComponent($.cookie("boxServerName"));
  47. this.boxPlayerName = encodeURIComponent($.cookie("boxPlayerName"));
  48. this.serverName = encodeURIComponent(getURLParam("serverName"));
  49. this.playerName = encodeURIComponent(getURLParam("playerName"));
  50. this.historyId = getURLParam("historyId");
  51. this.gameZone = getURLParam("gameZone");
  52. this.userId = getURLParam("userId");
  53. this.boxUserId = $.cookie("boxUserId");
  54. this.championId = getURLParam("championId");
  55. this.hero = getURLParam("hero");
  56. this.favorate = 0;
  57. this.suffix = "&serverName=" + this.serverName + "&playerName=" + this.playerName;
  58. if(this.hero) this.suffix += "&hero=" + this.hero;
  59. this.p = 1;//页码
  60. this.listData = null;//缓存list列表数据到本地
  61. this.$loading = $("#loading");
  62. this.$boxContent = $(".recent-record__list");
  63. this.$recordDetail = $("#recordDetail");
  64. this.$recordDataLayer = $("#recordDataLayer");
  65. this.$collect = $("#collect");
  66. this.$recordTarget = $("#recordTarget");
  67. this.$body = $("body");
  68. this.$wanScriptName = $("#wanScriptName");
  69. this.navStatus = 1; // 默认个人成就
  70. //饼图默认设置
  71. this.highchartsOpts = {
  72. chart: {
  73. type: 'pie'
  74. },
  75. plotOptions: {
  76. series: {
  77. dataLabels: {
  78. enabled: false
  79. }
  80. }
  81. },
  82. tooltip: {
  83. enabled:false
  84. },
  85. drilldown: {
  86. series: null
  87. }
  88. };
  89. this.init();
  90. };
  91. Record.prototype = {
  92. constructor: Record,
  93. init: function() {
  94. var self = this;
  95. self.bindEvents();
  96. self._getListData();
  97. $('#modeTabs>li').each(function(item) {
  98. var pageName = $(this).data('name');
  99. $(this).find('a').attr('href', pageName + '.html?serverName=' + self.serverName + '&playerName=' + self.playerName + '&userId=' + self.userId + '&gameZone=' + self.gameZone);
  100. });
  101. // 非本人才显示返回按钮
  102. if ( this.boxUserId != this.userId ) {
  103. $('.common-page__goBack').css('visibility', 'visible');
  104. }
  105. },
  106. // 事件绑定
  107. bindEvents: function() {
  108. var self = this;
  109. //我的收藏/TA的收藏r
  110. this.$collect.on('click', function(e) {
  111. e.preventDefault();
  112. var filterData = [];
  113. for(var i=0,len=self.listData.length;i<len;i++) {
  114. var item = self.listData[i];
  115. if(item.collect) {
  116. filterData.push(item);
  117. }
  118. }
  119. self.listData = filterData;
  120. var renderArr = filterData.slice(0, 8);
  121. self.$recordDetail.html('');
  122. self._renderList(renderArr);
  123. });
  124. //分页上一页、下一页点击
  125. this.$body.delegate(".zj-page .zj-s", "click", function(e) {
  126. e.preventDefault();
  127. var page = $(this).attr("data-page");
  128. if(page == 0 || page == (self.totalPage + 1)) return;
  129. self.p = page;
  130. self._renderList(self.listData.slice((page - 1) * 7, page * 7));
  131. });
  132. //分页点击去到哪一页
  133. this.$body.delegate(".zj-page .go-page", "click", function(e) {
  134. e.preventDefault();
  135. var page = $(".zj-cur").val();
  136. if(page <= 0 || page >= (self.totalPage + 1)) return;
  137. self.p = page;
  138. self._renderList(self.listData.slice((page - 1) * 7, page * 7));
  139. });
  140. //enter
  141. this.$body.delegate(".zj-page .zj-cur", "keyup", function(e) {
  142. if(event.keyCode==13) {
  143. var page = $(this).val();
  144. if(page <= 0 || page >= (self.totalPage + 1)) return;
  145. self.p = page;
  146. self._renderList(self.listData.slice((page - 1) * 8, page * 8));
  147. }
  148. });
  149. //点击左边栏li item时拿到其matchId并获取其对应detail数据
  150. this.$body.delegate(".l-box .recent-list li", "click", function(e) {
  151. e.preventDefault();
  152. var id = $(this).attr("data-id"),
  153. name = $(this).attr("data-name"),
  154. enname = $(this).attr("data-enname");
  155. $(this).addClass("hover").siblings().removeClass("hover");
  156. self.matchId = id;
  157. self._getDetailDataDone(id, name, enname);
  158. });
  159. //收藏/取消收藏
  160. this.$body.delegate(".fav-btn", "click", function(e) {
  161. e.preventDefault();
  162. e.stopPropagation();
  163. var _this = this;
  164. var isAdd = $(this).hasClass("add-fav");
  165. var action = isAdd ? 'collect' : 'delete';
  166. var id = $(this).attr("data-id");
  167. var url = "http://api.lolbox.duowan.com/api/v2/player/" + self.gameZone + "/" + self.userId + "/game/" + action + "/?game_id=" + id;
  168. $.ajax({
  169. url: url,
  170. type: 'get',
  171. dataType: 'jsonp',
  172. success: function(result) {
  173. if ( result ) {
  174. if( isAdd ) {
  175. $( _this ).removeClass("add-fav").addClass("fav").attr("title", "点击删除此收藏");
  176. } else {
  177. if( confirm('确认删除此收藏吗?') ) {
  178. $( _this ).removeClass("fav").addClass("add-fav").attr("title", "点击收藏比赛");
  179. }
  180. }
  181. }
  182. }
  183. });
  184. });
  185. this.$body.delegate(".zj-table tr a", "click", function(e) {
  186. var userid = $(this).attr("user-id");
  187. var sn = $(this).attr("game-zone");
  188. var pn = $(this).attr("data-playerName");
  189. if(!userid || userid == 0) {
  190. location.href = 'http://lolbox.duowan.com/staticPub/v3.1/playerList.html?sn=' + sn + '&pn=' + encodeURIComponent(pn);
  191. return false;
  192. }
  193. })
  194. // 详细战绩&个人成就导航
  195. this.$body.delegate(".record-nav li", "click", function(e) {
  196. e.preventDefault();
  197. e.stopPropagation();
  198. self.navStatus = $(this).index(); // 记录导航状态
  199. var tab = $(this).data('tab');
  200. $(this).addClass('active').siblings().removeClass('active');
  201. $('.tab-content').hide();
  202. $('#' + tab).show();
  203. // 导航点击统计
  204. var curIndex = $(this).index();
  205. var StatId = [
  206. {'id': 'click/grzj', 'desc': '点击/个人战绩'},
  207. {'id': 'click/xxzj', 'desc': '点击/详细战绩'}
  208. ];
  209. try{
  210. window.external.data_report( StatId[curIndex].id, StatId[curIndex].desc );
  211. }catch(e){}
  212. });
  213. // 返回上一页
  214. $('.common-page__goBack').on('click', function() {
  215. window.history.back();
  216. return false;
  217. });
  218. // 刷新按钮
  219. $('.common-page__reflash').on('click', function() {
  220. location.reload();
  221. });
  222. /*鼠标悬浮在用户头像的弹窗*/
  223. $(document).on('mouseenter', '.history-recordTab__userIcon', function() {
  224. self.userRecordDetail();
  225. }).on('mouseleave', '.history-recordTab__userIcon', function() {
  226. setTimeout(function() {
  227. var isHover = $('.userRecordDetail').hasClass('hover');
  228. if ( !isHover ) {
  229. $('.userRecordDetail').hide();
  230. }
  231. }, 0.5*1000)
  232. });
  233. $(document).on('mouseenter', '.userRecordDetail', function() {
  234. $(this).addClass('hover');
  235. }).on('mouseleave', '.userRecordDetail', function() {
  236. $(this).removeClass('hover').hide();
  237. });
  238. // 近期战绩下拉筛选列表 - 导航
  239. $(document).on('click', '.recent-nav__input', function() {
  240. $(this).toggleClass('on');
  241. $('.recent-nav__list').toggle();
  242. })
  243. // 近期战绩下拉筛选列表 - 选项
  244. $(document).on('click', '.recent-nav__list li', function(e) {
  245. e.preventDefault();
  246. var key = $(this).find('a').html();
  247. $('.recent-nav__input')
  248. .removeClass('on')
  249. .find('.key').html(key);
  250. $('.recent-nav__list').hide();
  251. self._getListData(key);
  252. })
  253. },
  254. // 获取左侧比赛列表
  255. _getListData: function(type) {
  256. var self = this;
  257. var game_type = {'匹配赛': 3, '排位赛': 4, '大乱斗': 6};
  258. var url = this.baseUrl + this.gameZone + '/'+this.userId+'/game_recent/';
  259. var args = {};
  260. self.championId && ( args.champion_id = self.championId );
  261. game_type[type] && ( args.game_type = game_type[type] );
  262. var boxUrlData = $.cookie("boxUrlData");
  263. var wsSecret = boxUrlData.split("&")[1];
  264. var ts = boxUrlData.split("&")[0];
  265. args['wsSecret'] = wsSecret;
  266. args['ts'] = ts;
  267. $.ajax({
  268. url: url,
  269. data: args,
  270. type: 'GET',
  271. dataType: 'jsonp',
  272. success: function(data, status, xhr) {
  273. if (xhr && xhr.status && xhr.status == 200) {
  274. var list = data.game_list;
  275. var renderArr = list.slice(0, 7);
  276. self.isSelf = data.is_myself;
  277. self.listData = list;
  278. self.totalPage = Math.ceil(list.length / 7);
  279. self._renderList(renderArr);
  280. //从数组第一个元素中获取到serverName的中文名
  281. var sn_cn = list[0] ? list[0].game_zone.alias : null;
  282. var crumbs = sn_cn ? decodeURIComponent(self.playerName) + "(" + sn_cn + ")" : decodeURIComponent(self.playerName);
  283. self.$recordTarget.attr("href", "playerDetail.html?serverName=" + self.serverName + "&playerName=" + self.playerName + "&userId=" + self.userId + "&gameZone=" + self.gameZone)
  284. .html(crumbs);
  285. }
  286. }
  287. });
  288. },
  289. // 获取玩家比赛详情
  290. _getDetailData: function(id) {
  291. var url = this.baseUrl + this.gameZone + "/"+this.userId+"/game/"+ id + '/';
  292. var args = {};
  293. // var boxUrlData = window.external.PostGameId(this.gameZone, this.userId, id);
  294. // var wsSecret = boxUrlData.split("&")[1];
  295. // var ts = boxUrlData.split("&")[0];
  296. // args['wsSecret'] = wsSecret;
  297. // args['ts'] = ts;
  298. return $.ajax({
  299. url: url,
  300. data: args,
  301. type: 'GET',
  302. dataType: 'jsonp'
  303. });
  304. },
  305. _getDetailDataDone: function(id, name, enname) {
  306. var self = this;
  307. this.$loading.show();
  308. self.$recordDetail.hide();
  309. this._getDetailData(id).done(function(data) {
  310. self._renderDetail(data, name, enname);
  311. self.$loading.hide();
  312. self.$recordDetail.show();
  313. }).fail(function() {
  314. self.$loading.hide();
  315. self.$recordDetail.show();
  316. });
  317. },
  318. /*渲染左侧的战绩列表*/
  319. _renderList: function(data) {
  320. var self = this;
  321. // 左侧列表渲染
  322. data.totalPage = self.totalPage;
  323. data.p = self.p;
  324. data.isSelf = self.isSelf;
  325. self.$boxContent.html(boxContentTpl({data: data}));
  326. // 历史战绩对应详情初始化
  327. if(data && data.length > 0) {
  328. if ( self.historyId ) {
  329. getHistoryData(self.historyId);
  330. }else{
  331. getHistoryData(0);
  332. }
  333. }
  334. // 获取左侧第N个li历史战绩数据
  335. function getHistoryData(index) {
  336. var champion = data[index].champion,
  337. enname = champion.name,
  338. name = champion.display_name.concat(champion.title);
  339. self.matchId = data[index].game_id;
  340. self._getDetailDataDone(self.matchId, name, enname);
  341. $('.recent-list li').eq(index).addClass('hover');
  342. }
  343. },
  344. /*渲染历史战绩 - 个人成就*/
  345. _renderDetail: function(data, name, enname) {
  346. var template, self = this;
  347. if(data.player_game_list) {
  348. // 模板渲染
  349. this.$recordDetail.html(recordDetailTpl({data: data}));
  350. this.$recordDataLayer.html(recordDataLayerTpl({data: data}));
  351. // 显示显示默认或记录的导航位置
  352. $('.record-nav li').eq(self.navStatus).click();
  353. // 获取推荐视频
  354. self.positionRender(data.player_game_list[0]);
  355. // 显示广告
  356. $(".ad-wrap").show();
  357. } else {
  358. template = "<div class='tip-no-data'><img src='img/clothes-commit-fail.png'><p>由于未知原因,此场比赛消失在遥远的二次元空间中。</p></div>";
  359. this.$recordDetail.html(template);
  360. }
  361. },
  362. // 位置数据渲染
  363. positionRender: function(data) {
  364. // 位置计算
  365. var position_map = {'is_support': '辅助', 'is_adc': '输出', 'is_jungler': '打野'};
  366. var loseData = data.team_lose.player_champions;
  367. var allData = data.team_win.player_champions.concat(loseData); //输的和赢的数据合并
  368. var userId = encodeURIComponent(getURLParam("userId"));
  369. var key = getPositionKey(allData);
  370. $('.historyRecord-userInfo__position').html(position_map[key]);
  371. // 遍历战绩
  372. function getPositionKey(o) {
  373. for (var i = 0; i < o.length; i++) {
  374. var itemUserId = o[i].player.user_id;
  375. if ( userId == itemUserId ) {
  376. if ( o[i].is_jungler ) {
  377. return 'is_jungler';
  378. break;
  379. }
  380. if ( o[i].is_support ) {
  381. return 'is_support';
  382. break;
  383. }
  384. if ( o[i].is_adc ) {
  385. return 'is_adc';
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. return position_map[key];
  392. },
  393. /*
  394. * @ 历史战绩-个人战绩TAB详细战绩弹窗
  395. * @ 注意!!!这里有坑,数据是来自详细战绩弹窗
  396. */
  397. userRecordDetail: function() {
  398. var self = this;
  399. var userName = decodeURIComponent(self.playerName).replace(/(^\s+)|(\s+$)/g,"");
  400. var recordList = $('.data-layer .layer');
  401. /*从历史战绩-个人战绩TAB #data-layer列表中拿到弹窗数据*/
  402. for (var i = 0; i < recordList.length; i++) {
  403. var listName = $(recordList[i]).find('.tip-user-name').text().replace(/(^\s+)|(\s+$)/g,"");
  404. if ( userName == listName.replace(/^\s+/,"") ) {
  405. var dom = $(recordList[i]).html();
  406. $('.userRecordDetail-con').html(dom);
  407. getUserLevel();
  408. break;
  409. }
  410. }
  411. /*获取用户段位*/
  412. function getUserLevel() {
  413. $.ajax({
  414. url: 'http://api.lolbox.duowan.com/api/v2/player/'+ self.gameZone+'/'+ self.userId+'/',
  415. dataType: 'jsonp',
  416. success: function(o) {
  417. var data = o && o.player_list && o.player_list[0];
  418. var tierRank = data.tier_rank, tierName;
  419. if (tierRank && tierRank['tier'] && tierRank['tier']['const'] > 0) {
  420. tierName = tierRank['tier']['name_cn'] + ' ' + tierRank['rank']['name'];
  421. } else {
  422. tierName = '-';
  423. }
  424. var dom = '<div class="tip-level"></div><div class="tip-topright"><p><em class="zj-zdl zj-s"></em>' + data.box_score + '</p><p class="zj-blue">' + tierName + '</p></div>';
  425. $('.userRecordDetail .tip-topright-wrap').html(dom);
  426. $('.userRecordDetail').show();
  427. }
  428. });
  429. }
  430. }
  431. };
  432. // URL解析
  433. function getURLParam(name) {
  434. var value = location.search.match(new RegExp("[?&]" + name + "=([^&]*)(&?)", "i"));
  435. return value ? decodeURIComponent(value[1]) : value;
  436. }
  437. // 删除字符串空格
  438. function Trim(str,is_global){
  439. var result;
  440. result = str.replace(/(^\s+)|(\s+$)/g,"");
  441. if(is_global.toLowerCase()=="g")
  442. result = result.replace(/\s/g,"");
  443. return result;
  444. }
  445. new Record();
  446. });