-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
118 lines (97 loc) · 4.9 KB
/
Copy pathapp.py
File metadata and controls
118 lines (97 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import streamlit as st
import pandas as pd
import os
import re
from datetime import datetime
# --- 数据配置 ---
DATA_FILE = "smart_todo.csv"
def load_data():
if os.path.exists(DATA_FILE):
df = pd.read_csv(DATA_FILE)
df['创建时间'] = pd.to_datetime(df['创建时间'])
if '置顶' not in df.columns: df['置顶'] = False
return df
return pd.DataFrame(columns=["创建时间", "标题", "正文", "联系人", "时间标记", "地点标记", "优先级", "状态", "置顶"])
def save_data(df):
df.to_csv(DATA_FILE, index=False)
# --- 页面设置 ---
st.set_page_config(page_title="iNote Pro", layout="wide")
if 'df' not in st.session_state:
st.session_state.df = load_data()
# --- 输入区 ---
st.subheader("📝 快速记录")
with st.container(border=True):
raw_text = st.text_area("内容", key="raw_content", height=100, placeholder="第一行标题 @联系人\n后续为详情...")
col1, col2, col3 = st.columns([1, 1, 1])
with col1:
priority = st.selectbox("优先级", ["⭐ 普通", "🔥 紧急", "📅 长期"])
with col2:
# 恢复时间选项
use_date = st.checkbox("设置提醒")
task_date = st.date_input("提醒日期", value=datetime.now()) if use_date else "未设置"
with col3:
location = st.text_input("📍 地点", key="task_location")
if st.button("📥 存入并记下一条", use_container_width=True):
if raw_text.strip():
lines = raw_text.split('\n')
full_title = lines[0]
body = "\n".join(lines[1:]) if len(lines) > 1 else ""
# 解析联系人
contacts = re.findall(r'@(\w+)', full_title)
auto_contact = " / ".join(contacts) if contacts else ""
new_item = {
"创建时间": datetime.now(),
"标题": full_title, # 保留原始标题含@XXX
"正文": body,
"联系人": auto_contact,
"时间标记": str(task_date),
"地点标记": location,
"优先级": priority,
"状态": "待办",
"置顶": False
}
st.session_state.df = pd.concat([pd.DataFrame([new_item]), st.session_state.df], ignore_index=True)
save_data(st.session_state.df)
st.rerun()
st.divider()
# --- 待办流展示 ---
st.subheader("📋 待办")
todo_df = st.session_state.df[st.session_state.df['状态'] == "待办"].copy()
todo_df = todo_df.sort_values(by=['置顶', '创建时间'], ascending=[False, False])
if not todo_df.empty:
for idx, row in todo_df.iterrows():
with st.container(border=True):
# 第一行:标题 + 置顶图标
t_col1, t_col2 = st.columns([0.9, 0.1])
t_col1.markdown(f"**{row['标题']}**")
if row['置顶']: t_col2.write("📌")
# 第二行:优先级小标签(标题下方)
st.markdown(f"<span style='background-color: #f0f2f6; padding: 2px 8px; border-radius: 10px; font-size: 0.8rem;'>{row['优先级']}</span>", unsafe_allow_html=True)
# 正文内容
if row['正文']:
st.info(row['正文'])
# 第三行:辅助信息
meta = []
if row['联系人']: meta.append(f"👤 {row['联系人']}")
if row['地点标记']: meta.append(f"📍 {row['地点标记']}")
if row['时间标记'] != "未设置": meta.append(f"📅 {row['时间标记']}")
meta.append(f"🕒 {row['创建时间'].strftime('%m-%d %H:%M')}")
st.markdown(f"<p style='color: gray; font-size: 0.75rem; margin-top: 5px;'>{' | '.join(meta)}</p>", unsafe_allow_html=True)
# 第四行:功能按钮并列排列
# 使用小列宽让按钮紧凑
b_col1, b_col2, b_col3, b_spacer = st.columns([1, 1, 1, 2])
if b_col1.button("✅", key=f"done_{idx}", help="标记完成", use_container_width=True):
st.session_state.df.at[idx, '状态'] = "已完成"
save_data(st.session_state.df)
st.rerun()
top_icon = "📍" if row['置顶'] else "📌"
if b_col2.button(top_icon, key=f"top_{idx}", help="置顶/取消", use_container_width=True):
st.session_state.df.at[idx, '置顶'] = not row['置顶']
save_data(st.session_state.df)
st.rerun()
if b_col3.button("🗑️", key=f"del_{idx}", help="删除", use_container_width=True):
st.session_state.df = st.session_state.df.drop(idx)
save_data(st.session_state.df)
st.rerun()
else:
st.write("暂无待办")