document.addEventListener('DOMContentLoaded', () => { const p = new URLSearchParams(window.location.search); const vod_id = p.get('vod_id'); if (vod_id) { initVideoDetail(); } else { initVideoList(); } function initVideoList() { let queryData = { pg: '', t: '', wd: '' }; let pagecount = ''; 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}
  • `); if (!res.data.class.length) return $('.joe_video__type-list').html(`
  • 暂无数据!
  • `); 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 (isLoading) return; $(this).addClass('active').siblings().removeClass('active'); queryData.pg = 1; queryData.t = t; queryData.wd = ''; $('.joe_video__list-search input').val(''); renderDom(); }); function renderDom() { window.scrollTo({ top: 0, behavior: 'smooth' }); $('.joe_video__list-item').css('display', '').html(''); isLoading = true; $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'maccms_list', ac: 'videolist', t: queryData.t, pg: queryData.pg, wd: queryData.wd }, success(res) { if (res.code !== 1) return $('.joe_video__list-item').css('display', 'block').html('

    数据加载失败!请检查!

    '); if (!res.data.list.length) { $('.joe_video__list-item').css('display', 'block').html('

    暂无数据!

    '); } else { let htmlStr = ''; res.data.list.forEach(_ => { htmlStr += ` ${_.vod_year}
    ${_.vod_name}

    ${_.vod_name}

    `; }); $('.joe_video__list-item').html(htmlStr); } pagecount = res.data.pagecount; initPagination(); }, complete: () => (isLoading = false) }); } function initPagination() { if (pagecount == 0) return $('.joe_video__pagination').hide(); $('.joe_video__pagination').show(); let htmlStr = ''; if (queryData.pg != 1) { htmlStr += `
  • 首页
  • ${queryData.pg - 1}
  • `; } htmlStr += `
  • ${queryData.pg}
  • `; if (queryData.pg != pagecount) { htmlStr += `
  • ${queryData.pg + 1}
  • `; } if (queryData.pg < pagecount) 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; queryData.pg = Number(pg); renderDom(); }); const searchFn = () => { const val = $('.joe_video__list-search input').val(); if (isLoading) return; queryData.pg = 1; queryData.t = ''; queryData.wd = val; $('.joe_video__type-list .item').first().addClass('active').siblings().removeClass('active'); renderDom(); }; $('.joe_video__list-search .button').on('click', searchFn); $('.joe_video__list-search .input').on('keyup', e => e.keyCode === 13 && searchFn()); } function initVideoDetail() { const player = $('.joe_video__player-play').attr('data-player'); $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'maccms_list', ac: 'detail', ids: vod_id }, success(res) { if (res.code !== 1) return $('.joe_video__detail-info').html(`

    ${res.data}

    `); if (!res.data.list.length) return $('.joe_video__detail-info').html(`

    数据抓取异常!请检查!

    `); const item = res.data.list[0]; /* 设置视频详情 */ $('.joe_video__detail-info').html(`
    ${item.vod_name} ${item.vod_year}
    ${item.vod_name + (item.vod_remarks ? ' - ' + item.vod_remarks : '')}
    类型:${item.vod_class || '未知'}
    主演:${item.vod_actor || '未知'}
    导演:${item.vod_director || '未知'}
    简介:${getContent(item)}
    `); /* 设置视频播放标题 */ $('.joe_video__player .joe_video__contain-title').html('正在播放:' + item.vod_name); /* 设置播放链接 */ let parseList = str => { let htmlStr = ''; let arr = str.split('#'); arr.forEach(_ => (htmlStr += `
  • ${_.split('$')[0] || ''}
  • `)); return htmlStr; }; let playFromArr = item.vod_play_from.split('$$$'); let playUrlArr = item.vod_play_url.split('$$$'); let maps = new Map(); playFromArr.forEach((element, index) => maps.set(element, playUrlArr[index] || [])); let htmlStr = ''; let index = 0; for (let [key, value] of maps) { index++; htmlStr += `
    播放线路 ${index}
    `; } $('.joe_video__player').after(htmlStr); $('.joe_video__source').first().find('.joe_video__source-list .item').first().click(); } }); $(document).on('click', '.joe_video__source-list .item', function () { $('.joe_video__source-list .item').removeClass('active'); $(this).addClass('active'); const url = $(this).attr('data-src') || $(this).html(); $('.joe_video__player-play').attr({ src: player + url }); const offset = $('.joe_video__player').offset().top - $('.joe_header').height() - 15; window.scrollTo({ top: offset, behavior: 'smooth' }); }); } function getContent(item) { if (item.vod_content) { return item.vod_content.replace(/<[^>]+>/g, ''); } else if (item.vod_blurb) { return item.vod_blurb.replace(/<[^>]+>/g, ''); } else { return '暂无简介'; } } });