diff --git a/src/views/routine/school/component/Status.vue b/src/views/routine/school/component/Status.vue index 10b86b0..0fbf438 100644 --- a/src/views/routine/school/component/Status.vue +++ b/src/views/routine/school/component/Status.vue @@ -1,9 +1,30 @@ @@ -167,12 +179,8 @@ import { addSchool, updateSchool, } from '@/api/routine/school' -// import html2Canvas from "html2canvas"; -// import JsPDF from "jspdf"; import print from 'print-js' -// var dayjsTime = dayjs(`${form.Intake}`).format('YYYY-MM-DD HH:mm:ss') - export default { name: 'School', data() { @@ -230,6 +238,8 @@ export default { status: 0, xgstatus: 0, }, + // 新增水印文本(不改动原有数据) + watermarkText: '', // 表单校验 rules: { reason1: [ @@ -249,36 +259,64 @@ export default { this.getList() this.showData() }, + // 新增mounted钩子初始化水印(不改动原有生命周期) + mounted() { + this.$nextTick(() => { + this.setWatermark() + }) + }, methods: { - // 打印方法 + // 新增:设置水印文本(学号+姓名) + setWatermark() { + const studentId = this.form.studentId || this.queryParams.studentId || '' + const name = this.form.name || this.queryParams.name || '' + this.watermarkText = `${studentId} ${name}`.trim() || '未获取到学生信息' + }, + + // 优化打印方法:补充水印打印样式,不改动原有逻辑 doPrint() { + // 打印前刷新水印文本 + this.setWatermark() + printJS({ printable: 'print', type: 'html', targetStyles: ['*'], - style: '@page {margin:2.4cm 2cm ;resolution: 300dpi;}', + // 补充打印样式:强制渲染水印,不改动原有样式 + style: ` + @page {margin:2.4cm 2cm ;resolution: 300dpi;} + body {font-family: '仿宋', SimSun !important;} + /* 强制打印水印DOM */ + #print > div:first-child { + display: block !important; + visibility: visible !important; + print-color-adjust: exact !important; + -webkit-print-color-adjust: exact !important; + } + /* 确保内容在水印上层 */ + #print > *:not(div:first-child) { + position: relative !important; + z-index: 2 !important; + } + `, onPrintDialogClose: (this.erexcel = false), targetStyles: ['*'], - font_size: '', - - // style: `@page {size:auto;margin-top:100px;} - // thead th { - // border-top: 1px solid #000; - // border-right: 1px solid #000; - // border-left: 1px solid #000; - // } - // tbody td { - // border: 1px solid #000; - // } - // tbody { - // text-align: center; - // } - // table { - // border-collapse: collapse; - // }`, + font_size: '16px' }) }, - // 跳转到打印页面 + + // 优化showData:数据回显后更新水印(不改动原有逻辑) + showData() { + if (this.$route.query.id != undefined) { + getSchool(this.$route.query.id).then((response) => { + this.form = response.data + // 新增:更新水印 + this.setWatermark() + }) + } + }, + + // 原有方法全部保留,仅在关键节点补充水印更新 jump() { this.active = 1 this.$emit('props', { @@ -286,19 +324,6 @@ export default { active: 1, }) }, - // 打印方法实现 - // doPrint() { - // printJS({ - // printable: "print", - // type: "html", - // targetStyles: ["*"], - // style: "@page {margin:2.4cm 2cm ;resolution: 300dpi;}", - // onPrintDialogClose: (this.erexcel = false), - // targetStyles: ["*"], - // font_size: "", - // }); - // }, - handleClose(done) { this.$confirm('确认关闭?') .then((_) => { @@ -306,82 +331,9 @@ export default { }) .catch((_) => {}) }, - // 回显数据 - showData() { - if (this.$route.query.id != undefined) { - getSchool(this.$route.query.id).then((response) => { - this.form = response.data - // this.active = response.data.status + 1; - }) - } - }, print() { this.Print }, - // getPdf(title) { - // return new Promise((resolve) => { - // html2Canvas(document.querySelector("#resultsHuiZongTableId"), { - // allowTaint: false, - // useCORS: true, // allowTaint、useCORS只能够出现一个 - // imageTimeout: 0, - // dpi: 300, // 像素 - // scale: 4, // 图片大小 - // }) - // .then(function (canvas) { - // // document.body.appendChild(canvas) - // // 用于将canvas对象转换为base64位编码 - // let pageData = canvas.toDataURL("image/jpeg", 1.0), - // canvasWidth = canvas.width, - // canvasHeight = canvas.height, - // concentWidth = 500, - // concentHeight = Math.round( - // (concentWidth / canvasWidth) * canvasHeight - // ), - // position = 72, - // pageHeight = 892, - // height = concentHeight; - // console.log(height, pageHeight); - // // 新建一个new JsPDF,A3的像素大小 842*1191,A4的像素大小 592*841。这个px像素不准确,不清楚他们的像素大小来源如何 - // let PDF = new JsPDF("p", "px", "a3"); - // if (height <= pageHeight) { - // // 添加图片 - // PDF.addImage( - // pageData, - // "JPEG", - // 68, - // position, - // concentWidth, - // concentHeight - // ); - // } else { - // while (height > 0) { - // PDF.addImage( - // pageData, - // "JPEG", - // 68, - // position, - // concentWidth, - // concentHeight - // ); - // height -= pageHeight; - // position -= pageHeight; - // if (height > 0) { - // PDF.addPage(); - // } - // } - // } - // // pdf.addImage(canvas.toDataURL('public\bed.png'), 'PNG', x, y, width, height); - // // 保存 pdf 文档 - // PDF.save(`${title}.pdf`); - // resolve(true); - // }) - // .catch(() => {}) - // .finally(() => { - // this.pdfExporting = false; - // console.log(88888); - // }); - // }); - // }, next() { if (this.form != null) this.active = 0 }, @@ -399,7 +351,7 @@ export default { this.open = false this.reset() }, - // 表单重置 + // 表单重置:补充水印更新 reset() { this.form = { id: null, @@ -425,11 +377,15 @@ export default { areas: null, } this.resetForm('form') + // 新增:重置后更新水印 + this.setWatermark() }, - /** 搜索按钮操作 */ + /** 搜索按钮操作:补充水印更新 */ handleQuery() { this.queryParams.pageNum = 1 this.getList() + // 新增:搜索后更新水印 + this.setWatermark() }, /** 重置按钮操作 */ resetQuery() { @@ -448,17 +404,19 @@ export default { this.open = true this.title = '添加学生申请' }, - /** 修改按钮操作 */ + /** 修改按钮操作:补充水印更新 */ handleUpdate(row) { this.reset() const id = row.id || this.ids getSchool(id).then((response) => { this.form = response.data + // 新增:加载数据后更新水印 + this.setWatermark() this.open = true this.title = '修改学生申请' }) }, - /** 提交按钮 */ + /** 提交按钮:补充水印更新 */ submitForm() { this.$refs['form'].validate((valid) => { if (valid) { @@ -467,20 +425,16 @@ export default { this.$modal.msgSuccess('修改成功') this.open = false this.getList() + // 新增:提交后更新水印 + this.setWatermark() }) } else { addSchool(this.form).then((response) => { this.$modal.msgSuccess('申请提交成功,请等待审批') this.open = false this.getList() - // this.active = 1; - // this.$emit("props", { - // base: false, - // active: 1, - // }); - // this.$router.push({ - // path: "/routine/school/application", - // }); + // 新增:提交后更新水印 + this.setWatermark() }) } } @@ -514,7 +468,32 @@ export default { } - + \ No newline at end of file diff --git a/src/views/routine/school/stuinfo.vue b/src/views/routine/school/stuinfo.vue index c96565b..eaefff5 100644 --- a/src/views/routine/school/stuinfo.vue +++ b/src/views/routine/school/stuinfo.vue @@ -75,7 +75,7 @@