From 7ad40ba37543cdce033982e5ea92b63791d219bf Mon Sep 17 00:00:00 2001 From: haiyangcui Date: Thu, 22 Oct 2020 18:22:41 +0200 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/History.vue | 43 +++++++++++++++++++++++++++++++++++++- src/components/Setting.vue | 2 +- src/components/Star.vue | 2 +- src/lib/dexie/history.js | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/components/History.vue b/src/components/History.vue index 3859097..035e046 100644 --- a/src/components/History.vue +++ b/src/components/History.vue @@ -2,7 +2,8 @@
- + 导出 + 导入 清空
@@ -48,6 +49,8 @@ import { mapMutations } from 'vuex' import { history, sites } from '../lib/dexie' import zy from '../lib/site/tools' import Sortable from 'sortablejs' +import { remote } from 'electron' +import fs from 'fs' const { clipboard } = require('electron') export default { @@ -169,6 +172,44 @@ export default { } }) }, + exportHistory () { + this.getAllhistory() + const arr = [...this.history] + const str = JSON.stringify(arr, null, 2) + const options = { + filters: [ + { name: 'JSON file', extensions: ['json'] } + ] + } + remote.dialog.showSaveDialog(options).then(result => { + if (!result.canceled) { + fs.writeFileSync(result.filePath, str) + this.$message.success('已保存成功') + } + }).catch(err => { + this.$message.error(err) + }) + }, + importHistory () { + const options = { + filters: [ + { name: 'JSON file', extensions: ['json'] } + ], + properties: ['openFile', 'multiSelections'] + } + remote.dialog.showOpenDialog(options).then(result => { + if (!result.canceled) { + result.filePaths.forEach(file => { + var str = fs.readFileSync(file) + const json = JSON.parse(str) + history.bulkAdd(json).then(res => { + this.$message.success('导入成功') + this.getAllhistory() + }) + }) + } + }) + }, clearAllHistory () { history.clear().then(res => { this.history = [] diff --git a/src/components/Setting.vue b/src/components/Setting.vue index 33bcf27..7338628 100644 --- a/src/components/Setting.vue +++ b/src/components/Setting.vue @@ -319,7 +319,7 @@ export default { }, expShortcut () { const arr = [...this.shortcutList] - const str = JSON.stringify(arr, null, 4) + const str = JSON.stringify(arr, null, 2) clipboard.writeText(str) this.$message.success('已复制到剪贴板') }, diff --git a/src/components/Star.vue b/src/components/Star.vue index 73c7bc9..d12b4a9 100644 --- a/src/components/Star.vue +++ b/src/components/Star.vue @@ -301,7 +301,7 @@ export default { }, exportFavoritesEvent () { const arr = [...this.list] - const str = JSON.stringify(arr, null, 4) + const str = JSON.stringify(arr, null, 2) const options = { filters: [ { name: 'JSON file', extensions: ['json'] }, diff --git a/src/lib/dexie/history.js b/src/lib/dexie/history.js index 6ca8112..06b6f33 100644 --- a/src/lib/dexie/history.js +++ b/src/lib/dexie/history.js @@ -4,6 +4,9 @@ export default { async add (doc) { return await history.add(doc) }, + async bulkAdd (doc) { + return await history.bulkAdd(doc) + }, async find (doc) { return await history.get(doc) },