fix: 组长可选负责人 — 新增 /users/brief 轻量接口
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 2m7s
Build and Deploy Web / build-and-deploy (push) Successful in 1m53s

- 新增 GET /api/users/brief 仅返回 id+name,任何登录用户可调用
- Projects.vue / ProjectDetail.vue 改用 brief() 接口,去掉 user:view 权限守卫
- 解决组长新建项目时负责人下拉框"无数据"的问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
seaislee1209 2026-02-25 16:07:01 +08:00
parent 74106ac21b
commit 32658fa608
4 changed files with 16 additions and 7 deletions

View File

@ -28,6 +28,16 @@ def _can_view_cost(user: User) -> bool:
return "user:view_cost" in (user.permissions or []) return "user:view_cost" in (user.permissions or [])
@router.get("/brief")
def list_users_brief(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user)
):
"""轻量接口:仅返回 id+name任何登录用户可调用用于下拉选择等场景"""
users = db.query(User.id, User.name).filter(User.is_active == 1).order_by(User.name).all()
return [{"id": u.id, "name": u.name} for u in users]
@router.get("", response_model=List[UserOut]) @router.get("", response_model=List[UserOut])
def list_users( def list_users(
db: Session = Depends(get_db), db: Session = Depends(get_db),

View File

@ -48,6 +48,7 @@ export const authApi = {
// ── 用户 ── // ── 用户 ──
export const userApi = { export const userApi = {
list: () => api.get('/users'), list: () => api.get('/users'),
brief: () => api.get('/users/brief'),
create: (data) => api.post('/users', data), create: (data) => api.post('/users', data),
update: (id, data) => api.put(`/users/${id}`, data), update: (id, data) => api.put(`/users/${id}`, data),
get: (id) => api.get(`/users/${id}`), get: (id) => api.get(`/users/${id}`),

View File

@ -726,8 +726,8 @@ function formatSecs(s) {
async function openEdit() { async function openEdit() {
const p = project.value const p = project.value
if (authStore.hasPermission('user:view') && !users.value.length) { if (!users.value.length) {
try { users.value = await userApi.list() } catch {} try { users.value = await userApi.brief() } catch {}
} }
Object.assign(editForm, { Object.assign(editForm, {
name: p.name, project_type: p.project_type, status: p.status || '制作中', leader_id: p.leader_id, name: p.name, project_type: p.project_type, status: p.status || '制作中', leader_id: p.leader_id,
@ -763,8 +763,8 @@ async function load() {
if (authStore.hasPermission('efficiency:view')) { if (authStore.hasPermission('efficiency:view')) {
try { efficiency.value = await projectApi.efficiency(id) } catch {} try { efficiency.value = await projectApi.efficiency(id) } catch {}
} }
if (authStore.hasPermission('user:view') && !users.value.length) { if (!users.value.length) {
try { users.value = await userApi.list() } catch {} try { users.value = await userApi.brief() } catch {}
} }
await nextTick() await nextTick()
initProgressChart() initProgressChart()

View File

@ -212,9 +212,7 @@ async function handleCreate() {
onMounted(async () => { onMounted(async () => {
load() load()
if (authStore.hasPermission('user:view')) { try { users.value = await userApi.brief() } catch {}
try { users.value = await userApi.list() } catch {}
}
}) })
</script> </script>