刘光辉
8 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<script lang="ts" setup>
import type { AuditFieldDiff } from './auditDiff';
 
import { computed } from 'vue';
 
import { formatAuditDiffValue, getAuditDiffDisplayValue, getSafeAuditDiffFieldLabel, hasAuditDiffValue, isSensitiveAuditDiff } from './auditDiff';
 
interface AuditDiffTableRow {
  diff: AuditFieldDiff;
  index: number;
  key: string;
}
 
const props = withDefaults(
  defineProps<{
    diffs: AuditFieldDiff[];
    hideTechnicalFieldNames?: boolean;
    maskSensitive?: boolean;
  }>(),
  {
    hideTechnicalFieldNames: false,
    maskSensitive: false,
  },
);
const emit = defineEmits<{ viewChild: [diff: AuditFieldDiff] }>();
 
const columns = [
  { dataIndex: 'field', key: 'field', title: '字段', width: 170 },
  { dataIndex: 'oldValue', key: 'oldValue', title: '变更前', width: 250 },
  { dataIndex: 'newValue', key: 'newValue', title: '变更后', width: 250 },
];
 
const rows = computed<AuditDiffTableRow[]>(() =>
  props.diffs.map((diff, index) => ({
    diff,
    index,
    key: `${diff.field || 'field'}-${index}`,
  })),
);
 
function getFieldLabel(row: AuditDiffTableRow) {
  if (props.hideTechnicalFieldNames) return getSafeAuditDiffFieldLabel(row.diff, row.index);
  return row.diff.fieldName || row.diff.field || '未命名字段';
}
 
function getValueText(diff: AuditFieldDiff, side: 'new' | 'old') {
  if (diff.masked || (props.maskSensitive && isSensitiveAuditDiff(diff))) return '敏感信息已隐藏';
 
  const value = getAuditDiffDisplayValue(diff, side);
  return hasAuditDiffValue(value) ? formatAuditDiffValue(value) : '空值';
}
 
function isChildDiff(diff: AuditFieldDiff) {
  return diff.jnpfKey === 'table' && !!diff.chidData?.length && !!diff.chidField?.length;
}
</script>
 
<template>
  <a-table
    class="audit-diff-table"
    size="small"
    :columns="columns"
    :data-source="rows"
    :pagination="false"
    :scroll="{ x: 670 }"
    row-key="key"
    table-layout="fixed">
    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'field'">
        <div class="audit-diff-field" :title="getFieldLabel(record)">
          <span>{{ getFieldLabel(record) }}</span>
          <a-tag v-if="record.diff.technical" :bordered="false">技术字段</a-tag>
        </div>
      </template>
      <template v-else-if="column.key === 'oldValue'">
        <div v-if="isChildDiff(record.diff)" class="audit-diff-cell audit-diff-cell-child">子表行级变化</div>
        <div v-else class="audit-diff-cell audit-diff-cell-old">{{ getValueText(record.diff, 'old') }}</div>
      </template>
      <template v-else-if="column.key === 'newValue'">
        <a-button v-if="isChildDiff(record.diff)" type="link" size="small" class="audit-child-diff-button" @click="emit('viewChild', record.diff)">
          查看子表变更
        </a-button>
        <div v-else class="audit-diff-cell audit-diff-cell-new">{{ getValueText(record.diff, 'new') }}</div>
      </template>
    </template>
  </a-table>
</template>
 
<style lang="scss" scoped>
.audit-diff-table {
  width: 100%;
 
  :deep(.ant-table-cell) {
    vertical-align: top;
  }
}
 
.audit-diff-field {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}
 
.audit-diff-cell {
  max-height: 160px;
  padding: 3px 7px;
  overflow: auto;
  line-height: 1.6;
  white-space: pre-wrap;
  border-radius: 4px;
  overflow-wrap: anywhere;
}
 
.audit-diff-cell-old {
  background: var(--error-color-hover);
}
 
.audit-diff-cell-new {
  background: var(--success-color-hover);
}
 
.audit-diff-cell-child {
  color: var(--text-color-secondary);
  background: var(--component-background);
}
 
.audit-child-diff-button {
  height: auto;
  padding: 3px 0;
}
</style>