145 lines
5.5 KiB
Python
145 lines
5.5 KiB
Python
import pandas as pd
|
|
from nicegui import ui
|
|
from config.config import load_config
|
|
import os
|
|
|
|
|
|
def create_header():
|
|
with ui.header().classes("app-header items-center justify-between shadow-md"):
|
|
with ui.row().classes("items-center gap-2"):
|
|
ui.image("/assets/icon.ico").classes("w-8 h-8").props("fit=contain")
|
|
ui.label("尚城幼儿园成长报告助手").classes("text-xl font-bold")
|
|
|
|
with ui.row().classes("items-center gap-4"):
|
|
ui.label("By 寒寒 | 这里的每一份评语都充满爱意").classes(
|
|
"text-xs opacity-90"
|
|
)
|
|
ui.button(icon="home", on_click=lambda: ui.navigate.to("/")).props(
|
|
"flat round color=white"
|
|
).tooltip("回到首页")
|
|
|
|
|
|
def create_data_page():
|
|
ui.add_head_html('<link href="/assets/style.css" rel="stylesheet" />')
|
|
|
|
create_header()
|
|
|
|
with ui.column().classes("w-full max-w-6xl mx-auto p-4 gap-4 thin-scrollbar"):
|
|
with ui.card().classes("func-card"):
|
|
with ui.row().classes("items-center justify-between w-full"):
|
|
ui.label("📊 班级幼儿数据").classes("section-title text-blue")
|
|
ui.button(
|
|
"刷新表格", icon="sync", on_click=lambda: ui.navigate.to("/data")
|
|
).props("outline color=primary")
|
|
|
|
with ui.card().classes("func-card"):
|
|
load_data()
|
|
|
|
|
|
def load_data():
|
|
conf_data = load_config("config.toml")
|
|
excel_path = conf_data.get("excel_file")
|
|
|
|
with (
|
|
ui.dialog() as detail_dialog,
|
|
ui.card().classes(
|
|
"w-[600px] p-0 profile-dialog rounded-3xl overflow-hidden shadow-2xl"
|
|
),
|
|
):
|
|
with ui.row().classes(
|
|
"w-full bg-gradient-to-r from-blue-50 to-indigo-50 items-center justify-between"
|
|
):
|
|
with ui.column().classes("gap-0"):
|
|
ui.label("幼儿成长档案").classes(
|
|
"text-xl p-4 font-black text-slate-800"
|
|
)
|
|
ui.button(icon="close", on_click=detail_dialog.close).props(
|
|
"flat round color=primary"
|
|
).classes("bg-white/50")
|
|
|
|
with ui.column().classes("w-full p-6 h-[450px] overflow-auto gap-0"):
|
|
content_container = ui.column().classes("w-full")
|
|
|
|
with ui.row().classes(
|
|
"w-full p-5 bg-slate-50/80 backdrop-blur-md border-t justify-end gap-3"
|
|
):
|
|
ui.button("确认", on_click=detail_dialog.close).props(
|
|
"unelevated color=blue-6"
|
|
).classes("px-10 rounded-xl shadow-lg shadow-blue-200 font-bold")
|
|
|
|
def handle_cell_click(e):
|
|
row_data = e.args["data"]
|
|
content_container.clear()
|
|
|
|
student_name = row_data.get("姓名", "详细数据")
|
|
|
|
with content_container:
|
|
with ui.row().classes(
|
|
"w-full items-center p-4 bg-blue-600 rounded-2xl shadow-md shadow-blue-100"
|
|
):
|
|
ui.avatar("person", color="white", text_color="blue-6").props(
|
|
"size=48px"
|
|
)
|
|
with ui.column().classes("gap-0 text-white"):
|
|
ui.label(student_name).classes("text-lg font-bold")
|
|
|
|
for key, value in row_data.items():
|
|
if key == "姓名":
|
|
continue
|
|
with ui.element("div").classes("info-item w-full flex flex-col gap-1"):
|
|
ui.label(key).classes("font-bold text-blue-800")
|
|
ui.label(str(value)).classes("info-value flex-1")
|
|
|
|
detail_dialog.open()
|
|
|
|
if not excel_path or not os.path.exists(excel_path):
|
|
with ui.column().classes("w-full items-center p-12 text-slate-400"):
|
|
ui.icon("folder_off", size="64px")
|
|
ui.label("数据文件未找到,请检查配置路径").classes("mt-4")
|
|
return
|
|
|
|
try:
|
|
df = pd.read_excel(excel_path)
|
|
for col in df.select_dtypes(include=["datetime"]):
|
|
df[col] = df[col].dt.strftime("%Y-%m-%d")
|
|
df = df.fillna("-")
|
|
|
|
with ui.row().classes(
|
|
"bg-blue-50 w-full p-3 px-6 items-center rounded-t-xl border-b border-blue-100"
|
|
):
|
|
ui.icon("fact_check", color="primary", size="20px")
|
|
ui.label(f"班级:{conf_data.get('class_name', '未设定')}").classes(
|
|
"text-sm font-bold text-blue-800"
|
|
)
|
|
ui.separator().props("vertical").classes("mx-2")
|
|
ui.label(f"共加载 {len(df)} 条幼儿记录").classes("text-xs text-slate-500")
|
|
ui.space()
|
|
ui.label("💡 提示:点击行可展开完整评语详情").classes(
|
|
"text-xs text-amber-600 bg-amber-50 px-2 py-1 rounded"
|
|
)
|
|
|
|
ui.aggrid(
|
|
{
|
|
"columnDefs": [
|
|
{
|
|
"headerName": col,
|
|
"field": col,
|
|
"sortable": True,
|
|
"filter": True,
|
|
"cellClass": "text-slate-600",
|
|
"suppressMovable": True,
|
|
}
|
|
for col in df.columns
|
|
],
|
|
"rowData": df.to_dict("records"),
|
|
"pagination": True,
|
|
"paginationPageSize": 20,
|
|
"theme": "balham",
|
|
}
|
|
).classes("w-full flex-grow h-[550px] border-none").on(
|
|
"cellClicked", handle_cell_click
|
|
)
|
|
|
|
except Exception as e:
|
|
ui.notify(f"加载数据时发生错误: {e}", type="negative", position="top")
|