label('预览提示词') ->icon('heroicon-o-eye') ->color('info') ->modalHeading('提示词预览') ->modalDescription('查看变量替换后的实际提示词内容') ->modalWidth(MaxWidth::FourExtraLarge) ->modalSubmitAction(false) ->modalCancelActionLabel('关闭') ->form(function ($record, $livewire) { $service = app(PromptTemplateService::class); // 获取当前表单数据 $data = $livewire->data ?? []; $promptTemplate = $data['prompt']['prompt_template'] ?? ''; if (empty($promptTemplate)) { return [ Placeholder::make('empty') ->label('') ->content('请先输入提示词模板内容'), ]; } // 如果是编辑模式,使用记录的终端信息 // 如果是创建模式,使用表单数据创建临时终端对象 if ($record) { $terminal = $record; } else { // 创建临时终端对象用于预览 $terminal = new \App\Models\Terminal([ 'name' => $data['name'] ?? '新终端', 'code' => $data['code'] ?? 'TEMP-001', 'station_id' => $data['station_id'] ?? null, ]); } // 替换变量 $previewContent = $service->replaceVariables($promptTemplate, $terminal); // 验证变量 $invalidVariables = $service->validateVariables($promptTemplate); return [ Placeholder::make('original') ->label('原始模板') ->content(function () use ($promptTemplate) { return view('filament.components.prompt-preview-original', [ 'content' => $promptTemplate, ]); }), Placeholder::make('preview') ->label('预览结果') ->content(function () use ($previewContent) { return view('filament.components.prompt-preview-result', [ 'content' => $previewContent, ]); }), Placeholder::make('validation') ->label('变量验证') ->content(function () use ($invalidVariables) { return view('filament.components.prompt-preview-validation', [ 'invalidVariables' => $invalidVariables, ]); }) ->visible(fn () => !empty($invalidVariables)), ]; }); } }