From 803181b4f7b0e2f6f5d1e011a28021fd1c49fdc1 Mon Sep 17 00:00:00 2001 From: haiyangcui Date: Sun, 25 Oct 2020 13:49:58 +0100 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BA=90=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=90=8EFilm=E9=A1=B5=E9=9D=A2=E4=B8=8D?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/EditSites.vue | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/EditSites.vue b/src/components/EditSites.vue index 3935234..e299ca1 100644 --- a/src/components/EditSites.vue +++ b/src/components/EditSites.vue @@ -177,7 +177,8 @@ export default { this.multipleSelection = rows }, handleSortChange (column, prop, order) { - this.updateDatabase() + this.syncTableData() + this.updateDatabase(this.sites) }, saveBatchEdit () { this.multipleSelection.forEach(ele => { @@ -326,10 +327,16 @@ export default { }, moveToTopEvent (i) { this.sites.sort(function (x, y) { return x.key === i.key ? -1 : y.key === i.key ? 1 : 0 }) - this.updateDatabase() + this.updateDatabase(this.sites) }, - isActiveChangeEvent () { - this.updateDatabase() + syncTableData () { + if (this.$refs.editSitesTable.tableData && this.$refs.editSitesTable.tableData.length === this.sites.length) { + this.sites = this.$refs.editSitesTable.tableData + } + }, + isActiveChangeEvent (row) { + this.syncTableData() + this.updateDatabase(this.sites) }, resetId (inArray) { var id = 1 @@ -338,17 +345,14 @@ export default { id += 1 }) }, - updateDatabase () { - if (this.$refs.editSitesTable.tableData && this.$refs.editSitesTable.tableData.length === this.sites.length) { - this.sites = this.$refs.editSitesTable.tableData - } + updateDatabase (data) { sites.clear().then(res => { var id = 1 - this.sites.forEach(ele => { + data.forEach(ele => { ele.id = id id += 1 }) - sites.bulkAdd(this.sites) + sites.bulkAdd(data).then(this.getSites()) }) }, removeAllSites () { @@ -356,12 +360,12 @@ export default { }, rowDrop () { const tbody = document.getElementById('sites-table').querySelector('.el-table__body-wrapper tbody') - const _this = this + var _this = this Sortable.create(tbody, { onEnd ({ newIndex, oldIndex }) { const currRow = _this.sites.splice(oldIndex, 1)[0] _this.sites.splice(newIndex, 0, currRow) - _this.updateDatabase() + _this.updateDatabase(_this.sites) } }) }