2024-07-27 15:10:51 +08:00

225 lines
5.9 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({
myModal: null as any,
data: {
videoCanIUse: false,
videoInfo: {},
videoList: [],
batchList: [],
videoPlayerCurrent: 0,
videoPlayernum: 4,
videoErrorText: '',
page: 1,
statusBarHeight: getApp().globalData.statusBarHeight,
id: ''
},
onLoad() {
const videoCanIUse = tt.canIUse('video-player');
this.setData({
videoCanIUse,
})
},
onShow() {
const page = this.data.page;
this.initFn(page);
},
handelCount(count: any) {
if (count > 999) {
const isCount: any = (count / 100000).toFixed(2);
const ik = parseFloat(isCount) * 100
return `${ik}k`;
}
return count;
},
async initFn(page: any) {
// const params = {
// "uid": 127457025,
// "platform": "devtools",
// "is_b": 2,
// "sid": "2"
// }
// const videoreadRes: any = await httpRequest('/videoread', 'POST', params);
const getNewModule2Res: any = await httpRequest('/getNewModule2', 'POST', { page });
// console.log(getNewModule2)
// 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;
// }
// console.log(getNewModule2Res, "getNewModule2Res")
if (getNewModule2Res.status == 1 && Array.isArray(getNewModule2Res.data.module)) {
const moduleList = getNewModule2Res.data.module;
const batchList = this.data.batchList;
const ls = moduleList.map((m: any) => {
return {
...m,
count: this.handelCount(m.count)
}
})
if (page == 1) {
this.setData({
batchList: ls,
page,
})
} else {
this.setData({
batchList: batchList.concat(ls),
page,
})
}
}
// this.setData({
// batchList,
// videoInfo
// })
},
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}`);
context?.pause?.();
nextContext?.play?.();
this.selectComponent(`#${nextId}`, (res: any) => {
// console.log(res, "resres")
res?.hidePauseIcon()
});
this.setData({
videoPlayerCurrent: current,
videoErrorText: ''
})
if (current + 5 >= batchList.length) {
const page = this.data.page;
this.initFn(page + 1)
}
},
videoPlayerEnded(err: any) {
console.log(err, 'videoPlayerEnded')
const videoPlayerCurrent = this.data.videoPlayerCurrent;
this.setData({
videoPlayerCurrent: videoPlayerCurrent + 1,
videoErrorText: ''
})
},
videError(ev: any) {
const errMsg = ev.detail.errMsg;
console.log(errMsg, "errMsgerrMsg")
let errMsgText = '';
if (errMsg == 'Video is forbidden in playletplease use video-player instead') {
errMsgText = '抱歉,当前抖音版本过低,请升级抖音'
} else {
errMsgText = errMsg;
}
this.setData({
videoErrorText: errMsgText
})
},
videPlayerError(ev: any) {
const errMsg = ev.detail.errMsg;
let errMsgText = '';
if (errMsg == 'Video is forbidden in playletplease use video-player instead') {
errMsgText = '抱歉,当前抖音版本过低,请升级抖音'
} else {
errMsgText = errMsg;
}
this.setData({
videoErrorText: errMsgText
})
},
toPathVideo(ev: any) {
const sid = ev.currentTarget.dataset.sid;
tt.navigateTo({
url: `/pages/videoDetail/videoDetail?sid=${sid}`,
});
},
handelCollection(ev: any) {
const id = ev.currentTarget.dataset.id;
let batchList: any = this.data.batchList;
const idx = batchList.findIndex((m: any) => m.id == id);
const bookcase = batchList[idx].bookcase;
const count = batchList[idx].count;
console.log(bookcase, "bookcase")
if (bookcase) {
const context: any = tt.createVideoContext(`${id}`);
context?.pause?.();
this.myModal?.show?.();
} else {
const params = {
sid: id
}
httpRequest('/addkeep', 'POST', params).then((res: any) => {
if (res.status == 1) {
batchList[idx].bookcase = bookcase == 1 ? 0 : 1;
batchList[idx].count = this.handelCount(count + 1)
this.setData({
batchList: batchList
})
tt.showToast({
title: '收藏成功',
icon: 'none'
});
}
})
}
this.setData({
id: id
})
},
modalConfirm() {
const id = this.data.id;
let batchList: any = this.data.batchList;
const idx = batchList.findIndex((m: any) => m.id == id);
const bookcase = batchList[idx].bookcase;
const count = batchList[idx].count;
const params = {
ids: id
}
const context: any = tt.createVideoContext(`${id}`);
context?.play?.();
httpRequest('/chasingdramadel', 'POST', params).then((res: any) => {
if (res.status == 1) {
batchList[idx].bookcase = bookcase == 1 ? 0 : 1;
batchList[idx].count = this.handelCount(count - 1)
this.setData({
batchList: batchList
})
tt.showToast({
title: '取消成功',
icon: 'none'
});
}
})
},
modalCancel() {
const id = this.data.id;
const context: any = tt.createVideoContext(`${id}`);
context?.play?.();
},
myModalRef(ref: any) {
this.myModal = ref
},
})