// e:\project\dy_video_all\初晴剧场\pages\recommend\recommend.ts import { httpRequest } from "../../utils/httpReques" Page({ myModal: null as any, data: { videoCanIUse: false, videoInfo: {}, videoList: [], batchList: [], videoPlayerCurrent: 0, videoPlayernum: 4, videoErrorText: '', safeAreaBottom: 0, platform: '', anthologyFlag: false, toOptions: {}, sid: "", selectionTabs: [], selectionConList: [], roderCurrent: 0, // collectionItem: {}, nextbatchList: [], selectedId: '', unlockFlag: true, adBanner: null }, onLoad(options: any) { const videoCanIUse = tt.canIUse('video-player'); tt.getSystemInfo({ success: (res: any) => { this.setData({ platform: res.platform, videoCanIUse, }) } }) this.setData({ toOptions: options, sid: options?.sid || '' }) const params = { ...options } this.initFn(params); this.adInit() }, onShow() { }, async initFn(params: any) { const videoreadRes: any = await httpRequest('/videoread', 'POST', params); let videoInfo: any = {} if (videoreadRes.status == 1 && Array.isArray(videoreadRes.data)) { videoInfo = videoreadRes.data[0]; } const batchlistRes: any = await httpRequest('/batchlist', 'POST', params); let batchList: any = []; if (batchlistRes.status == 1 && Array.isArray(batchlistRes.data)) { batchList = batchlistRes.data; } const ol = this.getAnthology(batchList); let nextbatchList = []; const nextbatchRes: any = await httpRequest('/nextbatch', 'POST', params); if (nextbatchRes?.status == 1 && Array.isArray(nextbatchRes?.data)) { nextbatchList = nextbatchRes.data; } videoInfo.isCount = this.handelCount(videoInfo.count || 0) this.setData({ batchList, videoInfo: videoInfo, videoPlayerCurrent: videoInfo?.order - 1, selectionTabs: ol.tabList, selectionConList: ol.orderDataList, nextbatchList, unlockFlag: true }) // 第${videoInfo?.order}集 tt.setNavigationBarTitle({ title: `${videoInfo.title}`, }); }, async handelSeiperChange(ev: any) { const current = ev.detail.current; const videoPlayerCurrent = this.data.videoPlayerCurrent; const batchList: any = this.data.batchList; const id = batchList[videoPlayerCurrent]?.id; const nextId = batchList[current]?.id; const context: any = tt.createVideoContext(`${id}`); const nextContext: any = tt.createVideoContext(`${nextId}`); // const selectionConList = this.data.selectionConList; // const collectionItem: any = this.data.collectionItem; const sid = this.data.sid; // const videoInfo: any = this.data.videoInfo; // const collectionItem = batchList[current] const params = { sid: sid, // id: collectionItem?.id id: nextId, } httpRequest('/videoread', 'POST', params).then((videoreadRes: any) => { let newVideoInfo: any = {} if (videoreadRes.status == 1 && Array.isArray(videoreadRes.data)) { newVideoInfo = videoreadRes.data[0]; } context?.pause?.(); // let lk = this.data.selectionConList; // let bs = batchList if (newVideoInfo.chackpay == 1) { httpRequest('/batchlist', 'POST', params).then((batchlistRes: any) => { if (batchlistRes.status == 1 && Array.isArray(batchlistRes.data)) { const ol = this.getAnthology(batchlistRes.data); newVideoInfo.isCount = this.handelCount(newVideoInfo.count || 0) this.setData({ videoInfo: newVideoInfo, videoPlayerCurrent: current, anthologyFlag: false, // collectionItem: collectionItem, unlockFlag: true, selectionConList: ol.orderDataList, batchList: batchlistRes.data }) nextContext?.play?.(); } }) // const ny: any = selectionConList.map((m: any) => { // const temp: any = m.temp.map((k: any) => { // return { // ...k, // isvip: k.id == newVideoInfo.id ? 0 : k.isvip, // } // }) // return { // ...m, // temp // } // }) // const bk: any = batchList.map((m: any) => { // return { // ...m, // isvip: m.id == newVideoInfo.id ? 0 : m.isvip, // } // }) // this.setData({ // selectionConList: ny, // batchList: bk // }) } else { newVideoInfo.isCount = this.handelCount(newVideoInfo.count || 0) this.setData({ videoInfo: newVideoInfo, videoPlayerCurrent: current, anthologyFlag: false, // collectionItem: collectionItem, // selectionConList: lk, unlockFlag: true, // batchList: bs }) } // this.selectComponent(`#${nextId}`, (res: any) => { // res?.hidePauseIcon() // }); }) }, videoPlayerEnded() { const videoPlayerCurrent = this.data.videoPlayerCurrent; // const batchList = this.data.batchList; // if (videoPlayerCurrent + 1 <= batchList.length) { // const videoreadRes: any = await httpRequest('/videoread', 'POST', params); this.setData({ videoPlayerCurrent: videoPlayerCurrent + 1, videoErrorText: '', // collectionItem }) // } }, videError(ev: any) { const errMsg = ev.detail.errMsg; let errMsgText = ''; if (errMsg == 'Video is forbidden in playlet,please use video-player instead') { errMsgText = '抱歉,当前抖音版本过低,请升级抖音'; this.setData({ videoErrorText: errMsgText }) } // else { // errMsgText = errMsg; // } }, videPlayerError(ev: any) { // console.log(ev, "errMsgTexterrMsgText") const errMsg = ev.detail.errMsg; let errMsgText = ''; if (errMsg == 'Video is forbidden in playlet,please use video-player instead') { errMsgText = '抱歉,当前抖音版本过低,请升级抖音'; this.setData({ videoErrorText: errMsgText }) } // else { // errMsgText = errMsg; // } }, // toPathVideoDetail() { // tt.navigateTo({ // url: `pages/videoDetail/videoDetail`, // }); // }, anthologyTap(ev: any) { const id = ev.currentTarget.dataset.id; const context: any = tt.createVideoContext(`${id}`); context?.pause?.(); this.setData({ anthologyFlag: true, selectedId: id }) }, handelAnthologyClose() { const selectedId = this.data.selectedId; const context: any = tt.createVideoContext(`${selectedId}`); context?.play?.(); this.setData({ anthologyFlag: false }) }, handelCollection(ev: any) { const id = ev.currentTarget.dataset.id; const videoInfo: any = this.data.videoInfo const bookcase = videoInfo.bookcase; const count = videoInfo.count || 0; if (bookcase) { const context: any = tt.createVideoContext(`${videoInfo.id}`); context?.pause?.(); this.myModal?.show?.(); } else { const params = { sid: id } httpRequest('/addkeep', 'POST', params).then((res: any) => { if (res.status == 1) { const ic: any = count + 1; videoInfo.bookcase = videoInfo?.bookcase == 1 ? 0 : 1; videoInfo.count = ic; videoInfo.isCount = this.handelCount(ic) this.setData({ videoInfo: videoInfo // videoInfo: { // ...videoInfo, // bookcase: bookcase == 1 ? 0 : 1, // count: count + 1, // isCount: this.handelCount(count + 1) // }, }) tt.showToast({ title: '收藏成功', icon: 'none' }); } }) } }, handelCount(count: any) { if (count > 999) { const isCount: any = (count / 100000).toFixed(2); const ik = parseFloat(isCount) * 100 return `${ik}k`; } return count; }, getAnthology(ls: any) { const num = 30; let remain = 0; let temp: any = []; const mlist: any = []; const tabList: any = []; if (Array.isArray(ls)) { ls.forEach((m, idx) => { if (num * remain + num < idx + 1) { remain += 1; temp = []; } m.idx = idx; temp.push(m); let obj = { firstNum: num * remain + 1, lastNum: idx + 1, temp: [...temp], }; let tObj = { name: `${num * remain + 1}-${idx + 1}`, }; mlist[remain] = obj; tabList[remain] = tObj; }); } return { orderDataList: mlist, tabList: tabList } }, handelOrderTabs(ev: any) { const idx = ev.currentTarget.dataset.idx; this.setData({ roderCurrent: idx }) }, handelSelection(ev: any) { const orderItem = ev.currentTarget.dataset.item; const batchList: any = this.data.batchList; // console.log(collectionItem,"collectionItem----handelSelection") if (orderItem.order > 1 && orderItem.isvip) { const isvip = batchList[orderItem.order - 2]?.isvip if (isvip) { tt.showToast({ title: `为了保证剧情连贯,请按顺序观看`, icon: 'none' }); // this.setData({ // collectionItem // }) return; } } this.setData({ videoPlayerCurrent: orderItem.idx, // collectionItem }) }, toPathPay() { const videoInfo: any = this.data.videoInfo; const sid = this.data.sid; // console.log(collectionItem, "collectionItem") tt.navigateTo({ url: `/pages/pay/pay?sid=${sid}&id=${videoInfo.id}&toStatus=1`, }); }, watchAdvertisement() { let adBanner: any = this.data.adBanner; tt.showToast({ title: `广告加载中...`, icon: 'none', }); adBanner.show().then(() => { // res: any console.log("视频广告展示"); }); }, adInit() { let isAdBanner: any = this.data.adBanner; // const context: any = tt.createVideoContext(`${videoInfo.id}`); // this.watchInfo.isvip = 0; if (!isAdBanner) { const adBanner: any = tt.createRewardedVideoAd({ adUnitId: "wh0y4vcxsbk7ixwktg", }); // 监听错误 adBanner.onError((err: any) => { tt.hideLoading({}); switch (err.errCode) { case 1004: // 无合适的广告 break; default: // 更多请参考错误码文档 } }); // 监听视频播放完成 adBanner.onClose((res: any) => { console.log(res, "resres") if (res.isEnded) { // const videoIndex = batchList.findIndex( // (r: any) => r.id === videoInfo.id // ); // batchList[videoIndex].isvip = 0; // 购买成功 或者本来就是免费 // batchList[videoIndex].state = "play"; // batchList[videoIndex].playIng = true; // batchList[videoIndex].isplay = true; // context?.play?.(); // const bk: any = []; // batchList.forEach((m: any) => { // bk.push({ // ...m, // isvip: m.id == videoInfo.id ? 0 : m.isvip, // }) // }) // const ny: any = []; // selectionConList.forEach((m: any) => { // const temp: any = []; // m.temp.forEach((k: any) => { // temp.push({ // ...k, // isvip: k.id == videoInfo.id ? 0 : k.isvip, // }) // }) // const bb = { // ...m, // temp // } // ny.push(bb) // }) const videoInfo: any = this.data.videoInfo; const batchList: any = this.data.batchList; const selectionConList = this.data.selectionConList; const ny: any = selectionConList.map((m: any) => { const temp: any = m.temp.map((k: any) => { return { ...k, isvip: k.id == videoInfo.id ? 0 : k.isvip, } }) return { ...m, temp } }) const bk: any = batchList.map((m: any) => { return { ...m, isvip: m.id == videoInfo.id ? 0 : m.isvip, } }) const params = { sid: videoInfo.sid, id: videoInfo.id, }; // transferadRes: any httpRequest('/transferad', 'POST', params).then(() => { videoInfo.chackpay = 1; this.setData({ batchList: bk, videoInfo: videoInfo, selectionConList: ny }) }) } else { tt.showToast({ title: '看完广告方可解锁', icon: 'none', duration: 2000 }) } }); // 预加载资源 adBanner.load(); this.setData({ adBanner: adBanner, }) } }, toPathVideoitself(ev: any) { const sid = ev.currentTarget.dataset.sid; const params = { sid } this.setData({ sid: sid, options: { sid } }) this.initFn(params); }, async handelReplace() { const sid = this.data.sid; const options = this.data.toOptions; const params = { ...options, sid: sid } let nextbatchList = []; const nextbatchRes: any = await httpRequest('/nextbatch', 'POST', params); if (nextbatchRes.status == 1 && Array.isArray(nextbatchRes.data)) { nextbatchList = nextbatchRes.data; } this.setData({ nextbatchList }) }, handelEpisode(ev: any) { const current = ev.detail.current; this.setData({ roderCurrent: current }) }, hideUnlock() { this.setData({ unlockFlag: false }) }, showUnlockFlag() { this.setData({ unlockFlag: true }) }, myModalRef(ref: any) { this.myModal = ref }, modalConfirm() { const videoInfo: any = this.data.videoInfo; const params = { ids: videoInfo.sid } const context: any = tt.createVideoContext(`${videoInfo.id}`); context?.play?.(); httpRequest('/chasingdramadel', 'POST', params).then((res: any) => { if (res.status == 1) { // const kb = { // ...videoInfo, // bookcase: videoInfo?.bookcase == 1 ? 0 : 1, // count: videoInfo?.count - 1, // isCount: this.handelCount(videoInfo?.count - 1) // } const ic: any = videoInfo?.count - 1; videoInfo.bookcase = videoInfo?.bookcase == 1 ? 0 : 1; videoInfo.count = ic; videoInfo.isCount = this.handelCount(ic) this.setData({ videoInfo: videoInfo }) tt.showToast({ title: '取消成功', icon: 'none' }); } }) }, modalCancel() { const videoInfo: any = this.data.videoInfo; const context: any = tt.createVideoContext(`${videoInfo.id}`); context?.play?.(); }, })