Compare commits

..

No commits in common. "8051d4a027f24b553c14ddab6acefad7b41862f3" and "89c680d369760e80f9d6e7c1a11faf711040f35a" have entirely different histories.

2 changed files with 19 additions and 56 deletions

Binary file not shown.

63
main.py
View File

@ -8,7 +8,12 @@ app = FastAPI()
@app.get("/")
async def root():
return "welcome to fastAPI!"
return {"message": "Hello World"}
@app.get("/hello/{name}")
async def say_hello(name: str):
return {"message": f"Hello {name}"}
@app.post("/user/login")
@ -29,21 +34,21 @@ async def login(request: Request):
@app.get("/api/get-menu")
async def get_menu():
base_url = "http://127.0.0.1:8000/api/menu-image/"
directory = "assets/images/icon"
pic_list = [
{id: 1, "menu_name": "政策查询", "url": "/pages/policy/policy", "icon_name": "政策解读.png"},
{id: 2, "menu_name": "问答", "url": "/pages/qa/qa", "icon_name": "问答.png"},
{id: 3, "menu_name": "信息管理", "url": "/pages/assist/assist", "icon_name": "群众信息管理.png"},
{id: 4, "menu_name": "招聘", "url": "/pages/recruit/recruit", "icon_name": "招聘.png"}
{id: 1, "menu_name": "政策查询", "url": "/pages/policy/policy", "path": "assets/images/icon/政策解读.png"},
{id: 2, "menu_name": "问答", "url": "/pages/qa/qa", "path": "assets/images/icon/问答.png"},
{id: 3, "menu_name": "信息管理", "url": "/pages/assist/assist", "path": "assets/images/icon/群众信息管理.png"},
{id: 4, "menu_name": "招聘", "url": "/pages/recruit/recruit", "path": "assets/images/icon/招聘.png"}
]
data = []
for item in pic_list:
with open(item['path'], "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode()
data.append({
"id": item[id],
"menu_name": item['menu_name'],
"url": item['url'],
"image_url": base_url + item['icon_name']
"base64EncodedImage": encoded_string
})
return {
@ -87,45 +92,3 @@ async def get_swiper_image(image_id: str):
except FileNotFoundError:
# 如果文件没有找到返回404错误
raise HTTPException(status_code=404, detail="Image not found")
@app.get("/api/menu-image/{image_name}.png")
async def get_menu_image(image_name: str):
base_image_path = "assets/images/icon"
# 构造图片文件的完整路径
image_path = f"{base_image_path}/{image_name}.png" # 假设图片格式为png根据需要修改
print(image_path)
try:
# 返回图片文件的响应
return FileResponse(image_path)
except FileNotFoundError:
# 如果文件没有找到返回404错误
raise HTTPException(status_code=404, detail="Image not found")
@app.get("/api/policy-list")
async def get_policy_list():
policy_list = [
{"title": "政策标题1", "date": "2024-01-01"},
{"title": "政策标题2", "date": "2023-01-02"},
{"title": "政策标题3", "date": "2022-01-02"},
{"title": "政策标题4", "date": "2023-01-02"},
{"title": "政策标题5", "date": "2022-01-02"},
{"title": "政策标题6", "date": "2023-01-02"},
{"title": "政策标题7", "date": "2021-01-02"},
{"title": "政策标题8", "date": "2021-01-02"},
{"title": "政策标题9", "date": "2024-02-02"},
{"title": "政策标题10", "date": "2024-03-02"},
{"title": "政策标题11", "date": "2024-04-02"},
{"title": "政策标题12", "date": "2024-01-02"},
{"title": "政策标题13", "date": "2024-01-02"},
{"title": "政策标题14", "date": "2024-01-02"},
{"title": "政策标题15", "date": "2024-01-02"},
{"title": "政策标题16", "date": "2024-01-02"},
{"title": "政策标题17", "date": "2024-01-02"}
]
return {
"code": 0,
"msg": "ok",
"data": policy_list
}