//progress 进度条的数值(0-100)
onProgressChange: function (progress, tb) {
vm.progress = progress;
var percentage = progress / 100;
vm.location = percentage > 0 ? vm.locations.cfiFromPercentage(percentage) : 0
if (tb == 1) {
vm.rendition.display(vm.location);
}
console.log(vm.rendition.currentLocation());
},
onProgressInput: function (progress) {
var percentage = progress / 100;
vm.location = percentage > 0 ? vm.locations.cfiFromPercentage(percentage) : 0
vm.progress = progress;
this.$refs.progress.style.backgroundSize = `${progress}% 100%`;
},
//上一页
prevPage: function () {
vm.rendition.prev().then(() => {
var currentLocation = vm.rendition.currentLocation();
var cfi = currentLocation.start.cfi;
vm.refreshLocation(cfi);
var progress = Math.floor(((vm.locations.percentageFromCfi(currentLocation.start.cfi)).toFixed(5)) * 10000) / 100;
vm.progress = progress;
vm.onProgressInput(progress);
})
},
//下一页
nextPage: function () {
vm.rendition.next().then(() => {
var currentLocation = vm.rendition.currentLocation();
var cfi = currentLocation.start.cfi;
var progress = Math.floor(((vm.locations.percentageFromCfi(currentLocation.start.cfi)).toFixed(5)) * 10000) / 100;
vm.refreshLocation(cfi);
console.log(vm.section);
vm.progress = progress;
vm.onProgressInput(progress);
})
},
//渲染图书
registerBook: function () {
vm.bookName = localStorage.knowledgeId;
var url = base_url + "/mobile/downloadFile.epub?userId=" + userId + "&method=getEpub&resourceId=" + vm.bookName;
vm.book = ePub(url);
// vm.book = ePub("../static/quan20.epub");
// console.log(vm.book);
vm.rendition = vm.book.renderTo("reader", {
width: window.innerWidth,
height: vm.winHeight
});
if (localStorage.getItem(vm.bookName+'progress')) {
var tar = JSON.parse(localStorage.getItem(vm.bookName+'progress'));
vm.book.rendition.display(tar.start.cfi);
} else {
localStorage.progress = 0;
vm.book.rendition.display();
}
vm.book.ready.then(() => {
vm.navigation = vm.book.navigation;//目录
console.log(vm.navigation);
//执行分页
return vm.book.locations.generate(750 * (window.innerWidth / 375));
}).then(result => {
console.log(result);
//获取locations对象
vm.locations = vm.book.locations;
if (localStorage.getItem(vm.bookName)) {
vm.bookmark = $.parseJSON(localStorage.getItem(vm.bookName));
var currentLocation = vm.rendition.currentLocation();
var cfi = currentLocation.start.cfi;
vm.refreshLocation(cfi);
}
console.log(vm.locations);
vm.bookAvailable = true;
var pross = localStorage.progress;
vm.onProgressChange(pross, 2);
})
if (vm.rendition.themes) {
vm.rendition.themes.fontSize(vm.defaultFontSize + 'px');
}
vm.themeList.forEach(theme => {
vm.rendition.themes.register(theme.name, theme.style)
})
},