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')
|
||||
|
||||
@@ -20,6 +20,47 @@ class ViewDocument extends ViewRecord
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('retry_conversion')
|
||||
->label('重试转换')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('warning')
|
||||
->visible(fn (): bool => $this->record->conversion_status === 'failed')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('重试文档转换')
|
||||
->modalDescription(fn (): string =>
|
||||
'确定要重新转换文档 "' . $this->record->title . '" 吗?' .
|
||||
($this->record->conversion_error ? "\n\n上次失败原因:" . $this->record->conversion_error : '')
|
||||
)
|
||||
->modalSubmitActionLabel('确认重试')
|
||||
->action(function () {
|
||||
try {
|
||||
// 重置转换状态
|
||||
$this->record->conversion_status = 'pending';
|
||||
$this->record->conversion_error = null;
|
||||
$this->record->save();
|
||||
|
||||
// 重新派发转换任务
|
||||
\App\Jobs\ConvertDocumentToMarkdown::dispatch($this->record);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('重试成功')
|
||||
->body('文档转换任务已重新加入队列,请稍后查看转换结果。')
|
||||
->send();
|
||||
|
||||
// 刷新页面数据
|
||||
$this->refreshFormData([
|
||||
'conversion_status',
|
||||
'conversion_error',
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title('重试失败')
|
||||
->body('无法重新派发转换任务:' . $e->getMessage())
|
||||
->send();
|
||||
}
|
||||
}),
|
||||
Actions\Action::make('preview')
|
||||
->label('预览 Markdown')
|
||||
->icon('heroicon-o-eye')
|
||||
@@ -107,6 +148,24 @@ class ViewDocument extends ViewRecord
|
||||
->label('文件大小')
|
||||
->formatStateUsing(fn ($state): string => DocumentResource::formatFileSize($state)),
|
||||
|
||||
TextEntry::make('conversion_status')
|
||||
->label('转换状态')
|
||||
->badge()
|
||||
->color(fn (?string $state): string => match ($state) {
|
||||
'completed' => 'success',
|
||||
'processing' => 'info',
|
||||
'pending' => 'warning',
|
||||
'failed' => 'danger',
|
||||
default => 'gray',
|
||||
})
|
||||
->formatStateUsing(fn (?string $state): string => match ($state) {
|
||||
'completed' => '已完成',
|
||||
'processing' => '转换中',
|
||||
'pending' => '等待转换',
|
||||
'failed' => '转换失败',
|
||||
default => '未知',
|
||||
}),
|
||||
|
||||
TextEntry::make('created_at')
|
||||
->label('上传时间')
|
||||
->dateTime('Y年m月d日 H:i:s'),
|
||||
@@ -117,6 +176,19 @@ class ViewDocument extends ViewRecord
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make('转换错误信息')
|
||||
->schema([
|
||||
ViewEntry::make('conversion_error')
|
||||
->label('')
|
||||
->view('filament.resources.document.conversion-error-detail')
|
||||
->viewData([
|
||||
'document' => $this->record,
|
||||
]),
|
||||
])
|
||||
->visible(fn ($record) => $record->conversion_status === 'failed' && !empty($record->conversion_error))
|
||||
->collapsible()
|
||||
->collapsed(false),
|
||||
|
||||
Section::make('文档预览')
|
||||
->schema([
|
||||
ViewEntry::make('preview')
|
||||
|
||||
Reference in New Issue
Block a user