feat(admin): 为职位管理页面添加分页功能

This commit is contained in:
TianyangZhang 2026-03-25 17:01:06 +08:00
parent 11c1104ab1
commit 85e5cbd9c9
1 changed files with 29 additions and 6 deletions

View File

@ -23,6 +23,15 @@
</template>
</el-table-column>
</el-table>
<div style="margin-top: 16px; text-align: right;">
<el-pagination
v-model:current-page="currentPage"
:page-size="pageSize"
:total="total"
@current-change="handlePageChange"
layout="total, prev, pager, next, jumper"
/>
</div>
<el-dialog v-model="dialogVisible" :title="editingJob ? '编辑职位' : '发布职位'" width="600px">
<el-form :model="form" label-width="90px">
@ -78,12 +87,22 @@ const form = reactive({
title: '', category: '', location: '', salary: '',
description: '', status: 'draft', organization_id: null
})
const currentPage = ref(1)
const pageSize = ref(20)
const total = ref(0)
const fetchJobs = async () => {
const fetchJobs = async (page = 1) => {
loading.value = true
const { data } = await manageJobs()
jobs.value = data.results
loading.value = false
try {
const { data } = await manageJobs(page)
jobs.value = data.results
total.value = data.count
currentPage.value = page
} catch (error) {
ElMessage.error('加载职位列表失败,请重试')
} finally {
loading.value = false
}
}
const fetchOrgs = async () => {
@ -112,6 +131,10 @@ function openDialog(job = null) {
dialogVisible.value = true
}
function handlePageChange(newPage) {
fetchJobs(newPage)
}
async function handleSave() {
if (auth.isSuperAdmin && !form.organization_id) {
return ElMessage.warning('请选择所属公司')
@ -124,7 +147,7 @@ async function handleSave() {
else await createJob(payload)
ElMessage.success('保存成功')
dialogVisible.value = false
fetchJobs()
fetchJobs(1)
} catch (e) {
ElMessage.error(e.response?.data?.detail || '保存失败')
} finally {
@ -136,7 +159,7 @@ async function handleDelete(id) {
await ElMessageBox.confirm('确认删除该职位?', '提示', { type: 'warning' })
await deleteJob(id)
ElMessage.success('已删除')
fetchJobs()
fetchJobs(1)
}
onMounted(() => {