@@ -7,14 +7,62 @@ import {
77 Text ,
88} from "scripting"
99import { EmptyPickupBlock , PickupRow } from "./common"
10- import { getAllPickupInfo , handleAnyData , loadConfig , safeRefreshWidget } from "../utils"
10+ import { clearPreviewResults , getPreviewPickupInfo , handleAnyData , loadConfig , safeRefreshWidget } from "../utils"
1111
1212export 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 )
0 commit comments