fix: 修复清空本地数据时内存数据未及时清空的问题

This commit is contained in:
ZiuChen 2022-10-10 19:07:23 +08:00
parent 85291cd2cf
commit 1e408a5770
2 changed files with 10 additions and 11 deletions

View File

@ -22,6 +22,11 @@ export default function initPlugin() {
this.dataBase = {} this.dataBase = {}
this.createTime = d.getTime() this.createTime = d.getTime()
this.updateTime = d.getTime() this.updateTime = d.getTime()
this.defaultDB = {
data: [],
createTime: this.createTime,
updateTime: this.updateTime
}
} }
init() { init() {
const isExist = existsSync(this.path) const isExist = existsSync(this.path)
@ -46,13 +51,8 @@ export default function initPlugin() {
} }
return return
} }
const defaultDB = { this.dataBase = this.defaultDB
data: [], this.updateDataBaseLocal(this.defaultDB)
createTime: this.createTime,
updateTime: this.updateTime
}
this.dataBase = defaultDB
this.updateDataBaseLocal(defaultDB)
} }
watchDataBaseUpdate() { watchDataBaseUpdate() {
watch(this.path, (eventType, filename) => { watch(this.path, (eventType, filename) => {
@ -101,9 +101,8 @@ export default function initPlugin() {
this.updateDataBaseLocal() this.updateDataBaseLocal()
} }
emptyDataBase() { emptyDataBase() {
this.dataBase.data = [] window.db.dataBase.data = []
this.updateDataBase() this.updateDataBaseLocal(this.defaultDB)
this.updateDataBaseLocal()
} }
filterDataBaseViaId(id) { filterDataBaseViaId(id) {
return this.dataBase.data.filter((item) => item.id === id) return this.dataBase.data.filter((item) => item.id === id)

View File

@ -169,7 +169,7 @@ const updateShowList = (type, toTop = true) => {
const restoreDataBase = () => { const restoreDataBase = () => {
// //
ElMessageBox.confirm('确定要清空剪贴板记录吗', '提示', { ElMessageBox.confirm('即将清空剪贴板记录(包括收藏内容)', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'