2024-05-28 10:27:58 +08:00

345 lines
8.6 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.

// 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: []
},
onLoad(options: any) {
const videoCanIUse = tt.canIUse('video-player');
console.log(options, "options")
tt.getSystemInfo({
success: (res: any) => {
this.setData({
platform: res.platform,
videoCanIUse,
toOptions: options,
sid: options?.sid || ''
})
}
})
},
onShow() {
this.initFn();
},
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,
})
// 第${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 collectionItem: any = this.data.collectionItem;
const sid = this.data.sid;
const videoInfo = 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()
// });
this.setData({
videoInfo: {
...videoInfo,
...newVideoInfo,
},
videoPlayerCurrent: current,
anthologyFlag: false,
collectionItem: collectionItem,
videoErrorText: ''
})
},
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 playletplease 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 playletplease use video-player instead') {
errMsgText = '抱歉,当前抖音版本过低,请升级抖音';
this.setData({
videoErrorText: errMsgText
})
}
// else {
// errMsgText = errMsg;
// }
},
// toPathVideoDetail() {
// tt.navigateTo({
// url: `pages/videoDetail/videoDetail`,
// });
// },
anthologyTap() {
this.setData({
anthologyFlag: true
})
},
handelAnthologyClose() {
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() {
},
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
})
}
})