Compare commits
No commits in common. "8051d4a027f24b553c14ddab6acefad7b41862f3" and "89c680d369760e80f9d6e7c1a11faf711040f35a" have entirely different histories.
8051d4a027
...
89c680d369
Binary file not shown.
75
main.py
75
main.py
|
|
@ -8,7 +8,12 @@ app = FastAPI()
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
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")
|
@app.post("/user/login")
|
||||||
|
|
@ -29,22 +34,22 @@ async def login(request: Request):
|
||||||
|
|
||||||
@app.get("/api/get-menu")
|
@app.get("/api/get-menu")
|
||||||
async def get_menu():
|
async def get_menu():
|
||||||
base_url = "http://127.0.0.1:8000/api/menu-image/"
|
|
||||||
directory = "assets/images/icon"
|
|
||||||
pic_list = [
|
pic_list = [
|
||||||
{id: 1, "menu_name": "政策查询", "url": "/pages/policy/policy", "icon_name": "政策解读.png"},
|
{id: 1, "menu_name": "政策查询", "url": "/pages/policy/policy", "path": "assets/images/icon/政策解读.png"},
|
||||||
{id: 2, "menu_name": "问答", "url": "/pages/qa/qa", "icon_name": "问答.png"},
|
{id: 2, "menu_name": "问答", "url": "/pages/qa/qa", "path": "assets/images/icon/问答.png"},
|
||||||
{id: 3, "menu_name": "信息管理", "url": "/pages/assist/assist", "icon_name": "群众信息管理.png"},
|
{id: 3, "menu_name": "信息管理", "url": "/pages/assist/assist", "path": "assets/images/icon/群众信息管理.png"},
|
||||||
{id: 4, "menu_name": "招聘", "url": "/pages/recruit/recruit", "icon_name": "招聘.png"}
|
{id: 4, "menu_name": "招聘", "url": "/pages/recruit/recruit", "path": "assets/images/icon/招聘.png"}
|
||||||
]
|
]
|
||||||
data = []
|
data = []
|
||||||
for item in pic_list:
|
for item in pic_list:
|
||||||
data.append({
|
with open(item['path'], "rb") as image_file:
|
||||||
"id": item[id],
|
encoded_string = base64.b64encode(image_file.read()).decode()
|
||||||
"menu_name": item['menu_name'],
|
data.append({
|
||||||
"url": item['url'],
|
"id": item[id],
|
||||||
"image_url": base_url + item['icon_name']
|
"menu_name": item['menu_name'],
|
||||||
})
|
"url": item['url'],
|
||||||
|
"base64EncodedImage": encoded_string
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"code": 0,
|
"code": 0,
|
||||||
|
|
@ -86,46 +91,4 @@ async def get_swiper_image(image_id: str):
|
||||||
return FileResponse(image_path)
|
return FileResponse(image_path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# 如果文件没有找到,返回404错误
|
# 如果文件没有找到,返回404错误
|
||||||
raise HTTPException(status_code=404, detail="Image not found")
|
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
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue