feat(admin): 岗位发布支持超级管理员选择企业

- 超级管理员发布职位时,表单新增「所属公司」下拉选择器
- 支持集团 + 子公司层级选择(子公司用 '└' 缩进显示)
- 职位列表新增「所属公司」列,方便区分各企业岗位
- 保存前验证:超级管理员未选公司时提示「请选择所属公司」
- 普通管理员(admin)看不到选择器,后端自动绑定其公司
- 编辑职位时自动回填公司选择
- 优化错误提示:保存失败时显示后端返回的具体错误信息

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
TianyangZhang 2026-03-25 13:13:03 +08:00
parent 7e86ec5ea0
commit e3bdb0b496
1 changed files with 62 additions and 9 deletions

View File

@ -6,6 +6,7 @@
</div> </div>
<el-table :data="jobs" v-loading="loading" border> <el-table :data="jobs" v-loading="loading" border>
<el-table-column prop="title" label="职位名称" /> <el-table-column prop="title" label="职位名称" />
<el-table-column prop="organization_name" label="所属公司" />
<el-table-column prop="location" label="地点" /> <el-table-column prop="location" label="地点" />
<el-table-column prop="salary" label="薪资" /> <el-table-column prop="salary" label="薪资" />
<el-table-column prop="status" label="状态"> <el-table-column prop="status" label="状态">
@ -24,7 +25,21 @@
</el-table> </el-table>
<el-dialog v-model="dialogVisible" :title="editingJob ? '编辑职位' : '发布职位'" width="600px"> <el-dialog v-model="dialogVisible" :title="editingJob ? '编辑职位' : '发布职位'" width="600px">
<el-form :model="form" label-width="80px"> <el-form :model="form" label-width="90px">
<!-- 超管才需要选择公司 -->
<el-form-item v-if="auth.isSuperAdmin" label="所属公司">
<el-select v-model="form.organization_id" placeholder="请选择公司" style="width:100%" filterable>
<template v-for="org in allOrgs" :key="org.id">
<el-option :label="org.name" :value="org.id" />
<el-option
v-for="child in org.children"
:key="child.id"
:label="'└ ' + child.name"
:value="child.id"
/>
</template>
</el-select>
</el-form-item>
<el-form-item label="职位名称"><el-input v-model="form.title" /></el-form-item> <el-form-item label="职位名称"><el-input v-model="form.title" /></el-form-item>
<el-form-item label="职位类别"><el-input v-model="form.category" /></el-form-item> <el-form-item label="职位类别"><el-input v-model="form.category" /></el-form-item>
<el-form-item label="工作地点"><el-input v-model="form.location" /></el-form-item> <el-form-item label="工作地点"><el-input v-model="form.location" /></el-form-item>
@ -44,17 +59,25 @@
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, onMounted } from 'vue' import { ref, reactive, onMounted } from 'vue'
import { useAuthStore } from '@/stores/auth'
import { manageJobs, createJob, updateJob, deleteJob } from '@/api/jobs' import { manageJobs, createJob, updateJob, deleteJob } from '@/api/jobs'
import { getOrganizations } from '@/api/organizations'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
const auth = useAuthStore()
const jobs = ref([]) const jobs = ref([])
const allOrgs = ref([])
const loading = ref(false) const loading = ref(false)
const saving = ref(false) const saving = ref(false)
const dialogVisible = ref(false) const dialogVisible = ref(false)
const editingJob = ref(null) const editingJob = ref(null)
const form = reactive({ title: '', category: '', location: '', salary: '', description: '', status: 'draft' }) const form = reactive({
title: '', category: '', location: '', salary: '',
description: '', status: 'draft', organization_id: null
})
const fetchJobs = async () => { const fetchJobs = async () => {
loading.value = true loading.value = true
@ -63,23 +86,50 @@ const fetchJobs = async () => {
loading.value = false loading.value = false
} }
const fetchOrgs = async () => {
const { data } = await getOrganizations()
allOrgs.value = data.results
}
function openDialog(job = null) { function openDialog(job = null) {
editingJob.value = job editingJob.value = job
if (job) Object.assign(form, job) if (job) {
else Object.assign(form, { title: '', category: '', location: '', salary: '', description: '', status: 'draft' }) Object.assign(form, {
title: job.title,
category: job.category,
location: job.location,
salary: job.salary,
description: job.description,
status: job.status,
organization_id: job.organization?.id ?? job.organization ?? null,
})
} else {
Object.assign(form, {
title: '', category: '', location: '', salary: '',
description: '', status: 'draft', organization_id: null
})
}
dialogVisible.value = true dialogVisible.value = true
} }
async function handleSave() { async function handleSave() {
if (auth.isSuperAdmin && !form.organization_id) {
return ElMessage.warning('请选择所属公司')
}
saving.value = true saving.value = true
try { try {
if (editingJob.value) await updateJob(editingJob.value.id, form) const payload = { ...form }
else await createJob(form) if (!auth.isSuperAdmin) delete payload.organization_id
if (editingJob.value) await updateJob(editingJob.value.id, payload)
else await createJob(payload)
ElMessage.success('保存成功') ElMessage.success('保存成功')
dialogVisible.value = false dialogVisible.value = false
fetchJobs() fetchJobs()
} catch { ElMessage.error('保存失败') } } catch (e) {
finally { saving.value = false } ElMessage.error(e.response?.data?.detail || '保存失败')
} finally {
saving.value = false
}
} }
async function handleDelete(id) { async function handleDelete(id) {
@ -89,5 +139,8 @@ async function handleDelete(id) {
fetchJobs() fetchJobs()
} }
onMounted(fetchJobs) onMounted(() => {
fetchJobs()
if (auth.isSuperAdmin) fetchOrgs()
})
</script> </script>