解决分页排序问题

main
wuyize 2022-07-14 15:01:39 +08:00
parent 6be4f0f9a5
commit 3a7b41876a
2 changed files with 18 additions and 52 deletions

View File

@ -70,10 +70,13 @@ const tableData = ref([])
const currentPage = ref(1) const currentPage = ref(1)
const pageSize = ref(10) const pageSize = ref(10)
const total = ref(0) const total = ref(0)
const sortBy = ref(null)
const asc = ref(null)
const redirect = () => { const redirect = () => {
router.push({path: '/project/closed', query: {currentPage: currentPage.value, pageSize: pageSize.value}}) router.push({path: '/project/closed', query: {currentPage: currentPage.value, pageSize: pageSize.value, sortBy: sortBy.value, asc: asc.value}})
} }
const getClosedProjects = () => { const getClosedProjects = () => {
proxy.dialogFormVisible = false
const that = this; const that = this;
request({ request({
url: 'project', url: 'project',
@ -81,8 +84,8 @@ const getClosedProjects = () => {
params: { params: {
pageCurrent: currentPage.value, pageCurrent: currentPage.value,
pageSize: pageSize.value, pageSize: pageSize.value,
sortBy: 'projectClosedDate', sortBy: asc.value ? sortBy.value : 'projectClosedDate',
asc: false, asc: asc.value === 'ascending',
paramMap: { paramMap: {
completed: true completed: true
} }
@ -97,30 +100,11 @@ const getClosedProjects = () => {
console.log(error) console.log(error)
}) })
} }
const onSortChange = (val) => { const onSortChange = (val) => {
console.log(val) sortBy.value = val.prop
const that = this; asc.value = val.order
request({ redirect()
url: 'project',
method: 'get',
params: {
pageCurrent: currentPage.value,
pageSize: pageSize.value,
sortBy: val.order ? val.prop : 'projectClosedDate',
asc: val.order === 'ascending',
paramMap: {
completed: true
}
}
}).then(response => {
if (response.data.code === 200) {
//console.log(response.data.data.records)
total.value = response.data.data.total
tableData.value = response.data.data.records
}
}).catch(function (error) {
console.log(error)
})
} }
// //

View File

@ -85,8 +85,10 @@ const tableData = ref([])
const currentPage = ref(1) const currentPage = ref(1)
const pageSize = ref(10) const pageSize = ref(10)
const total = ref(0) const total = ref(0)
const sortBy = ref(null)
const asc = ref(null)
const redirect = () => { const redirect = () => {
router.push({path: '/', query: {currentPage: currentPage.value, pageSize: pageSize.value}}) router.push({path: '/', query: {currentPage: currentPage.value, pageSize: pageSize.value, sortBy: sortBy.value, asc: asc.value}})
} }
const getProjects = () => { const getProjects = () => {
proxy.dialogFormVisible = false proxy.dialogFormVisible = false
@ -97,8 +99,8 @@ const getProjects = () => {
params: { params: {
pageCurrent: currentPage.value, pageCurrent: currentPage.value,
pageSize: pageSize.value, pageSize: pageSize.value,
sortBy: 'projectCreatedTime', sortBy: asc.value ? sortBy.value : 'projectCreatedTime',
asc: false, asc: asc.value === 'ascending',
paramMap: { paramMap: {
completed: false completed: false
} }
@ -115,29 +117,9 @@ const getProjects = () => {
} }
const onSortChange = (val) => { const onSortChange = (val) => {
console.log(val) sortBy.value = val.prop
const that = this; asc.value = val.order
request({ redirect()
url: 'project',
method: 'get',
params: {
pageCurrent: currentPage.value,
pageSize: pageSize.value,
sortBy: val.order ? val.prop : 'projectCreatedTime',
asc: val.order === 'ascending',
paramMap: {
completed: false
}
}
}).then(response => {
if (response.data.code === 200) {
//console.log(response.data.data.records)
total.value = response.data.data.total
tableData.value = response.data.data.records
}
}).catch(function (error) {
console.log(error)
})
} }