gree_leran/unpackage/dist/dev/mp-weixin/pages/video/video.js

120 lines
4.1 KiB
JavaScript
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.

"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
data() {
return {
screenHeight: 0,
statusBarHeight: 0,
navBarHeight: 0,
originList: [],
// 源数据
displaySwiperList: [],
// swiper需要的数据
displayIndex: 0,
// 用于显示swiper的真正的下标数值只有012。
originIndex: 0,
// 记录源数据的下标
changeIndex: 0,
//控制video是否渲染
page: 0,
// 视频分页
num: 0,
flag: true
};
},
onLoad() {
common_vendor.wx$1.getSystemInfo({
success: (res) => {
this.screenHeight = res.screenHeight;
this.statusBarHeight = res.statusBarHeight;
if (res.system.substring(0, 3) == "iOS") {
this.navBarHeight = 42;
} else {
this.navBarHeight = 40;
}
}
});
this.getPageID();
},
methods: {
/* 生成随机的 pageID */
getPageID() {
let pageID = parseInt(Math.random() * (0 - 100 + 1) + 100);
this.getVideoList(pageID);
},
/* 获取视频数据 */
getVideoList(pageID) {
common_vendor.index.request({
url: "https://api.apiopen.top/api/getMiniVideo?page=" + pageID + "&size=10&pageSize=10",
// 请求数据接口
data: {},
success: (res) => {
if (res.data.code == 200) {
res.data.result.list.forEach((item) => {
let obj = {};
obj.src = item.playurl;
obj.title = item.title;
this.originList.push(obj);
});
}
if (this.flag) {
this.flag = false;
this.initSwiperData(0);
}
}
});
},
changed(event) {
let {
current
} = event.detail;
let originListLength = this.originList.length;
this.changeIndex = current;
if (this.displayIndex - current == 2 || this.displayIndex - current == -1) {
this.originIndex = this.originIndex + 1 == originListLength ? 0 : this.originIndex + 1;
this.displayIndex = this.displayIndex + 1 == 3 ? 0 : this.displayIndex + 1;
this.initSwiperData(this.originIndex);
this.num++;
console.log("num", this.num, this.originList.length);
if (this.num + 5 >= this.originList.length) {
this.getPageID();
}
} else if (this.displayIndex - current == -2 || this.displayIndex - current == 1) {
this.originIndex = this.originIndex - 1 == -1 ? originListLength - 1 : this.originIndex - 1;
this.displayIndex = this.displayIndex - 1 == -1 ? 2 : this.displayIndex - 1;
this.initSwiperData(this.originIndex);
if (this.num > 0) {
this.num--;
}
}
},
initSwiperData(originIndex = this.originIndex) {
let originListLength = this.originList.length;
let displayList = [];
displayList[this.displayIndex] = this.originList[originIndex];
displayList[this.displayIndex - 1 == -1 ? 2 : this.displayIndex - 1] = this.originList[originIndex - 1 == -1 ? originListLength - 1 : originIndex - 1];
displayList[this.displayIndex + 1 == 3 ? 0 : this.displayIndex + 1] = this.originList[originIndex + 1 == originListLength ? 0 : originIndex + 1];
this.displaySwiperList = displayList;
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: common_vendor.f($data.displaySwiperList, (item, index, i0) => {
return common_vendor.e({
a: index == $data.changeIndex
}, index == $data.changeIndex ? {
b: item.src
} : {}, {
c: common_vendor.t(item.title),
d: index
});
}),
b: common_vendor.o((...args) => _ctx.transition && _ctx.transition(...args)),
c: common_vendor.o((...args) => $options.changed && $options.changed(...args)),
d: $data.screenHeight - $data.navBarHeight + "px"
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "E:/DAN/wexinxiaochengxude/NewCode2/gree_leran/pages/video/video.vue"]]);
wx.createPage(MiniProgramPage);