新增一键复制差异主键
This commit is contained in:
@@ -939,17 +939,28 @@ function displayDifferences() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let html = `
|
let html = `
|
||||||
<!-- 字段筛选按钮 -->
|
<!-- 字段筛选按钮和操作按钮 -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div class="btn-group btn-group-sm flex-wrap" role="group">
|
<div class="row">
|
||||||
<button type="button" class="btn btn-outline-primary active" onclick="filterByField('')">
|
<div class="col-md-8">
|
||||||
全部 (${filteredDifferenceResults.length})
|
<div class="btn-group btn-group-sm flex-wrap" role="group">
|
||||||
</button>
|
<button type="button" class="btn btn-outline-primary active" onclick="filterByField('')">
|
||||||
${Object.entries(fieldStats).map(([field, count]) => `
|
全部 (${filteredDifferenceResults.length})
|
||||||
<button type="button" class="btn btn-outline-secondary" onclick="filterByField('${field}')">
|
</button>
|
||||||
${field} (${count})
|
${Object.entries(fieldStats).map(([field, count]) => `
|
||||||
</button>
|
<button type="button" class="btn btn-outline-secondary" onclick="filterByField('${field}')">
|
||||||
`).join('')}
|
${field} (${count})
|
||||||
|
</button>
|
||||||
|
`).join('')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<button type="button" class="btn btn-success btn-sm" onclick="copyDifferenceKeys()">
|
||||||
|
<i class="fas fa-copy"></i> 复制差异主键
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1989,6 +2000,70 @@ function copyRawData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 复制差异主键
|
||||||
|
function copyDifferenceKeys() {
|
||||||
|
console.log('copyDifferenceKeys 被调用');
|
||||||
|
console.log('filteredDifferenceResults:', filteredDifferenceResults);
|
||||||
|
|
||||||
|
if (!filteredDifferenceResults || filteredDifferenceResults.length === 0) {
|
||||||
|
showAlert('warning', '无差异数据可复制');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 收集所有差异记录的主键
|
||||||
|
const differenceKeys = [];
|
||||||
|
const uniqueKeys = new Set();
|
||||||
|
|
||||||
|
filteredDifferenceResults.forEach(diff => {
|
||||||
|
console.log('处理差异记录:', diff);
|
||||||
|
if (diff.key) {
|
||||||
|
let keyText = '';
|
||||||
|
|
||||||
|
if (typeof diff.key === 'object' && !Array.isArray(diff.key)) {
|
||||||
|
// 复合主键:转换为逗号分隔格式
|
||||||
|
keyText = Object.values(diff.key).join(',');
|
||||||
|
} else {
|
||||||
|
// 单主键或其他格式
|
||||||
|
keyText = String(diff.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('提取的主键:', keyText);
|
||||||
|
|
||||||
|
// 避免重复主键
|
||||||
|
if (!uniqueKeys.has(keyText)) {
|
||||||
|
uniqueKeys.add(keyText);
|
||||||
|
differenceKeys.push(keyText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('收集到的主键列表:', differenceKeys);
|
||||||
|
|
||||||
|
if (differenceKeys.length === 0) {
|
||||||
|
showAlert('warning', '未找到有效的主键数据');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将主键列表转换为文本格式(每行一个)
|
||||||
|
const keyText = differenceKeys.join('\n');
|
||||||
|
console.log('准备复制的文本:', keyText);
|
||||||
|
|
||||||
|
// 复制到剪贴板
|
||||||
|
navigator.clipboard.writeText(keyText).then(() => {
|
||||||
|
console.log('复制成功');
|
||||||
|
showAlert('success', `已复制 ${differenceKeys.length} 个差异主键到剪贴板`);
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('复制失败:', err);
|
||||||
|
showAlert('danger', '复制失败,请手动选择复制');
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理差异主键失败:', error);
|
||||||
|
showAlert('danger', '处理差异主键失败: ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 显示差异数据的原生数据
|
// 显示差异数据的原生数据
|
||||||
function showDifferenceRawData(keyStr) {
|
function showDifferenceRawData(keyStr) {
|
||||||
showRawData(keyStr); // 复用相同的原生数据显示逻辑
|
showRawData(keyStr); // 复用相同的原生数据显示逻辑
|
||||||
|
Reference in New Issue
Block a user