197 lines
5.1 KiB
TypeScript
197 lines
5.1 KiB
TypeScript
// 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: '',
|
||
page: 1,
|
||
statusBarHeight: getApp().globalData.statusBarHeight
|
||
},
|
||
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,
|
||
})
|
||
if (current + 5 >= batchList.length) {
|
||
const page = this.data.page;
|
||
this.initFn(page + 1)
|
||
}
|
||
|
||
},
|
||
videoPlayerEnded() {
|
||
console.log('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 playlet,please 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 playlet,please 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].bookcase;
|
||
batchList[idx].bookcase = bookcase == 1 ? 0 : 1;
|
||
if (bookcase) {
|
||
const params = {
|
||
ids: id
|
||
}
|
||
httpRequest('/chasingdramadel', 'POST', params).then((res: any) => {
|
||
if (res.status == 1) {
|
||
batchList[idx].count = this.handelCount(count - 1)
|
||
this.setData({
|
||
batchList: batchList
|
||
})
|
||
tt.showToast({
|
||
title: '取消成功',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
})
|
||
} else {
|
||
const params = {
|
||
sid: id
|
||
}
|
||
httpRequest('/addkeep', 'POST', params).then((res: any) => {
|
||
if (res.status == 1) {
|
||
batchList[idx].count = this.handelCount(count + 1)
|
||
this.setData({
|
||
batchList: batchList
|
||
})
|
||
tt.showToast({
|
||
title: '收藏成功',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
})
|
||
|
||
}
|
||
|
||
},
|
||
}) |