document.addEventListener('DOMContentLoaded', () => { const p = new URLSearchParams(window.location.search); if (!p.get('profileRoom')) initLiveList(); function initLiveList() { let queryData = { page: 1, gameId: '', index: 0, isLoading: false, totalPage: 0 }; $('.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() { window.scrollTo({ top: 0, behavior: 'smooth' }); 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}
    ${_.nick}
    ${_.nick}

    ${_.introduction}

    ${parseNum(_.totalCount)} ${_.gameFullName}
    `; }); $('.joe_live__list').html(htmlStr); queryData.totalPage = res.data.totalPage; initPagination(); }, complete: () => (queryData.isLoading = false) }); } function initPagination() { let htmlStr = ''; if (queryData.page != 1) { htmlStr += `
  • 首页
  • ${queryData.page - 1}
  • `; } htmlStr += `
  • ${queryData.page}
  • `; if (queryData.page != queryData.totalPage) { htmlStr += `
  • ${queryData.page + 1}
  • `; } if (queryData.page < queryData.totalPage) htmlStr += `
  • 末页
  • `; $('.joe_live__pagination').html(htmlStr); } $('.joe_live__pagination').on('click', '.joe_live__pagination-item', function () { const page = $(this).attr('data-page'); if (!page || queryData.isLoading) return; queryData.page = Number(page); renderLiveList(); }); function parseNum(num = 0) { if (num >= 10000) return Math.round(num / 1000) / 10 + '万'; return num; } } });