From 3a2a16a1680450c1b35b82bf3a106d7c99b32c39 Mon Sep 17 00:00:00 2001 From: haiyangcui Date: Wed, 9 Sep 2020 23:20:48 +0200 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0"=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E6=BA=90"=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/components/EditSites.vue | 69 ++++++++++++++++++++++++++++++++---- src/components/Setting.vue | 11 ------ src/lib/dexie/sites.js | 3 ++ 4 files changed, 67 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 9610ef2..9dfb1c6 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "modern-normalize": "^0.6.0", "mousetrap": "^1.6.5", "qrcode.vue": "^1.7.0", + "randomstring": "^1.1.5", "vue": "^2.6.11", "vue-infinite-loading": "^2.4.5", "vue-waterfall-plugin": "^1.0.7", diff --git a/src/components/EditSites.vue b/src/components/EditSites.vue index e519281..76b89c2 100644 --- a/src/components/EditSites.vue +++ b/src/components/EditSites.vue @@ -2,7 +2,9 @@
- 源管理 +
+
添加新源
+
关闭 @@ -13,6 +15,35 @@
+
+
    +
  • + 源名称 + Api接口 + Download接口 + + + + +
  • +
  • + + + + + + + + + + + 添加 + 关闭 + +
  • +
  • +
+
    @@ -40,19 +71,25 @@ export default { data () { return { show: false, - sites: [] + sites: [], + showAddSite: false, + newSite: { + name: '', + api: '', + download: '' + } } }, components: { draggable }, computed: { - view: { + setting: { get () { - return this.$store.getters.getView + return this.$store.getters.getSetting }, set (val) { - this.SET_VIEW(val) + this.SET_SETTING(val) } }, editSites: { @@ -65,7 +102,7 @@ export default { } }, methods: { - ...mapMutations(['SET_VIEW', 'SET_EDITSITES']), + ...mapMutations(['SET_SETTING', 'SET_EDITSITES']), close () { this.editSites.show = false }, @@ -91,6 +128,26 @@ export default { id += 1 }) }) + }, + openAddSite () { + this.showAddSite = true + }, + closeAddSite () { + this.showAddSite = false + }, + addNewSite () { + var randomstring = require('randomstring') + var doc = { + key: randomstring.generate(6), + id: this.sites[this.sites.length - 1].id + 1, + name: this.newSite.name, + api: this.newSite.api, + download: this.newSite.download + } + sites.add(doc).then(res => { + this.$message.success('添加新源成功!') + this.getSites() + }) } }, created () { diff --git a/src/components/Setting.vue b/src/components/Setting.vue index a6397e9..03deebc 100644 --- a/src/components/Setting.vue +++ b/src/components/Setting.vue @@ -95,17 +95,6 @@
    重置源
    -
    -
    默认源
    -
    -
      -
    • {{ i.name }}
    • -
    -
    -
    -
    -
    说明文档
    -
diff --git a/src/lib/dexie/sites.js b/src/lib/dexie/sites.js index 4d84e64..9b8db1c 100644 --- a/src/lib/dexie/sites.js +++ b/src/lib/dexie/sites.js @@ -15,5 +15,8 @@ export default { }, async add (doc) { return await sites.add(doc) + }, + async remove (id) { + return await sites.delete(id) } }