ReportAutoLearn.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="report-autolearn admin-page">
  3. <el-card>
  4. <PageHeader slot="header" title="报告自学习">
  5. <el-button size="small" @click="fetchClusters" icon="el-icon-refresh">刷新</el-button>
  6. </PageHeader>
  7. <el-alert title='自学习机制:当同一类型的未知报告积累到3份后,系统自动标记为"可生成"状态,管理员可在此生成报告类型和指纹规则。' type='info' :closable='false' show-icon style='margin-bottom: 16px;' />
  8. <div class="adm-table-wrap">
  9. <el-table :data="clusters" v-loading="loading" border stripe height="100%">
  10. <el-table-column prop="id" label="ID" width="60">
  11. <template slot="header">
  12. <span class="sort-header" @click.stop="onSortClick('id', $event)">ID{{ sortIcon('id') }}</span>
  13. </template>
  14. </el-table-column>
  15. <el-table-column prop="clusterKey" label="聚类键" width="140">
  16. <template slot="header">
  17. <span class="sort-header" @click.stop="onSortClick('clusterKey', $event)">聚类键<span v-if="sortIndex('clusterKey') !== null" class="sort-index" :class="sortClass('clusterKey') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('clusterKey') }}</span>{{ sortIcon('clusterKey') }}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column prop="reportCount" label="报告数" width="80">
  21. <template slot="header">
  22. <span class="sort-header" @click.stop="onSortClick('reportCount', $event)">报告数{{ sortIcon('reportCount') }}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column label="状态" width="100">
  26. <template slot-scope="{ row }">
  27. <StatusTag :type="row.status === 'ready' ? 'warning' : 'success'" :text="row.status === 'ready' ? '可生成' : '已生成'" />
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="generatedTypeId" label="类型ID" width="140">
  31. <template slot="header">
  32. <span class="sort-header" @click.stop="onSortClick('generatedTypeId', $event)">类型ID<span v-if="sortIndex('generatedTypeId') !== null" class="sort-index" :class="sortClass('generatedTypeId') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('generatedTypeId') }}</span>{{ sortIcon('generatedTypeId') }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="updatedAt" label="更新时间" width="180">
  36. <template slot="header">
  37. <span class="sort-header" @click.stop="onSortClick('updatedAt', $event)">更新时间<span v-if="sortIndex('updatedAt') !== null" class="sort-index" :class="sortClass('updatedAt') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('updatedAt') }}</span>{{ sortIcon('updatedAt') }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="操作" width="180" fixed="right">
  41. <template slot-scope="{ row }">
  42. <el-button size="mini" type="primary" @click="handleDetail(row)">详情</el-button>
  43. <el-button v-if="row.status === 'ready'" size="mini" type="success" @click="handleGenerate(row)">生成类型</el-button>
  44. <el-button v-if="row.status === 'generated'" size="mini" type="primary" @click="handleViewType(row)" plain>查看类型</el-button>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </div>
  49. </el-card>
  50. <el-dialog :visible.sync="detailVisible" title="聚类详情" width="750px">
  51. <template v-if="currentCluster">
  52. <el-descriptions :column="2" border size="small">
  53. <el-descriptions-item label="聚类键">{{ currentCluster.clusterKey }}</el-descriptions-item>
  54. <el-descriptions-item label="报告数">{{ currentCluster.reportCount }}</el-descriptions-item>
  55. <el-descriptions-item label="状态">{{ currentCluster.status === 'ready' ? '可生成' : '已生成' }}</el-descriptions-item>
  56. <el-descriptions-item label="类型ID">{{ currentCluster.generatedTypeId || '—' }}</el-descriptions-item>
  57. </el-descriptions>
  58. <h4>公共文本特征</h4>
  59. <pre class="detail-pre">{{ currentCluster.commonSignatures }}</pre>
  60. <h4>LLM 解析模板</h4>
  61. <pre class="detail-pre">{{ formatJson(currentCluster.llmTemplate) }}</pre>
  62. </template>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script>
  67. import { getUnknownClusters, generateTypeFromCluster } from '@/api/reportParser'
  68. import SortMixin from '@/mixins/SortMixin'
  69. export default {
  70. name: 'ReportAutoLearn',
  71. mixins: [SortMixin],
  72. data() {
  73. return {
  74. loading: false,
  75. clusters: [],
  76. sortableColumns: { id: 'ID', reportCount: '报告数', clusterKey: '聚类键', generatedTypeId: '类型ID', updatedAt: '更新时间' },
  77. detailVisible: false,
  78. currentCluster: null,
  79. }
  80. },
  81. mounted() { this.fetchClusters() },
  82. methods: {
  83. loadList() {
  84. this.fetchClusters()
  85. },
  86. async fetchClusters() {
  87. this.loading = true
  88. try {
  89. var params = { page: 1, size: 50 }
  90. if (this.sortState.length > 0) params.sort = this.sortState
  91. const res = await getUnknownClusters(params)
  92. this.clusters = (res.data?.records || res.data || []).filter(
  93. c => c.status === 'ready' || c.status === 'generated')
  94. } catch (e) { this.$message.error('加载失败') }
  95. this.loading = false
  96. },
  97. formatJson(str) {
  98. if (!str) return ''
  99. try { return JSON.stringify(JSON.parse(str), null, 2) } catch (e) { return str }
  100. },
  101. handleDetail(row) {
  102. this.currentCluster = row
  103. this.detailVisible = true
  104. },
  105. handleGenerate(row) {
  106. this.$confirm('确认为此聚类生成报告类型和指纹规则?系统将自动通过 opencode 生成采集脚本并测试,生成后需在"报告类型管理"中审核启用。', '提示', { type: 'warning' })
  107. .then(async () => {
  108. try {
  109. const res = await generateTypeFromCluster({ clusterId: row.id })
  110. this.$message.success('已生成类型: ' + (res.data?.typeId || ''))
  111. this.fetchClusters()
  112. } catch (e) { this.$message.error('生成失败') }
  113. }).catch(() => {})
  114. },
  115. handleViewType(row) {
  116. this.$router.push('/report-types')
  117. },
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. .detail-pre {
  123. background: var(--adm-bg-header);
  124. border: 1px solid var(--adm-border-split);
  125. border-radius: 4px;
  126. padding: 10px;
  127. max-height: 300px;
  128. overflow: auto;
  129. font-size: 12px;
  130. white-space: pre-wrap;
  131. word-break: break-all;
  132. }
  133. </style>