fix: classification results empty and res.data access issues
Backend: - Add GET /classifications/results endpoint with project/level/keyword filters - Add column relationship to ClassificationResult model - Fix test data generator to fetch column IDs from DB after bulk insert Frontend: - Fix request.ts interceptor to return full response body (keep total/pagination) - Fix all pages to use res.data instead of res - Add getClassificationResults API in classification.ts - Implement fetchData in Classification.vue with proper filtering and pagination - Fix same res.data issue in Category.vue, Metadata.vue, Project.vue, DataSource.vue, Dashboard.vue, Task.vue
This commit is contained in:
@@ -76,3 +76,34 @@ export function deleteRule(id: number) {
|
||||
export function getTemplates() {
|
||||
return request.get('/classifications/templates')
|
||||
}
|
||||
|
||||
export interface ClassificationResultItem {
|
||||
id: number
|
||||
project_id: number
|
||||
column_id?: number
|
||||
column_name?: string
|
||||
data_type?: string
|
||||
comment?: string
|
||||
table_name?: string
|
||||
database_name?: string
|
||||
source_name?: string
|
||||
category_id?: number
|
||||
category_name?: string
|
||||
level_id?: number
|
||||
level_name?: string
|
||||
level_color?: string
|
||||
source: string
|
||||
confidence: number
|
||||
status: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export function getClassificationResults(params: {
|
||||
project_id?: number
|
||||
level_id?: number
|
||||
keyword?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}) {
|
||||
return request.get('/classifications/results', { params })
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ request.interceptors.response.use(
|
||||
ElMessage.error(res.message || '请求失败')
|
||||
return Promise.reject(new Error(res.message))
|
||||
}
|
||||
return res.data
|
||||
return res
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
const status = error.response?.status
|
||||
|
||||
@@ -236,7 +236,7 @@ const ruleRules = {
|
||||
async function fetchLevels() {
|
||||
try {
|
||||
const res: any = await getDataLevels()
|
||||
levels.value = res || []
|
||||
levels.value = res.data || []
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '加载分级失败')
|
||||
}
|
||||
@@ -245,7 +245,7 @@ async function fetchLevels() {
|
||||
async function fetchCategories() {
|
||||
try {
|
||||
const res: any = await getCategoryTree()
|
||||
categoryTree.value = res || []
|
||||
categoryTree.value = res.data || []
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '加载分类失败')
|
||||
}
|
||||
@@ -267,7 +267,7 @@ async function fetchRules() {
|
||||
async function fetchTemplates() {
|
||||
try {
|
||||
const res: any = await getTemplates()
|
||||
templates.value = res || []
|
||||
templates.value = res.data || []
|
||||
} catch (e: any) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@@ -75,8 +75,7 @@ import { ref, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import { getProjects } from '@/api/project'
|
||||
import { getDataLevels } from '@/api/classification'
|
||||
import { getTaskItems } from '@/api/task'
|
||||
import { getDataLevels, getClassificationResults } from '@/api/classification'
|
||||
|
||||
const loading = ref(false)
|
||||
const resultList = ref<any[]>([])
|
||||
@@ -100,16 +99,15 @@ function confidenceClass(v: number) {
|
||||
async function fetchData() {
|
||||
loading.value = true
|
||||
try {
|
||||
if (!filterProjectId.value) {
|
||||
resultList.value = []
|
||||
total.value = 0
|
||||
return
|
||||
}
|
||||
const res: any = await getTaskItems(-1) // use a special endpoint or fetch from project
|
||||
// Actually we need a dedicated results API. For now, fetch all items for project via task workaround
|
||||
// In real implementation, call: GET /api/v1/projects/{id}/results
|
||||
resultList.value = []
|
||||
total.value = 0
|
||||
const res: any = await getClassificationResults({
|
||||
project_id: filterProjectId.value || undefined,
|
||||
level_id: filterLevelId.value || undefined,
|
||||
keyword: filterKeyword.value || undefined,
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
})
|
||||
resultList.value = res.data || []
|
||||
total.value = res.total || 0
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '加载失败')
|
||||
} finally {
|
||||
|
||||
@@ -118,7 +118,7 @@ function filterNode(value: string, data: TreeNode) {
|
||||
async function fetchTree() {
|
||||
try {
|
||||
const res: any = await getMetadataTree()
|
||||
treeData.value = res || []
|
||||
treeData.value = res.data || []
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '加载失败')
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ const filteredLabelItems = computed(() => {
|
||||
async function fetchData() {
|
||||
try {
|
||||
const res: any = await getMyTasks()
|
||||
tasks.value = res || []
|
||||
tasks.value = res.data || []
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '加载失败')
|
||||
}
|
||||
@@ -186,7 +186,7 @@ async function openLabel(task: TaskItem) {
|
||||
}
|
||||
try {
|
||||
const res: any = await getTaskItems(task.id)
|
||||
labelItems.value = (res || []).map((item: any) => ({
|
||||
labelItems.value = (res.data || []).map((item: any) => ({
|
||||
...item,
|
||||
_category_id: item.category_id,
|
||||
_level_id: item.level_id,
|
||||
|
||||
Reference in New Issue
Block a user