diff --git a/src/resource/manager/VMManager.vue b/src/resource/manager/VMManager.vue index 9ca04de40e1a44e802a2e6f7f3435300142dfed0..f4580463d4f7347526e00d3fa71452dc471c61f2 100644 --- a/src/resource/manager/VMManager.vue +++ b/src/resource/manager/VMManager.vue @@ -250,7 +250,9 @@ export default { isShowForm: false, dataLoading: true, language: localStorage.getItem('language'), - timer: null + timer: null, + currentSortOrder: null, + currentSortProp: '' } }, methods: { @@ -281,7 +283,22 @@ export default { this.isShowForm = true }, sortMethod (column) { + if (column.order !== null) { + let _hostIp = sessionStorage.getItem('hostIp') + resController.queryVMsByMechost(_hostIp).then(res => { + this.paginationData = this.transferData(res.data.data) + this.sortAction(column) + this.dataLoading = false + }).catch((error) => { + this.dataLoading = false + console.log(error) + }) + } + }, + sortAction (column) { + this.currentSortProp = column.prop if (column.order === 'ascending') { + this.currentSortOrder = 'ascending' this.paginationData.sort((a, b) => { let _tempA = column.prop === 'instanceName' ? a['instanceName'] : a['status'] let _tempB = column.prop === 'instanceName' ? b['instanceName'] : b['status'] @@ -291,6 +308,7 @@ export default { return -1 }) } else if (column.order === 'descending') { + this.currentSortOrder = 'descending' this.paginationData.sort((a, b) => { let _tempA = column.prop === 'instanceName' ? a['instanceName'] : a['status'] let _tempB = column.prop === 'instanceName' ? b['instanceName'] : b['status'] @@ -496,6 +514,13 @@ export default { let _hostIp = sessionStorage.getItem('hostIp') resController.queryVMsByMechost(_hostIp).then(res => { this.paginationData = this.transferData(res.data.data) + if (this.currentSortOrder !== null) { + let _column = { + order: this.currentSortOrder, + prop: this.currentSortProp + } + this.sortAction(_column) + } this.dataLoading = false }).catch(() => { this.dataLoading = false