yemeishu преди 1 месец
родител
ревизия
55d0391e84

+ 23 - 16
app/Filament/Pages/UploadExamPaper.php

@@ -165,13 +165,13 @@ class UploadExamPaper extends Page
             })->toArray();
 
         // 2. 获取所有Paper记录(包括草稿和已评分)
-        $paperQuery = \App\Models\Paper::with(['createdByUser'])->latest();
+        $paperQuery = \App\Models\Paper::with(['student'])->latest();
 
         // 如果选择了学生,则筛选该学生的记录
         if (!empty($this->studentId)) {
-            $paperQuery->where('created_by', $this->studentId);
+            $paperQuery->where('student_id', $this->studentId);
         }
-        
+
         $allPapers = $paperQuery->take(5)
             ->get()
             ->map(function($paper) {
@@ -181,17 +181,17 @@ class UploadExamPaper extends Page
 
                 return [
                     'type' => $type,
-                    'id' => $paper->id,
+                    'id' => $paper->paper_id,
                     'record_id' => null,
-                    'paper_id' => $paper->id,
-                    'student_id' => $paper->created_by,
-                    'student_name' => $paper->createdByUser?->full_name ?? $paper->created_by,
+                    'paper_id' => $paper->paper_id,
+                    'student_id' => $paper->student_id,
+                    'student_name' => $paper->student?->name ?? $paper->student_id,
                     'paper_type' => $paperType,
-                    'paper_name' => $paper->title ?? '未命名试卷',
-                    'status' => $paper->difficulty_level,
-                    'total_questions' => 0, // papers表没有question_count字段
+                    'paper_name' => $paper->paper_name ?? '未命名试卷',
+                    'status' => $paper->difficulty_category,
+                    'total_questions' => $paper->question_count ?? 0,
                     'created_at' => $paper->created_at->format('Y-m-d H:i'),
-                    'is_completed' => $paper->difficulty_level !== null,
+                    'is_completed' => $paper->status === 'completed',
                     'icon_color' => $iconColor,
                 ];
             })->toArray();
@@ -216,15 +216,22 @@ class UploadExamPaper extends Page
         }
 
         try {
-            return \App\Models\Paper::where('created_by', $this->studentId)
+            // 使用 Student 关联查询试卷
+            $student = \App\Models\Student::find($this->studentId);
+            if (!$student) {
+                \Log::warning('未找到指定学生', ['student_id' => $this->studentId]);
+                return [];
+            }
+
+            return $student->papers()
                 ->withCount('questions') // 添加题目计数
                 ->orderBy('created_at', 'desc')
                 ->take(20)
                 ->get()
                 ->map(function($paper) {
                     return [
-                        'paper_id' => $paper->id,
-                        'paper_name' => $paper->title ?? '未命名试卷',
+                        'paper_id' => $paper->paper_id, // 使用 paper_id 而不是 id
+                        'paper_name' => $paper->paper_name ?? '未命名试卷',
                         'total_questions' => $paper->questions_count ?? 0,
                         'total_score' => $paper->total_score ?? 0,
                         'created_at' => $paper->created_at->format('Y-m-d H:i'),
@@ -266,7 +273,7 @@ class UploadExamPaper extends Page
 
         try {
             // 首先检查试卷是否存在
-            $paper = \App\Models\Paper::find($this->selectedPaperId);
+            $paper = \App\Models\Paper::where('paper_id', $this->selectedPaperId)->first();
             if (!$paper) {
                 \Log::warning('未找到指定试卷', ['paper_id' => $this->selectedPaperId]);
                 return [];
@@ -275,7 +282,7 @@ class UploadExamPaper extends Page
             // 使用关联关系查询题目
             $paperWithQuestions = \App\Models\Paper::with(['questions' => function($query) {
                 $query->orderBy('question_number');
-            }])->find($this->selectedPaperId);
+            }])->where('paper_id', $this->selectedPaperId)->first();
 
             $questions = $paperWithQuestions ? $paperWithQuestions->questions : collect([]);
 

+ 149 - 0
app/Filament/Resources/TeacherResource.php

@@ -0,0 +1,149 @@
+<?php
+
+namespace App\Filament\Resources;
+
+use App\Filament\Resources\TeacherResource\Pages;
+use App\Models\Teacher;
+use App\Models\User;
+use Filament\Forms\Components\TextInput;
+use Filament\Forms\Components\Select;
+use Filament\Forms\Components\Textarea;
+use Filament\Resources\Resource;
+use Filament\Schemas\Schema;
+use Filament\Tables;
+use Filament\Tables\Table;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Hash;
+
+class TeacherResource extends Resource
+{
+    protected static ?string $model = Teacher::class;
+
+    protected static bool $shouldRegisterNavigation = false;
+
+    public static function form(Schema $schema): Schema
+    {
+        return $schema->schema([
+            TextInput::make('teacher_id')
+                ->label('教师ID')
+                ->disabled()
+                ->hidden(fn (?Teacher $record) => blank($record))
+                ->formatStateUsing(fn (?Teacher $record): string => $record?->teacher_id ?? ''),
+            TextInput::make('name')
+                ->label('教师姓名')
+                ->required()
+                ->maxLength(128)
+                ->placeholder('请输入教师姓名'),
+            TextInput::make('subject')
+                ->label('教授科目')
+                ->required()
+                ->maxLength(64)
+                ->placeholder('例如:数学、语文、英语等'),
+            TextInput::make('user.email')
+                ->label('邮箱地址(可选)')
+                ->email()
+                ->placeholder('请输入邮箱地址')
+                ->reactive()
+                ->afterStateUpdated(fn ($state, callable $set) => $state ? $set('user.username', explode('@', $state)[0] ?? '') : null),
+            TextInput::make('user.username')
+                ->label('用户名')
+                ->required()
+                ->maxLength(64)
+                ->placeholder('登录用户名'),
+            TextInput::make('user.password_hash')
+                ->label('密码')
+                ->required()
+                ->password()
+                ->revealable()
+                ->dehydrateStateUsing(fn ($state) => Hash::make($state))
+                ->placeholder('请输入密码'),
+            Textarea::make('remark')
+                ->label('备注')
+                ->rows(3)
+                ->placeholder('请输入备注信息(可选)')
+                ->columnSpanFull(),
+        ])->columns(2);
+    }
+
+    public static function table(Table $table): Table
+    {
+        return $table
+            ->columns([
+                Tables\Columns\TextColumn::make('teacher_id')
+                    ->label('教师ID')
+                    ->badge()
+                    ->color('primary')
+                    ->copyable()
+                    ->copyMessage('教师ID已复制')
+                    ->copyMessageDuration(1500)
+                    ->sortable()
+                    ->searchable(),
+                Tables\Columns\TextColumn::make('name')
+                    ->label('姓名')
+                    ->weight('bold')
+                    ->searchable()
+                    ->sortable(),
+                Tables\Columns\TextColumn::make('subject')
+                    ->label('教授科目')
+                    ->badge()
+                    ->color('info')
+                    ->sortable(),
+                Tables\Columns\TextColumn::make('user.email')
+                    ->label('邮箱')
+                    ->copyable()
+                    ->sortable(),
+                Tables\Columns\TextColumn::make('user.username')
+                    ->label('用户名')
+                    ->sortable(),
+                Tables\Columns\TextColumn::make('students_count')
+                    ->label('学生数量')
+                    ->counts('students')
+                    ->sortable()
+                    ->alignCenter()
+                    ->badge()
+                    ->color('success'),
+                Tables\Columns\TextColumn::make('created_at')
+                    ->label('创建时间')
+                    ->dateTime('Y-m-d H:i')
+                    ->sortable()
+                    ->toggleable(isToggledHiddenByDefault: true),
+            ])
+            ->filters([
+                Tables\Filters\SelectFilter::make('subject')
+                    ->label('教授科目')
+                    ->options(fn () => self::subjectOptions())
+                    ->placeholder('全部科目'),
+            ])
+            ->actions([])
+            ->bulkActions([])
+            ->emptyStateHeading('暂无教师记录')
+            ->emptyStateDescription('开始添加第一位教师吧')
+            ->emptyStateActions([]);
+    }
+
+    public static function getPages(): array
+    {
+        return [
+            'index' => Pages\ListTeachers::route('/'),
+            'create' => Pages\CreateTeacher::route('/create'),
+            'view' => Pages\ViewTeacher::route('/{record}'),
+            'edit' => Pages\EditTeacher::route('/{record}/edit'),
+        ];
+    }
+
+    protected static function subjectOptions(): array
+    {
+        return [
+            'math' => '数学',
+            'chinese' => '语文',
+            'english' => '英语',
+            'physics' => '物理',
+            'chemistry' => '化学',
+            'biology' => '生物',
+            'history' => '历史',
+            'geography' => '地理',
+            'politics' => '政治',
+            'other' => '其他',
+        ];
+    }
+}

+ 25 - 0
app/Filament/Resources/TeacherResource/Pages/ViewTeacher.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Filament\Resources\TeacherResource\Pages;
+
+use App\Filament\Resources\TeacherResource;
+use Filament\Resources\Pages\ViewRecord;
+
+class ViewTeacher extends ViewRecord
+{
+    protected static string $resource = TeacherResource::class;
+
+    public function getTitle(): string
+    {
+        return '教师详情';
+    }
+
+    public function getBreadcrumbs(): array
+    {
+        return [
+            '#' => '师生管理',
+            static::getResource()::getUrl('index') => '教师管理',
+            static::getResource()::getUrl('view', ['record' => $this->record]) => '教师详情',
+        ];
+    }
+}

+ 21 - 12
app/Models/Paper.php

@@ -7,30 +7,39 @@ use Illuminate\Database\Eloquent\Model;
 class Paper extends Model
 {
     protected $table = 'papers';
-    protected $primaryKey = 'id';
-    public $incrementing = true;
-    protected $keyType = 'int';
+    protected $primaryKey = 'paper_id';
+    public $incrementing = false;
+    protected $keyType = 'string';
     public $timestamps = true;
     
     const CREATED_AT = 'created_at';
     const UPDATED_AT = 'updated_at';
     
     protected $fillable = [
-        'id',
-        'title',
-        'subject',
+        'paper_id',
+        'student_id',
+        'teacher_id',
+        'paper_name',
+        'paper_type',
+        'question_count',
         'total_score',
-        'duration',
-        'difficulty_level',
-        'created_by',
+        'status',
+        'difficulty_category',
+        'completed_at',
         'analysis_id', // AI分析记录ID
     ];
     
     protected $casts = [
+        'paper_id' => 'string',
+        'student_id' => 'string',
+        'teacher_id' => 'string',
+        'question_count' => 'integer',
+        'total_score' => 'float',
+        'status' => 'string',
+        'difficulty_category' => 'string',
         'created_at' => 'datetime',
         'updated_at' => 'datetime',
-        'total_score' => 'float',
-        'duration' => 'integer',
+        'completed_at' => 'datetime',
     ];
     
     /**
@@ -38,7 +47,7 @@ class Paper extends Model
      */
     public function questions()
     {
-        return $this->hasMany(PaperQuestion::class, 'paper_id', 'id');
+        return $this->hasMany(PaperQuestion::class, 'paper_id', 'paper_id');
     }
 
     /**

+ 24 - 5
app/Models/PaperQuestion.php

@@ -8,16 +8,14 @@ class PaperQuestion extends Model
 {
     protected $table = 'paper_questions';
     protected $primaryKey = 'id';
-    public $incrementing = false;
-    protected $keyType = 'string';
-    public $timestamps = false;
     
     protected $fillable = [
-        'id',
         'paper_id',
+        'question_id',
         'question_bank_id',
         'knowledge_point',
         'question_type',  // choice-选择题, fill-填空题, answer-解答题
+        'question_text',
         'difficulty',
         'score',
         'estimated_time',
@@ -28,14 +26,19 @@ class PaperQuestion extends Model
     ];
     
     protected $casts = [
+        'paper_id' => 'string',
+        'question_id' => 'string',
         'question_bank_id' => 'integer',
+        'question_type' => 'string',
+        'question_text' => 'string',
         'difficulty' => 'float',
         'score' => 'float',
         'estimated_time' => 'integer',
         'question_number' => 'integer',
         'is_correct' => 'boolean',
         'score_obtained' => 'float',
-        'question_type' => 'string',
+        'created_at' => 'datetime',
+        'updated_at' => 'datetime',
     ];
     
     /**
@@ -53,4 +56,20 @@ class PaperQuestion extends Model
     {
         return $this->belongsTo(\App\Models\Question::class, 'question_bank_id', 'id');
     }
+
+    /**
+     * 按 question_id 查询题目的作用域
+     */
+    public function scopeByQuestionId($query, $questionId)
+    {
+        return $query->where('question_id', $questionId);
+    }
+
+    /**
+     * 按 question_bank_id 查询题目的作用域
+     */
+    public function scopeByQuestionBankId($query, $questionBankId)
+    {
+        return $query->where('question_bank_id', $questionBankId);
+    }
 }

+ 18 - 0
app/Models/Student.php

@@ -77,4 +77,22 @@ class Student extends Model
     {
         return $this->belongsTo(User::class, 'student_id', 'user_id');
     }
+
+    /**
+     * 获取学生的试卷列表
+     */
+    public function papers()
+    {
+        return $this->hasMany(\App\Models\Paper::class, 'student_id', 'student_id');
+    }
+
+    /**
+     * 获取学生最近生成的试卷
+     */
+    public function recentPapers($limit = 10)
+    {
+        return $this->hasMany(\App\Models\Paper::class, 'student_id', 'student_id')
+            ->orderBy('created_at', 'desc')
+            ->limit($limit);
+    }
 }

+ 2 - 1
app/Services/QuestionBankService.php

@@ -412,11 +412,12 @@ class QuestionBankService
                     }
 
                     $questionInsertData[] = [
-                        'id' => $paperId . '_q' . ($index + 1),
                         'paper_id' => $paperId,
+                        'question_id' => $question['question_code'] ?? $question['question_id'] ?? null,
                         'question_bank_id' => $question['id'] ?? $question['question_id'] ?? 0,
                         'knowledge_point' => $knowledgePoint,
                         'question_type' => $questionType,
+                        'question_text' => $question['stem'] ?? $question['content'] ?? $question['question_text'] ?? '',
                         'difficulty' => $difficultyValue,
                         'score' => $question['score'] ?? 5, // 默认5分
                         'estimated_time' => $question['estimated_time'] ?? 300,

+ 64 - 0
database/migrations/2025_11_26_053536_add_paper_fields_to_papers_table.php

@@ -0,0 +1,64 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('papers', function (Blueprint $table) {
+            // 添加 paper_id 字段(字符串类型,作为试卷的主标识符)
+            $table->string('paper_id', 64)->unique()->after('id')->comment('试卷唯一标识符');
+
+            // 添加学生和教师信息
+            $table->string('student_id', 64)->nullable()->after('paper_id')->comment('学生ID');
+            $table->string('teacher_id', 64)->nullable()->after('student_id')->comment('教师ID');
+
+            // 添加试卷基本信息
+            $table->string('paper_name', 255)->nullable()->after('teacher_id')->comment('试卷名称');
+            $table->string('paper_type', 32)->nullable()->after('paper_name')->comment('试卷类型:auto_generated, manual, custom');
+            $table->integer('question_count')->default(0)->after('paper_type')->comment('题目数量');
+
+            // 添加试卷状态和难度
+            $table->string('status', 32)->default('draft')->after('question_count')->comment('试卷状态:draft, completed, graded');
+            $table->string('difficulty_category', 32)->default('基础')->after('status')->comment('难度分类:基础, 进阶, 竞赛');
+
+            // 创建索引
+            $table->index('student_id', 'idx_papers_student_id');
+            $table->index('teacher_id', 'idx_papers_teacher_id');
+            $table->index('status', 'idx_papers_status');
+            $table->index('paper_type', 'idx_papers_type');
+            $table->index('difficulty_category', 'idx_papers_difficulty');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('papers', function (Blueprint $table) {
+            // 删除索引
+            $table->dropIndex('idx_papers_student_id');
+            $table->dropIndex('idx_papers_teacher_id');
+            $table->dropIndex('idx_papers_status');
+            $table->dropIndex('idx_papers_type');
+            $table->dropIndex('idx_papers_difficulty');
+
+            // 删除字段
+            $table->dropColumn('paper_id');
+            $table->dropColumn('student_id');
+            $table->dropColumn('teacher_id');
+            $table->dropColumn('paper_name');
+            $table->dropColumn('paper_type');
+            $table->dropColumn('question_count');
+            $table->dropColumn('status');
+            $table->dropColumn('difficulty_category');
+        });
+    }
+};

+ 44 - 0
database/migrations/2025_11_26_053600_change_paper_questions_paper_id_type.php

@@ -0,0 +1,44 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        // MySQL 不支持直接修改列类型,需要先删除再添加
+        Schema::table('paper_questions', function (Blueprint $table) {
+            // 删除旧的 paper_id 字段
+            $table->dropColumn('paper_id');
+        });
+
+        Schema::table('paper_questions', function (Blueprint $table) {
+            // 添加新的字符串类型的 paper_id 字段
+            $table->string('paper_id', 64)->nullable()->after('id')->comment('试卷标识符');
+            $table->index('paper_id', 'idx_paper_questions_paper_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('paper_questions', function (Blueprint $table) {
+            // 删除字符串类型的 paper_id
+            $table->dropIndex('idx_paper_questions_paper_id');
+            $table->dropColumn('paper_id');
+        });
+
+        Schema::table('paper_questions', function (Blueprint $table) {
+            // 恢复 bigint 类型的 paper_id
+            $table->bigInteger('paper_id')->unsigned()->nullable()->after('id');
+            $table->index('paper_id', 'idx_paper_questions_paper_id');
+        });
+    }
+};

+ 48 - 0
database/migrations/2025_11_26_055244_add_grading_fields_to_paper_questions.php

@@ -0,0 +1,48 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('paper_questions', function (Blueprint $table) {
+            // 添加评分相关字段
+            $table->text('student_answer')->nullable()->after('question_bank_id')->comment('学生答案');
+            $table->boolean('is_correct')->nullable()->after('student_answer')->comment('是否正确');
+            $table->decimal('score_obtained', 5, 2)->nullable()->after('is_correct')->comment('实际得分');
+            $table->boolean('has_been_graded')->default(false)->after('score_obtained')->comment('是否已评分');
+            $table->timestamp('graded_at')->nullable()->after('has_been_graded')->comment('评分时间');
+
+            // 创建索引
+            $table->index('is_correct', 'idx_paper_questions_is_correct');
+            $table->index('has_been_graded', 'idx_paper_questions_has_been_graded');
+            $table->index('graded_at', 'idx_paper_questions_graded_at');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('paper_questions', function (Blueprint $table) {
+            // 删除索引
+            $table->dropIndex('idx_paper_questions_is_correct');
+            $table->dropIndex('idx_paper_questions_has_been_graded');
+            $table->dropIndex('idx_paper_questions_graded_at');
+
+            // 删除字段
+            $table->dropColumn('student_answer');
+            $table->dropColumn('is_correct');
+            $table->dropColumn('score_obtained');
+            $table->dropColumn('has_been_graded');
+            $table->dropColumn('graded_at');
+        });
+    }
+};

+ 38 - 0
database/migrations/2025_11_26_055518_add_completed_at_to_papers.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('papers', function (Blueprint $table) {
+            // 添加 completed_at 字段,记录试卷完成时间
+            $table->timestamp('completed_at')->nullable()->after('updated_at')->comment('试卷完成时间');
+
+            // 创建索引优化查询
+            $table->index('completed_at', 'idx_papers_completed_at');
+            $table->index(['status', 'completed_at'], 'idx_papers_status_completed_at');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('papers', function (Blueprint $table) {
+            // 删除索引
+            $table->dropIndex('idx_papers_status_completed_at');
+            $table->dropIndex('idx_papers_completed_at');
+
+            // 删除字段
+            $table->dropColumn('completed_at');
+        });
+    }
+};

+ 144 - 0
public/test-math-render.html

@@ -0,0 +1,144 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>数学公式渲染测试</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            max-width: 800px;
+            margin: 0 auto;
+            padding: 20px;
+            line-height: 1.6;
+        }
+        .test-section {
+            margin: 20px 0;
+            padding: 20px;
+            border: 1px solid #ddd;
+            border-radius: 8px;
+            background-color: #f9f9f9;
+        }
+        .math-render {
+            background-color: white;
+            padding: 10px;
+            border-radius: 4px;
+            margin: 10px 0;
+        }
+        .status {
+            background-color: #e8f5e8;
+            padding: 10px;
+            border-radius: 4px;
+            margin: 10px 0;
+            font-weight: bold;
+        }
+        .error {
+            background-color: #f8d7da;
+            color: #721c24;
+        }
+        .success {
+            background-color: #d4edda;
+            color: #155724;
+        }
+    </style>
+</head>
+<body>
+    <h1>数学公式渲染测试</h1>
+
+    <div class="test-section">
+        <h2>测试1: 基础数学公式</h2>
+        <div class="math-render">
+            $x^2 + 2x + 1 = 0$ 是一个二次方程。
+        </div>
+    </div>
+
+    <div class="test-section">
+        <h2>测试2: 包含LaTeX命令的题目(类似OCR记录)</h2>
+        <div class="math-render">
+            已知集合A={-1,1,3},B={0,1,3},,则A∪B=A.{1,3} B.{-1,1,3} C.{0,1,3} D.{-1,0,1,3}
+        </div>
+    </div>
+
+    <div class="test-section">
+        <h2>测试3: 函数题目</h2>
+        <div class="math-render">
+            函数$f(x) = \\ln x + x - 2$的零点所在的区间为
+        </div>
+    </div>
+
+    <div class="test-section">
+        <h2>测试4: 复杂数学公式(可能引起问题)</h2>
+        <div class="math-render">
+            已知幂函数$$f \left(x \right) = x^{a}$$,则"a>0"是"f(x)在(0,+∞)上单调递增"的
+            A.充分不必要条件 B.必要不充分条件
+            C.充分必要条件 D.既不充分也不必要条件
+        </div>
+    </div>
+
+    <div class="test-section">
+        <h2>测试5: 混合格式</h2>
+        <div class="math-render">
+            混合格式:$\\frac{1}{2}$、$$\\frac{\\sqrt{3}}{2}$$和$\\frac{\\sqrt{2}}{2}$
+        </div>
+    </div>
+
+    <div id="status" class="status">
+        <div>正在加载数学渲染库...</div>
+    </div>
+
+    <script>
+        // 简化的测试版本,直接引入必要的库
+        console.log('开始加载测试页面...');
+
+        // 模拟简化版的数学渲染逻辑
+        function simpleTestRender() {
+            const elements = document.querySelectorAll('.math-render');
+            let processedCount = 0;
+            let errorCount = 0;
+
+            elements.forEach((elem, index) => {
+                try {
+                    let content = elem.innerHTML || elem.textContent;
+
+                    // 检测是否包含数学公式
+                    if (content.includes('$') || content.includes('\\(') || content.includes('\\[')) {
+                        console.log(`处理数学公式 ${index + 1}:`, content.substring(0, 50) + '...');
+
+                        // 简单的公式标准化
+                        content = content.replace(/\\left/g, '(');
+                        content = content.replace(/\\right/g, ')');
+                        content = content.replace(/\\\\/g, '\\');
+
+                        elem.innerHTML = content;
+                        processedCount++;
+                    }
+                } catch (e) {
+                    console.error(`处理元素 ${index + 1} 时出错:`, e);
+                    errorCount++;
+                }
+            });
+
+            const statusDiv = document.getElementById('status');
+            if (errorCount === 0) {
+                statusDiv.className = 'status success';
+                statusDiv.innerHTML = `
+                    <div>✅ 数学公式处理完成!</div>
+                    <div>成功处理 ${processedCount} 个包含公式的元素</div>
+                `;
+            } else {
+                statusDiv.className = 'status error';
+                statusDiv.innerHTML = `
+                    <div>❌ 处理过程中发现 ${errorCount} 个错误</div>
+                    <div>请检查浏览器控制台获取详细信息</div>
+                `;
+            }
+        }
+
+        // 页面加载完成后执行测试
+        document.addEventListener('DOMContentLoaded', function() {
+            console.log('页面加载完成,开始处理数学公式...');
+            setTimeout(simpleTestRender, 100);
+        });
+    </script>
+</body>
+</html>