Переход на Vue 3, в процессе

This commit is contained in:
Book Pauk
2021-10-29 15:27:04 +07:00
parent 00cb2dc274
commit 76e09ef34e
7 changed files with 31 additions and 25 deletions

View File

@@ -85,36 +85,42 @@ class App {
//sanitize //sanitize
this.$root.sanitize = sanitizeHtml; this.$root.sanitize = sanitizeHtml;
//global keyHooks //global event hooks
this.keyHooks = []; this.eventHooks = {};
this.keyHook = (event) => { this.eventHook = (hookName, event) => {
for (const hook of this.keyHooks) if (!this.eventHooks[hookName])
return;
for (const hook of this.eventHooks[hookName])
hook(event); hook(event);
} }
this.$root.addKeyHook = (hook) => { this.$root.addEventHook = (hookName, hook) => {
if (this.keyHooks.indexOf(hook) < 0) if (!this.eventHooks[hookName])
this.keyHooks.push(hook); this.eventHooks[hookName] = [];
if (this.eventHooks[hookName].indexOf(hook) < 0)
this.eventHooks[hookName].push(hook);
} }
this.$root.removeKeyHook = (hook) => { this.$root.removeEventHook = (hookName, hook) => {
const i = this.keyHooks.indexOf(hook); if (!this.eventHooks[hookName])
return;
const i = this.eventHooks[hookName].indexOf(hook);
if (i >= 0) if (i >= 0)
this.keyHooks.splice(i, 1); this.eventHooks[hookName].splice(i, 1);
} }
document.addEventListener('keyup', (event) => { document.addEventListener('keyup', (event) => {
this.keyHook(event); this.eventHook('key', event);
}); });
document.addEventListener('keypress', (event) => { document.addEventListener('keypress', (event) => {
this.keyHook(event); this.eventHook('key', event);
}); });
document.addEventListener('keydown', (event) => { document.addEventListener('keydown', (event) => {
this.keyHook(event); this.eventHook('key', event);
}); });
window.addEventListener('resize', () => { window.addEventListener('resize', (event) => {
this.$root.$emit('resize'); this.eventHook('resize', event);
}); });
} }

View File

@@ -62,9 +62,9 @@
:nodes="nodes" :nodes="nodes"
node-key="key" node-key="key"
tick-strategy="leaf" tick-strategy="leaf"
:selected.sync="selected" v-model:selected="selected"
:ticked.sync="ticked" v-model:ticked="ticked"
:expanded.sync="expanded" v-model:expanded="expanded"
selected-color="black" selected-color="black"
:filter="search" :filter="search"
no-nodes-label="Закладок пока нет" no-nodes-label="Закладок пока нет"

View File

@@ -270,9 +270,9 @@ class ExternalLibs {
created() { created() {
this.oldStartLink = ''; this.oldStartLink = '';
this.justOpened = true; this.justOpened = true;
this.$root.addKeyHook(this.keyHook); this.$root.addEventHook('key', this.keyHook);
this.$root.$on('resize', async() => { this.$root.addEventHook('resize', async() => {
await utils.sleep(200); await utils.sleep(200);
this.frameResize(); this.frameResize();
}); });

View File

@@ -279,7 +279,7 @@ class Reader {
this.reader = this.$store.state.reader; this.reader = this.$store.state.reader;
this.config = this.$store.state.config; this.config = this.$store.state.config;
this.$root.addKeyHook(this.keyHook); this.$root.addEventHook('key', this.keyHook);
this.lastActivePage = false; this.lastActivePage = false;

View File

@@ -14,7 +14,7 @@
:data="tableData" :data="tableData"
:columns="columns" :columns="columns"
row-key="key" row-key="key"
:pagination.sync="pagination" v-model:pagination="pagination"
separator="cell" separator="cell"
hide-bottom hide-bottom
virtual-scroll virtual-scroll

View File

@@ -149,7 +149,7 @@ class TextPage {
await this.doPageAnimation(); await this.doPageAnimation();
}, 10); }, 10);
this.$root.$on('resize', async() => { this.$root.addEventHook('resize', async() => {
this.$nextTick(this.onResize); this.$nextTick(this.onResize);
await utils.sleep(500); await utils.sleep(500);
this.$nextTick(this.onResize); this.$nextTick(this.onResize);

View File

@@ -148,8 +148,8 @@ class StdDialog {
hotKeyCode = ''; hotKeyCode = '';
created() { created() {
if (this.$root.addKeyHook) { if (this.$root.addEventHook) {
this.$root.addKeyHook(this.keyHook); this.$root.addEventHook('key', this.keyHook);
} }
} }