index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <div class="app-container">
  3. <div class="pagination-container" v-loading.fullscreen.lock="loading">
  4. <div class="tasks-container">
  5. <div class="tasks">
  6. <div
  7. class="task-item"
  8. v-for="task in questionTasks"
  9. :key="task.task_id"
  10. :class="{ 'task-item-selected': selectedTaskId === task.task_id }"
  11. @click="handleTaskClick(task.task_id)"
  12. >
  13. <div class="task-question">{{ task.question }}</div>
  14. </div>
  15. </div>
  16. <div class="pagination">
  17. <el-pagination
  18. @current-change="handleCurrentChange"
  19. :current-page="pageNumber"
  20. :page-size="pageSize"
  21. :total="total"
  22. layout="prev, pager, next"
  23. />
  24. </div>
  25. </div>
  26. <div class="task-detail-container">
  27. <el-descriptions
  28. class="margin-top"
  29. title="任务详情"
  30. :column="3"
  31. border
  32. v-if="selectedTask"
  33. >
  34. <el-descriptions-item label="任务ID">
  35. {{ selectedTask?.task_id }}
  36. </el-descriptions-item>
  37. <el-descriptions-item label="问题">
  38. {{ selectedTask?.question }}
  39. </el-descriptions-item>
  40. <el-descriptions-item label="任务状态">{{ selectedTask?.statusText }}</el-descriptions-item>
  41. <el-descriptions-item label="知识类别">
  42. {{ KnowledgeType[selectedTask?.knowledgeType] || '' }}
  43. </el-descriptions-item>
  44. <el-descriptions-item label="内容知识子类别">
  45. {{ QueryTypeEnum[selectedTask?.query_type] || '-' }}
  46. </el-descriptions-item>
  47. <el-descriptions-item label="是否需要存储">
  48. {{ selectedTask?.need_store === NeedStoreEnum.需要存储 ? '是' : '否' }}
  49. </el-descriptions-item>
  50. </el-descriptions>
  51. <div class="querys-header">Query词条</div>
  52. <el-collapse accordion @change="handleCollapseChange">
  53. <el-collapse-item
  54. v-for="query in selectedQueries"
  55. :key="query.query"
  56. :title="query.query"
  57. :name="query.query"
  58. class="query-title"
  59. >
  60. <div v-loading="query.loading" class="query-data-container">
  61. <div v-if="query.data" class="query-data-content">
  62. {{ query.data }}
  63. </div>
  64. <div v-else-if="!query.loading" class="query-data-empty">
  65. 暂无数据
  66. </div>
  67. </div>
  68. </el-collapse-item>
  69. </el-collapse>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script lang="ts">
  75. import { defineComponent, ref, watch } from 'vue';
  76. import { ElPagination, ElDescriptions, ElCollapse, ElCollapseItem } from 'element-plus';
  77. import { DATA_CRAWLING_BASE_URL } from "@/config";
  78. import axios from 'axios';
  79. import { KnowledgeType, NeedStoreEnum, QueryTask, QueryTypeEnum, QuestionTask, TaskStatusEnum } from '@/types/DataCrawing';
  80. export default defineComponent({
  81. name: 'DataCrawling',
  82. components: {
  83. ElPagination,
  84. ElDescriptions,
  85. ElCollapse,
  86. ElCollapseItem,
  87. },
  88. setup() {
  89. const questionTasks = ref<QuestionTask[]>([]);
  90. const pageNumber = ref(1);
  91. const pageSize = ref(10);
  92. const total = ref(0);
  93. const loading = ref(false);
  94. const selectedTaskId = ref<string | null>(null);
  95. const selectedTask = ref<QuestionTask | null>(null);
  96. const selectedQueries = ref<QueryTask[]>([]);
  97. const activeCollapseName = ref<string | number | null>(null);
  98. // 监听selectedTaskId变化
  99. watch(selectedTaskId, (newVal) => {
  100. selectedTask.value = questionTasks.value.find(task => task.task_id === newVal) || null;
  101. selectedQueries.value = selectedTask.value?.queries || [];
  102. activeCollapseName.value = null; // 重置展开状态
  103. });
  104. const renderTaskStatus = (status: TaskStatusEnum) => {
  105. return TaskStatusEnum[status];
  106. };
  107. const fetchData = async () => {
  108. loading.value = true;
  109. try {
  110. const response = await axios.get(`${DATA_CRAWLING_BASE_URL}/tasks`, {
  111. params: {
  112. page_number: pageNumber.value,
  113. page_size: pageSize.value,
  114. },
  115. });
  116. console.log('Response:', response);
  117. if (response && response.data) {
  118. questionTasks.value = response.data.tasks;
  119. total.value = response.data.total;
  120. selectedTaskId.value = response.data.tasks[0]?.task_id || null;
  121. }
  122. } catch (error) {
  123. console.error('Error fetching data:', error);
  124. } finally {
  125. loading.value = false;
  126. }
  127. };
  128. const handleCurrentChange = (newPage: number) => {
  129. pageNumber.value = newPage;
  130. fetchData();
  131. };
  132. const handleTaskClick = (taskId: string) => {
  133. selectedTaskId.value = taskId;
  134. };
  135. const handleCollapseChange = async (activeName: string | number | (string | number)[]) => {
  136. console.log('activeName:', activeName);
  137. // 查找对应的 query
  138. const query = selectedQueries.value.find(q => q.query === activeName);
  139. // 如果这个 query 已经有数据了,就不再请求
  140. if (query && !query.data && !query.loading) {
  141. query.loading = true;
  142. try {
  143. // 第一步:请求 knowledge-query/data 接口
  144. const queryResponse = await axios.get(`${DATA_CRAWLING_BASE_URL}/knowledge-query/data`, {
  145. params: {
  146. suggest_task_id: query.task_id || selectedTaskId.value,
  147. query: query.query,
  148. },
  149. });
  150. if (queryResponse.data && queryResponse.data.request_id) {
  151. query.request_id = queryResponse.data.request_id;
  152. // 第二步:使用 request_id 请求 knowledge-store/data 接口
  153. const storeResponse = await axios.get(`${DATA_CRAWLING_BASE_URL}/knowledge-store/data`, {
  154. params: {
  155. request_id: query.request_id,
  156. },
  157. });
  158. if (storeResponse.data && storeResponse.data.data) {
  159. query.data = storeResponse.data.data;
  160. }
  161. }
  162. } catch (error) {
  163. console.error('Error fetching query data:', error);
  164. } finally {
  165. query.loading = false;
  166. }
  167. }
  168. };
  169. fetchData();
  170. return {
  171. questionTasks,
  172. pageNumber,
  173. pageSize,
  174. total,
  175. handleCurrentChange,
  176. loading,
  177. selectedTaskId,
  178. selectedTask,
  179. handleTaskClick,
  180. renderTaskStatus,
  181. NeedStoreEnum,
  182. KnowledgeType,
  183. QueryTypeEnum,
  184. selectedQueries,
  185. handleCollapseChange,
  186. };
  187. },
  188. });
  189. </script>
  190. <style scoped>
  191. .app-container {
  192. min-height: calc(100vh - 71px);
  193. background: rgba(138,147,228,0.1);
  194. font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  195. }
  196. .pagination-container {
  197. box-sizing: border-box;
  198. height: calc(100vh - 90px);
  199. max-height: calc(100vh - 90px);
  200. display: flex;
  201. justify-content: center;
  202. align-items: flex-start;
  203. gap: 20px;
  204. padding: 0 20px;
  205. }
  206. .tasks-container {
  207. display: flex;
  208. box-sizing: border-box;
  209. padding-top: 20px;
  210. flex-direction: column;
  211. justify-content: space-between;
  212. align-items: flex-start;
  213. width: 35%;
  214. max-width: 400px;
  215. height: 100%;
  216. overflow-y: auto;
  217. background: white;
  218. border-radius: 12px;
  219. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  220. border: 1px solid #e8ecf0;
  221. }
  222. .task-detail-container {
  223. box-sizing: border-box;
  224. flex: 1;
  225. padding: 30px;
  226. height: calc(100vh - 110px);
  227. max-height: calc(100vh - 110px);
  228. overflow-y: auto;
  229. background: white;
  230. border-radius: 12px;
  231. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  232. border: 1px solid #e8ecf0;
  233. }
  234. .pagination {
  235. width: 100%;
  236. padding: 20px;
  237. border-top: 1px solid #f0f2f5;
  238. background: #fafbfc;
  239. border-radius: 0 0 12px 12px;
  240. }
  241. .tasks {
  242. box-sizing: border-box;
  243. width: 100%;
  244. padding: 20px;
  245. flex: 1;
  246. overflow-y: auto;
  247. }
  248. .task-item {
  249. box-sizing: border-box;
  250. padding: 18px 20px;
  251. margin-bottom: 8px;
  252. background: white;
  253. border-radius: 10px;
  254. cursor: pointer;
  255. transition: all 0.3s ease;
  256. border: 2px solid transparent;
  257. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  258. position: relative;
  259. }
  260. .task-item:hover {
  261. border-color: rgba(138, 147, 228, 0.3);
  262. box-shadow: 0 4px 16px rgba(138, 147, 228, 0.12);
  263. transform: translateY(-1px);
  264. }
  265. .task-item-selected {
  266. background: linear-gradient(135deg, rgba(138, 147, 228, 0.1) 0%, rgba(138, 147, 228, 0.05) 100%);
  267. border-color: rgba(138, 147, 228, 0.4);
  268. box-shadow: 0 4px 16px rgba(138, 147, 228, 0.15);
  269. }
  270. .task-item-selected:hover {
  271. background: linear-gradient(135deg, rgba(138, 147, 228, 0.15) 0%, rgba(138, 147, 228, 0.08) 100%);
  272. }
  273. .task-item-selected::before {
  274. content: '';
  275. position: absolute;
  276. left: 0;
  277. top: 0;
  278. bottom: 0;
  279. width: 4px;
  280. background: linear-gradient(to bottom, #8a93e4, #6b73d1);
  281. border-radius: 0 2px 2px 0;
  282. }
  283. .task-question {
  284. font-size: 15px;
  285. color: #2c3e50;
  286. line-height: 1.6;
  287. font-weight: 500;
  288. margin: 0;
  289. }
  290. .query-data-container {
  291. padding: 20px;
  292. min-height: 120px;
  293. }
  294. .query-data-content {
  295. font-size: 14px;
  296. color: #2c3e50;
  297. line-height: 1.8;
  298. white-space: pre-wrap;
  299. word-wrap: break-word;
  300. background: linear-gradient(135deg, #f8f9fa 0%, #f1f3f4 100%);
  301. padding: 20px;
  302. border-radius: 8px;
  303. border-left: 4px solid #8a93e4;
  304. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  305. }
  306. .query-data-empty {
  307. text-align: center;
  308. color: #95a5a6;
  309. font-size: 14px;
  310. padding: 40px;
  311. background: #f8f9fa;
  312. border-radius: 8px;
  313. border: 2px dashed #e9ecef;
  314. }
  315. .task-detail-container :deep(.el-descriptions__title) {
  316. font-size: 20px;
  317. line-height: 1.6;
  318. font-weight: 600;
  319. color: #2c3e50;
  320. margin: 0 0 20px 0;
  321. padding-bottom: 12px;
  322. border-bottom: 2px solid #f0f2f5;
  323. }
  324. .task-detail-container :deep(.el-descriptions) {
  325. margin-bottom: 30px;
  326. }
  327. .task-detail-container :deep(.el-descriptions__body) {
  328. background: #fafbfc;
  329. border-radius: 8px;
  330. }
  331. .task-detail-container :deep(.el-descriptions-item__label) {
  332. font-weight: 600;
  333. color: #5a6c7d;
  334. }
  335. .task-detail-container :deep(.el-descriptions-item__content) {
  336. color: #2c3e50;
  337. font-weight: 500;
  338. }
  339. .querys-header {
  340. font-size: 20px;
  341. line-height: 1.6;
  342. font-weight: 600;
  343. color: #2c3e50;
  344. margin: 0 0 20px 0;
  345. padding-bottom: 12px;
  346. border-bottom: 2px solid #f0f2f5;
  347. }
  348. .query-title :deep(.el-collapse-item__header) {
  349. font-size: 15px;
  350. color: #2c3e50;
  351. font-weight: 500;
  352. padding: 16px 20px;
  353. background: #f8f9fa;
  354. border-radius: 8px;
  355. margin-bottom: 8px;
  356. transition: all 0.3s ease;
  357. }
  358. .query-title :deep(.el-collapse-item__header:hover) {
  359. background: #f0f2f5;
  360. color: #8a93e4;
  361. }
  362. .query-title :deep(.el-collapse-item__wrap) {
  363. border: none;
  364. background: transparent;
  365. }
  366. .query-title :deep(.el-collapse-item__content) {
  367. padding: 0;
  368. background: transparent;
  369. }
  370. .query-title :deep(.el-collapse-item__arrow) {
  371. color: #8a93e4;
  372. font-weight: bold;
  373. }
  374. </style>