| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <x-filament-panels::page>
- <!-- 数学公式渲染组件 -->
- <x-math-render />
- <div class="space-y-6">
- <!-- 后台生成状态栏 - 仅在生成中显示 -->
- @if($isGenerating && $currentTaskId)
- <div class="bg-blue-50 border-l-4 border-blue-400 p-4 rounded-r-lg animate-pulse">
- <div class="flex items-center">
- <div class="animate-spin rounded-full h-5 w-5 border-b-2 border-blue-600 mr-3"></div>
- <div class="flex-1">
- <p class="text-sm text-blue-800">
- <strong>正在后台生成题目...</strong>
- </p>
- <p class="text-xs text-blue-600 mt-1">
- 任务 ID: {{ $currentTaskId }} | AI生成完成后将自动刷新页面
- </p>
- </div>
- <button type="button" wire:click="$set('isGenerating', false)" class="text-blue-400 hover:text-blue-600">
- <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
- </svg>
- </button>
- </div>
- </div>
- @endif
- <!-- 生成表单 -->
- <div class="bg-white p-6 rounded-lg border">
- <h2 class="text-lg font-semibold mb-4">生成配置</h2>
- <div class="space-y-4">
- <!-- 知识点选择 -->
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">
- 知识点 <span class="text-red-500">*</span>
- </label>
- <select wire:model.live="generateKpCode" class="w-full border rounded p-2">
- <option value="">选择知识点</option>
- @foreach($this->knowledgePointOptions as $code => $name)
- <option value="{{ $code }}">{{ $code }} - {{ $name }}</option>
- @endforeach
- </select>
- </div>
- <!-- 技能选择 -->
- @if(!empty($this->skillsOptions))
- <div>
- <div class="flex items-center justify-between mb-2">
- <label class="block text-sm font-medium">
- 选择技能 <span class="text-red-500">*</span>
- <span class="text-xs text-gray-500 ml-2">({{ count($selectedSkills) }}/{{ count($this->skillsOptions) }} 已选)</span>
- </label>
- <button type="button"
- class="text-sm text-blue-600 hover:underline {{ count($selectedSkills) === count($this->skillsOptions) && count($this->skillsOptions) > 0 ? 'font-semibold' : '' }}"
- wire:click="toggleAllSkills">
- {{ count($selectedSkills) === count($this->skillsOptions) && count($this->skillsOptions) > 0 ? '取消全选' : '全选' }}
- </button>
- </div>
- <div class="max-h-64 overflow-y-auto border rounded p-3 grid grid-cols-2 gap-2">
- @foreach($this->skillsOptions as $skill)
- <label class="flex items-center space-x-2">
- <input type="checkbox"
- value="{{ $skill['code'] }}"
- @checked(in_array($skill['code'], $selectedSkills, true))
- wire:model="selectedSkills"
- class="rounded border-gray-300 text-primary focus:ring-primary">
- <span class="text-sm">
- <span class="font-medium">{{ $skill['code'] }}</span>
- <span class="text-gray-600 ml-2">{{ $skill['name'] }}</span>
- <span class="text-xs text-gray-400 ml-2">(权重: {{ $skill['weight'] ?? 1 }})</span>
- </span>
- </label>
- @endforeach
- </div>
- </div>
- @else
- <div class="bg-blue-50 border border-blue-200 rounded p-3">
- <div class="flex items-start">
- <svg class="w-5 h-5 text-blue-600 mt-0.5 mr-2" fill="currentColor" viewBox="0 0 20 20">
- <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
- </svg>
- <div>
- <p class="text-sm text-blue-800 font-medium">
- 该知识点暂未关联技能
- </p>
- <p class="text-xs text-blue-700 mt-1">
- 将基于知识点本身生成题目,无需额外技能限制
- </p>
- </div>
- </div>
- </div>
- @endif
- <!-- 题目数量 -->
- <div>
- <label class="block text-sm font-medium text-gray-700 mb-2">题目数量</label>
- <input type="number" wire:model="questionCount" min="1" max="500" class="w-full border rounded p-2">
- </div>
- <!-- 提示词模板 -->
- <div>
- <div class="flex items-center justify-between mb-2">
- <label class="block text-sm font-medium text-gray-700">
- 提示词模板
- </label>
- <a href="{{ route('filament.admin.pages.prompt-management') }}"
- class="text-xs text-blue-600 hover:underline"
- target="_blank">
- 去提示词管理
- </a>
- </div>
- <select wire:model="promptTemplate" class="w-full border rounded p-2">
- <option value="">使用默认模板</option>
- @foreach($this->promptOptions as $name => $label)
- <option value="{{ $name }}">{{ $label }}</option>
- @endforeach
- </select>
- <p class="text-xs text-gray-500 mt-1">仅展示激活的“题目生成”模板,后台调整后可即时生效。</p>
- </div>
- <!-- 生成按钮 -->
- <div class="flex justify-end pt-4">
- <button
- type="button"
- wire:click="executeGenerate"
- wire:loading.attr="disabled"
- wire:loading.class="bg-yellow-500 cursor-not-allowed opacity-90"
- wire:loading.class.remove="bg-blue-600 hover:bg-blue-700"
- wire:target="executeGenerate"
- class="px-6 py-2 bg-blue-600 hover:bg-blue-700 rounded font-medium transition-all duration-200 flex items-center gap-2 text-white"
- >
- @if($isGenerating)
- <svg class="animate-spin h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
- <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
- <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
- </svg>
- <span class="text-white font-semibold">生成中...</span>
- @else
- <svg class="w-4 h-4 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
- </svg>
- <span class="text-white font-semibold">开始生成</span>
- @endif
- </button>
- </div>
- </div>
- </div>
- </div>
- <script>
- document.addEventListener('livewire:init', () => {
- // ✅ 捕获回调参数,直接检查状态 - 避免盲目轮询
- Livewire.on('start-async-task-monitoring', () => {
- console.log('[QuestionGen] 开始监控任务状态');
- const taskId = @this.currentTaskId;
- if (!taskId) {
- console.error('[QuestionGen] 未找到任务ID');
- return;
- }
- window.currentTaskId = taskId;
- let checkCount = 0;
- const maxChecks = 5; // 最多检查5次
- function checkCallbackStatus() {
- checkCount++;
- console.log(`[QuestionGen] 检查回调 #${checkCount}/${maxChecks}`);
- // 直接调用 API 检查回调数据 - GET 请求无需 CSRF
- fetch(`/api/questions/callback/${taskId}`, {
- method: 'GET',
- headers: {
- 'X-Requested-With': 'XMLHttpRequest',
- 'Accept': 'application/json',
- }
- })
- .then(response => response.json())
- .then(data => {
- console.log('[QuestionGen] 回调数据:', data);
- // ✅ 如果有状态字段,说明回调已收到
- if (data.status) {
- if (data.status === 'completed') {
- console.log('[QuestionGen] ✅ 任务完成');
- @this.set('isGenerating', false);
- @this.set('currentTaskId', null);
- // 显示成功通知
- setTimeout(() => {
- window.location.reload();
- }, 1000);
- } else if (data.status === 'failed') {
- console.log('[QuestionGen] ❌ 任务失败');
- @this.set('isGenerating', false);
- @this.set('currentTaskId', null);
- }
- } else if (checkCount < maxChecks) {
- // 没收到回调,继续检查
- setTimeout(checkCallbackStatus, 3000);
- } else {
- // 达到最大检查次数,停止
- console.log('[QuestionGen] 检查超时,停止监控');
- @this.set('isGenerating', false);
- @this.set('currentTaskId', null);
- }
- })
- .catch(error => {
- console.error('[QuestionGen] 检查回调失败:', error);
- if (checkCount < maxChecks) {
- setTimeout(checkCallbackStatus, 3000);
- }
- });
- }
- // 立即检查一次
- checkCallbackStatus();
- // 15秒后强制停止
- setTimeout(() => {
- if (checkCount < maxChecks) {
- console.log('[QuestionGen] 强制停止监控');
- @this.set('isGenerating', false);
- @this.set('currentTaskId', null);
- }
- }, 15000);
- });
- // 监听强制关闭状态栏事件
- Livewire.on('force-close-status-bar', () => {
- console.log('[QuestionGen] 强制关闭状态栏');
- @this.set('isGenerating', false);
- @this.set('currentTaskId', null);
- });
- });
- </script>
- </x-filament-panels::page>
|