2025-04-29 17:08:42 +08:00

273 lines
10 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { httpRequest } from "../../utils/httpReques";
const {
PlayletExtension,
getPlayletManager
}: any = tt;
// 可以使用tt.canIUse('PlayletExtension')判断是否可用不可用可调用tt.navigateTo等跳转离开
PlayletExtension({
pm: undefined,
options: undefined,
data: {
watchInfo: {},
nextbatchList: [],
adCountdown: 0,
adCountdownShowAd: false,
timerAd: null
},
provide() {
// 返回值就是要提供的数据, 初始化数据, 不会监听变动
return {
adCountdown: this.data.adCountdown,
adCountdownShowAd: this.data.adCountdownShowAd,
};
},
methods: {
//监听player的值
emitInfoFromChildren(val, data) {
console.log('收到消息', val)
console.log('收到消息', data)
if (val == "advunlock") {
this.init('advunlock', data)
}
if (val == "change") {
this.init('change', data)
}
if (val == 'adCountdownChange') {
console.log(val, "adCountdownChange")
const is_timerAd = this.data.timerAd;
clearInterval(is_timerAd);
const chapterCatalog = getApp().globalData.chapterCatalog;
this.pm.setCatalog({
freeList: chapterCatalog.freeList,
lockList: chapterCatalog.lockList
})
this.setData({
adCountdown: 0,
adCountdownShowAd: false
})
this.setProvide({
adCountdown: 0,
adCountdownShowAd: false
});
}
},
//监听charge的值
emitChargeInfoFromChildren(val, data) {
console.log('收到消息', val)
console.log('收到消息', data)
console.log(val == "charge" && data == "success")
if (val == "charge" && data == "success") {
const data = tt.getStorageSync('currentvideo')
this.init('charge', data)
}
},
onLoad(options) {
const caniuse = !!tt.canIUse('PlayletExtension');
// console.log('行业SDK版本号', tt.getIndustrySdkInfo().version);
// console.log('TMAR版本号', tt.getSystemInfoSync().SDKUpdateVersion);
// console.error('caniuse', caniuse);
const pm = getPlayletManager();
this.pm = pm;
// tid=2334
// options.tid = 2334
this.options = options;
this.setData({
tt_album_id: options.tt_album_id,
tt_episode_id: options.tt_episode_id,
seq: options.seq,
})
},
async onReady() {
console.log('页面完成Ready', JSON.stringify(options))
const pm = getPlayletManager();
const options = this.options;
// 初始化自定义组件
// this.pm.setConfig({
// activityInfo: [
// {
// icon: "https://dyxykjweb.hunanjj.cn/sta_images/icon/welfare_gift_icon.png",
// title: "福利",
// },
// ],
// objectFit: 'contain'
// });
//是否展示解锁页
this.pm.setConfig({
showLockPage: false
});
//播放器分享按钮
this.pm.onTapShare((e) => {
console.log(`/pages/videoByte/videoByte?is_continue=0&tt_album_id=${this.data?.watchInfo?.album_id}&tt_episode_id=${this.data?.watchInfo?.episode_id}&tid=${this.options?.tid || ""}&launchsite=${this.options?.launchsite || ""}`)
return { // 分享数据
title: "古言剧场",
desc: "精彩剧情,尽在古言剧场",
path: `/pages/videoByte/videoByte?is_continue=0&tt_album_id=${this.data?.watchInfo?.album_id}&tt_episode_id=${this.data?.watchInfo?.episode_id}&tid=${this.options?.tid || ""}&launchsite=${this.options?.launchsite || ""}`,
imageUrl: this.data?.watchInfo?.cover,
}
})
//初始化页面分享内容
this.pm.getPlayletInfo().then(res => {
console.log('getPlayletInfo', res)
this.setData({
tt_album_id: res.albumId,
tt_episode_id: res.episodeId,
seq: res.seq
})
this.pm.setConfig({
shareParam: { // 分享数据
title: "古言剧场",
desc: "精彩剧情,尽在古言剧场",
path: `/pages/videoByte/videoByte?is_continue=0&tt_album_id=${this.data?.watchInfo?.album_id}&tt_episode_id=${this.data?.watchInfo?.episode_id}&tid=${this.options?.tid || ""}&launchsite=${this.options?.launchsite || ""}`,
imageUrl: this.data?.watchInfo?.cover,
}
// title: this.watchInfo.title,
// imageUrl: this.watchInfo.cover,
// desc: `精彩剧情,尽在${this.pageGlobalData.appName}`,
// path: `/pages/videobyte/index?tt_album_id=${this.$store.state.currentVideoInfo.album_id}&tt_episode_id=${this.$store.state.currentVideoInfo.episode_id}&is_continue=0&tid=${this.$store.state.linkParams.tid || ""}&launchsite=${this.$store.state.linkParams.launchsite || ""}`,
});
});
this.init();
},
async init(status?: string, data?: any) {
console.log("data", data)
let params = {
...this.options,
album_id: !!data ? data.album_id : this.options.tt_album_id,
episode_id: !!data ? data.episode_id : this.options.tt_episode_id,
sid: null,
id: null,
tt_album_id: null,
tt_episode_id: null,
adunlocking: status == 'advunlock' ? 1 : null
}
console.log('params', params)
//初始化目录
const res: any = await httpRequest('/douyinNewRead', 'post', params);
//添加历史记录时,后面不用执行了
if (status == 'addhistory') {
return
}
//设置剧集上锁状态
const _freeList = res.data.freelist != null ? res.data.freelist : [];
const _lockList = res.data.locklist != null ? res.data.locklist : [];
const _watchinfo: any = {
...res.data.library,
...res.data.video,
...res.data.read_data
}
// const adCountdown = _watchinfo.adCountdown
let adCountdown = 0;
let localFreeList = _freeList;
let localLockList = _lockList;
let timerAd = null;
const is_timerAd_a = this.data.timerAd;
if (_watchinfo.adCountdown && (_watchinfo.chackpay == 2 || _watchinfo.isvip == 1)) {
adCountdown = _watchinfo.adCountdown;
// adCountdown = 20;
//本地设置本集免费,与免费试看相关
localFreeList = [..._freeList, { start_episode_no: _watchinfo.order, end_episode_no: _watchinfo.order }]
localLockList = _lockList.filter((ite: any) => ite.start_episode_no != _watchinfo.order)
if (is_timerAd_a) {
clearInterval(is_timerAd_a);
}
timerAd = setInterval(() => {
const adCountdown = this.data.adCountdown;
const is_timerAd = this.data.timerAd;
if (adCountdown <= 1) {
clearInterval(is_timerAd);
const chapterCatalog = getApp().globalData.chapterCatalog;
this.pm.setCatalog({
freeList: chapterCatalog.freeList,
lockList: chapterCatalog.lockList
})
this.setData({
adCountdown: 0,
adCountdownShowAd: true
})
this.setProvide({
adCountdown: 0,
adCountdownShowAd: true
});
} else {
this.setData({
adCountdown: adCountdown - 1,
})
this.setProvide({
adCountdown: adCountdown - 1,
});
}
}, 1000);
}
this.pm.setCatalog({
freeList: localFreeList,
lockList: localLockList
})
this.setData({
watchInfo: _watchinfo,
adCountdown: adCountdown,
timerAd: timerAd,
adCountdownShowAd: false
})
this.setProvide({
adCountdown: adCountdown,
adCountdownShowAd: false
});
tt.setStorageSync('watchInfo', _watchinfo);
const _chapterList = { freeList: _freeList, lockList: _lockList }
tt.setStorageSync('chapterList', _chapterList);
getApp().globalData.chapterCatalog = _chapterList;
},
},
lifetimes: {
ready() {
console.log('ready')
},
created() {
console.log('created')
},
attached() {
console.log('attached')
},
detached() {
console.log('detached')
const lastfreevideo = tt.getStorageSync('lastfreevideo')
if (lastfreevideo.status == 'free') {
this.init('addhistory', lastfreevideo)
}
const is_timerAd = this.data.timerAd;
if (is_timerAd) {
clearInterval(is_timerAd);
}
},
},
pageLifetimes: {
hide() {
console.log('触发hide')
},
}
});