Enhance week report generation by adding image appendix feature. Implemented a new method to build an images section at the end of the report, which includes task images and descriptions. Cleaned up unused placeholders and improved formatting for better readability.

This commit is contained in:
Ethanfly 2026-01-09 12:35:20 +08:00
parent 3955dd6049
commit 6f9bb5f43b

View File

@ -228,6 +228,7 @@ PROMPT;
*/
private function insertImagesToReport(string $report, array $tasks): string
{
// 首先尝试替换AI生成的占位符
foreach ($tasks as $index => $task) {
$num = $index + 1;
@ -263,9 +264,53 @@ PROMPT;
// 清理可能产生的多余空行
$report = preg_replace('/\n{3,}/', "\n\n", $report);
// 收集所有有图片的任务,并在报告末尾添加截图附录
$imagesSection = $this->buildImagesSection($tasks);
if (!empty($imagesSection)) {
$report .= $imagesSection;
}
return $report;
}
/**
* 构建图片附录部分
*/
private function buildImagesSection(array $tasks): string
{
$images = [];
foreach ($tasks as $index => $task) {
if (!empty($task['image'])) {
$num = $index + 1;
$imageUrl = asset('storage/' . $task['image']);
// 提取任务描述的前30个字符作为图片说明
$desc = mb_substr(trim($task['description']), 0, 50);
if (mb_strlen(trim($task['description'])) > 50) {
$desc .= '...';
}
$images[] = [
'num' => $num,
'url' => $imageUrl,
'desc' => $desc,
];
}
}
if (empty($images)) {
return '';
}
$section = "\n\n---\n\n## 附:任务截图\n\n";
foreach ($images as $img) {
$section .= "**任务{$img['num']}**: {$img['desc']}\n\n";
$section .= "![任务{$img['num']}截图]({$img['url']})\n\n";
}
return $section;
}
/**
* 下载Markdown格式
*/