1616// under the License.
1717
1818<template >
19- <a-table
20- size = " small "
21- :columns = " fetchColumns() "
22- :dataSource = " items "
23- :rowKey = " item => item.id "
24- :loading = " loading "
25- :pagination = " false " >
19+ <div >
20+ < a-input-search
21+ v-if = " showSearch "
22+ style = " width : 25 vw ; float : right ; margin-bottom : 10 px ; z-index : 8 "
23+ :placeholder = " $t('label.search') "
24+ v-model = " filter "
25+ @search = " handleSearch " / >
2626
27- <template v-if =" routerlink " :slot =" routerlink .name " slot-scope="text, item">
28- <router-link :to =" { path: routerlink.prefix + item.id }" v-if =" routerlink.prefix" >{{ text }}</router-link >
29- <span v-else >{{ text }}</span >
30- </template >
31- <template slot="state" slot-scope="text">
32- <status :text =" text ? text : ''" />{{ text }}
33- </template >
27+ <a-table
28+ size =" small"
29+ :columns =" fetchColumns()"
30+ :dataSource =" items"
31+ :rowKey =" item => item.id"
32+ :loading =" loading"
33+ :pagination =" false"
34+ @change =" handleTableChange"
35+ @handle-search-filter =" handleTableChange" >
36+
37+ <template v-for =" (column , index ) in Object .keys (routerlinks ({})) " :slot =" column " slot-scope="text, item" >
38+ <span :key =" index" >
39+ <router-link :set =" routerlink = routerlinks(item)" :to =" { path: routerlink[column] }" >{{ text }}</router-link >
40+ </span >
41+ </template >
42+
43+ <template slot="state" slot-scope="text">
44+ <status :text =" text ? text : ''" />{{ text }}
45+ </template >
46+
47+ <template slot="status" slot-scope="text">
48+ <status :text =" text ? text : ''" />{{ text }}
49+ </template >
50+
51+ </a-table >
52+
53+ <div style =" display : block ; text-align : right ; margin-top : 10px ;" >
54+ <a-pagination
55+ size =" small"
56+ :current =" options.page"
57+ :pageSize =" options.pageSize"
58+ :total =" total"
59+ :showTotal =" total => `Total ${total} items`"
60+ :pageSizeOptions =" ['10', '20', '40']"
61+ @change =" handleTableChange"
62+ @showSizeChange =" handlePageSizeChange"
63+ showSizeChanger />
64+ </div >
65+ </div >
3466
35- </a-table >
3667</template >
3768
3869<script >
@@ -45,13 +76,17 @@ export default {
4576 Status
4677 },
4778 props: {
79+ resource: {
80+ type: Object ,
81+ default : () => {}
82+ },
4883 apiName: {
4984 type: String ,
5085 required: true
5186 },
52- routerlink : {
53- type: Object ,
54- default : () => {}
87+ routerlinks : {
88+ type: Function ,
89+ default : () => { return {} }
5590 },
5691 params: {
5792 type: Object ,
@@ -60,12 +95,35 @@ export default {
6095 columns: {
6196 type: Array ,
6297 required: true
98+ },
99+ showSearch: {
100+ type: Boolean ,
101+ default: true
63102 }
64103 },
65104 data () {
66105 return {
67106 loading: false ,
68- items: []
107+ items: [],
108+ total: 0 ,
109+ filter: ' ' ,
110+ options: {
111+ page: 1 ,
112+ pageSize: 10 ,
113+ keyword: null
114+ }
115+ }
116+ },
117+ watch: {
118+ resource (newItem , oldItem ) {
119+ if (newItem !== oldItem) {
120+ this .fetchData ()
121+ }
122+ },
123+ ' $i18n.locale' (to, from) {
124+ if (to !== from) {
125+ this .fetchData ()
126+ }
69127 }
70128 },
71129 mounted () {
@@ -74,11 +132,11 @@ export default {
74132 methods: {
75133 fetchData () {
76134 this .loading = true
77- var params = this .params
135+ var params = { ... this .params , ... this . options }
78136 params .listall = true
79137 params .response = ' json'
80138 params .details = ' min'
81- api (this .apiName , this . params ).then (json => {
139+ api (this .apiName , params).then (json => {
82140 var responseName
83141 var objectName
84142 for (const key in json) {
@@ -89,6 +147,7 @@ export default {
89147 }
90148 for (const key in json[responseName]) {
91149 if (key === ' count' ) {
150+ this .total = json[responseName][key]
92151 continue
93152 }
94153 objectName = key
@@ -112,6 +171,23 @@ export default {
112171 })
113172 }
114173 return columns
174+ },
175+ handleSearch (value ) {
176+ this .filter = value
177+ this .options .page = 1
178+ this .options .pageSize = 10
179+ this .options .keyword = this .filter
180+ this .fetchData ()
181+ },
182+ handleTableChange (page , pagesize ) {
183+ this .options .page = page
184+ this .options .pageSize = pagesize
185+ this .fetchData ()
186+ },
187+ handlePageSizeChange (page , pagesize ) {
188+ this .options .page = 1
189+ this .options .pageSize = pagesize
190+ this .fetchData ()
115191 }
116192 }
117193}
0 commit comments