重构getSinglePageData
This commit is contained in:
parent
27b2dead71
commit
73f669d170
@ -40,19 +40,16 @@ export async function getPageTypeRouteName(entity: string): Promise<string> {
|
||||
*/
|
||||
export async function getSinglePageData(pagetype: string): Promise<{ success: boolean; data?: any; message?: string }> {
|
||||
try {
|
||||
const url = `/api/action/jingrow.client.get_single`
|
||||
const url = `/api/data/${encodeURIComponent(pagetype)}/${encodeURIComponent(pagetype)}`
|
||||
const res = await axios.get(url, {
|
||||
params: {
|
||||
pagetype: pagetype
|
||||
},
|
||||
headers: get_session_api_headers(),
|
||||
withCredentials: true
|
||||
})
|
||||
|
||||
if (res.data?.message) {
|
||||
if (res.data?.data) {
|
||||
return {
|
||||
success: true,
|
||||
data: res.data.message
|
||||
data: res.data.data
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
@ -64,7 +61,7 @@ export async function getSinglePageData(pagetype: string): Promise<{ success: bo
|
||||
console.error('Failed to get single page data:', error)
|
||||
return {
|
||||
success: false,
|
||||
message: error.response?.data?.message || error.message || '获取单页数据失败'
|
||||
message: error.response?.data?.detail || error.message || '获取单页数据失败'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +122,10 @@ def get_all(pagetype: str, filters: List[List[Any]] = None, fields: List[str] =
|
||||
|
||||
def get_single(pagetype: str):
|
||||
"""获取 single 类型 pagetype 配置,返回 {success, config|error} 结构。"""
|
||||
return Page(pagetype).get_single()
|
||||
data = get_pg(pagetype, pagetype)
|
||||
if data is None:
|
||||
return {'success': False, 'error': f'{pagetype}配置不存在'}
|
||||
return {'success': True, 'config': data}
|
||||
|
||||
|
||||
def get_module_app(pagetype: str):
|
||||
|
||||
@ -198,16 +198,5 @@ async def get_record_count(request: Request, pagetype: str):
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/api/single/{pagetype}")
|
||||
async def get_single(request: Request, pagetype: str):
|
||||
"""获取single类型pagetype记录"""
|
||||
try:
|
||||
result = jingrow.get_single(pagetype)
|
||||
if isinstance(result, dict) and result.get('success'):
|
||||
return JSONResponse(content={"data": result.get('config', {})})
|
||||
raise HTTPException(status_code=404, detail=(result or {}).get('error', '配置不存在') if isinstance(result, dict) else '配置不存在')
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user