Улучшение отображения загрузки списка недавних

This commit is contained in:
Book Pauk
2019-08-22 23:37:55 +07:00
parent 0c654d9346
commit 696f434c90
2 changed files with 32 additions and 19 deletions

View File

@@ -122,28 +122,33 @@ export default @Component({
class HistoryPage extends Vue { class HistoryPage extends Vue {
loading = false; loading = false;
search = null; search = null;
tableData = null; tableData = [];
key = 0;
created() { created() {
} }
init() { init() {
bookManager.addEventListener(this.bookManagerEvent);
this.updateTableData(5);
this.$nextTick(() => { this.$nextTick(() => {
//this.$refs.input.focus(); //this.$refs.input.focus();
}); });
(async() => {//отбражение подгрузки списка (async() => {//отбражение подгрузки списка
await utils.sleep(1000); if (this.initing)
if (this.bookManagerLoaded) return;
this.updateTableData(); this.initing = true;
else {
await this.updateTableData(5);
await utils.sleep(200);
await this.updateTableData(15);
await utils.sleep(800);
if (!bookManager.loaded) {
let i = 0; let i = 0;
let j = 5; let j = 5;
while (i < 500 && !this.bookManagerLoaded) { while (i < 500 && !bookManager.loaded) {
if (i % j == 0) { if (i % j == 0) {
bookManager.sortedRecentCached = null; bookManager.sortedRecentCached = null;
this.updateTableData(100); await this.updateTableData(100);
j *= 2; j *= 2;
} }
@@ -151,21 +156,19 @@ class HistoryPage extends Vue {
i++; i++;
} }
} }
await this.updateTableData();
this.initing = false;
})(); })();
} }
bookManagerEvent(eventName) {
if (eventName == 'load-stored-finish') {
this.updateTableData();
this.bookManagerLoaded = true;
}
}
rowKey(row) { rowKey(row) {
return row.key; return row.rowKey;
} }
updateTableData(limit) { async updateTableData(limit) {
while (this.updating) await utils.sleep(100);
this.updating = true;
this.key++;
let result = []; let result = [];
this.loading = !!limit; this.loading = !!limit;
@@ -227,6 +230,7 @@ class HistoryPage extends Vue {
url: book.url, url: book.url,
path: book.path, path: book.path,
key: book.key, key: book.key,
rowKey: book.key + this.key.toString(),
}); });
if (result.length >= 100) if (result.length >= 100)
break; break;
@@ -241,7 +245,16 @@ class HistoryPage extends Vue {
item.desc.author.toLowerCase().includes(search.toLowerCase()) item.desc.author.toLowerCase().includes(search.toLowerCase())
}); });
/*for (let i = 0; i < result.length; i++) {
if (!_.isEqual(this.tableData[i], result[i])) {
this.$set(this.tableData, i, result[i]);
await utils.sleep(10);
}
}
if (this.tableData.length > result.length)
this.tableData.splice(result.length);*/
this.tableData = result; this.tableData = result;
this.updating = false;
} }
headerCellStyle(cell) { headerCellStyle(cell) {

View File

@@ -392,7 +392,7 @@ class Reader extends Vue {
if (eventName == 'recent-changed') { if (eventName == 'recent-changed') {
if (this.historyActive) { if (this.historyActive) {
this.$refs.historyPage.updateTableData(); await this.$refs.historyPage.updateTableData();
} }
const oldBook = this.mostRecentBookReactive; const oldBook = this.mostRecentBookReactive;