knowledge-graph-component.blade.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <div>
  2. <div class="space-y-4">
  3. {{-- 控制栏 --}}
  4. <div class="flex items-center justify-between">
  5. <div class="flex items-center gap-2">
  6. <button
  7. wire:click="toggleStats"
  8. class="inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:text-gray-300 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"
  9. >
  10. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  11. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
  12. </svg>
  13. {{ $showStats ? '隐藏' : '显示' }}统计
  14. </button>
  15. <button
  16. wire:click="refreshGraph"
  17. class="inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 dark:text-gray-300 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"
  18. >
  19. <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  20. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
  21. </svg>
  22. 刷新
  23. </button>
  24. </div>
  25. <div class="text-sm text-gray-500 dark:text-gray-400">
  26. @if($selectedKpCode)
  27. 当前选中: <span class="font-medium">{{ $selectedKpCode }}</span>
  28. @else
  29. 全图模式
  30. @endif
  31. </div>
  32. </div>
  33. {{-- 图谱可视化区域 --}}
  34. <div class="relative bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700" style="height: 600px;">
  35. @if($isLoading)
  36. <div class="absolute inset-0 flex items-center justify-center bg-white/80 dark:bg-gray-800/80 z-10">
  37. <div class="flex items-center gap-3">
  38. <svg class="animate-spin h-6 w-6 text-indigo-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
  39. <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
  40. <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>
  41. </svg>
  42. <span class="text-gray-600 dark:text-gray-300">加载知识图谱...</span>
  43. </div>
  44. </div>
  45. @endif
  46. @if(!empty($graphData['nodes']))
  47. {{-- 这里将嵌入图谱可视化库(如 D3.js、vis.js 等) --}}
  48. <div id="knowledge-graph-viz" class="w-full h-full"></div>
  49. {{-- 图例 --}}
  50. <div class="absolute top-4 right-4 bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700 p-4 shadow-lg">
  51. <h4 class="text-sm font-medium text-gray-900 dark:text-gray-100 mb-2">图例</h4>
  52. <div class="space-y-2 text-xs">
  53. <div class="flex items-center gap-2">
  54. <div class="w-3 h-3 rounded-full bg-blue-500"></div>
  55. <span class="text-gray-600 dark:text-gray-400">知识点</span>
  56. </div>
  57. <div class="flex items-center gap-2">
  58. <div class="w-3 h-3 rounded bg-green-500"></div>
  59. <span class="text-gray-600 dark:text-gray-400">题库</span>
  60. </div>
  61. <div class="flex items-center gap-2">
  62. <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
  63. <span class="text-gray-600 dark:text-gray-400">技能点</span>
  64. </div>
  65. </div>
  66. </div>
  67. @else
  68. <div class="absolute inset-0 flex items-center justify-center">
  69. <div class="text-center text-gray-500 dark:text-gray-400">
  70. <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  71. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-1.447-.894L15 4m0 13V4m0 0L9 7"></path>
  72. </svg>
  73. <p class="mt-2">暂无知识图谱数据</p>
  74. </div>
  75. </div>
  76. @endif
  77. </div>
  78. {{-- 统计信息 --}}
  79. @if($showStats && !empty($graphData['nodes']))
  80. <div class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6">
  81. <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-4">图谱统计</h3>
  82. <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
  83. <div class="text-center">
  84. <div class="text-2xl font-bold text-indigo-600 dark:text-indigo-400">{{ count($graphData['nodes']) }}</div>
  85. <div class="text-sm text-gray-500 dark:text-gray-400">知识点</div>
  86. </div>
  87. <div class="text-center">
  88. <div class="text-2xl font-bold text-green-600 dark:text-green-400">{{ count($graphData['edges']) }}</div>
  89. <div class="text-sm text-gray-500 dark:text-gray-400">关联关系</div>
  90. </div>
  91. <div class="text-center">
  92. @php
  93. $totalQuestions = 0;
  94. foreach($graphData['nodes'] as $node) {
  95. $totalQuestions += $node['question_count'] ?? 0;
  96. }
  97. @endphp
  98. <div class="text-2xl font-bold text-blue-600 dark:text-blue-400">{{ $totalQuestions }}</div>
  99. <div class="text-sm text-gray-500 dark:text-gray-400">关联题目</div>
  100. </div>
  101. <div class="text-center">
  102. @php
  103. $totalSkills = 0;
  104. foreach($graphData['nodes'] as $node) {
  105. $totalSkills += $node['skills_count'] ?? 0;
  106. }
  107. @endphp
  108. <div class="text-2xl font-bold text-yellow-600 dark:text-yellow-400">{{ $totalSkills }}</div>
  109. <div class="text-sm text-gray-500 dark:text-gray-400">技能点</div>
  110. </div>
  111. </div>
  112. </div>
  113. @endif
  114. {{-- 节点详情 --}}
  115. @if(!empty($selectedNodeData))
  116. <div class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6">
  117. <div class="flex items-center justify-between mb-4">
  118. <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">节点详情</h3>
  119. <button
  120. wire:click="$set('selectedNodeData', null)"
  121. class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-200"
  122. >
  123. <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  124. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
  125. </svg>
  126. </button>
  127. </div>
  128. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  129. <div>
  130. <h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">基本信息</h4>
  131. <dl class="space-y-2 text-sm">
  132. <div class="flex">
  133. <dt class="w-24 text-gray-500 dark:text-gray-400">名称:</dt>
  134. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['cn_name'] ?? $selectedNodeData['kp_code'] }}</dd>
  135. </div>
  136. <div class="flex">
  137. <dt class="w-24 text-gray-500 dark:text-gray-400">代码:</dt>
  138. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['kp_code'] }}</dd>
  139. </div>
  140. <div class="flex">
  141. <dt class="w-24 text-gray-500 dark:text-gray-400">学段:</dt>
  142. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['phase'] ?? '-' }}</dd>
  143. </div>
  144. <div class="flex">
  145. <dt class="w-24 text-gray-500 dark:text-gray-400">类别:</dt>
  146. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['category'] ?? '-' }}</dd>
  147. </div>
  148. </dl>
  149. </div>
  150. <div>
  151. <h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">统计信息</h4>
  152. <dl class="space-y-2 text-sm">
  153. <div class="flex">
  154. <dt class="w-24 text-gray-500 dark:text-gray-400">题目数:</dt>
  155. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['question_count'] ?? 0 }}</dd>
  156. </div>
  157. <div class="flex">
  158. <dt class="w-24 text-gray-500 dark:text-gray-400">技能数:</dt>
  159. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['skills_count'] ?? 0 }}</dd>
  160. </div>
  161. <div class="flex">
  162. <dt class="w-24 text-gray-500 dark:text-gray-400">重要度:</dt>
  163. <dd class="text-gray-900 dark:text-gray-100">{{ $selectedNodeData['importance'] ?? 0 }}</dd>
  164. </div>
  165. </dl>
  166. </div>
  167. </div>
  168. @if(!empty($selectedNodeData['skills']))
  169. <div class="mt-4">
  170. <h4 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">技能列表</h4>
  171. <div class="flex flex-wrap gap-2">
  172. @foreach($selectedNodeData['skills'] as $skill)
  173. <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-indigo-100 text-indigo-800 dark:bg-indigo-900 dark:text-indigo-200">
  174. {{ $skill['skill_name'] ?? $skill['skill_code'] ?? 'Unknown' }}
  175. </span>
  176. @endforeach
  177. </div>
  178. </div>
  179. @endif
  180. </div>
  181. @endif
  182. </div>
  183. </div>
  184. @push('scripts')
  185. <script>
  186. // 这里将添加图谱可视化逻辑
  187. // 使用 vis.js 或 D3.js 实现交互式图谱
  188. document.addEventListener('livewire:initialized', () => {
  189. // 监听数据变化并更新可视化
  190. Livewire.on('graphDataUpdated', (data) => {
  191. updateVisualization(data);
  192. });
  193. });
  194. function updateVisualization(data) {
  195. // 实现图谱更新逻辑
  196. console.log('Updating graph visualization:', data);
  197. }
  198. </script>
  199. @endpush