From c4f0a30c51d3a17f06fadff764c3951c8a44af92 Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Thu, 9 Jan 2020 11:05:01 +0800 Subject: [PATCH] :bug: Fix: removeById handler error ISSUES CLOSED: #382 --- src/renderer/pages/Gallery.vue | 17 +++++++---------- src/universal/datastore/index.ts | 8 ++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/renderer/pages/Gallery.vue b/src/renderer/pages/Gallery.vue index ec5e0e81..56e82858 100644 --- a/src/renderer/pages/Gallery.vue +++ b/src/renderer/pages/Gallery.vue @@ -237,9 +237,8 @@ export default class extends Vue { cancelButtonText: '取消', type: 'warning' }).then(() => { - const file = this.$db.get('uploaded').getById(id) - // @ts-ignore - this.$db.read().get('uploaded').removeById(id).write() + const file = this.$db.getById('uploaded', id) + this.$db.removeById('uploaded', id) ipcRenderer.send('removeFiles', [file]) const obj = { title: '操作结果', @@ -250,7 +249,8 @@ export default class extends Vue { return true } this.getGallery() - }).catch(() => { + }).catch((e) => { + console.log(e) return true }) } @@ -302,11 +302,9 @@ export default class extends Vue { let files: ImgInfo[] = [] Object.keys(this.choosedList).forEach(key => { if (this.choosedList[key]) { - // @ts-ignore - const file = this.$db.read().get('uploaded').getById(key).value() + const file = this.$db.getById('uploaded', key) files.push(file) - // @ts-ignore - this.$db.read().get('uploaded').removeById(key).write() + this.$db.removeById('uploaded', key) } }) this.choosedList = {} @@ -332,8 +330,7 @@ export default class extends Vue { // choosedList -> { [id]: true or false }; true means choosed. false means not choosed. Object.keys(this.choosedList).forEach(key => { if (this.choosedList[key]) { - // @ts-ignore - const item = this.$db.read().get('uploaded').getById(key).value() + const item = this.$db.getById('uploaded', key) copyString += pasteStyle(style, item) + '\n' this.choosedList[key] = false } diff --git a/src/universal/datastore/index.ts b/src/universal/datastore/index.ts index b5296279..970ef87b 100644 --- a/src/universal/datastore/index.ts +++ b/src/universal/datastore/index.ts @@ -61,6 +61,14 @@ class DB { unset (key: string, value: any): boolean { return this.read().get(key).unset(value).value() } + getById (key: string, id: string) { + // @ts-ignore + return this.read().get(key).getById(id).value() + } + removeById (key: string, id: string) { + // @ts-ignore + return this.read().get(key).removeById(id).write() + } } export default new DB()