/* 直播页面需要用到JS */ console.time('Live.js执行时长'); document.addEventListener('DOMContentLoaded', () => { const p = new URLSearchParams(window.location.search); const gameId = p.get('gameId'); if (gameId) { } else { initLiveList(); } /* 初始化直播列表 */ function initLiveList() { let queryData = { page: 1, gameId: '', index: 0, isLoading: false }; /* 点击切换分类 */ $('.joe_live__type-title .icon').on('click', function () { if (queryData.isLoading) return; if (queryData.index === 3) queryData.index = 0; queryData.index++; renderLiveType(); }); /* 分类列表点击事件 */ $('.joe_live__type-list').on('click', '.item', function () { if (queryData.isLoading) return; $(this).addClass('active').siblings().removeClass('active'); queryData.page = 1; queryData.gameId = $(this).attr('data-gameId'); renderLiveList(); }); /* 渲染分类 */ renderLiveType(); function renderLiveType() { $.ajax({ url: '/usr/themes/joe/assets/json/joe.live.json', success(res) { const item = res[queryData.index]; $('.joe_live__type-title .text').html(item.name); let htmlStr = '
  • 全部
  • '; item.list.forEach(_ => (htmlStr += `
  • ${_.name}
  • `)); $('.joe_live__type-list').html(htmlStr); $('.joe_live__type-list .item').first().click(); } }); } /* 渲染列表 */ function renderLiveList() { queryData.isLoading = true; $('.joe_live__list').html(''); $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'huya_list', page: queryData.page, gameId: queryData.gameId }, success(res) { if (res.code !== 1) return; let htmlStr = ''; res.data.datas.forEach(_ => { htmlStr += `
    ${_.recommendTagName} ${_.introduction}

    ${_.introduction}

    ${_.nick} ${_.nick}
    ${parseNum(_.totalCount)} ${_.gameFullName}
    `; }); $('.joe_live__list').html(htmlStr); new LazyLoad('.screenshot_lazyload'); }, complete: () => (queryData.isLoading = false) }); } function parseNum(num = 0) { if (num >= 10000) return Math.round(num / 1000) / 10 + '万'; return num; } } console.timeEnd('Live.js执行时长'); });