新增增加打印机

This commit is contained in:
gyq
2024-04-03 15:57:58 +08:00
parent da00851195
commit 07d7df0416
19 changed files with 1562 additions and 540 deletions

79
public/print.css Normal file
View File

@@ -0,0 +1,79 @@
* {
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding: 0 8mm;
}
.print_view {
padding: 20px 0;
}
.print_view .title {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-bottom: 4px;
}
.print_view .title.t1 {
font-size: 24px;
}
.print_view .title.t2 {
margin-bottom: 15px;
}
.print_view .row {
margin-top: 2px;
font-size: 12px;
}
.print_view .row.between {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.print_view .line {
margin: 10px 0;
border-bottom: 1px solid #000;
}
.print_view .table {
width: 100%;
}
.print_view .table tr {
width: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.print_view .table tr:not(:last-child) {
margin-bottom: 10px;
}
.print_view .table tr td {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
font-size: 12px;
}
.print_view .table tr td:nth-child(1) {
-webkit-box-flex: 2;
-ms-flex: 2;
flex: 2;
}
.print_view .table tr td:not(:first-child) {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.print_view .table tr td .sku {
font-size: 10px;
}

View File

@@ -6,54 +6,88 @@
<head>
<meta charset="UTF-8" />
<title>Print preview</title>
<link rel="stylesheet" href="./print.css" />
</head>
<body>
<div id="app">
<div class="html2canvas">
<section>#B5 B6</section>
<section>喔喔奶茶 x22</section>
<section>麻辣味</section></section></section>
<section>03-08 16:32 ¥123.00</section>
<div class="print_view">
<div class="title t1">{{data.shop_name}}</div>
<div class="title t2">结算单【{{data.carts[0].masterId}}】</div>
<div class="row">订单号:202404021023542223445</div>
<div class="row">交易时间:2024-04-02 10:15</div>
<div class="row">收银员:【POS-1】1</div>
<div class="line"></div>
<table class="table">
<tr>
<td>品名</td>
<td>单价</td>
<td>数量</td>
<td>小计</td>
</tr>
<tr v-for="item in data.carts" :key="item.id">
<td>
<div>{{item.name}}</div>
<div class="sku">{{item.skuName}}</div>
</td>
<td>{{item.salePrice}}</td>
<td>{{item.number}}</td>
<td>{{item.totalAmount}}</td>
</tr>
</table>
<div class="line"></div>
<div class="row between">
<span>合计:</span>
<span>30.00</span>
</div>
<div class="row between">
<span>合计:</span>
<span>30.00</span>
</div>
<div class="row between">
<span>原价:20.00节省了0</span>
</div>
<div class="row between">
<span>积分:</span>
<span>0</span>
</div>
<div class="row between">
<span>余额:</span>
<span>0.00</span>
</div>
<div class="line"></div>
<div class="row">备注:</div>
<div class="row">打印时间:2024-04-02 10:15</div>
</div>
</div>
<script type="module">
// const { ipcRenderer } = require("electron");
// import {
// createApp,
// ref,
// onMounted,
// } from "../node_modules/vue/dist/vue.esm-browser.js";
const { ipcRenderer } = require("electron");
import {
createApp,
ref,
onMounted,
} from "../node_modules/vue/dist/vue.esm-browser.js";
// import html2canvas from '../node_modules/html2canvas/dist/html2canvas.esm.js'
createApp({
setup() {
const data = ref({});
// html2canvas(document.querySelector('.html2canvas')).then(canvas => {
// console.log(canvas)
// document.querySelector('#app').appendChild(canvas)
// }).catch(err=> {
// console.log(err);
// })
onMounted(() => {
ipcRenderer.on("getParams", (event, arg) => {
data.value = JSON.parse(arg);
console.log(data.value);
// createApp({
// setup() {
// const data = ref({});
// setTimeout(() => {
// ipcRenderer.send("printStart");
// }, 500);
});
});
// onMounted(() => {
// ipcRenderer.on("getParams", (event, arg) => {
// // console.log(arg);
// data.value = JSON.parse(arg);
// setTimeout(() => {
// ipcRenderer.send("printStart");
// },500)
// });
// });
// return {
// data,
// };
// },
// }).mount("#app");
return {
data,
};
},
}).mount("#app");
</script>
</body>
</html>

71
public/print.scss Normal file
View File

@@ -0,0 +1,71 @@
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
padding: 0 8mm;
}
.print_view {
padding: 20px 0;
.title {
display: flex;
justify-content: center;
margin-bottom: 4px;
&.t1 {
font-size: 24px;
}
&.t2 {
margin-bottom: 15px;
}
}
.row {
margin-top: 2px;
font-size: 12px;
&.between {
display: flex;
justify-content: space-between;
}
}
.line {
margin: 10px 0;
border-bottom: 1px solid #000;
}
.table {
width: 100%;
tr {
width: 100%;
display: flex;
&:not(:last-child) {
margin-bottom: 10px;
}
td {
flex: 1;
font-size: 12px;
&:nth-child(1) {
flex: 2;
}
&:not(:first-child) {
display: flex;
justify-content: flex-end;
}
.sku {
font-size: 10px;
}
}
}
}
}