6eb7eff7 by lihua

修改下载报告

1 parent 6034856e
......@@ -149,6 +149,9 @@ export const dataSourceTypeList = [{
}, {
value: 2,
label: '文件导入'
}, {
value: 3,
label: '文件夹'
}];
/** 获取数据库选择列表 */
......@@ -340,4 +343,11 @@ export const exportAnonReport = (params) => request({
url: `${import.meta.env.VITE_APP_DIGITAL_CONTRACT_URL}/anon-task/download-report?taskGuid=${params.taskGuid}&taskExecGuid=${params.execGuid}`,
method: 'post',
responseType: 'blob'
})
export const htmlToWord = (params) => request({
url: `${import.meta.env.VITE_APP_ANONYMIZATION_BASEURL}/anon-task/download/html-to-word`,
method: 'postJsonD',
data: params,
responseType: 'blob'
})
\ No newline at end of file
......
......@@ -8,12 +8,14 @@ import {
getAnonAnalyzePageData,
getAnonAnalyzeResult,
getAnonTaskDetail,
htmlToWord,
} from '@/api/modules/dataAnonymization';
import { changeNum, download } from '@/utils/common';
import { ElMessage } from 'element-plus';
import anonResultAnalysis from './components/anonResultAnalysis.vue';
import { commonPageConfig } from '@/utils/enum';
import { calcColumnWidth } from '@/utils';
import html2canvas from 'html2canvas';
const route = useRoute();
const router = useRouter();
......@@ -52,6 +54,8 @@ const originResultTableFieldColumn = ref({});
/** 结果分析中的字段表格数据 */
const resultData: any = ref([]);
/** 全部未分页的数据,下载word时使用。 */
const fullResultData: any = ref([]);
/** 结果分析中的字段信息 */
const analysisResultTableFields: any = ref([]);
......@@ -100,52 +104,118 @@ watch(
}
);
const getAnalysisResultPageData = () => {
const getAnalysisResultPageData = (isFull = false) => {
analysisResultLoading.value = true;
getAnonAnalyzePageData({
pageIndex: pageInfo.value.curr,
pageSize: pageInfo.value.limit,
pageSize: isFull ? -1 : pageInfo.value.limit,
taskExecGuid: taskExecGuid.value,
}).then((res: any) => {
analysisResultLoading.value = false;
if (res?.code == proxy.$passCode) {
pageInfo.value.rows =
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];
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);
});
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;
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;
}
downPromise.value = exportAnonReport({
taskGuid: route.query.guid,
execGuid: taskExecGuid.value
}).then((res: any) => {
downPromise.value = null;
if (res && !res.msg) {
download(res, (route.query.taskName || oldAnonTaskValueInfo.value.taskName) + '_匿名化评估报告.docx', 'word')
} else {
res?.msg && ElMessage.error(res?.msg);
}
let dom = domClone.value || (domClone.value = document.createElement('div'));
let report = resultReportRef.value?.report;
dom.innerHTML = report?.innerHTML;
resultDataLoading.value = true;
loadingText.value = '报告正在下载中,请勿关闭浏览器...';
downPromise.value = convertHtml2Img(report, dom).then(() => {
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(() => {
......@@ -160,12 +230,12 @@ onMounted(() => {
onBeforeMount(() => {
resultDataLoading.value = true;
getAnonAnalyzeResult(taskExecGuid.value).then((res: any) => {
resultDataLoading.value = false;
resultDataLoading.value = false;
if (res?.code == proxy.$passCode) {
analysisResultInfo.value = res.data || {};
analysisResultTableFields.value = res.data?.column || [];
pageInfo.value.curr = 1;
getAnalysisResultPageData();
getAnalysisResultPageData(true);
} else {
res?.msg && proxy.$ElMessage.error(res.msg);
}
......@@ -182,13 +252,24 @@ onBeforeMount(() => {
</script>
<template>
<div class="table_tool_wrap" v-loading="resultDataLoading" ref="containerRef">
<el-button style="margin-bottom: 8px;" type="primary" @click="transfer" v-preReClick>下载评估报告</el-button>
<anonResultAnalysis :show-title="true" :analysis-result-info="analysisResultInfo"
: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"
@page-change="pageChange"></anonResultAnalysis>
<div class="table_tool_wrap" v-loading="resultDataLoading" ref="containerRef" :element-loading-text="loadingText">
<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">下载评估报告</el-button>
</div>
<anonResultAnalysis ref="resultReportRef" :show-title="true" :analysis-result-info="analysisResultInfo"
:isWordStyle="isWordStyle" :style="isWordStyle ? {
height: 'calc(100% - 36px)',
'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>
......
{
"compilerOptions": {
"noUnusedLocals": true,
"noUnusedParameters": true,
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!