// e:\project\dy_video_all\初晴剧场\pages\recommend\recommend.ts import { httpRequest } from "../../utils/httpReques" Page({ 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: '', adBanner: null, unlockFlag: true }, onLoad(options: any) { const videoCanIUse = tt.canIUse('video-player'); console.log(options, "options") tt.getSystemInfo({ success: (res: any) => { this.setData({ platform: res.platform, videoCanIUse, }) } }) this.setData({ toOptions: options, sid: options?.sid || '' }) this.initFn(); }, onShow() { }, async initFn() { const sid = this.data.sid; const options = this.data.toOptions; console.log(options, "initFninitFninitFn") const params = { ...options, sid: sid } 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; } this.setData({ batchList, videoInfo: { ...videoInfo, isCount: this.handelCount(videoInfo.count) }, 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 } const videoreadRes: any = await httpRequest('/videoread', 'POST', params); let newVideoInfo: any = {} if (videoreadRes.status == 1 && Array.isArray(videoreadRes.data)) { newVideoInfo = videoreadRes.data[0]; } context?.pause?.(); if (newVideoInfo.chackpay == 1) { nextContext?.play?.(); } // this.selectComponent(`#${nextId}`, (res: any) => { // res?.hidePauseIcon() // }); const lk: any = []; selectionConList.forEach((m: any) => { const bm = { ...m, temp: [] } m.temp.forEach((k: any) => { if (k.id == videoInfo.id) { bm.temp.push({ ...k, isvip: 0 }) } else { bm.temp.push(k) } }) lk.push(bm) }) this.setData({ videoInfo: { ...videoInfo, ...newVideoInfo, }, videoPlayerCurrent: current, anthologyFlag: false, collectionItem: collectionItem, videoErrorText: '', selectionConList: lk, unlockFlag: true }) }, videoPlayerEnded() { const videoPlayerCurrent = this.data.videoPlayerCurrent; const batchList = this.data.batchList; console.log(videoPlayerCurrent + 2, batchList.length) // 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; console.log(bookcase, "bookcasebookcase") if (bookcase) { const params = { ids: id } httpRequest('/chasingdramadel', 'POST', params).then((res: any) => { if (res.status == 1) { this.setData({ videoInfo: { ...videoInfo, bookcase: bookcase == 1 ? 0 : 1, count: count - 1, isCount: this.handelCount(count - 1) } }) tt.showToast({ title: '取消成功', icon: 'none' }); } }) } else { const params = { sid: id } httpRequest('/addkeep', 'POST', params).then((res: any) => { if (res.status == 1) { this.setData({ 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 collectionItem = ev.currentTarget.dataset.item; const batchList: any = this.data.batchList; if (collectionItem.idx != 0) { const isvip = batchList[collectionItem.idx - 1]?.isvip if (isvip) { tt.showToast({ title: `为了保证剧情连贯,请按顺序观看`, icon: 'none' }); this.setData({ collectionItem }) return; } } this.setData({ videoPlayerCurrent: collectionItem.idx, // collectionItem }) }, toPathPay() { const collectionItem: any = this.data.collectionItem; const sid = this.data.sid; console.log(collectionItem, "collectionItem") tt.navigateTo({ url: `/pages/pay/pay?sid=${sid}&id=${collectionItem.id}&toStatus=1`, }); }, watchAdvertisement() { let adBanner: any = this.data.adBanner; const videoInfo: any = this.data.videoInfo; const batchList: any = this.data.batchList; const selectionConList = this.data.selectionConList; const context: any = tt.createVideoContext(`${videoInfo.id}`); // this.watchInfo.isvip = 0; if (!adBanner) { tt.showToast({ title: `广告加载中...`, }); adBanner = tt.createRewardedVideoAd({ adUnitId: "wh0y4vcxsbk7ixwktg", }); adBanner.show().then((res: any) => { console.log("视频广告展示"); console.log(res, "pppppppp") }); // 监听错误 adBanner.onError((err: any) => { tt.hideLoading({}); switch (err.errCode) { case 1004: // 无合适的广告 break; default: // 更多请参考错误码文档 } }); // 监听视频播放完成 adBanner.onClose(async (res: any) => { console.log(res, "resres") // 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 lk: any = []; selectionConList.forEach((m: any) => { const bm = { ...m, temp: [] } m.temp.forEach((k: any) => { if (k.id == videoInfo.id) { bm.temp.push({ ...k, isvip: 0 }) } else { bm.temp.push(k) } }) lk.push(bm) }) const params = { sid: videoInfo.sid, id: videoInfo.id, }; const transferadRes: any = await httpRequest('/transferad', 'POST', params); this.setData({ batchList: batchList, videoInfo: { ...videoInfo, chackpay: 1 }, selectionConList: lk }) }); // 预加载资源 adBanner.load(); } }, toPathVideoitself(ev: any) { const sid = ev.currentTarget.dataset.sid; this.setData({ sid: sid, options: { sid } }) this.initFn(); }, async handelReplace() { let nextbatchList = []; const nextbatchRes: any = await httpRequest('/nextbatch', 'POST'); 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 }) } })