/* 视频页面需要用到JS */ console.time('Video.js执行时长') document.addEventListener('DOMContentLoaded', () => { const p = new URLSearchParams(window.location.search) /* 判断渲染详情页还是列表页 */ if (p.get('vod_id')) { initVideoDetail() } else { initVideoList() } function initVideoList() { /* 当前的分类id */ let queryData = { pg: 0, t: -999 } /* 总页数 */ let total = 0 /* 是否正在加载列表 */ let isLoading = false /* 获取视频分类 */ $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'maccms_list' }, success(res) { if (res.code !== 1) return $('.joe_video__type-list').html(`
  • ${res.data}
  • `) let htmlStr = '
  • 全部
  • ' res.data.class.forEach(_ => (htmlStr += `
  • ${_.type_name}
  • `)) $('.joe_video__type-list').html(htmlStr) $('.joe_video__type-list .item').first().click() } }) /* 点击切换分类 */ $('.joe_video__type-list').on('click', '.item', function () { const t = $(this).attr('data-t') if (t === queryData.t || isLoading) return window.scrollTo({ top: 0, behavior: 'smooth' }) $(this).addClass('active').siblings().removeClass('active') queryData.pg = 0 queryData.t = t renderDom() }) /* 渲染视频列表 */ function renderDom() { isLoading = true $('.joe_video__list-item').html('') $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'maccms_list', t: queryData.t, pg: queryData.pg, ac: 'videolist' }, success(res) { if (res.code !== 1) return let htmlStr = '' res.data.list.forEach(_ => { htmlStr += ` ${_.vod_year}
    ${_.vod_name}

    ${_.vod_name}

    ` }) $('.joe_video__list-item').html(htmlStr) new LazyLoad('.video_lazyload') isLoading = false total = res.data.pagecount initPagination() } }) } /* 初始化分页 */ function initPagination() { let htmlStr = '' if (queryData.pg !== 0) htmlStr += `
  • ${queryData.pg}
  • ` htmlStr += `
  • ${queryData.pg + 1}
  • ` if (queryData.pg != total) htmlStr += `
  • ${queryData.pg + 2}
  • ` if (queryData.pg < total) htmlStr += `
  • ` $('.joe_video__pagination').html(htmlStr) } /* 切换分页 */ $('.joe_video__pagination').on('click', '.joe_video__pagination-item', function () { const pg = $(this).attr('data-pg') if (!pg || isLoading) return window.scrollTo({ top: 0, behavior: 'smooth' }) queryData.pg = Number(pg) renderDom() }) } function initVideoDetail() {} console.timeEnd('Video.js执行时长') })