fix: 组长可选负责人 — 新增 /users/brief 轻量接口
- 新增 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:
parent
74106ac21b
commit
32658fa608
@ -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),
|
||||||
|
|||||||
@ -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}`),
|
||||||
|
|||||||
@ -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()
|
||||||
|
|||||||
@ -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>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user