🐛 Fix: removeById handler error

ISSUES CLOSED: #382
This commit is contained in:
Molunerfinn
2020-01-09 11:05:01 +08:00
parent 762dc9b2cc
commit c4f0a30c51
2 changed files with 15 additions and 10 deletions
+7 -10
View File
@@ -237,9 +237,8 @@ export default class extends Vue {
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
const file = this.$db.get('uploaded').getById(id) const file = this.$db.getById('uploaded', id)
// @ts-ignore this.$db.removeById('uploaded', id)
this.$db.read().get('uploaded').removeById(id).write()
ipcRenderer.send('removeFiles', [file]) ipcRenderer.send('removeFiles', [file])
const obj = { const obj = {
title: '操作结果', title: '操作结果',
@@ -250,7 +249,8 @@ export default class extends Vue {
return true return true
} }
this.getGallery() this.getGallery()
}).catch(() => { }).catch((e) => {
console.log(e)
return true return true
}) })
} }
@@ -302,11 +302,9 @@ export default class extends Vue {
let files: ImgInfo[] = [] let files: ImgInfo[] = []
Object.keys(this.choosedList).forEach(key => { Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) { if (this.choosedList[key]) {
// @ts-ignore const file = this.$db.getById('uploaded', key)
const file = this.$db.read().get('uploaded').getById(key).value()
files.push(file) files.push(file)
// @ts-ignore this.$db.removeById('uploaded', key)
this.$db.read().get('uploaded').removeById(key).write()
} }
}) })
this.choosedList = {} this.choosedList = {}
@@ -332,8 +330,7 @@ export default class extends Vue {
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed. // choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
Object.keys(this.choosedList).forEach(key => { Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) { if (this.choosedList[key]) {
// @ts-ignore const item = this.$db.getById('uploaded', key)
const item = this.$db.read().get('uploaded').getById(key).value()
copyString += pasteStyle(style, item) + '\n' copyString += pasteStyle(style, item) + '\n'
this.choosedList[key] = false this.choosedList[key] = false
} }
+8
View File
@@ -61,6 +61,14 @@ class DB {
unset (key: string, value: any): boolean { unset (key: string, value: any): boolean {
return this.read().get(key).unset(value).value() 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() export default new DB()