| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <template>
- <div class="report-autolearn admin-page">
- <el-card>
- <PageHeader slot="header" title="报告自学习">
- <el-button size="small" @click="fetchClusters" icon="el-icon-refresh">刷新</el-button>
- </PageHeader>
- <el-alert title='自学习机制:当同一类型的未知报告积累到3份后,系统自动标记为"可生成"状态,管理员可在此生成报告类型和指纹规则。' type='info' :closable='false' show-icon style='margin-bottom: 16px;' />
- <div class="adm-table-wrap">
- <el-table :data="clusters" v-loading="loading" border stripe height="100%">
- <el-table-column prop="id" label="ID" width="60">
- <template slot="header">
- <span class="sort-header" @click.stop="onSortClick('id', $event)">ID{{ sortIcon('id') }}</span>
- </template>
- </el-table-column>
- <el-table-column prop="clusterKey" label="聚类键" width="140">
- <template slot="header">
- <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>
- </template>
- </el-table-column>
- <el-table-column prop="reportCount" label="报告数" width="80">
- <template slot="header">
- <span class="sort-header" @click.stop="onSortClick('reportCount', $event)">报告数{{ sortIcon('reportCount') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="状态" width="100">
- <template slot-scope="{ row }">
- <StatusTag :type="row.status === 'ready' ? 'warning' : 'success'" :text="row.status === 'ready' ? '可生成' : '已生成'" />
- </template>
- </el-table-column>
- <el-table-column prop="generatedTypeId" label="类型ID" width="140">
- <template slot="header">
- <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>
- </template>
- </el-table-column>
- <el-table-column prop="updatedAt" label="更新时间" width="180">
- <template slot="header">
- <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>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="180" fixed="right">
- <template slot-scope="{ row }">
- <el-button size="mini" type="primary" @click="handleDetail(row)">详情</el-button>
- <el-button v-if="row.status === 'ready'" size="mini" type="success" @click="handleGenerate(row)">生成类型</el-button>
- <el-button v-if="row.status === 'generated'" size="mini" type="primary" @click="handleViewType(row)" plain>查看类型</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </el-card>
- <el-dialog :visible.sync="detailVisible" title="聚类详情" width="750px">
- <template v-if="currentCluster">
- <el-descriptions :column="2" border size="small">
- <el-descriptions-item label="聚类键">{{ currentCluster.clusterKey }}</el-descriptions-item>
- <el-descriptions-item label="报告数">{{ currentCluster.reportCount }}</el-descriptions-item>
- <el-descriptions-item label="状态">{{ currentCluster.status === 'ready' ? '可生成' : '已生成' }}</el-descriptions-item>
- <el-descriptions-item label="类型ID">{{ currentCluster.generatedTypeId || '—' }}</el-descriptions-item>
- </el-descriptions>
- <h4>公共文本特征</h4>
- <pre class="detail-pre">{{ currentCluster.commonSignatures }}</pre>
- <h4>LLM 解析模板</h4>
- <pre class="detail-pre">{{ formatJson(currentCluster.llmTemplate) }}</pre>
- </template>
- </el-dialog>
- </div>
- </template>
- <script>
- import { getUnknownClusters, generateTypeFromCluster } from '@/api/reportParser'
- import SortMixin from '@/mixins/SortMixin'
- export default {
- name: 'ReportAutoLearn',
- mixins: [SortMixin],
- data() {
- return {
- loading: false,
- clusters: [],
- sortableColumns: { id: 'ID', reportCount: '报告数', clusterKey: '聚类键', generatedTypeId: '类型ID', updatedAt: '更新时间' },
- detailVisible: false,
- currentCluster: null,
- }
- },
- mounted() { this.fetchClusters() },
- methods: {
- loadList() {
- this.fetchClusters()
- },
- async fetchClusters() {
- this.loading = true
- try {
- var params = { page: 1, size: 50 }
- if (this.sortState.length > 0) params.sort = this.sortState
- const res = await getUnknownClusters(params)
- this.clusters = (res.data?.records || res.data || []).filter(
- c => c.status === 'ready' || c.status === 'generated')
- } catch (e) { this.$message.error('加载失败') }
- this.loading = false
- },
- formatJson(str) {
- if (!str) return ''
- try { return JSON.stringify(JSON.parse(str), null, 2) } catch (e) { return str }
- },
- handleDetail(row) {
- this.currentCluster = row
- this.detailVisible = true
- },
- handleGenerate(row) {
- this.$confirm('确认为此聚类生成报告类型和指纹规则?系统将自动通过 opencode 生成采集脚本并测试,生成后需在"报告类型管理"中审核启用。', '提示', { type: 'warning' })
- .then(async () => {
- try {
- const res = await generateTypeFromCluster({ clusterId: row.id })
- this.$message.success('已生成类型: ' + (res.data?.typeId || ''))
- this.fetchClusters()
- } catch (e) { this.$message.error('生成失败') }
- }).catch(() => {})
- },
- handleViewType(row) {
- this.$router.push('/report-types')
- },
- }
- }
- </script>
- <style scoped>
- .detail-pre {
- background: var(--adm-bg-header);
- border: 1px solid var(--adm-border-split);
- border-radius: 4px;
- padding: 10px;
- max-height: 300px;
- overflow: auto;
- font-size: 12px;
- white-space: pre-wrap;
- word-break: break-all;
- }
- </style>
|