From 1c74174a3a8fa2ab8e54fe6874c8e51486b9967a Mon Sep 17 00:00:00 2001 From: buvta <12312540+buvta@users.noreply.github.com> Date: Sun, 11 Oct 2020 14:11:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=96=E7=BC=96=E8=BE=91=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug已解决 --- src/components/EditSites.vue | 115 +++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/src/components/EditSites.vue b/src/components/EditSites.vue index e140fa5..2e155f2 100644 --- a/src/components/EditSites.vue +++ b/src/components/EditSites.vue @@ -3,7 +3,7 @@
-
添加新源
+
添加新源
导出
@@ -21,44 +21,35 @@
+
+ + + + + + + + + + + + + + 取消 + 保存 + + +
-
-
    -
  • - 源名称 - API接口 - DOWNLOAD接口 - - - - -
  • -
  • - - - - - - - - - - - 添加 - 关闭 - -
  • -
  • -
-
  • {{i.name}} + 编辑 删除
  • @@ -78,17 +69,33 @@ import draggable from 'vuedraggable' import { remote } from 'electron' import { sites as defaultSites } from '../lib/dexie/initData' import fs from 'fs' +import Vue from 'vue' +import ElementUI from 'element-ui' +Vue.use(ElementUI) + export default { name: 'editSites', data () { return { show: false, sites: [], - showAddSite: false, - newSite: { + dialogType: 'new', + dialogVisible: false, + siteInfo: { name: '', api: '', download: '' + }, + rules: { + name: [ + { required: true, message: '源站名不能为空', trigger: 'blur' } + ], + api: [ + { required: true, message: 'API地址不能为空', trigger: 'blur' } + ], + download: [ + { required: false, trigger: 'blur' } + ] } } }, @@ -123,6 +130,24 @@ export default { this.sites = res }) }, + addSite () { + this.dialogType = 'new' + this.dialogVisible = true + this.siteInfo = { + name: '', + api: '', + download: '' + } + }, + editSite (siteInfo) { + this.dialogType = 'edit' + this.dialogVisible = true + this.siteInfo = siteInfo + }, + closeDialog () { + this.dialogVisible = false + this.getSites() + }, removeEvent (e) { sites.remove(e.id).then(res => { this.getSites() @@ -141,32 +166,28 @@ export default { }) }) }, - openAddSite () { - this.showAddSite = true - }, - closeAddSite () { - this.showAddSite = false - }, - addNewSite () { - if (!this.newSite.name || !this.newSite.api) { + addOrEditSite () { + if (!this.siteInfo.name || !this.siteInfo.api) { this.$message.error('名称和API接口不能为空。') return } 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 + key: this.dialogType === 'edit' ? this.siteInfo.key : randomstring.generate(6), + id: this.dialogType === 'edit' ? this.siteInfo.id : this.sites[this.sites.length - 1].id + 1, + name: this.siteInfo.name, + api: this.siteInfo.api, + download: this.siteInfo.download } + if (this.dialogType === 'edit') sites.remove(this.siteInfo.id) sites.add(doc).then(res => { - this.newSite = { + this.siteInfo = { name: '', api: '', download: '' } - this.$message.success('添加新源成功!') + this.dialogType === 'edit' ? this.$message.success('修改成功!') : this.$message.success('添加新源成功!') + this.dialogVisible = false this.getSites() }) },