question-management.blade.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. {{-- 访问计算属性触发懒加载 --}}
  2. @php
  3. $questionsData = $this->questions;
  4. $metaData = $this->meta;
  5. $statisticsData = $this->statistics;
  6. @endphp
  7. <x-filament-panels::page>
  8. <div class="space-y-6">
  9. {{-- 操作按钮栏 --}}
  10. <div class="flex justify-end gap-3">
  11. <button
  12. type="button"
  13. class="filament-button filament-button-size-sm filament-button-color-primary filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  14. wire:click="$dispatch('open-prompt-modal')"
  15. >
  16. <span class="filament-button-icon mr-2">
  17. @svg('heroicon-m-document-text', 'h-4 w-4')
  18. </span>
  19. 管理提示词
  20. </button>
  21. <button
  22. type="button"
  23. class="filament-button filament-button-size-sm filament-button-color-success filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  24. wire:click="$dispatch('ai-generate')"
  25. >
  26. <span class="filament-button-icon mr-2">
  27. @svg('heroicon-m-sparkles', 'h-4 w-4')
  28. </span>
  29. 生成题目
  30. </button>
  31. <button
  32. type="button"
  33. class="filament-button filament-button-size-sm filament-button-color-warning filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  34. wire:click="$dispatch('refresh-data')"
  35. wire:loading.attr="disabled"
  36. >
  37. <span class="filament-button-icon mr-2" wire:loading.remove>
  38. @svg('heroicon-m-arrow-path', 'h-4 w-4')
  39. </span>
  40. <span wire:loading>刷新中...</span>
  41. <span wire:loading.remove>刷新</span>
  42. </button>
  43. <button
  44. type="button"
  45. class="filament-button filament-button-size-sm filament-button-color-danger filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  46. onclick="window.location.reload()"
  47. >
  48. <span class="filament-button-icon mr-2">
  49. @svg('heroicon-m-arrow-path', 'h-4 w-4')
  50. </span>
  51. 强制刷新
  52. </button>
  53. </div>
  54. {{-- 统计信息卡片 --}}
  55. <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
  56. <div class="bg-white p-4 rounded-lg border">
  57. <div class="text-sm text-gray-500">题目总数</div>
  58. <div class="text-2xl font-bold text-primary-600">
  59. {{ $statisticsData['total'] ?? 0 }}
  60. </div>
  61. </div>
  62. <div class="bg-white p-4 rounded-lg border">
  63. <div class="text-sm text-gray-500">基础难度</div>
  64. <div class="text-2xl font-bold text-green-600">
  65. {{ $statisticsData['by_difficulty']['0.3'] ?? 0 }}
  66. </div>
  67. </div>
  68. <div class="bg-white p-4 rounded-lg border">
  69. <div class="text-sm text-gray-500">中等难度</div>
  70. <div class="text-2xl font-bold text-yellow-600">
  71. {{ $statisticsData['by_difficulty']['0.6'] ?? 0 }}
  72. </div>
  73. </div>
  74. <div class="bg-white p-4 rounded-lg border">
  75. <div class="text-sm text-gray-500">拔高难度</div>
  76. <div class="text-2xl font-bold text-red-600">
  77. {{ $statisticsData['by_difficulty']['0.85'] ?? 0 }}
  78. </div>
  79. </div>
  80. </div>
  81. {{-- 任务进度显示 --}}
  82. @if($isGenerating && $currentTaskId)
  83. <div class="bg-white p-6 rounded-lg border border-primary-200 bg-primary-50">
  84. <div class="flex items-center justify-between mb-4">
  85. <div class="flex items-center gap-3">
  86. <div class="animate-spin rounded-full h-5 w-5 border-b-2 border-primary-600"></div>
  87. <h3 class="text-lg font-semibold text-primary-900">AI正在生成题目</h3>
  88. </div>
  89. <button
  90. type="button"
  91. class="text-sm text-gray-500 hover:text-gray-700"
  92. wire:click="$dispatch('cancel-generate')"
  93. >
  94. 取消
  95. </button>
  96. </div>
  97. <div class="space-y-3">
  98. <div class="flex justify-between text-sm">
  99. <span class="text-gray-600">{{ $currentTaskMessage }}</span>
  100. <span class="font-medium text-gray-900">{{ $currentTaskProgress }}%</span>
  101. </div>
  102. <div class="w-full bg-gray-200 rounded-full h-2">
  103. <div
  104. class="bg-primary-600 h-2 rounded-full transition-all duration-500"
  105. style="width: {{ $currentTaskProgress }}%"
  106. ></div>
  107. </div>
  108. <div class="text-xs text-gray-500">
  109. 任务ID: {{ $currentTaskId }}
  110. </div>
  111. </div>
  112. </div>
  113. @endif
  114. {{-- 搜索和筛选 --}}
  115. <div class="bg-white p-4 rounded-lg border">
  116. <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
  117. <div>
  118. <label class="block text-sm font-medium text-gray-700 mb-2">
  119. 搜索题目
  120. </label>
  121. <input
  122. type="text"
  123. wire:model.live.debounce.300ms="search"
  124. placeholder="输入题目内容、答案或编号"
  125. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
  126. />
  127. </div>
  128. <div>
  129. <label class="block text-sm font-medium text-gray-700 mb-2">
  130. 知识点筛选
  131. </label>
  132. <input
  133. type="text"
  134. wire:model.live="selectedKpCode"
  135. placeholder="如:KP1001"
  136. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
  137. />
  138. </div>
  139. <div>
  140. <label class="block text-sm font-medium text-gray-700 mb-2">
  141. 难度筛选
  142. </label>
  143. <input
  144. type="text"
  145. wire:model.live="selectedDifficulty"
  146. placeholder="0.3/0.6/0.85"
  147. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
  148. />
  149. </div>
  150. <div>
  151. <label class="block text-sm font-medium text-gray-700 mb-2">
  152. 每页显示
  153. </label>
  154. <input
  155. type="number"
  156. wire:model.live="perPage"
  157. min="10"
  158. max="100"
  159. step="5"
  160. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
  161. />
  162. </div>
  163. </div>
  164. </div>
  165. {{-- 题目列表 --}}
  166. <div class="bg-white rounded-lg border overflow-hidden">
  167. <div class="overflow-x-auto" wire:loading.class="opacity-50">
  168. <table class="min-w-full divide-y divide-gray-200">
  169. <thead class="bg-gray-50">
  170. <tr>
  171. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  172. 题目编号
  173. </th>
  174. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  175. 知识点
  176. </th>
  177. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  178. 题干
  179. </th>
  180. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  181. 关联技能
  182. </th>
  183. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  184. 难度
  185. </th>
  186. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  187. 来源
  188. </th>
  189. <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
  190. 操作
  191. </th>
  192. </tr>
  193. </thead>
  194. <tbody class="bg-white divide-y divide-gray-200">
  195. @forelse($questionsData as $question)
  196. <tr class="hover:bg-gray-50">
  197. <td class="px-6 py-4 whitespace-nowrap">
  198. <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
  199. {{ $question['question_code'] ?? 'N/A' }}
  200. </span>
  201. </td>
  202. <td class="px-6 py-4 whitespace-nowrap">
  203. <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-indigo-100 text-indigo-800">
  204. {{ $question['kp_code'] ?? 'N/A' }}
  205. </span>
  206. </td>
  207. <td class="px-6 py-4">
  208. <div class="text-sm text-gray-900 max-w-xs">
  209. {{ \Illuminate\Support\Str::limit($question['stem'] ?? 'N/A', 80) }}
  210. </div>
  211. </td>
  212. <td class="px-6 py-4">
  213. @php
  214. $skills = $question['skills'] ?? [];
  215. if (is_string($skills)) {
  216. $skills = json_decode($skills, true) ?? [];
  217. }
  218. $skillNames = [];
  219. foreach ($skills as $skill) {
  220. // 处理不同格式的技能数据
  221. if (is_string($skill)) {
  222. // 如果是字符串,直接显示
  223. $skillNames[] = $skill;
  224. } elseif (is_array($skill)) {
  225. // 如果是对象,显示skill_name或skill_code
  226. $skillNames[] = $skill['skill_name'] ?? $skill['skill_code'] ?? 'N/A';
  227. }
  228. }
  229. $skillText = implode(', ', array_slice($skillNames, 0, 2));
  230. if (count($skillNames) > 2) {
  231. $skillText .= ' ...';
  232. }
  233. @endphp
  234. <div class="text-xs text-gray-600 max-w-xs">
  235. @if(!empty($skillText))
  236. <span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-100 text-purple-800">
  237. {{ $skillText }}
  238. </span>
  239. @else
  240. <span class="text-gray-400">无关联技能</span>
  241. @endif
  242. </div>
  243. </td>
  244. <td class="px-6 py-4 whitespace-nowrap">
  245. @php
  246. $difficulty = $question['difficulty'] ?? null;
  247. $difficultyLabel = match (true) {
  248. !$difficulty => 'N/A',
  249. (float)$difficulty <= 0.4 => '基础',
  250. (float)$difficulty <= 0.7 => '中等',
  251. default => '拔高',
  252. };
  253. $difficultyColor = match (true) {
  254. !$difficulty => 'gray',
  255. (float)$difficulty <= 0.4 => 'success',
  256. (float)$difficulty <= 0.7 => 'warning',
  257. default => 'danger',
  258. };
  259. @endphp
  260. <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-{{ $difficultyColor }}-100 text-{{ $difficultyColor }}-800">
  261. {{ $difficultyLabel }}
  262. </span>
  263. </td>
  264. <td class="px-6 py-4 whitespace-nowrap">
  265. @php
  266. $source = $question['source'] ?? '';
  267. $sourceLabel = str_contains($source, 'ai::') ? 'AI 生成' : '手工录入';
  268. $sourceColor = str_contains($source, 'ai::') ? 'blue' : 'gray';
  269. @endphp
  270. <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-{{ $sourceColor }}-100 text-{{ $sourceColor }}-800">
  271. {{ $sourceLabel }}
  272. </span>
  273. </td>
  274. <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
  275. <button type="button" class="text-indigo-600 hover:text-indigo-900 mr-3">
  276. 查看
  277. </button>
  278. <button
  279. type="button"
  280. class="text-red-600 hover:text-red-900"
  281. wire:click="deleteQuestion('{{ $question['question_code'] }}')"
  282. wire:confirm="确定要删除题目 {{ $question['question_code'] }} 吗?此操作不可撤销!"
  283. wire:loading.attr="disabled"
  284. wire:loading.text="删除中..."
  285. >
  286. 删除
  287. </button>
  288. </td>
  289. </tr>
  290. @empty
  291. <tr>
  292. <td colspan="7" class="px-6 py-12 text-center text-sm text-gray-500">
  293. <div class="flex flex-col items-center">
  294. @svg('heroicon-m-document-magnifying-glass', 'w-12 h-12 text-gray-400')
  295. 暂无题目数据
  296. <p class="mt-2 text-xs text-gray-400">
  297. 请尝试调整搜索条件或生成新题目
  298. </p>
  299. </div>
  300. </td>
  301. </tr>
  302. @endforelse
  303. </tbody>
  304. </table>
  305. </div>
  306. {{-- 分页信息 --}}
  307. @if(!empty($metaData) && ($metaData['total'] ?? 0) > 0)
  308. <div class="bg-white px-4 py-3 border-t border-gray-200 sm:px-6">
  309. <div class="flex items-center justify-between">
  310. <div class="text-sm text-gray-700">
  311. 显示第 {{ (($metaData['page'] ?? 1) - 1) * ($metaData['per_page'] ?? 25) + 1 }} 到
  312. {{ min(($metaData['page'] ?? 1) * ($metaData['per_page'] ?? 25), $metaData['total'] ?? 0) }} 条,
  313. 共 {{ $metaData['total'] ?? 0 }} 条记录
  314. </div>
  315. <div class="flex items-center gap-2">
  316. <button
  317. type="button"
  318. class="px-3 py-1 text-sm border rounded {{ $currentPage <= 1 ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-50' }}"
  319. wire:click="previousPage"
  320. @disabled($currentPage <= 1)
  321. >
  322. 上一页
  323. </button>
  324. @foreach($this->getPages() as $page)
  325. <button
  326. type="button"
  327. class="px-3 py-1 text-sm border rounded {{ $page === $currentPage ? 'bg-primary-50 text-primary-700 border-primary-300' : 'hover:bg-gray-50' }}"
  328. wire:click="gotoPage({{ $page }})"
  329. >
  330. {{ $page }}
  331. </button>
  332. @endforeach
  333. <button
  334. type="button"
  335. class="px-3 py-1 text-sm border rounded {{ $currentPage >= ($metaData['total_pages'] ?? 1) ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-50' }}"
  336. wire:click="nextPage"
  337. @disabled($currentPage >= ($metaData['total_pages'] ?? 1))
  338. >
  339. 下一页
  340. </button>
  341. </div>
  342. </div>
  343. </div>
  344. @endif
  345. </div>
  346. {{-- 加载指示器 --}}
  347. <div wire:loading class="fixed top-4 right-4 bg-primary-600 text-white px-4 py-2 rounded-lg shadow-lg flex items-center gap-2 z-50">
  348. <div class="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full"></div>
  349. <span>加载中...</span>
  350. </div>
  351. {{-- 生成题目模态框 --}}
  352. @if($showGenerateModal)
  353. <div class="fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4" x-data>
  354. <div class="bg-white rounded-lg shadow-xl max-w-4xl w-full max-h-[90vh] overflow-y-auto">
  355. <div class="p-6 border-b">
  356. <h3 class="text-lg font-semibold">生成题目</h3>
  357. </div>
  358. <div class="p-6 space-y-4">
  359. {{-- 选择知识点 --}}
  360. <div>
  361. <label class="block text-sm font-medium text-gray-700 mb-2">
  362. 选择知识点 <span class="text-red-500">*</span>
  363. </label>
  364. <select
  365. wire:model.live="generateKpCode"
  366. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
  367. >
  368. <option value="">请选择知识点</option>
  369. @foreach($this->knowledgePointOptions as $code => $name)
  370. <option value="{{ $code }}">{{ $code }} - {{ $name }}</option>
  371. @endforeach
  372. </select>
  373. </div>
  374. {{-- 选择技能 --}}
  375. @if(!empty($this->skillsOptions))
  376. <div>
  377. <div class="flex items-center justify-between mb-2">
  378. <label class="block text-sm font-medium text-gray-700">
  379. 选择技能 <span class="text-red-500">*</span>
  380. <span class="text-xs text-gray-500 ml-2">(已选择 {{ count($selectedSkills) }} / {{ count($this->skillsOptions) }})</span>
  381. </label>
  382. <button
  383. type="button"
  384. class="text-sm text-primary-600 hover:text-primary-700"
  385. wire:click="toggleAllSkills"
  386. >
  387. {{ count($selectedSkills) === count($this->skillsOptions) ? '取消全选' : '全选' }}
  388. </button>
  389. </div>
  390. <div class="grid grid-cols-1 md:grid-cols-2 gap-2 max-h-48 overflow-y-auto border rounded-lg p-3">
  391. @foreach($this->skillsOptions as $skill)
  392. <label class="flex items-center space-x-2 cursor-pointer">
  393. <input
  394. type="checkbox"
  395. value="{{ $skill['code'] }}"
  396. wire:model="selectedSkills"
  397. class="rounded border-gray-300 text-primary-600 focus:ring-primary-500"
  398. />
  399. <span class="text-sm">
  400. <span class="font-medium">{{ $skill['code'] }}</span>
  401. <span class="text-gray-600"> - {{ $skill['name'] }}</span>
  402. <span class="text-xs text-gray-400">(权重: {{ $skill['weight'] }})</span>
  403. </span>
  404. </label>
  405. @endforeach
  406. </div>
  407. </div>
  408. @else
  409. <div class="text-sm text-gray-500 italic">
  410. 请先选择知识点以加载技能列表
  411. </div>
  412. @endif
  413. {{-- 题目数量 --}}
  414. <div>
  415. <label class="block text-sm font-medium text-gray-700 mb-2">
  416. 题目数量
  417. </label>
  418. <input
  419. type="number"
  420. wire:model="questionCount"
  421. min="1"
  422. max="500"
  423. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
  424. />
  425. <p class="mt-1 text-xs text-gray-500">建议单次生成不超过200道题</p>
  426. </div>
  427. </div>
  428. <div class="p-6 border-t bg-gray-50 flex justify-end gap-3">
  429. <button
  430. type="button"
  431. class="filament-button filament-button-size-sm filament-button-color-gray filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  432. wire:click="closeGenerateModal"
  433. >
  434. 取消
  435. </button>
  436. <button
  437. type="button"
  438. class="filament-button filament-button-size-sm filament-button-color-success filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  439. wire:click="executeGenerate"
  440. wire:loading.attr="disabled"
  441. >
  442. <span wire:loading.remove>开始生成</span>
  443. <span wire:loading>生成中...</span>
  444. </button>
  445. </div>
  446. </div>
  447. </div>
  448. @endif
  449. {{-- 提示词编辑模态框 --}}
  450. @if($showPromptModal)
  451. <div class="fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4" x-data>
  452. <div class="bg-white rounded-lg shadow-xl max-w-5xl w-full max-h-[90vh] overflow-hidden flex flex-col">
  453. <div class="p-6 border-b">
  454. <h3 class="text-lg font-semibold">管理提示词模板</h3>
  455. <p class="mt-1 text-sm text-gray-500">
  456. 自定义AI题目生成的提示词模板,支持变量替换
  457. </p>
  458. </div>
  459. <div class="flex-1 overflow-y-auto p-6">
  460. <div class="space-y-4">
  461. <div>
  462. <label class="block text-sm font-medium text-gray-700 mb-2">
  463. 提示词模板内容
  464. </label>
  465. <textarea
  466. wire:model="promptTemplate"
  467. rows="20"
  468. class="filament-forms-input block w-full rounded-lg border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm font-mono"
  469. placeholder="输入提示词模板..."
  470. ></textarea>
  471. <p class="mt-2 text-xs text-gray-500">
  472. 可用变量:{knowledge_point}, {grade_level}, {basic_ratio}, {intermediate_ratio}, {advanced_ratio}, {choice}, {fill}, {solution}, {count}, {skill_coverage}
  473. </p>
  474. </div>
  475. </div>
  476. </div>
  477. <div class="p-6 border-t bg-gray-50 flex justify-between items-center">
  478. <div class="text-sm text-gray-500">
  479. <span class="font-medium">{{ strlen($promptTemplate ?? '') }}</span> 个字符
  480. </div>
  481. <div class="flex gap-3">
  482. <button
  483. type="button"
  484. class="filament-button filament-button-size-sm filament-button-color-gray filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  485. wire:click="closePromptModal"
  486. >
  487. 取消
  488. </button>
  489. <button
  490. type="button"
  491. class="filament-button filament-button-size-sm filament-button-color-primary filament-button-icon-start inline-flex items-center justify-center px-4 py-2 text-sm font-medium transition-colors border border-transparent rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
  492. wire:click="savePrompt"
  493. wire:loading.attr="disabled"
  494. >
  495. <span wire:loading.remove>保存</span>
  496. <span wire:loading>保存中...</span>
  497. </button>
  498. </div>
  499. </div>
  500. </div>
  501. </div>
  502. @endif
  503. </div>
  504. {{-- 任务状态轮询 --}}
  505. <script>
  506. document.addEventListener('livewire:init', () => {
  507. Livewire.on('poll-task', () => {
  508. setTimeout(() => {
  509. @this.call('pollTaskStatus');
  510. }, 2000); // 每2秒轮询一次
  511. });
  512. // 监听页面刷新事件
  513. Livewire.on('refresh-page', () => {
  514. setTimeout(() => {
  515. window.location.reload();
  516. }, 500); // 延迟500ms刷新,给用户时间看到成功消息
  517. });
  518. // 监听实时回调通知
  519. Livewire.on('task-failed', (event) => {
  520. const { taskId, error, kpCode } = event[0];
  521. // 显示详细错误通知
  522. const notification = document.createElement('div');
  523. notification.className = 'fixed top-4 right-4 bg-red-50 border border-red-200 rounded-lg shadow-lg p-4 max-w-md z-50';
  524. notification.innerHTML = `
  525. <div class="flex items-start">
  526. <div class="flex-shrink-0">
  527. <svg class="h-5 w-5 text-red-400" fill="currentColor" viewBox="0 0 20 20">
  528. <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
  529. </svg>
  530. </div>
  531. <div class="ml-3">
  532. <h3 class="text-sm font-medium text-red-800">题目生成失败</h3>
  533. <div class="mt-2 text-sm text-red-700">
  534. <p>任务ID: ${taskId}</p>
  535. <p>知识点: ${kpCode}</p>
  536. <p class="mt-1 font-mono text-xs">${error}</p>
  537. </div>
  538. <div class="mt-3 flex space-x-2">
  539. <button onclick="this.closest('.fixed').remove()" class="text-sm text-red-600 hover:text-red-800 underline">
  540. 关闭
  541. </button>
  542. </div>
  543. </div>
  544. </div>
  545. `;
  546. document.body.appendChild(notification);
  547. // 5秒后自动移除
  548. setTimeout(() => {
  549. if (notification.parentNode) {
  550. notification.parentNode.removeChild(notification);
  551. }
  552. }, 10000);
  553. });
  554. // 监听任务成功回调
  555. Livewire.on('task-completed', (event) => {
  556. const { taskId, kpCode, total } = event[0];
  557. // 显示成功通知
  558. const notification = document.createElement('div');
  559. notification.className = 'fixed top-4 right-4 bg-green-50 border border-green-200 rounded-lg shadow-lg p-4 max-w-md z-50';
  560. notification.innerHTML = `
  561. <div class="flex items-start">
  562. <div class="flex-shrink-0">
  563. <svg class="h-5 w-5 text-green-400" fill="currentColor" viewBox="0 0 20 20">
  564. <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"></path>
  565. </svg>
  566. </div>
  567. <div class="ml-3">
  568. <h3 class="text-sm font-medium text-green-800">题目生成成功</h3>
  569. <div class="mt-2 text-sm text-green-700">
  570. <p>任务ID: ${taskId}</p>
  571. <p>知识点: ${kpCode}</p>
  572. <p>已成功生成 ${total} 道题目</p>
  573. </div>
  574. <div class="mt-3">
  575. <button onclick="location.reload()" class="text-sm text-green-600 hover:text-green-800 underline">
  576. 刷新页面
  577. </button>
  578. </div>
  579. </div>
  580. </div>
  581. `;
  582. document.body.appendChild(notification);
  583. // 3秒后自动移除
  584. setTimeout(() => {
  585. if (notification.parentNode) {
  586. notification.parentNode.removeChild(notification);
  587. }
  588. }, 5000);
  589. });
  590. });
  591. </script>
  592. </x-filament-panels::page>