diff --git a/modules/data_comparison.py b/modules/data_comparison.py index 12f35f1..5bd554d 100644 --- a/modules/data_comparison.py +++ b/modules/data_comparison.py @@ -279,6 +279,11 @@ def compare_json_arrays(array1, array2): def format_json_for_display(value): """格式化JSON用于显示""" + # 处理None值 + if value is None: + return "null" + + # 处理非字符串类型 if not isinstance(value, str): return str(value) diff --git a/static/js/app.js b/static/js/app.js index 46ab4d0..ff146ca 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -911,11 +911,14 @@ function displayDifferences() { // 保存当前搜索框的值 const currentSearchValue = document.getElementById('differenceSearch')?.value || ''; - if (!filteredDifferenceResults.length) { + if (!filteredDifferenceResults || !filteredDifferenceResults.length) { differencesContainer.innerHTML = '
未发现差异
'; return; } + // 调试日志:检查差异数据 + console.log('差异数据:', filteredDifferenceResults); + // 按主键分组差异 const groupedDifferences = groupDifferencesByKey(filteredDifferenceResults); const totalGroups = Object.keys(groupedDifferences).length; @@ -995,10 +998,19 @@ function displayDifferences() { `; // 显示当前页的主键组 - currentPageKeys.forEach((key, groupIndex) => { - const diffs = groupedDifferences[key]; + currentPageKeys.forEach((keyStr, groupIndex) => { + const diffs = groupedDifferences[keyStr]; const globalIndex = startIndex + groupIndex + 1; + // 将字符串化的key解析回对象 + let keyObj; + try { + keyObj = JSON.parse(keyStr); + } catch (e) { + // 如果解析失败,假设它本身就是一个简单值 + keyObj = keyStr; + } + html += `主键: ${formatCompositeKey(key)}
+主键: ${formatCompositeKey(keyObj)}
-${escapeHtml(diff.pro_value)}+
${escapeHtml(proValue)}
${escapeHtml(diff.test_value)}+
${escapeHtml(testValue)}
无数据可对比
'; return; @@ -2256,6 +2385,12 @@ function normalizeValue(value) { function renderTreeView(containerId, data) { const container = document.getElementById(containerId); + // 确保容器存在 + if (!container) { + console.error('树形视图容器不存在:', containerId); + return; + } + if (!data) { container.innerHTML = '无数据
'; return;