62fd5365 by zhen

优化分页组件props

1 parent 6ac9f8bb
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
5 layout="total, prev, pager, next, sizes, jumper" 5 layout="total, prev, pager, next, sizes, jumper"
6 :total="pagination.total" 6 :total="pagination.total"
7 :current-page.sync="pagination.page" 7 :current-page.sync="pagination.page"
8 :page-size.sync="pagination.size"
8 @current-change="handleCurrentChange" 9 @current-change="handleCurrentChange"
9 @size-change="handleSizeChange" 10 @size-change="handleSizeChange"
10 ></el-pagination> 11 ></el-pagination>
...@@ -14,38 +15,17 @@ ...@@ -14,38 +15,17 @@
14 <script> 15 <script>
15 export default { 16 export default {
16 props: { 17 props: {
17 total: { 18 pagination: {
18 type: Number, 19 type: Object,
19 default: 0 20 default: () => ({ size: 10, total: 0, page: 1 })
20 } 21 }
21 }, 22 },
22 data() {
23 return {
24 pagination: {
25 size: 10,
26 total: this.total,
27 page: 1
28 }
29 }
30 },
31 watch: {
32 total(val) {
33 this.pagination.total = val
34 }
35 },
36 mounted() {
37 this.$emit('pager', { ...this.pagination })
38 },
39 methods: { 23 methods: {
40 changeCurrentSize(page) {
41 this.pagination.page = page
42 this.handleCurrentChange(page)
43 },
44 handleCurrentChange(page) { 24 handleCurrentChange(page) {
45 this.$emit('pager', { ...this.pagination, page }) 25 this.$emit('pagination', { ...this.pagination, page })
46 }, 26 },
47 handleSizeChange(size) { 27 handleSizeChange(size) {
48 this.$emit('pager', { ...this.pagination, size }) 28 this.$emit('pagination', { ...this.pagination, size })
49 } 29 }
50 } 30 }
51 } 31 }
......
...@@ -103,11 +103,7 @@ ...@@ -103,11 +103,7 @@
103 </template> 103 </template>
104 </el-table-column> 104 </el-table-column>
105 </el-table> 105 </el-table>
106 <FooterPaginationfrom 106 <FooterPaginationfrom :pagination="pagination"></FooterPaginationfrom>
107 ref="paginationRef"
108 :total="total"
109 @pager="handleGetPager"
110 ></FooterPaginationfrom>
111 </Card> 107 </Card>
112 </template> 108 </template>
113 109
...@@ -132,14 +128,25 @@ export default { ...@@ -132,14 +128,25 @@ export default {
132 times: ['', ''] 128 times: ['', '']
133 }, 129 },
134 tableData: [], 130 tableData: [],
135 pagination: null, 131 pagination: { size: 10, total: 0, page: 1 },
136 loading: false, 132 loading: false
137 total: 0
138 } 133 }
139 }, 134 },
135 watch: {
136 'pagination.size'() {
137 this.handleGetResourceMonitorList()
138 },
139 'pagination.page'() {
140 this.handleGetResourceMonitorList()
141 }
142 },
143 mounted() {
144 this.handleGetResourceMonitorList()
145 },
140 methods: { 146 methods: {
141 async handleGetResourceMonitorList() { 147 async handleGetResourceMonitorList() {
142 try { 148 try {
149 this.loading = true
143 const { 150 const {
144 result: { list, total } 151 result: { list, total }
145 } = await getResourceMonitorList({ 152 } = await getResourceMonitorList({
...@@ -151,14 +158,19 @@ export default { ...@@ -151,14 +158,19 @@ export default {
151 row: this.pagination.size 158 row: this.pagination.size
152 }) 159 })
153 this.tableData = list 160 this.tableData = list
154 this.total = total 161 this.pagination.total = total
155 } catch (error) { 162 } catch (error) {
156 console.log(error) 163 console.log(error)
164 } finally {
165 this.loading = false
157 } 166 }
158 }, 167 },
159 submit() { 168 submit() {
160 // 会触发pager事件 169 if (this.pagination.page === 1) {
161 this.$refs.paginationRef.changeCurrentSize(1) 170 this.handleGetResourceMonitorList()
171 } else {
172 this.pagination.page = 1
173 }
162 }, 174 },
163 onReset() { 175 onReset() {
164 this.ruleForm = { 176 this.ruleForm = {
...@@ -168,20 +180,6 @@ export default { ...@@ -168,20 +180,6 @@ export default {
168 } 180 }
169 this.submit() 181 this.submit()
170 }, 182 },
171 handleGetPager(data) {
172 this.pagination = data
173 this.handleQueryOrderList()
174 },
175 async handleQueryOrderList() {
176 try {
177 this.loading = true
178 await this.handleGetResourceMonitorList()
179 } catch (error) {
180 console.log(error)
181 } finally {
182 this.loading = false
183 }
184 },
185 handleDetail(row) { 183 handleDetail(row) {
186 this.$router.push({ 184 this.$router.push({
187 path: 'monitor-details', 185 path: 'monitor-details',
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!