|
21 | 21 | :placeholder="$t('label.search')" |
22 | 22 | v-model="searchQuery" |
23 | 23 | style="margin-bottom: 10px;" |
24 | | - @search="fetchData" /> |
| 24 | + @search="handleSearch" /> |
25 | 25 | <a-table |
26 | 26 | size="small" |
27 | 27 | style="overflow-y: auto" |
28 | 28 | :loading="loading" |
29 | 29 | :columns="columns" |
30 | | - :dataSource="hosts" |
| 30 | + :dataSource="items" |
31 | 31 | :pagination="false" |
32 | 32 | :rowKey="record => record.id"> |
33 | 33 | <div slot="suitability" slot-scope="record"> |
@@ -95,6 +95,7 @@ export default { |
95 | 95 | return { |
96 | 96 | loading: true, |
97 | 97 | hosts: [], |
| 98 | + items: [], |
98 | 99 | selectedHost: {}, |
99 | 100 | searchQuery: '', |
100 | 101 | totalCount: 0, |
@@ -129,23 +130,34 @@ export default { |
129 | 130 | }, |
130 | 131 | methods: { |
131 | 132 | fetchData () { |
132 | | - this.loading = true |
133 | | - api('findHostsForMigration', { |
134 | | - virtualmachineid: this.resource.id, |
135 | | - keyword: this.searchQuery, |
136 | | - page: this.page, |
137 | | - pagesize: this.pageSize |
138 | | - }).then(response => { |
139 | | - this.hosts = response.findhostsformigrationresponse.host |
140 | | - this.totalCount = response.findhostsformigrationresponse.count |
141 | | - if (this.totalCount > 0) { |
142 | | - this.totalCount -= 1 |
143 | | - } |
144 | | - }).catch(error => { |
145 | | - this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`) |
146 | | - }).finally(() => { |
147 | | - this.loading = false |
148 | | - }) |
| 133 | + var page = 1 |
| 134 | + const hosts = [] |
| 135 | + const getNextPage = () => { |
| 136 | + this.loading = true |
| 137 | + api('findHostsForMigration', { |
| 138 | + virtualmachineid: this.resource.id, |
| 139 | + listAll: true, |
| 140 | + details: 'min', |
| 141 | + page: page, |
| 142 | + pageSize: 500 |
| 143 | + }).then(response => { |
| 144 | + if (response && response.findhostsformigrationresponse && response.findhostsformigrationresponse.host) { |
| 145 | + hosts.push(...response.findhostsformigrationresponse.host) |
| 146 | + } |
| 147 | + if (response.findhostsformigrationresponse.host) { |
| 148 | + page++ |
| 149 | + getNextPage() |
| 150 | + } |
| 151 | + }).catch(error => { |
| 152 | + this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`) |
| 153 | + }).finally(() => { |
| 154 | + this.hosts = hosts |
| 155 | + this.totalCount = this.hosts.length |
| 156 | + this.items = this.hosts.slice(0, Math.min(this.totalCount, this.pageSize)) |
| 157 | + this.loading = false |
| 158 | + }) |
| 159 | + } |
| 160 | + getNextPage() |
149 | 161 | }, |
150 | 162 | submitForm () { |
151 | 163 | this.loading = true |
@@ -181,15 +193,27 @@ export default { |
181 | 193 | this.$message.error(`${this.$t('message.migrating.vm.to.host.failed')} ${this.selectedHost.name}`) |
182 | 194 | }) |
183 | 195 | }, |
| 196 | + handleSearch () { |
| 197 | + this.loading = true |
| 198 | + this.page = 1 |
| 199 | + this.items = this.hosts.filter(x => x.name.toLowerCase().includes(this.searchQuery)) |
| 200 | + this.totalCount = this.items.length |
| 201 | + this.items = this.items.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize)) |
| 202 | + this.loading = false |
| 203 | + }, |
184 | 204 | handleChangePage (page, pageSize) { |
| 205 | + this.loading = true |
185 | 206 | this.page = page |
186 | 207 | this.pageSize = pageSize |
187 | | - this.fetchData() |
| 208 | + this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize)) |
| 209 | + this.loading = false |
188 | 210 | }, |
189 | 211 | handleChangePageSize (currentPage, pageSize) { |
| 212 | + this.loading = true |
190 | 213 | this.page = currentPage |
191 | 214 | this.pageSize = pageSize |
192 | | - this.fetchData() |
| 215 | + this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize)) |
| 216 | + this.loading = false |
193 | 217 | } |
194 | 218 | }, |
195 | 219 | filters: { |
|
0 commit comments