question-preview-tool.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <div class="max-w-7xl mx-auto py-8 px-4">
  2. <!-- 标题 -->
  3. <div class="text-center mb-8">
  4. <h1 class="text-2xl font-bold text-gray-800">题目预览验证工具</h1>
  5. <p class="text-gray-500 mt-2">验证题目在网页和PDF中的显示效果</p>
  6. </div>
  7. <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
  8. <!-- 左侧:输入表单 -->
  9. <div class="bg-white rounded-lg shadow p-6">
  10. <h2 class="text-lg font-semibold text-gray-700 mb-4">输入题目内容</h2>
  11. <!-- 题干 -->
  12. <div class="mb-4">
  13. <label class="block text-sm font-medium text-gray-700 mb-1">
  14. 题干 <span class="text-red-500">*</span>
  15. </label>
  16. <textarea
  17. wire:model="stem"
  18. rows="5"
  19. class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
  20. placeholder="粘贴题干内容,支持 LaTeX 公式(如 $$\sqrt{2}$$ 或 $x^2$)"
  21. ></textarea>
  22. </div>
  23. <!-- 选项 -->
  24. <div class="mb-4">
  25. <label class="block text-sm font-medium text-gray-700 mb-2">
  26. 选项(选填,不填则为填空/解答题)
  27. </label>
  28. <div class="grid grid-cols-2 gap-3">
  29. <div>
  30. <label class="text-xs text-gray-500">A</label>
  31. <input
  32. type="text"
  33. wire:model="optionA"
  34. class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500"
  35. placeholder="选项 A"
  36. >
  37. </div>
  38. <div>
  39. <label class="text-xs text-gray-500">B</label>
  40. <input
  41. type="text"
  42. wire:model="optionB"
  43. class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500"
  44. placeholder="选项 B"
  45. >
  46. </div>
  47. <div>
  48. <label class="text-xs text-gray-500">C</label>
  49. <input
  50. type="text"
  51. wire:model="optionC"
  52. class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500"
  53. placeholder="选项 C"
  54. >
  55. </div>
  56. <div>
  57. <label class="text-xs text-gray-500">D</label>
  58. <input
  59. type="text"
  60. wire:model="optionD"
  61. class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500"
  62. placeholder="选项 D"
  63. >
  64. </div>
  65. </div>
  66. </div>
  67. <!-- 答案 -->
  68. <div class="mb-4">
  69. <label class="block text-sm font-medium text-gray-700 mb-1">答案</label>
  70. <input
  71. type="text"
  72. wire:model="answer"
  73. class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500"
  74. placeholder="正确答案"
  75. >
  76. </div>
  77. <!-- 解析 -->
  78. <div class="mb-6">
  79. <label class="block text-sm font-medium text-gray-700 mb-1">解析/解题思路</label>
  80. <textarea
  81. wire:model="solution"
  82. rows="4"
  83. class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500"
  84. placeholder="解题思路或解析内容"
  85. ></textarea>
  86. </div>
  87. <!-- 操作按钮 -->
  88. <div class="flex flex-wrap gap-3">
  89. <button
  90. wire:click="previewWeb"
  91. class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition flex items-center gap-2"
  92. >
  93. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  94. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
  95. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
  96. </svg>
  97. 网页预览
  98. </button>
  99. <button
  100. wire:click="previewPdf"
  101. wire:loading.attr="disabled"
  102. wire:loading.class="opacity-50 cursor-wait"
  103. wire:target="previewPdf"
  104. class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 transition flex items-center gap-2"
  105. >
  106. <svg wire:loading.remove wire:target="previewPdf" class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  107. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
  108. </svg>
  109. <svg wire:loading wire:target="previewPdf" class="w-4 h-4 animate-spin" fill="none" viewBox="0 0 24 24">
  110. <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
  111. <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>
  112. </svg>
  113. <span wire:loading.remove wire:target="previewPdf">PDF 预览</span>
  114. <span wire:loading wire:target="previewPdf">生成中...</span>
  115. </button>
  116. <button
  117. wire:click="previewBoth"
  118. wire:loading.attr="disabled"
  119. class="px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700 transition flex items-center gap-2"
  120. >
  121. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  122. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"/>
  123. </svg>
  124. 同时预览
  125. </button>
  126. <button
  127. wire:click="clearForm"
  128. class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition"
  129. >
  130. 清空
  131. </button>
  132. </div>
  133. </div>
  134. <!-- 右侧:预览区域 -->
  135. <div class="space-y-6">
  136. <!-- 网页预览 -->
  137. @if($showWebPreview)
  138. <div class="bg-white rounded-lg shadow">
  139. <div class="px-4 py-3 border-b border-gray-200 flex items-center gap-2">
  140. <span class="text-blue-600">
  141. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  142. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
  143. </svg>
  144. </span>
  145. <h3 class="font-semibold text-gray-700">网页效果预览</h3>
  146. </div>
  147. <div id="web-preview-area" class="p-4 math-preview">
  148. <!-- 题干 -->
  149. @if($stem)
  150. <div class="question-stem" data-math="{{ $stem }}">
  151. {{ $stem }}
  152. </div>
  153. @endif
  154. <!-- 选项 -->
  155. @if($optionA || $optionB || $optionC || $optionD)
  156. <div class="question-options">
  157. @if($optionA)
  158. <div class="question-option">
  159. <span class="font-medium">A.</span>
  160. <span data-math="{{ $optionA }}">{{ $optionA }}</span>
  161. </div>
  162. @endif
  163. @if($optionB)
  164. <div class="question-option">
  165. <span class="font-medium">B.</span>
  166. <span data-math="{{ $optionB }}">{{ $optionB }}</span>
  167. </div>
  168. @endif
  169. @if($optionC)
  170. <div class="question-option">
  171. <span class="font-medium">C.</span>
  172. <span data-math="{{ $optionC }}">{{ $optionC }}</span>
  173. </div>
  174. @endif
  175. @if($optionD)
  176. <div class="question-option">
  177. <span class="font-medium">D.</span>
  178. <span data-math="{{ $optionD }}">{{ $optionD }}</span>
  179. </div>
  180. @endif
  181. </div>
  182. @endif
  183. <!-- 答案 -->
  184. @if($answer)
  185. <div class="question-answer">
  186. <span class="font-medium text-green-700">答案:</span>
  187. <span data-math="{{ $answer }}">{{ $answer }}</span>
  188. </div>
  189. @endif
  190. <!-- 解析 -->
  191. @if($solution)
  192. <div class="question-solution">
  193. <div class="font-medium text-gray-700 mb-2">解题思路:</div>
  194. <div data-math="{{ $solution }}">{{ $solution }}</div>
  195. </div>
  196. @endif
  197. </div>
  198. </div>
  199. @endif
  200. <!-- PDF 预览 -->
  201. @if($showPdfPreview || $pdfError)
  202. <div class="bg-white rounded-lg shadow">
  203. <div class="px-4 py-3 border-b border-gray-200 flex items-center gap-2">
  204. <span class="text-green-600">
  205. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  206. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/>
  207. </svg>
  208. </span>
  209. <h3 class="font-semibold text-gray-700">PDF 效果预览</h3>
  210. @if($pdfUrl)
  211. <a href="{{ $pdfUrl }}" target="_blank" class="ml-auto text-sm text-blue-600 hover:underline">
  212. 新窗口打开
  213. </a>
  214. @endif
  215. </div>
  216. <div class="p-4">
  217. @if($pdfError)
  218. <div class="text-red-600 bg-red-50 p-4 rounded">
  219. <p class="font-medium">生成失败</p>
  220. <p class="text-sm mt-1">{{ $pdfError }}</p>
  221. </div>
  222. @elseif($pdfUrl)
  223. <iframe
  224. src="{{ $pdfUrl }}"
  225. class="w-full h-[600px] border border-gray-200 rounded"
  226. ></iframe>
  227. @endif
  228. </div>
  229. </div>
  230. @endif
  231. <!-- 使用提示 -->
  232. @if(!$showWebPreview && !$showPdfPreview && !$pdfError)
  233. <div class="bg-gray-50 rounded-lg p-6 text-center text-gray-500">
  234. <svg class="w-12 h-12 mx-auto mb-3 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  235. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
  236. </svg>
  237. <p>在左侧输入题目内容</p>
  238. <p class="text-sm mt-1">点击预览按钮查看渲染效果</p>
  239. <div class="mt-4 text-left text-xs text-gray-400 bg-white p-3 rounded border">
  240. <p class="font-medium mb-2">支持的 LaTeX 格式:</p>
  241. <ul class="space-y-1">
  242. <li><code class="bg-gray-100 px-1">$...$</code> 行内公式</li>
  243. <li><code class="bg-gray-100 px-1">$$...$$</code> 块级公式</li>
  244. <li><code class="bg-gray-100 px-1">\(...\)</code> 行内公式(会自动转换)</li>
  245. <li><code class="bg-gray-100 px-1">\[...\]</code> 块级公式(会自动转换)</li>
  246. </ul>
  247. </div>
  248. </div>
  249. @endif
  250. </div>
  251. </div>
  252. </div>