index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import Vue from 'vue';
  2. import lib from 'lib';
  3. export default {
  4. data() {
  5. return {
  6. heroData : {},
  7. heroMetaData:{},
  8. rolesCH : [],
  9. heroMetaInfo:{}
  10. }
  11. },
  12. mounted() {
  13. this.getHeroMetaData();
  14. this.getHeroData();
  15. },
  16. beforeDestroy() {
  17. },
  18. methods: {
  19. /**获取英雄数据 */
  20. getHeroData(){
  21. let self = this,
  22. url =`${lib.apiUrl}/v2/champion/?var=Ashe`;
  23. lib.get(url,ret => {
  24. if(ret.champion_list&&ret.champion_list[0]){
  25. self.heroData = ret.champion_list[0];
  26. self.formatHeroData(self.heroData);
  27. }
  28. });
  29. },
  30. formatHeroData(data){
  31. let rolesMap = {
  32. "Marksman" : "射手",
  33. "Support" : "辅助"
  34. },
  35. roles = data.roles;
  36. roles.forEach(item => {
  37. this.rolesCH.push(rolesMap[item]);
  38. })
  39. },
  40. /**获取英雄技巧、背景信息 */
  41. getHeroMetaData(){
  42. let self = this,
  43. url =`http://static.lolbox.duowan.com/metas/champions/Ashe.js`;
  44. lib.get(url,ret => {
  45. if(ret&&ret.data){
  46. self.heroMetaData = ret.data;
  47. self.heroMetaInfo = ret.data.info;
  48. }
  49. })
  50. },
  51. /*切换导航栏*/
  52. switchNav(event) {
  53. var target = event.currentTarget,
  54. tab_id = $(target).attr('data-for'),
  55. toshow_ele = $("#" + tab_id),
  56. wrap = $("#h-content-wrap");
  57. if (tab_id == null || toshow_ele == null || $(target).hasClass("active")) return;
  58. $(target).closest("li").addClass("active")
  59. .siblings().removeClass("active");
  60. wrap.children(".content-section.active").removeClass("active");
  61. toshow_ele.addClass("active");
  62. this.moveUnderline($(target));
  63. },
  64. /*移动下划线至激活nav*/
  65. moveUnderline($ele) {
  66. var $underline = $('#nav_underline'),
  67. underline_width = $underline.width(),
  68. width = $ele.width(),
  69. left = $ele.offset().left;
  70. $underline.css("transform", 'translateX(' + (left + width / 2) + 'px)');
  71. },
  72. /*切换技能*/
  73. switchAblibity(event) {
  74. var $target = $(event.currentTarget),
  75. index = $target.index(),
  76. ability_wrap = $('#ability_wrap');
  77. if ($target.hasClass("active")) return;
  78. $target.addClass("active")
  79. .siblings().removeClass("active");
  80. ability_wrap.children().eq(index).addClass("active")
  81. .siblings().removeClass("active");
  82. },
  83. /*partenr-counter 查看更多*/
  84. showMorePC(event) {
  85. var $ele = $(event.currentTarget),
  86. ulist = $ele.parent().prev(),
  87. text = $ele.text();
  88. switch (text) {
  89. case "查看更多": ulist.slideDown("fast");
  90. $ele.text("隐藏");
  91. break;
  92. case "隐藏": ulist.slideUp("fast");
  93. $ele.text("查看更多");
  94. break;
  95. default: return;
  96. }
  97. }
  98. }
  99. }