mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2025-12-31 03:17:49 +00:00
表格分页处理
This commit is contained in:
@@ -60,14 +60,17 @@ const props = defineProps({
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
pageInfo: {
|
page: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
pageAttrs: {
|
pageAttrs: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default () {
|
default () {
|
||||||
return {}
|
return {
|
||||||
|
layout: 'total, sizes, prev, pager, next',
|
||||||
|
pageSizes: [10, 20, 50]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -89,6 +92,9 @@ const calcColumns = computed(() => {
|
|||||||
}
|
}
|
||||||
return _columns
|
return _columns
|
||||||
})
|
})
|
||||||
|
|
||||||
|
defineEmits(['pageSizeChange', 'currentPageChange'])
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -118,10 +124,21 @@ const calcColumns = computed(() => {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</common-table-column>
|
</common-table-column>
|
||||||
<el-pagination v-if="pageInfo" />
|
|
||||||
</el-table>
|
</el-table>
|
||||||
|
<el-pagination
|
||||||
|
v-if="page && page.totalCount"
|
||||||
|
class="common-pagination"
|
||||||
|
v-bind="pageAttrs"
|
||||||
|
:total="page.totalCount"
|
||||||
|
:page-size="page.pageSize"
|
||||||
|
:current-page="page.pageIndex"
|
||||||
|
@size-change="$emit('pageSizeChange', $event)"
|
||||||
|
@current-change="$emit('currentPageChange', $event)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.common-pagination {
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -3,13 +3,16 @@
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
export const PAGE_SIZE = 10
|
export const PAGE_SIZE = 10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页数量选项
|
* 默认分页数据
|
||||||
* @type {number[]}
|
*
|
||||||
|
* @param pageSize
|
||||||
|
* @return {{pageIndex: number, pageSize: number, totalCount: number, pageNumber:number}}
|
||||||
*/
|
*/
|
||||||
export const PAGE_SIZE_LIST = [10, 20, 50]
|
export const useDefaultPage = (pageSize = PAGE_SIZE) => {
|
||||||
/**
|
return {
|
||||||
* 默认分页跳转
|
pageSize,
|
||||||
* @type {string}
|
pageIndex: 1
|
||||||
*/
|
}
|
||||||
export const PAGE_LAYOUT = 'total, prev, pager, next'
|
}
|
||||||
|
|||||||
20
src/services/user/UserService.js
Normal file
20
src/services/user/UserService.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* @typedef {Object} UserDto
|
||||||
|
* @property {number} id
|
||||||
|
* @property {string} nameCn
|
||||||
|
* @property {string} nameEn
|
||||||
|
* @property {string} address
|
||||||
|
* @property {string} gender
|
||||||
|
* @property {Date} birthday
|
||||||
|
*/
|
||||||
|
import { $httpPost } from '@/vendors/axios'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载用户数据
|
||||||
|
* @return {{success:boolean, message:string,userList: [UserDto]}}
|
||||||
|
*/
|
||||||
|
export const loadUsersResult = async config => {
|
||||||
|
const usersResult = await $httpPost('/api/users', config)
|
||||||
|
console.info('==================', usersResult)
|
||||||
|
return usersResult
|
||||||
|
}
|
||||||
@@ -48,4 +48,6 @@ export const useLoginConfigStore = defineStore('loginConfig', () => {
|
|||||||
return loginResult
|
return loginResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
persist: true
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,42 +1,33 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { loadUsersResult } from '@/services/user/UserService'
|
||||||
|
import { useDefaultPage } from '@/config'
|
||||||
|
|
||||||
const tableData = [
|
const page = ref(useDefaultPage())
|
||||||
{
|
|
||||||
id: '1',
|
const tableData = ref([])
|
||||||
birthday: '2016-05-03',
|
|
||||||
userName: 'Tom',
|
onMounted(async () => {
|
||||||
gender: 'male',
|
const usersResult = await loadUsersResult()
|
||||||
address: 'No. 189, Grove St, Los Angeles'
|
console.info('=================', usersResult)
|
||||||
},
|
if (usersResult.success && usersResult.resultData) {
|
||||||
{
|
const resultData = usersResult.resultData
|
||||||
id: '2',
|
tableData.value = resultData.userList
|
||||||
birthday: '2016-05-02',
|
Object.assign(page.value, resultData.page)
|
||||||
userName: 'Tom',
|
|
||||||
gender: 'female',
|
|
||||||
address: 'No. 189, Grove St, Los Angeles'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '3',
|
|
||||||
birthday: '2016-05-04',
|
|
||||||
userName: 'Tom',
|
|
||||||
gender: 'male',
|
|
||||||
address: 'No. 189, Grove St, Los Angeles'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
birthday: '2016-05-01',
|
|
||||||
userName: 'Tom',
|
|
||||||
gender: 'female',
|
|
||||||
address: 'No. 189, Grove St, Los Angeles'
|
|
||||||
}
|
}
|
||||||
]
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {[CommonTableColumn]}
|
* @type {[CommonTableColumn]}
|
||||||
*/
|
*/
|
||||||
const columns = [{
|
const columns = [{
|
||||||
label: '用户名',
|
label: '中文名',
|
||||||
property: 'userName',
|
property: 'nameCn',
|
||||||
|
link: '#/tables/edit'
|
||||||
|
}, {
|
||||||
|
label: '英文名',
|
||||||
|
property: 'nameEn',
|
||||||
link: '#/tables/edit'
|
link: '#/tables/edit'
|
||||||
}, {
|
}, {
|
||||||
label: '性别',
|
label: '性别',
|
||||||
@@ -81,7 +72,10 @@ const buttons = ref([{
|
|||||||
:columns="columns"
|
:columns="columns"
|
||||||
:buttons="buttons"
|
:buttons="buttons"
|
||||||
buttons-slot="buttons"
|
buttons-slot="buttons"
|
||||||
|
:page="page"
|
||||||
:buttons-column-attrs="{width:'300px'}"
|
:buttons-column-attrs="{width:'300px'}"
|
||||||
|
@page-size-change="console.info"
|
||||||
|
@current-page-change="console.info"
|
||||||
>
|
>
|
||||||
<template #gender="{item}">
|
<template #gender="{item}">
|
||||||
<el-tag
|
<el-tag
|
||||||
|
|||||||
Reference in New Issue
Block a user