MathRenderTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Livewire;
  3. use App\Livewire\Traits\WithMathRender;
  4. use Livewire\Attributes\Computed;
  5. use Livewire\Component;
  6. class MathRenderTest extends Component
  7. {
  8. use WithMathRender;
  9. public string $search = '';
  10. public int $currentPage = 1;
  11. public array $sampleQuestions = [
  12. [
  13. 'code' => 'Q001',
  14. 'content' => '已知二次函数 $f(x) = ax^2 + bx + c$,求 $f(2)$ 的值。',
  15. 'difficulty' => 0.3,
  16. ],
  17. [
  18. 'code' => 'Q002',
  19. 'content' => '计算定积分:$$\int_0^1 x^2 dx$$',
  20. 'difficulty' => 0.6,
  21. ],
  22. [
  23. 'code' => 'Q003',
  24. 'content' => '证明三角恒等式:$\sin^2(x) + \cos^2(x) = 1$',
  25. 'difficulty' => 0.85,
  26. ],
  27. [
  28. 'code' => 'Q004',
  29. 'content' => '求极限:$$\lim_{x \to 0} \frac{\sin(x)}{x}$$',
  30. 'difficulty' => 0.7,
  31. ],
  32. [
  33. 'code' => 'Q005',
  34. 'content' => '解方程:$ax^2 + bx + c = 0$',
  35. 'difficulty' => 0.4,
  36. ],
  37. ];
  38. #[Computed]
  39. public function questions(): array
  40. {
  41. $filtered = array_filter($this->sampleQuestions, function($question) {
  42. if (empty($this->search)) {
  43. return true;
  44. }
  45. return str_contains(strtolower($question['content']), strtolower($this->search));
  46. });
  47. return array_values($filtered);
  48. }
  49. public function render()
  50. {
  51. return view('livewire.math-render-test');
  52. }
  53. }