-
+ 导出
+ 导入
清空
@@ -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)
},