lbq
13 小时以前 56ca28233a84c5aa3ca93cae266b2d008ea348e1
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import * as React from 'react';
import {
    Avatar,
    Box,
    Button,
    List,
    Grid,
    ListItem,
    Typography,
    ListItemAvatar,
    ListItemButton,
    ListItemText,
} from '@mui/material';
import CommentIcon from '@mui/icons-material/Comment';
import CardWithIcon from '../components/CardWithIcon';
import { Link } from 'react-router-dom';
import {
    ReferenceField,
    FunctionField,
    useGetList,
    useTranslate,
    useIsDataLoaded,
} from 'react-admin';
 
const NbCard = (props) => {
    const { tasks, total, ...rset } = props;
    const translate = useTranslate();
    
    // 状态管理屏幕高度
    const [screenHeight, setScreenHeight] = React.useState(window.innerHeight);
    const [containerHeight, setContainerHeight] = React.useState('100vh');
 
    // 监听窗口大小变化
    React.useEffect(() => {
        const handleResize = () => {
            setScreenHeight(window.innerHeight);
        };
 
        window.addEventListener('resize', handleResize);
        
        // 计算容器高度(减去可能的头部导航栏高度)
        const calculateContainerHeight = () => {
            const headerHeight = 64; // 假设头部导航栏高度为64px
            const padding = 16; // 上下边距
            return `calc(${screenHeight}px - ${headerHeight + padding * 2}px)`;
        };
        
        setContainerHeight(calculateContainerHeight());
 
        return () => {
            window.removeEventListener('resize', handleResize);
        };
    }, [screenHeight]);
 
    return (
        <Box sx={{
            height: containerHeight, // 动态计算的高度
            maxHeight: 690, //containerHeight,
            display: 'flex',
            flexDirection: 'column',
            minHeight: '400px', // 最小高度保证
            // overflowY: 'auto'
        }}>
            <CardWithIcon
                icon={CommentIcon}
                title={translate('page.dashboard.pending_reviews')}
                subtitle={total}
                {...rset}
                sx={{
                    flex: 1,
                    display: 'flex',
                    flexDirection: 'column',
                    height: '100%',
                    minHeight: 0,
                }}
            >
                {/* 内容容器 - 自适应高度 */}
                <Box sx={{ 
                    flex: 1,
                    display: 'flex',
                    flexDirection: 'column',
                    minHeight: 0,
                    height: '100%',
                }}>
                    {/* 列表区域 - 自动滚动 */}
                    <Box sx={{
                        flex: 1,
                        overflow: 'auto',
                        minHeight: 0,
                        '&::-webkit-scrollbar': {
                            width: '6px',
                        },
                        '&::-webkit-scrollbar-track': {
                            background: 'transparent',
                        },
                        '&::-webkit-scrollbar-thumb': {
                            background: '#ccc',
                            borderRadius: '3px',
                            '&:hover': {
                                background: '#aaa',
                            }
                        }
                    }}>
                        <List sx={{ py: 0, minHeight: 'min-content' }}>
                            {tasks?.length > 0 ? (
                                tasks.map((record) => (
                                    <ListItem 
                                        key={record.id} 
                                        disablePadding
                                        sx={{
                                            borderBottom: '1px solid',
                                            borderColor: 'divider',
                                            '&:last-child': {
                                                borderBottom: 'none',
                                            }
                                        }}
                                    >
                                        <ListItemButton
                                            component={Link}
                                            to={`/task/${record.id}`}
                                            sx={{
                                                py: 1.5,
                                                px: 2,
                                                '&:hover': {
                                                    backgroundColor: 'action.hover',
                                                }
                                            }}
                                        >
                                            <Grid container spacing={1}>
                                                {/* 第一行:任务编码和类型 */}
                                                <Grid item xs={12} sx={{ display: 'flex', alignItems: 'center' }}>
                                                    <Box sx={{ 
                                                        display: 'flex', 
                                                        alignItems: 'center', 
                                                        minWidth: 0, 
                                                        flex: 1,
                                                        mr: 2
                                                    }}>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                fontWeight: 600,
                                                                color: 'primary.main',
                                                                minWidth: '80px',
                                                                flexShrink: 0,
                                                            }}
                                                        >
                                                            {translate("table.field.task.taskCode")}:
                                                        </Typography>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                color: 'text.primary',
                                                                fontWeight: 500,
                                                                overflow: 'hidden',
                                                                textOverflow: 'ellipsis',
                                                                whiteSpace: 'nowrap',
                                                            }}
                                                        >
                                                            {record?.taskCode}
                                                        </Typography>
                                                    </Box>
                                                    
                                                    <Box sx={{ 
                                                        display: 'flex', 
                                                        alignItems: 'center', 
                                                        minWidth: 0, 
                                                        flex: 1
                                                    }}>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                fontWeight: 600,
                                                                color: 'primary.main',
                                                                minWidth: '80px',
                                                                flexShrink: 0,
                                                            }}
                                                        >
                                                            {translate("table.field.task.taskType")}:
                                                        </Typography>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                color: 'text.primary',
                                                                overflow: 'hidden',
                                                                textOverflow: 'ellipsis',
                                                                whiteSpace: 'nowrap',
                                                            }}
                                                            title={record?.taskType$}
                                                        >
                                                            {record?.taskType$}
                                                        </Typography>
                                                    </Box>
                                                </Grid>
 
                                                {/* 第二行:状态和时间 */}
                                                <Grid item xs={12} sx={{ display: 'flex', alignItems: 'center' }}>
                                                    <Box sx={{ 
                                                        display: 'flex', 
                                                        alignItems: 'center', 
                                                        minWidth: 0, 
                                                        flex: 1,
                                                        mr: 2
                                                    }}>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                fontWeight: 600,
                                                                color: 'primary.main',
                                                                minWidth: '80px',
                                                                flexShrink: 0,
                                                            }}
                                                        >
                                                            {translate("table.field.task.taskStatus")}:
                                                        </Typography>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                color: getStatusColor(record?.taskStatus$),
                                                                fontWeight: 600,
                                                                px: 1,
                                                                py: 0.5,
                                                                borderRadius: 1,
                                                                backgroundColor: getStatusBackground(record?.taskStatus$),
                                                                fontSize: '0.75rem',
                                                            }}
                                                        >
                                                            {record?.taskStatus$}
                                                        </Typography>
                                                    </Box>
                                                    
                                                    <Box sx={{ 
                                                        display: 'flex', 
                                                        alignItems: 'center', 
                                                        minWidth: 0, 
                                                        flex: 1
                                                    }}>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                fontWeight: 600,
                                                                color: 'primary.main',
                                                                minWidth: '80px',
                                                                flexShrink: 0,
                                                            }}
                                                        >
                                                            {translate("table.field.task.startTime")}:
                                                        </Typography>
                                                        <Typography 
                                                            variant="body2" 
                                                            sx={{ 
                                                                color: 'text.secondary',
                                                                fontFamily: 'monospace',
                                                                fontSize: '0.875rem',
                                                            }}
                                                        >
                                                            {formatDateTime(record?.createTime)}
                                                        </Typography>
                                                    </Box>
                                                </Grid>
                                            </Grid>
                                        </ListItemButton>
                                    </ListItem>
                                ))
                            ) : (
                                // 空状态提示 - 居中显示
                                <Box sx={{ 
                                    display: 'flex', 
                                    alignItems: 'center', 
                                    justifyContent: 'center', 
                                    height: '100%',
                                    minHeight: 120,
                                    color: 'text.secondary'
                                }}>
                                    <Typography variant="body2">
                                        {translate('common.noData')}
                                    </Typography>
                                </Box>
                            )}
                        </List>
                    </Box>
 
                    {/* 底部按钮区域 - 固定在底部 */}
                    {tasks?.length > 0 && (
                        <Box sx={{ 
                            borderTop: '1px solid', 
                            borderColor: 'divider',
                            flexShrink: 0,
                            mt: 'auto',
                        }}>
                            <Button
                                component={Link}
                                to="/task"
                                size="small"
                                color="primary"
                                fullWidth
                                sx={{
                                    borderRadius: 0,
                                    py: 1,
                                    fontSize: '0.875rem',
                                    fontWeight: 500,
                                }}
                            >
                                {translate('pos.dashboard.all_reviews')}
                            </Button>
                        </Box>
                    )}
                </Box>
            </CardWithIcon>
        </Box>
    );
};
 
// 状态颜色映射
const getStatusColor = (status) => {
    const statusMap = {
        'pending': 'warning.main',
        'completed': 'success.main',
        'processing': 'info.main',
        'cancelled': 'error.main',
        'failed': 'error.main',
    };
    return statusMap[status?.toLowerCase()] || 'text.secondary';
};
 
// 状态背景色
const getStatusBackground = (status) => {
    const backgroundMap = {
        'pending': 'warning.light',
        'completed': 'success.light',
        'processing': 'info.light',
        'cancelled': 'error.light',
        'failed': 'error.light',
    };
    return backgroundMap[status?.toLowerCase()] || 'grey.100';
};
 
// 格式化日期时间
const formatDateTime = (dateTime) => {
    if (!dateTime) return '-';
    try {
        return new Date(dateTime).toLocaleDateString('zh-CN', {
            month: '2-digit',
            day: '2-digit',
            hour: '2-digit',
            minute: '2-digit'
        });
    } catch {
        return dateTime;
    }
};
 
export default NbCard;