/* 视频页面需要用到JS */
console.time('Video.js执行时长')
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() {
/* 当前的分类id */
let queryData = { pg: -999, t: -999 }
/* 总页数 */
let total = -999
/* 是否正在加载列表 */
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 (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() {
$('.joe_video__list-item').css('display', '').html('')
isLoading = true
$.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 $('.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}
`
})
$('.joe_video__list-item').html(htmlStr)
new LazyLoad('.video_lazyload')
}
total = res.data.pagecount
initPagination()
},
complete: () => (isLoading = false)
})
}
/* 初始化分页 */
function initPagination() {
let htmlStr = ''
if (queryData.pg !== 0) {
htmlStr += `
`
}
htmlStr += ``
if (queryData.pg != total) {
htmlStr += `
`
}
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() {
$.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_year}
- ${item.vod_name + (item.vod_remarks ? ' - ' + item.vod_remarks : '')}
- 类型:
${item.vod_class || '未知'}
- 主演:
${item.vod_actor || '未知'}
- 导演:
${item.vod_director || '未知'}
- 简介:
${getContent(item)}
`)
new LazyLoad('.video_lazyload')
}
})
}
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 '暂无简介'
}
}
console.timeEnd('Video.js执行时长')
})