fix: 添加单条记录GET端点,修复移动端编辑表单数据加载
- work-plans/mini-business/key-visits 均新增 GET /{id} 端点
- 三个移动端编辑表单改用单条端点加载数据
- 修复点击卡片进入编辑时空白的 bug
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,21 @@ async def list_key_visits(
|
||||
return [await _enrich(k, db) for k in result.scalars().all()]
|
||||
|
||||
|
||||
@router.get("/{item_id}")
|
||||
async def get_key_visit(
|
||||
item_id: str,
|
||||
current_user: dict = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(KeyVisit).where(KeyVisit.id == item_id))
|
||||
k = result.scalar_one_or_none()
|
||||
if not k:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
if current_user["role"] == "manager" and str(k.manager_id) != current_user["user_id"]:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
return await _enrich(k, db)
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def create_key_visit(
|
||||
data: KeyVisitCreate,
|
||||
|
||||
@@ -48,6 +48,21 @@ async def list_mini_business(
|
||||
return [await _enrich(m, db) for m in result.scalars().all()]
|
||||
|
||||
|
||||
@router.get("/{item_id}")
|
||||
async def get_mini_business(
|
||||
item_id: str,
|
||||
current_user: dict = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(MiniBusiness).where(MiniBusiness.id == item_id))
|
||||
m = result.scalar_one_or_none()
|
||||
if not m:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
if current_user["role"] == "manager" and str(m.manager_id) != current_user["user_id"]:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
return await _enrich(m, db)
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def create_mini_business(
|
||||
data: MiniBusinessCreate,
|
||||
|
||||
@@ -48,6 +48,21 @@ async def list_work_plans(
|
||||
return [await _enrich(w, db) for w in result.scalars().all()]
|
||||
|
||||
|
||||
@router.get("/{item_id}")
|
||||
async def get_work_plan(
|
||||
item_id: str,
|
||||
current_user: dict = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(WorkPlan).where(WorkPlan.id == item_id))
|
||||
wp = result.scalar_one_or_none()
|
||||
if not wp:
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
if current_user["role"] == "manager" and str(wp.manager_id) != current_user["user_id"]:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
return await _enrich(wp, db)
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def create_work_plan(
|
||||
data: WorkPlanCreate,
|
||||
|
||||
@@ -44,10 +44,9 @@ onMounted(async () => {
|
||||
}
|
||||
if (isEdit.value) {
|
||||
try {
|
||||
const res = await keyVisitsApi.list()
|
||||
const items = Array.isArray(res.data) ? res.data : (res.data.items || [])
|
||||
const d = items.find((x: any) => x.id === route.params.id)
|
||||
if (d) form.value = { customer_id: d.customer_id, urgency_level: d.urgency_level, description: d.description || '', progress_status: d.progress_status, planned_date: d.planned_date, planned_visitor: d.planned_visitor, visit_target: d.visit_target, manager_id: d.manager_id || auth.userId || '' }
|
||||
const res = await api.get(`/key-visits/${route.params.id}`)
|
||||
const d = res.data
|
||||
form.value = { customer_id: d.customer_id, urgency_level: d.urgency_level, description: d.description || '', progress_status: d.progress_status, planned_date: d.planned_date, planned_visitor: d.planned_visitor, visit_target: d.visit_target, manager_id: d.manager_id || auth.userId || '' }
|
||||
} catch (_) {}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -32,10 +32,9 @@ onMounted(async () => {
|
||||
}
|
||||
if (isEdit.value) {
|
||||
try {
|
||||
const res = await miniBusinessApi.list()
|
||||
const items = Array.isArray(res.data) ? res.data : (res.data.items || [])
|
||||
const d = items.find((x: any) => x.id === route.params.id)
|
||||
if (d) form.value = { customer_id: d.customer_id, product_type: d.product_type, amount: d.amount, follow_up_detail: d.follow_up_detail || '', status: d.status, expected_revenue_date: d.expected_revenue_date, manager_id: d.manager_id || auth.userId || '' }
|
||||
const res = await api.get(`/mini-business/${route.params.id}`)
|
||||
const d = res.data
|
||||
form.value = { customer_id: d.customer_id, product_type: d.product_type, amount: d.amount, follow_up_detail: d.follow_up_detail || '', status: d.status, expected_revenue_date: d.expected_revenue_date, manager_id: d.manager_id || auth.userId || '' }
|
||||
} catch (_) {}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user