|
|
@@ -47,29 +47,31 @@
|
|
|
</div>
|
|
|
<div style="height: 15px;"></div>
|
|
|
</template>
|
|
|
-
|
|
|
- <canvas id="canvas" width="580" height="400" ref="canvas"></canvas>
|
|
|
+ <!-- <div style="padding:10px 20px 40px 20px">
|
|
|
+ <van-slider v-model="scale" />
|
|
|
+ </div> -->
|
|
|
+ <canvas id="canvas" width="768" height="640" ref="canvas"></canvas>
|
|
|
<canvas id="qrcode-canvas" class="qrcode" ref="qrCanvas"></canvas>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
import resolveUrl from 'resolve-url';
|
|
|
-import domtoimage from 'dom-to-image';
|
|
|
import QRCode from 'qrcode';
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
visitorInfo: null,
|
|
|
- base64: ''
|
|
|
+ base64: '',
|
|
|
+ scale: 50
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
- console.log(resolveUrl(this.$http.axios.defaults.baseURL, `/visitorInfo/${this.$route.query.id}`));
|
|
|
- this.$http.get(`/visitorInfo/get/${this.$route.query.id}`).then(res => {
|
|
|
+ console.log(resolveUrl(this.$http.axios.defaults.baseURL, `/visitorInfo/${this.$route.query.id}?view=true`));
|
|
|
+ this.$http.get(`/visitorInfo/get/${this.$route.query.id}?view=true`).then(res => {
|
|
|
this.visitorInfo = res;
|
|
|
this.$nextTick(() => {
|
|
|
const qrCanvas = document.createElement('canvas');
|
|
|
- qrCanvas.width = 580;
|
|
|
+ qrCanvas.width = 400;
|
|
|
qrCanvas.height = 400;
|
|
|
QRCode.toCanvas(
|
|
|
qrCanvas,
|
|
|
@@ -82,38 +84,46 @@ export default {
|
|
|
if (error) console.error(error);
|
|
|
console.log('success!');
|
|
|
const ctx = this.$refs.canvas.getContext('2d');
|
|
|
- const qrSize = 280;
|
|
|
- const gap = qrSize / 3;
|
|
|
+ const qrSize = 360;
|
|
|
+ const gap = 130;
|
|
|
|
|
|
let fontFamily = ctx.font.replace(/\d+px\s/, '');
|
|
|
console.log(fontFamily);
|
|
|
ctx.fillStyle = '#ffffff';
|
|
|
- ctx.fillRect(0, 0, 580, 400);
|
|
|
- ctx.drawImage(qrCanvas, 20, 60, qrSize, qrSize);
|
|
|
+ ctx.fillRect(0, 0, this.$refs.canvas.width, this.$refs.canvas.height);
|
|
|
+ ctx.drawImage(qrCanvas, 40, 52, qrSize, qrSize);
|
|
|
+
|
|
|
+ // ctx.lineWidth = 20;
|
|
|
+ // ctx.strokeStyle = '#000000';
|
|
|
+ // ctx.setLineDash([12]);
|
|
|
+ // ctx.beginPath();
|
|
|
+ // ctx.rect(0, 0, this.$refs.canvas.width, this.$refs.canvas.height);
|
|
|
+ // ctx.stroke();
|
|
|
|
|
|
//label
|
|
|
- ctx.font = '23px ' + fontFamily;
|
|
|
+ ctx.font = '32px ' + fontFamily;
|
|
|
ctx.fillStyle = '#000000';
|
|
|
- ctx.fillText('姓名:', 320, 90);
|
|
|
+ ctx.fillText('姓名:', 420, 90);
|
|
|
|
|
|
ctx.fillStyle = '#000000';
|
|
|
- ctx.fillText('访问部门:', 320, 90 + gap);
|
|
|
+ ctx.fillText('访问部门:', 420, 90 + gap);
|
|
|
|
|
|
ctx.fillStyle = '#000000';
|
|
|
- ctx.fillText('访问时间:', 320, 90 + gap * 2);
|
|
|
+ ctx.fillText('访问时间:', 420, 90 + gap * 2);
|
|
|
|
|
|
//value
|
|
|
- ctx.font = 'bold 26px ' + fontFamily;
|
|
|
+ ctx.font = 'bold 36px ' + fontFamily;
|
|
|
ctx.fillStyle = '#000000';
|
|
|
- ctx.fillText(res.name, 320, 130);
|
|
|
+ ctx.fillText(res.name, 420, 140);
|
|
|
|
|
|
ctx.fillStyle = '#000000';
|
|
|
- ctx.fillText(res.visitDepartment, 320, 130 + gap);
|
|
|
+ ctx.fillText(res.visitDepartment, 420, 140 + gap);
|
|
|
|
|
|
ctx.fillStyle = '#000000';
|
|
|
- ctx.fillText(this.toDate(res.visitTime), 320, 130 + gap * 2);
|
|
|
+ ctx.fillText(this.toDate(res.visitTime), 420, 140 + gap * 2);
|
|
|
|
|
|
this.base64 = this.$refs.canvas.toDataURL().replace('data:image/png;base64,', '');
|
|
|
+ console.log(this.base64);
|
|
|
}
|
|
|
);
|
|
|
});
|
|
|
@@ -124,12 +134,15 @@ export default {
|
|
|
return time.split(' ')[0];
|
|
|
},
|
|
|
print() {
|
|
|
- this.$toast.loading();
|
|
|
- setTimeout(() => {
|
|
|
- this.$toast.clear();
|
|
|
- }, 5000);
|
|
|
+ this.$toast.loading({ duration: 5000 });
|
|
|
+ let canvas = document.createElement('canvas');
|
|
|
+ canvas.width = (this.$refs.canvas.width * this.scale) / 100;
|
|
|
+ canvas.height = (this.$refs.canvas.height * this.scale) / 100;
|
|
|
+ canvas.getContext('2d').drawImage(this.$refs.canvas, 0, 0, canvas.width, canvas.height);
|
|
|
+ let base64 = canvas.toDataURL().replace('data:image/png;base64,', '');
|
|
|
+ console.log(base64);
|
|
|
if (window.cordova && cordova.plugins.EmbeddedPrinter) {
|
|
|
- cordova.plugins.EmbeddedPrinter.printPic(this.base64);
|
|
|
+ cordova.plugins.EmbeddedPrinter.printPic(base64);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -205,7 +218,7 @@ export default {
|
|
|
}
|
|
|
#canvas {
|
|
|
transform-origin: 0 0;
|
|
|
- transform: scale(0.6);
|
|
|
+ transform: scale(0.45);
|
|
|
z-index: -1;
|
|
|
opacity: 0;
|
|
|
position: absolute;
|