Commit c0a26790 by Sendya

fix: table refresh(bool) reset pageNo = 1

parent 4c6df88e
...@@ -2,7 +2,7 @@ import T from 'ant-design-vue/es/table/Table' ...@@ -2,7 +2,7 @@ import T from 'ant-design-vue/es/table/Table'
import get from 'lodash.get' import get from 'lodash.get'
export default { export default {
data() { data () {
return { return {
needTotalList: [], needTotalList: [],
...@@ -55,11 +55,12 @@ export default { ...@@ -55,11 +55,12 @@ export default {
default: false default: false
}, },
showPagination: { showPagination: {
type: String,
default: 'auto' default: 'auto'
} }
}), }),
watch: { watch: {
'localPagination.current'(val) { 'localPagination.current' (val) {
this.$router.push({ this.$router.push({
name: this.$route.name, name: this.$route.name,
params: Object.assign({}, this.$route.params, { params: Object.assign({}, this.$route.params, {
...@@ -67,23 +68,23 @@ export default { ...@@ -67,23 +68,23 @@ export default {
}) })
}) })
}, },
pageNum(val) { pageNum (val) {
Object.assign(this.localPagination, { Object.assign(this.localPagination, {
current: val current: val
}) })
}, },
pageSize(val) { pageSize (val) {
Object.assign(this.localPagination, { Object.assign(this.localPagination, {
pageSize: val pageSize: val
}) })
}, },
showSizeChanger(val) { showSizeChanger (val) {
Object.assign(this.localPagination, { Object.assign(this.localPagination, {
showSizeChanger: val showSizeChanger: val
}) })
} }
}, },
created() { created () {
this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, { this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
current: this.pageNum, current: this.pageNum,
pageSize: this.pageSize, pageSize: this.pageSize,
...@@ -93,29 +94,38 @@ export default { ...@@ -93,29 +94,38 @@ export default {
this.loadData() this.loadData()
}, },
methods: { methods: {
refresh() { /**
this.loadData() * 表格重新加载方法
* 如果参数为 true, 则强制刷新到第一页
* @param Boolean bool
*/
refresh(bool = false) {
this.loadData(bool ? { current: 1 }: {})
}, },
loadData(pagination, filters, sorter) { /**
* 加载数据方法
* @param {Object} pagination 分页选项器
* @param {Object} filters 过滤条件
* @param {Object} sorter 排序条件
*/
loadData (pagination, filters, sorter) {
this.localLoading = true this.localLoading = true
var result = this.data( var result = this.data(Object.assign({
Object.assign({ pageNo: (pagination && pagination.current) ||
pageNo: (pagination && pagination.current) || this.localPagination.current,
this.localPagination.current, pageSize: (pagination && pagination.pageSize) ||
pageSize: (pagination && pagination.pageSize) || this.localPagination.pageSize
this.localPagination.pageSize },
}, (sorter && sorter.field && {
(sorter && sorter.field && { sortField: sorter.field
sortField: sorter.field }) || {},
}) || {}, (sorter && sorter.order && {
(sorter && sorter.order && { sortOrder: sorter.order
sortOrder: sorter.order }) || {}, {
}) || {}, { ...filters
...filters }
} ))
)
)
// 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data // 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data
if (result instanceof Promise) { if (result instanceof Promise) {
...@@ -143,7 +153,7 @@ export default { ...@@ -143,7 +153,7 @@ export default {
}) })
} }
}, },
initTotalList(columns) { initTotalList (columns) {
const totalList = [] const totalList = []
columns && columns instanceof Array && columns.forEach(column => { columns && columns instanceof Array && columns.forEach(column => {
if (column.needTotal) { if (column.needTotal) {
...@@ -160,7 +170,7 @@ export default { ...@@ -160,7 +170,7 @@ export default {
* @param selectedRowKeys * @param selectedRowKeys
* @param selectedRows * @param selectedRows
*/ */
updateSelect(selectedRowKeys, selectedRows) { updateSelect (selectedRowKeys, selectedRows) {
this.selectedRows = selectedRows this.selectedRows = selectedRows
const list = this.needTotalList const list = this.needTotalList
this.needTotalList = list.map(item => { this.needTotalList = list.map(item => {
...@@ -223,7 +233,7 @@ export default { ...@@ -223,7 +233,7 @@ export default {
} }
}, },
render() { render () {
const props = {} const props = {}
const localKeys = Object.keys(this.$data) const localKeys = Object.keys(this.$data)
const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) || this.alert const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) || this.alert
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
</template> </template>
<a-col :md="!advanced && 8 || 24" :sm="24"> <a-col :md="!advanced && 8 || 24" :sm="24">
<span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} "> <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
<a-button type="primary" @click="$refs.table.refresh()">查询</a-button> <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button> <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
<a @click="toggleAdvanced" style="margin-left: 8px"> <a @click="toggleAdvanced" style="margin-left: 8px">
{{ advanced ? '收起' : '展开' }} {{ advanced ? '收起' : '展开' }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment