anonResultReportView.vue
9.54 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<route lang="yaml">
name: anonResultReportView
</route>
<script lang="ts" setup name="anonResultReportView">
import {
getAnonAnalyzePageData,
getAnonAnalyzeResult,
getAnonTaskDetail,
htmlToWord,
sendAnonReport,
} from '@/api/modules/dataAnonymization';
import { changeNum, download } from '@/utils/common';
import { ElMessage } from 'element-plus';
import anonResultAnalysis from './components/anonResultAnalysis.vue';
import { commonPageConfig, USERROLE } from '@/utils/enum';
import { calcColumnWidth } from '@/utils';
import html2canvas from 'html2canvas';
const route = useRoute();
const router = useRouter();
const fullPath = route.fullPath;
const taskGuid = ref(route.query.guid);
const { proxy } = getCurrentInstance() as any;
const resultDataLoading = ref(false);
/** 是否是数据提供方 */
const isDataProvider = computed(() => {
return localStorage.getItem('userRole') == USERROLE.PROVIDER;
})
const downPromise: any = ref()
/** 提交保存和编辑后的执行guid */
const taskExecGuid = ref(route.query.execGuid);
/** 记录原始的值信息,防止上一步之后未修改数据时不调用接口 */
const oldAnonTaskValueInfo: any = ref({});
/** 执行结果信息 */
const analysisResultInfo: any = ref({});
const containerRef = ref();
const containerWidth = ref(containerRef.value?.offsetWidth || 0)
/** ------------------------- 匿名化分析结果页面数据展示 ---------------- */
const pageInfo: any = ref({
...commonPageConfig,
})
const pageChange = (info) => {
pageInfo.value.curr = Number(info.curr);
pageInfo.value.limit = Number(info.limit);
getAnalysisResultPageData();
}
/** 每列字段对应的列宽计算结果。 */
const originResultTableFieldColumn = ref({});
/** 结果分析中的字段表格数据 */
const resultData: any = ref([]);
/** 全部未分页的数据,下载word时使用。 */
const fullResultData: any = ref([]);
/** 结果分析中的字段信息 */
const analysisResultTableFields: any = ref([]);
const analysisResultLoading = ref(false);
/** otherWidth表示使用标题宽度时添加标题排序图标等宽度 */
const calcTableColumnWidth = (data: any[], prop, title, otherWidth = 0) => {
let d: any[] = [];
data.forEach((dt) => d.push(dt[prop]));
//样式使用默认值。
return calcColumnWidth(
d,
title,
{
fontSize: 14,
fontFamily: "SimSun",
},
{
fontSize: 14,
fontFamily: "SimSun",
},
otherWidth
);
};
watch(
resultData,
(val: any[], oldVal) => {
if (!analysisResultTableFields.value?.length) {
originResultTableFieldColumn.value = {};
return;
}
originResultTableFieldColumn.value = {};
analysisResultTableFields.value.forEach((field, index) => {
originResultTableFieldColumn.value[field.enName] = calcTableColumnWidth(
val?.slice(0, 20) || [],
field.enName,
field.chName,
24
);
});
},
{
deep: true,
}
);
const getAnalysisResultPageData = (isFull = false) => {
analysisResultLoading.value = true;
getAnonAnalyzePageData({
pageIndex: pageInfo.value.curr,
pageSize: isFull ? -1 : pageInfo.value.limit,
taskExecGuid: taskExecGuid.value,
}).then((res: any) => {
analysisResultLoading.value = false;
if (res?.code == proxy.$passCode) {
if (isFull) {
fullResultData.value = [];
res.data?.records?.forEach(d => {
let obj = {};
analysisResultTableFields.value.forEach(t => {
obj[t.enName] = d.fieldValue?.[t.enName];
});
obj['equivalenceClassNum'] = changeNum(d.equivalenceClassNum || 0, 0);
obj['reIdentifyRisk'] = changeNum(d.reIdentifyRisk || 0, 2);
obj['isGtThreshold'] = d.isGtThreshold;
fullResultData.value.push(obj);
});
resultData.value = fullResultData.value.slice(0, pageInfo.value.limit);
pageInfo.value.rows = fullResultData.value.length;
} else {
resultData.value = [];
res.data?.records?.forEach(d => {
let obj = {};
analysisResultTableFields.value.forEach(t => {
obj[t.enName] = d.fieldValue?.[t.enName];
});
obj['equivalenceClassNum'] = changeNum(d.equivalenceClassNum || 0, 0);
obj['reIdentifyRisk'] = changeNum(d.reIdentifyRisk || 0, 2);
obj['isGtThreshold'] = d.isGtThreshold;
resultData.value.push(obj);
});
pageInfo.value.rows = res.data?.totalRows ?? 0;
}
} else {
proxy.$ElMessage.error(res.msg);
}
})
}
const isWordStyle = ref(false);
/** 下载评估报告 */
const transfer = () => {
isWordStyle.value = true;
}
const domClone: any = ref(null);
const resultReportRef = ref();
const convertHtml2Img = (dom, domClone) => {
const element = <HTMLElement>dom.querySelector('.kpi-content')
if (!element) {
return Promise.resolve();
}
return html2canvas(element, {
allowTaint: true,
useCORS: true,
scale: 2,
}).then((canvas: any) => {
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
element.parentNode && ((<HTMLElement>element.parentNode).scrollTop = 0);
let url = canvas.toDataURL('image/jpeg');
let img = document.createElement('img');
if (url) {
// img.src = url.split(',')[1];
img.src = url;
img.width = 620;
img.height = 265;
img.crossOrigin = 'Anonymous';
}
const copyElement = <HTMLElement>domClone.querySelector('.kpi-content')
copyElement.parentNode?.replaceChild(img, copyElement);
})
}
const loadingText = ref('');
const getHTML = (reportResultContent) => {
let html = reportResultContent;
html = html.replace(/"/g, "'");
return html;
};
const downloadWord = () => {
if (downPromise.value) {
return;
}
let dom = domClone.value || (domClone.value = document.createElement('div'));
let report = resultReportRef.value?.report;
dom.innerHTML = report?.innerHTML;
resultDataLoading.value = true;
loadingText.value = `评测报告正在${route.query.dataOwner == '1' ? '发送' : '下载' }中,请勿关闭浏览器...`;
downPromise.value = convertHtml2Img(report, dom).then(() => {
if (route.query.dataOwner == '1') {
sendAnonReport({ taskGuid: taskGuid.value, html: encodeURIComponent(`<div>${getHTML(dom.innerHTML)}</div>`) }).then((res: any) => {
downPromise.value = null
loadingText.value = '';
resultDataLoading.value = false;
if (res?.code == proxy.$passCode) {
proxy.$ElMessage.success('评测报告发送成功');
} else {
res?.msg && ElMessage.error(res?.msg);
}
})
} else {
htmlToWord({ html: encodeURIComponent(`<div>${getHTML(dom.innerHTML)}</div>`) }).then((res: any) => {
downPromise.value = null
loadingText.value = '';
resultDataLoading.value = false;
if (res && !res.msg) {
download(res, (route.query.taskName || oldAnonTaskValueInfo.value.taskName) + '_匿名化评估报告.docx', 'word')
} else {
res?.msg && ElMessage.error(res?.msg);
}
})
}
}).catch(() => {
downPromise.value = null;
});
}
onMounted(() => {
nextTick(() => {
containerWidth.value = containerRef.value?.offsetWidth || 0;
})
window.onresize = () => {
containerWidth.value = containerRef.value?.offsetWidth || 0;
}
})
onBeforeMount(() => {
resultDataLoading.value = true;
getAnonAnalyzeResult(taskExecGuid.value).then((res: any) => {
resultDataLoading.value = false;
if (res?.code == proxy.$passCode) {
analysisResultInfo.value = res.data || {};
analysisResultTableFields.value = res.data?.column || [];
pageInfo.value.curr = 1;
getAnalysisResultPageData(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
});
getAnonTaskDetail(taskGuid.value).then((res: any) => {
if (res?.code == proxy.$passCode) {
oldAnonTaskValueInfo.value = res.data || {};
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
});
})
</script>
<template>
<div class="table_tool_wrap" v-loading="resultDataLoading" ref="containerRef" :element-loading-text="loadingText">
<!-- 连接器不需要显示下载报告按钮 -->
<template v-if="!isDataProvider">
<el-button v-show="!isWordStyle" style="margin-bottom: 8px;" type="primary" @click="transfer"
v-preReClick>预览Word评估报告</el-button>
<div v-show="isWordStyle" style="margin-bottom: 8px;">
<el-button @click="isWordStyle = false">返回</el-button>
<el-button type="primary" @click="downloadWord">{{ route.query.dataOwner == '1' ? '确认并发送评测报告' : '下载评测报告'
}}</el-button>
</div>
</template>
<anonResultAnalysis ref="resultReportRef" :show-title="true" :analysis-result-info="analysisResultInfo"
:isWordStyle="isWordStyle" :style="isWordStyle ? {
height: !isDataProvider ? 'calc(100% - 36px)' : '100%',
'overflow-y': 'auto',
'margin-right': '-16px',
'padding-right': '16px',
width: 'auto'
} : null" :analysis-result-loading="analysisResultLoading"
:analysis-result-table-fields="analysisResultTableFields" :old-anon-task-value-info="oldAnonTaskValueInfo"
:container-width="containerWidth" :origin-result-table-field-column="originResultTableFieldColumn"
:page-info="pageInfo" :result-data="resultData" :fullResultData="fullResultData" @page-change="pageChange">
</anonResultAnalysis>
</div>
</template>
<style lang="scss" scoped>
.table_tool_wrap {
width: 100%;
height: 100%;
padding: 8px 16px 16px;
overflow-y: auto;
}
</style>