feat(文档): 增加转换失败报错提醒和重试功能
- 在文档列表添加「重试转换」和「查看错误」操作按钮 - 在文档详情页添加「重试转换」功能和转换错误信息展示 - 创建错误详情视图,提供友好的错误信息和解决方案 - 重试功能会重置文档状态并重新派发转换任务 - 优化用户体验,提供清晰的错误提示和操作指引
This commit is contained in:
@@ -222,6 +222,57 @@ class DocumentResource extends Resource
|
||||
->placeholder('全部状态'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\Action::make('retry_conversion')
|
||||
->label('重试转换')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('warning')
|
||||
->visible(fn (Document $record): bool => $record->conversion_status === 'failed')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('重试文档转换')
|
||||
->modalDescription(fn (Document $record): string =>
|
||||
'确定要重新转换文档 "' . $record->title . '" 吗?' .
|
||||
($record->conversion_error ? "\n\n上次失败原因:" . $record->conversion_error : '')
|
||||
)
|
||||
->modalSubmitActionLabel('确认重试')
|
||||
->action(function (Document $record) {
|
||||
try {
|
||||
// 重置转换状态
|
||||
$record->conversion_status = 'pending';
|
||||
$record->conversion_error = null;
|
||||
$record->save();
|
||||
|
||||
// 重新派发转换任务
|
||||
\App\Jobs\ConvertDocumentToMarkdown::dispatch($record);
|
||||
|
||||
\Filament\Notifications\Notification::make()
|
||||
->success()
|
||||
->title('重试成功')
|
||||
->body('文档转换任务已重新加入队列,请稍后查看转换结果。')
|
||||
->send();
|
||||
} catch (\Exception $e) {
|
||||
\Filament\Notifications\Notification::make()
|
||||
->danger()
|
||||
->title('重试失败')
|
||||
->body('无法重新派发转换任务:' . $e->getMessage())
|
||||
->send();
|
||||
}
|
||||
}),
|
||||
Tables\Actions\Action::make('view_error')
|
||||
->label('查看错误')
|
||||
->icon('heroicon-o-exclamation-triangle')
|
||||
->color('danger')
|
||||
->visible(fn (Document $record): bool =>
|
||||
$record->conversion_status === 'failed' && !empty($record->conversion_error)
|
||||
)
|
||||
->modalHeading('转换错误详情')
|
||||
->modalContent(fn (Document $record): \Illuminate\Contracts\View\View =>
|
||||
view('filament.modals.conversion-error', [
|
||||
'document' => $record,
|
||||
'error' => $record->conversion_error,
|
||||
])
|
||||
)
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('关闭'),
|
||||
Tables\Actions\Action::make('preview')
|
||||
->label('预览 Markdown')
|
||||
->icon('heroicon-o-eye')
|
||||
|
||||
Reference in New Issue
Block a user