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() }) },