Skip to content

Commit df09dea

Browse files
committed
Package-Helper:improve:UI及操作逻辑调整
1 parent 73e39ea commit df09dea

9 files changed

Lines changed: 440 additions & 120 deletions

File tree

Package-Helper/app_intents.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const TogglePickedIntent = AppIntentManager.register({
3535
const index = pickedItems.findIndex(item => item.code === code)
3636

3737
if (index >= 0) {
38-
pickedItems[index].timestamp = 1
38+
pickedItems.splice(index, 1)
3939
} else {
4040
pickedItems.push({ code, timestamp: Date.now() })
4141
}
@@ -67,7 +67,7 @@ export const MarkAllPickedIntent = AppIntentManager.register({
6767
const code = singleCodeMatch[0]
6868
if (code && !existing.has(code)) {
6969
existing.add(code)
70-
pickedItems.push({ code, timestamp: 1 })
70+
pickedItems.push({ code, timestamp: Date.now() })
7171
}
7272
}
7373
}

Package-Helper/components/HomePage.tsx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Button,
3+
DisclosureGroup,
34
ForEach,
45
HStack,
56
List,
@@ -11,7 +12,7 @@ import {
1112
} from "scripting"
1213

1314
import { EmptyPickupBlock, MetricTile, PickupRow } from "./common"
14-
import { getAllPickupInfo, loadConfig } from "../utils"
15+
import { getHomePickupInfo, loadConfig } from "../utils"
1516

1617
export function HomePage(props: {
1718
onRefresh: () => void
@@ -20,10 +21,11 @@ export function HomePage(props: {
2021
onDelete: (code: string) => void
2122
}) {
2223
const cfg = loadConfig()
23-
const allItems = getAllPickupInfo(cfg)
24+
const allItems = getHomePickupInfo(cfg)
2425
const pendingItems = allItems.filter((item) => !item.picked)
2526
const pickedItems = allItems.filter((item) => item.picked)
2627
const [showRefreshToast, setShowRefreshToast] = useState(false)
28+
const [pickedExpanded, setPickedExpanded] = useState(false)
2729

2830
return (
2931
<NavigationStack>
@@ -123,28 +125,33 @@ export function HomePage(props: {
123125
subtitle="标记已取件后,会在这里保留最近状态。"
124126
/>
125127
) : (
126-
<ForEach
127-
count={pickedItems.slice(0, 3).length}
128-
itemBuilder={(index) => {
129-
const item = pickedItems.slice(0, 3)[index]
130-
return (
131-
<PickupRow
132-
key={`picked-${item.code}-${index}`}
133-
item={item}
134-
showDate={cfg.showDate}
135-
checked
136-
onToggle={props.onUnpicked}
137-
/>
138-
)
139-
}}
140-
onDelete={(indices) => {
141-
const shownItems = pickedItems.slice(0, 3)
142-
for (const index of indices) {
143-
const item = shownItems[index]
144-
if (item) props.onDelete(item.code)
145-
}
146-
}}
147-
/>
128+
<DisclosureGroup
129+
title={`最近已处理 (${pickedItems.length})`}
130+
isExpanded={pickedExpanded}
131+
onChanged={setPickedExpanded}
132+
>
133+
<ForEach
134+
count={pickedItems.length}
135+
itemBuilder={(index) => {
136+
const item = pickedItems[index]
137+
return (
138+
<PickupRow
139+
key={`picked-${item.code}-${index}`}
140+
item={item}
141+
showDate={cfg.showDate}
142+
checked
143+
onToggle={props.onUnpicked}
144+
/>
145+
)
146+
}}
147+
onDelete={(indices) => {
148+
for (const index of indices) {
149+
const item = pickedItems[index]
150+
if (item) props.onDelete(item.code)
151+
}
152+
}}
153+
/>
154+
</DisclosureGroup>
148155
)}
149156
</Section>
150157
</List>

Package-Helper/components/PreviewPage.tsx

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,62 @@ import {
77
Text,
88
} from "scripting"
99
import { EmptyPickupBlock, PickupRow } from "./common"
10-
import { getAllPickupInfo, handleAnyData, loadConfig, safeRefreshWidget } from "../utils"
10+
import { clearPreviewResults, getPreviewPickupInfo, handleAnyData, loadConfig, safeRefreshWidget } from "../utils"
1111

1212
export function PreviewPage(props: {
1313
onChanged: () => void
1414
onDelete: (code: string) => void
15+
onClear: () => void
1516
}) {
1617
const cfg = loadConfig()
17-
const previewItems = getAllPickupInfo(cfg).slice(0, cfg.widgetShowCount)
18+
const previewItems = getPreviewPickupInfo(cfg)
19+
20+
const groupedItems = [
21+
{
22+
title: "今天",
23+
items: previewItems.filter((item) => {
24+
const value = item.date || item.importedAt
25+
if (!value) return false
26+
const date = new Date(value)
27+
const now = new Date()
28+
return date.toDateString() === now.toDateString()
29+
}),
30+
},
31+
{
32+
title: "近3天",
33+
items: previewItems.filter((item) => {
34+
const value = item.date || item.importedAt
35+
if (!value) return false
36+
const time = new Date(value).getTime()
37+
if (!Number.isFinite(time)) return false
38+
const now = Date.now()
39+
const startOfToday = new Date()
40+
startOfToday.setHours(0, 0, 0, 0)
41+
return time < startOfToday.getTime() && time >= now - 3 * 24 * 60 * 60 * 1000
42+
}),
43+
},
44+
{
45+
title: "近7天",
46+
items: previewItems.filter((item) => {
47+
const value = item.date || item.importedAt
48+
if (!value) return false
49+
const time = new Date(value).getTime()
50+
if (!Number.isFinite(time)) return false
51+
const now = Date.now()
52+
return time < now - 3 * 24 * 60 * 60 * 1000 && time >= now - 7 * 24 * 60 * 60 * 1000
53+
}),
54+
},
55+
{
56+
title: "更早",
57+
items: previewItems.filter((item) => {
58+
const value = item.date || item.importedAt
59+
if (!value) return true
60+
const time = new Date(value).getTime()
61+
if (!Number.isFinite(time)) return true
62+
return time < Date.now() - 7 * 24 * 60 * 60 * 1000
63+
}),
64+
},
65+
].filter((group) => group.items.length > 0)
1866

1967
return (
2068
<NavigationStack>
@@ -23,6 +71,21 @@ export function PreviewPage(props: {
2371
navigationBarTitleDisplayMode="inline"
2472
listStyle="insetGroup"
2573
toolbar={{
74+
topBarLeading: (
75+
<Button
76+
title="清空"
77+
action={async () => {
78+
const ok = await Dialog.confirm({
79+
title: "清空解析结果",
80+
message: "这只会清空预览页中的解析结果,不会影响主页包裹。",
81+
confirmLabel: "清空",
82+
})
83+
if (!ok) return
84+
clearPreviewResults()
85+
props.onClear()
86+
}}
87+
/>
88+
),
2689
topBarTrailing: (
2790
<Button
2891
title=""
@@ -52,20 +115,22 @@ export function PreviewPage(props: {
52115
),
53116
}}
54117
>
55-
<Section header={<Text>解析预览</Text>}>
56-
{previewItems.length === 0 ? (
118+
{groupedItems.length === 0 ? (
119+
<Section header={<Text>解析预览</Text>}>
57120
<EmptyPickupBlock
58121
title="暂无可预览内容"
59122
subtitle="添加短信后,这里会展示当前解析出来的包裹结果。"
60123
/>
61-
) : (
124+
</Section>
125+
) : groupedItems.map((group) => (
126+
<Section key={group.title} header={<Text>{group.title}</Text>}>
62127
<ForEach
63-
count={previewItems.length}
128+
count={group.items.length}
64129
itemBuilder={(index) => {
65-
const item = previewItems[index]
130+
const item = group.items[index]
66131
return (
67132
<PickupRow
68-
key={`preview-${item.code}-${index}`}
133+
key={`preview-${group.title}-${item.code}-${index}`}
69134
item={item}
70135
showDate={cfg.showDate}
71136
checked={!!item.picked}
@@ -74,13 +139,13 @@ export function PreviewPage(props: {
74139
}}
75140
onDelete={(indices) => {
76141
for (const index of indices) {
77-
const item = previewItems[index]
142+
const item = group.items[index]
78143
if (item) props.onDelete(item.code)
79144
}
80145
}}
81146
/>
82-
)}
83-
</Section>
147+
</Section>
148+
))}
84149
</List>
85150
</NavigationStack>
86151
)

Package-Helper/components/RootTabView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { HomePage } from "./HomePage"
99
import { PreviewPage } from "./PreviewPage"
1010
import { SettingsPage } from "./SettingsPage"
1111
import { HOME_TAB, PREVIEW_TAB, SETTINGS_TAB } from "../types"
12-
import { deletePickup, markPicked, safeRefreshWidget, unmarkPicked } from "../utils"
12+
import { deleteHomePickup, deletePreviewPickup, markPicked, safeRefreshWidget, unmarkPicked } from "../utils"
1313

1414
export function RootTabView(props: {
1515
initialNotice?: string | null
@@ -32,8 +32,10 @@ export function RootTabView(props: {
3232
<PreviewPage
3333
onChanged={() => bump()}
3434
onDelete={(code) => {
35-
deletePickup(code)
36-
safeRefreshWidget()
35+
deletePreviewPickup(code)
36+
bump()
37+
}}
38+
onClear={() => {
3739
bump()
3840
}}
3941
/>
@@ -53,7 +55,7 @@ export function RootTabView(props: {
5355
bump()
5456
}}
5557
onDelete={(code) => {
56-
deletePickup(code)
58+
deleteHomePickup(code)
5759
safeRefreshWidget()
5860
bump()
5961
}}

Package-Helper/components/SettingsPage.tsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Image,
55
Navigation,
66
NavigationStack,
7+
Picker,
78
Slider,
89
Section,
910
Text,
@@ -25,6 +26,7 @@ import {
2526
resetConfig,
2627
saveConfig,
2728
safeRefreshWidget,
29+
CLEANUP_DAY_OPTIONS,
2830
} from "../utils"
2931

3032
export function SettingsPage(props: {
@@ -35,6 +37,9 @@ export function SettingsPage(props: {
3537
const [keywords, setKeywords] = useState<string[]>(cfg.keywords)
3638
const [showCount, setShowCount] = useState(cfg.widgetShowCount)
3739
const [showDate, setShowDate] = useState(cfg.showDate)
40+
const [autoCleanupPicked, setAutoCleanupPicked] = useState(cfg.autoCleanupPicked)
41+
const [autoCleanupPreview, setAutoCleanupPreview] = useState(cfg.autoCleanupPreview)
42+
const [cleanupDays, setCleanupDays] = useState(cfg.cleanupDays)
3843

3944
const [showSavedToast, setShowSavedToast] = useState(false)
4045
const [toastMessage, setToastMessage] = useState("已保存")
@@ -50,13 +55,19 @@ export function SettingsPage(props: {
5055
keywords: normalizeKeywords(next.keywords ?? keywords),
5156
widgetShowCount: clampShowCount(Number(next.widgetShowCount ?? showCount)),
5257
showDate: next.showDate ?? showDate,
58+
autoCleanupPicked: next.autoCleanupPicked ?? autoCleanupPicked,
59+
autoCleanupPreview: next.autoCleanupPreview ?? autoCleanupPreview,
60+
cleanupDays: next.cleanupDays ?? cleanupDays,
5361
}
5462

5563
saveConfig(merged)
5664
setAutoDetect(merged.autoDetectSMS)
5765
setKeywords(merged.keywords)
5866
setShowCount(merged.widgetShowCount)
5967
setShowDate(merged.showDate)
68+
setAutoCleanupPicked(merged.autoCleanupPicked)
69+
setAutoCleanupPreview(merged.autoCleanupPreview)
70+
setCleanupDays(merged.cleanupDays)
6071
if (!options?.silent) {
6172
presentToast("已保存")
6273
}
@@ -120,24 +131,51 @@ export function SettingsPage(props: {
120131
</HStack>
121132
<Slider
122133
min={1}
123-
max={50}
134+
max={8}
124135
step={1}
125136
value={showCount}
126137
onChanged={setShowCount}
127138
minValueLabel={<Text>1</Text>}
128-
maxValueLabel={<Text>50</Text>}
139+
maxValueLabel={<Text>8</Text>}
129140
label={<Text>显示条数</Text>}
130141
/>
131142
</VStack>
132143
</Section>
133144

145+
<Section header={<Text>自动清理</Text>}>
146+
<Toggle
147+
title="已取件过期自动清理"
148+
value={autoCleanupPicked}
149+
onChanged={setAutoCleanupPicked}
150+
/>
151+
152+
<Toggle
153+
title="解析预览过期自动清理"
154+
value={autoCleanupPreview}
155+
onChanged={setAutoCleanupPreview}
156+
/>
157+
158+
{autoCleanupPicked || autoCleanupPreview ? (
159+
<Picker
160+
title="清理周期"
161+
pickerStyle="menu"
162+
value={cleanupDays}
163+
onChanged={setCleanupDays}
164+
>
165+
{CLEANUP_DAY_OPTIONS.map((days) => (
166+
<Text key={`cleanup-${days}`} tag={days}>{days}</Text>
167+
))}
168+
</Picker>
169+
) : null}
170+
</Section>
171+
134172
<Section header={<Text>数据管理</Text>}>
135173
<CenterDestructiveRow
136174
title="清除已取记录"
137175
onPress={async () => {
138176
const ok = await Dialog.confirm({
139177
title: "清除已取记录",
140-
message: "仅清除已处理状态,已导入短信会保留。",
178+
message: "会从主页和小组件移除已取件记录,解析预览会保留。",
141179
confirmLabel: "清除",
142180
})
143181
if (!ok) return
@@ -162,6 +200,9 @@ export function SettingsPage(props: {
162200
setKeywords(DEFAULT_CONFIG.keywords)
163201
setShowCount(DEFAULT_CONFIG.widgetShowCount)
164202
setShowDate(DEFAULT_CONFIG.showDate)
203+
setAutoCleanupPicked(DEFAULT_CONFIG.autoCleanupPicked)
204+
setAutoCleanupPreview(DEFAULT_CONFIG.autoCleanupPreview)
205+
setCleanupDays(DEFAULT_CONFIG.cleanupDays)
165206
safeRefreshWidget()
166207
props.onChanged()
167208
presentToast("已重置")

Package-Helper/script.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"autoUpdateInterval": 86400
66
},
77
"description": "修改自:https://raw.githubusercontent.com/1085481057/Scripting/refs/heads/main/快递小助手.scripting",
8-
"color": "rgba(37, 99, 235, 1)",
8+
"color": "rgba(102, 196, 235, 1)",
99
"runInApp": true,
1010
"localizedDescriptions": {},
1111
"version": "",

0 commit comments

Comments
 (0)