Browse Source

fix:[表单模板]优化

lkf
15881625488@163.com 1 month ago
parent
commit
b6e5c0ae9c
2 changed files with 117 additions and 36 deletions
  1. +15
    -0
      src/api/business/study/studyFormFill.js
  2. +102
    -36
      src/views/business/study/comp/tbbd/Xq.vue

+ 15
- 0
src/api/business/study/studyFormFill.js View File

@ -16,6 +16,14 @@ export function studyFormFill_jcgj(query) {
params: query params: query
}) })
} }
export function studyFormFill_uploadFile(data) {
return request({
url: '/file/upload',
method: 'post',
data: data
})
}
//导出 //导出
export function studyFormFill_exportDetail(query) { export function studyFormFill_exportDetail(query) {
return request({ return request({
@ -24,6 +32,13 @@ export function studyFormFill_exportDetail(query) {
params: query params: query
}) })
} }
export function studyFormFill_exportByFileUrl(query) {
return request({
url: '/system/business/studyFormFill/exportByFileUrl',
method: 'get',
params: query
})
}
export function studyFormFill_jcgjqmxxList(query) { export function studyFormFill_jcgjqmxxList(query) {
return request({ return request({
url: '/system/business/studyFormFill/jcgjqmxxList', url: '/system/business/studyFormFill/jcgjqmxxList',

+ 102
- 36
src/views/business/study/comp/tbbd/Xq.vue View File

@ -28,8 +28,8 @@
<div class="edit-content"> <div class="edit-content">
<div class="detail-content" style="width: 100%; height: 100%; padding: 0px 10px;"> <div class="detail-content" style="width: 100%; height: 100%; padding: 0px 10px;">
<vue-html2pdf :show-layout="true" pdf-content-width="100%" :pdf-format="form.templatePdfSize" :pdf-quality="2" <vue-html2pdf :show-layout="true" pdf-content-width="100%" :pdf-format="form.templatePdfSize" :pdf-quality="2"
:float-layout="false" pdf-orientation="landscape" :paginate-elements-by-height="0" :enable-download="true"
:preview-modal="false" :filename="form.bdmc" @beforeDownload="addDynamicWatermark" ref="html2Pdf"
:float-layout="false" pdf-orientation="landscape" :paginate-elements-by-height="0" :enable-download="false"
:preview-modal="false" :filename="form.bdmc" @beforeDownload="handleBeforeDownload" ref="html2Pdf"
@progress="onProgress"> @progress="onProgress">
<section slot="pdf-content"> <section slot="pdf-content">
<div class="pdf-content"> <div class="pdf-content">
@ -150,7 +150,8 @@
</template> </template>
<script> <script>
import { studyFormFill_jcgjqmxxList, studyFormFill_tb, studyFormFill_info, studyFormFill_jcgj, studyFormFill_qmxx, studyFormFill_exportDetail } from "@/api/business/study/studyFormFill"
import { studyFormFill_jcgjqmxxList, studyFormFill_uploadFile, studyFormFill_exportByFileUrl, studyFormFill_tb, studyFormFill_info, studyFormFill_jcgj, studyFormFill_qmxx, studyFormFill_exportDetail } from "@/api/business/study/studyFormFill"
import { getToken } from "@/utils/auth"
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import JcgjList from "@/views/business/comps/common/JcgjList"; import JcgjList from "@/views/business/comps/common/JcgjList";
import JcgjExportList from "@/views/business/comps/common/JcgjExportList"; import JcgjExportList from "@/views/business/comps/common/JcgjExportList";
@ -163,6 +164,7 @@ export default {
data() { data() {
return { return {
watermarkText: '', watermarkText: '',
uploadFileUrl: process.env.VUE_APP_BASE_API + '/file/upload', //
opacity: 0.8, opacity: 0.8,
watermarkOpacity: 0.8, watermarkOpacity: 0.8,
watermarkSize: 40, watermarkSize: 40,
@ -225,6 +227,7 @@ export default {
created() { created() {
}, },
methods: { methods: {
//-
updateWatermark() { updateWatermark() {
// //
const text = this.nickName + ' ' + moment().format("YYYY-MM-DD HH:mm:ss"); const text = this.nickName + ' ' + moment().format("YYYY-MM-DD HH:mm:ss");
@ -251,37 +254,7 @@ export default {
container.style.backgroundImage = `url(${canvas.toDataURL()})`; container.style.backgroundImage = `url(${canvas.toDataURL()})`;
container.style.backgroundRepeat = 'repeat'; container.style.backgroundRepeat = 'repeat';
}, },
onProgress(progress) {
console.log(`生成进度: ${progress}%`)
this.removePageBreak()
if (progress == 100) {
this.showExport = false
this.$modal.closeLoading()
}
},
exportExcel(jcgjlx) {
this.$modal.loading()
this.jcgjlxExport = jcgjlx
this.showExport = true
studyFormFill_jcgjqmxxList({ jcgjlx: jcgjlx, id: this.form.id }).then(response => {
this.jcgjExportList = response.data.jcgj
this.qmxxExportList = response.data.qmxx
this.updateWatermark()
this.$refs.jcgjExportList.init(this.jcgjExportList)
setTimeout(() => {
this.$refs.html2Pdf.generatePdf({
margin: {
top: 20,
right: 15,
bottom: 20,
left: 15
},
})
}, 200);
this.saveSimpleLog({jcmc:'填报表单详情导出',jcmcEn:'Record Detail Export',name:this.form.bdmc+'('+this.form.bdbh+')',nameEn:this.form.bdmc+'('+this.form.bdbh+')'})
})
},
//
//-
async addDynamicWatermark({ pdfContent }) { async addDynamicWatermark({ pdfContent }) {
return new Promise((resolve) => { return new Promise((resolve) => {
const canvas = document.createElement('canvas') const canvas = document.createElement('canvas')
@ -336,12 +309,105 @@ export default {
setTimeout(() => resolve(), 100) setTimeout(() => resolve(), 100)
}) })
}, },
//
onProgress(progress) {
console.log(`生成进度: ${progress}%`)
this.removePageBreak()
if (progress == 100) {
this.showExport = false
// this.$modal.closeLoading()
}
},
//
exportExcel(jcgjlx) {
this.$modal.loading()
this.jcgjlxExport = jcgjlx
this.showExport = true
studyFormFill_jcgjqmxxList({ jcgjlx: jcgjlx, id: this.form.id }).then(response => {
this.jcgjExportList = response.data.jcgj
this.qmxxExportList = response.data.qmxx
// this.updateWatermark()
this.$refs.jcgjExportList.init(this.jcgjExportList)
setTimeout(() => {
this.$refs.html2Pdf.generatePdf({
margin: {
top: 20,
right: 15,
bottom: 20,
left: 15
},
})
}, 200);
this.saveSimpleLog({ jcmc: '填报表单详情导出', jcmcEn: 'Record Detail Export', name: this.form.bdmc + '(' + this.form.bdbh + ')', nameEn: this.form.bdmc + '(' + this.form.bdbh + ')' })
})
},
//blog
async handleBeforeDownload({ html2pdf, options, pdfContent }) {
this.$modal.loading()
// 1. 使 html2pdf PDF jsPDF
const pdf = await html2pdf()
.set(options) //
.from(pdfContent) // PDF
.toPdf() // PDF
.get('pdf'); // jsPDF
// 2. jsPDF Blob
const blob = pdf.output('blob');
// 3. Blob
await this.uploadPdfToServer(blob);
// .save()
// pdf.save('my-document.pdf');
},
//
async uploadPdfToServer(blob) {
const formData = new FormData();
formData.append('file', blob, 'hxhq-export-form.pdf');
try {
const response = await fetch(this.uploadFileUrl, {
method: 'POST',
headers: {
Authorization: "Bearer " + getToken(),
},
body: formData
});
//
if (!response.ok) {
//
const errorData = await response.json().catch(() => ({}));
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
}
// JSON
const data = await response.json();
// console.log('JSON:', data);
if (data.code == 200) {
studyFormFill_exportByFileUrl(
{
url: data.data.url,
studyFormFillId: this.form.id,
}
).then(response => {
window.open(process.env.VUE_APP_FILE_DOMAIN + response.msg)
}).finally(() => {
this.$modal.closeLoading()
})
} else {
this.$modal.msgError(data.msg)
this.$modal.closeLoading()
}
} catch (error) {
this.$modal.msgError("导出失败,稍后再试")
this.$modal.closeLoading()
}
},
// //
removePageBreak() { removePageBreak() {
document.querySelectorAll('.html2pdf__page-break').forEach(el => { document.querySelectorAll('.html2pdf__page-break').forEach(el => {
el.remove() el.remove()
}) })
}, },
//-
exportExcel_bak(jcgjlx) { exportExcel_bak(jcgjlx) {
this.$modal.loading() this.$modal.loading()
studyFormFill_exportDetail(_.merge({}, this.queryParamsJcgj, { jcgjlx: jcgjlx, lang: this.$store.getters.language.split("_")[0] })).then(response => { studyFormFill_exportDetail(_.merge({}, this.queryParamsJcgj, { jcgjlx: jcgjlx, lang: this.$store.getters.language.split("_")[0] })).then(response => {
@ -352,8 +418,8 @@ export default {
}, },
getJjcgjList(val) { getJjcgjList(val) {
this.$modal.loading() this.$modal.loading()
if(val){
this.queryParamsJcgj=_.merge({}, this.queryParamsJcgj, val)
if (val) {
this.queryParamsJcgj = _.merge({}, this.queryParamsJcgj, val)
} }
studyFormFill_jcgj(this.queryParamsJcgj).then(response => { studyFormFill_jcgj(this.queryParamsJcgj).then(response => {
this.jcgjList = response.rows this.jcgjList = response.rows

Loading…
Cancel
Save