This commit is contained in:
gyq 2024-05-24 17:54:54 +08:00
parent 6c1e34be7a
commit c54304f3d6
7 changed files with 57 additions and 147 deletions

View File

@ -1,86 +1 @@
"use strict";
const path = require("path");
const electron = require("electron");
let win;
electron.app.whenReady().then(() => {
win = new electron.BrowserWindow({
title: "银收客",
width: 1024,
height: 768,
fullscreenable: true,
fullscreen: process.env.VITE_DEV_SERVER_URL ? false : true,
simpleFullscreen: true,
frame: process.env.VITE_DEV_SERVER_URL ? true : false,
webPreferences: {
// 集成网页和 Node.js也就是在渲染进程中可以调用 Node.js 方法
nodeIntegration: true,
contextIsolation: false
}
});
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL);
} else {
win.loadFile(path.resolve(__dirname, "../dist/index.html"));
}
electron.app.on("activate", () => {
if (electron.BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
electron.ipcMain.on("quitHandler", (_, msg) => {
electron.app.quit();
});
electron.ipcMain.on("getPrintList", () => {
win.webContents.getPrintersAsync().then((res) => {
win.webContents.send("printList", res);
});
});
const printWin = new electron.BrowserWindow({
show: false,
width: 464,
height: 1726,
webPreferences: {
// 集成网页和 Node.js也就是在渲染进程中可以调用 Node.js 方法
nodeIntegration: true,
contextIsolation: false
}
});
if (process.env.VITE_DEV_SERVER_URL) {
printWin.loadFile(path.join(__dirname, "../public/print.html"));
} else {
printWin.loadFile(path.resolve(__dirname, "../dist/print.html"));
}
electron.ipcMain.on("printerInfoSync", (event, arg) => {
printWin.webContents.send("getParams", arg);
});
electron.ipcMain.on("printStart", (event, arg) => {
console.log(arg);
const _parmas = JSON.parse(arg);
let name = _parmas.deviceName;
printWin.webContents.print({
silent: true,
deviceName: name,
pageSize: {
width: 58e3,
height: 216e3
},
scaleFactor: 80,
landscape: false,
margins: {
marginType: "none",
top: 0,
bottom: 0,
left: 0,
right: 0
},
dpi: {
horizontal: 203,
vertical: 203
}
});
});
});
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin")
electron.app.quit();
});
"use strict";const s=require("path"),e=require("electron");let t;e.app.whenReady().then(()=>{t=new e.BrowserWindow({title:"银收客",width:1024,height:768,fullscreenable:!0,fullscreen:!process.env.VITE_DEV_SERVER_URL,simpleFullscreen:!0,frame:!!process.env.VITE_DEV_SERVER_URL,webPreferences:{nodeIntegration:!0,contextIsolation:!1}}),process.env.VITE_DEV_SERVER_URL?t.loadURL(process.env.VITE_DEV_SERVER_URL):t.loadFile(s.resolve(__dirname,"../dist/index.html")),e.app.on("activate",()=>{e.BrowserWindow.getAllWindows().length===0&&createWindow()}),e.ipcMain.on("quitHandler",(r,n)=>{e.app.quit()}),e.ipcMain.on("getPrintList",()=>{t.webContents.getPrintersAsync().then(r=>{t.webContents.send("printList",r)})});const i=new e.BrowserWindow({show:!1,width:464,height:1726,webPreferences:{nodeIntegration:!0,contextIsolation:!1}});process.env.VITE_DEV_SERVER_URL?i.loadFile(s.join(__dirname,"../public/print.html")):i.loadFile(s.resolve(__dirname,"../dist/print.html")),e.ipcMain.on("printerInfoSync",(r,n)=>{i.webContents.send("getParams",n)}),e.ipcMain.on("printStart",(r,n)=>{console.log(n);let o=JSON.parse(n).deviceName;i.webContents.print({silent:!0,deviceName:o,pageSize:{width:58e3,height:216e3},scaleFactor:80,landscape:!1,margins:{marginType:"none",top:0,bottom:0,left:0,right:0},dpi:{horizontal:203,vertical:203}})})});e.app.on("window-all-closed",()=>{process.platform!=="darwin"&&e.app.quit()});

View File

@ -1,7 +1,7 @@
{
"name": "vite-electron",
"private": true,
"version": "1.1.10",
"version": "1.1.13",
"main": "dist-electron/main.js",
"scripts": {
"dev": "chcp 65001 && vite",

View File

@ -19,13 +19,8 @@
</div>
<div class="number_wrap">
<div class="menus">
<div
class="item"
:class="{ active: payActive == index }"
v-for="(item, index) in payList"
:key="item.id"
@click="payTypeChange(index, item)"
>
<div class="item" :class="{ active: payActive == index }" v-for="(item, index) in payList" :key="item.id"
@click="payTypeChange(index, item)">
<div class="icon">
<el-image :src="item.icon" class="img"></el-image>
</div>
@ -40,12 +35,7 @@
</div>
<div class="keybord_wrap">
<div class="left">
<div
class="item"
v-for="item in 9"
:key="item"
@click="amountInput(`${item}`)"
>
<div class="item" v-for="item in 9" :key="item" @click="amountInput(`${item}`)">
{{ item }}
</div>
<div class="item" @click="amountInput('.')">.</div>
@ -63,12 +53,7 @@
</div>
</div>
</div>
<scanModal
ref="scanModalRef"
fast
:amount="money"
@success="scanCodeSuccess"
/>
<scanModal ref="scanModalRef" fast :amount="money" @success="scanCodeSuccess" />
</template>
<script setup>
@ -115,6 +100,7 @@ function payTypeChange(index, item) {
//
async function confirmOrder() {
if (payLoading.value) return
try {
if (payList.value[payActive.value].payType == "scanCode") {
scanModalRef.value.show();
@ -203,6 +189,7 @@ onMounted(() => {
border-bottom: 1px solid #ececec;
display: flex;
align-items: center;
.return {
$size: 50px;
width: $size;
@ -219,6 +206,7 @@ onMounted(() => {
font-size: var(--el-font-size-base);
}
}
.right {
.t1 {
display: flex;
@ -320,9 +308,7 @@ onMounted(() => {
flex: 1;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: var(--item-height) var(--item-height) var(--item-height) var(
--item-height
);
grid-template-rows: var(--item-height) var(--item-height) var(--item-height) var(--item-height);
gap: var(--el-font-size-base);
.item {

View File

@ -110,6 +110,7 @@ function payTypeChange(index, item) {
//
async function confirmOrder() {
if (payLoading.value) return
try {
if (payList.value[payActive.value].payType == 'scanCode') {
scanModalRef.value.show()

View File

@ -1,10 +1,7 @@
<template>
<div class="device_container">
<div class="header" @click="router.back()">
<el-icon
style="position: relative; top: 2px; margin-right: 4px"
size="22"
>
<el-icon style="position: relative; top: 2px; margin-right: 4px" size="22">
<ArrowLeft />
</el-icon>
<el-text>{{ form.id ? "编辑小票打印机" : "添加小票打印机" }}</el-text>
@ -26,28 +23,15 @@
</el-form-item>
<el-form-item label="选择设备">
<el-select v-model="form.config.deviceName">
<el-option
:label="item.name"
:value="item.name"
v-for="item in printList"
:key="item.name"
></el-option>
<el-option :label="item.name" :value="item.name" v-for="item in printList" :key="item.name"></el-option>
</el-select>
</el-form-item>
<el-form-item label="设备名称">
<el-input
v-model="form.name"
placeholder="请输入设备名称"
></el-input>
<el-input v-model="form.name" placeholder="请输入设备名称"></el-input>
</el-form-item>
<el-form-item label="打印份数">
<el-select v-model="form.config.printerNum">
<el-option
:label="item"
:value="item"
v-for="item in 4"
:key="item"
></el-option>
<el-option :label="item" :value="item" v-for="item in 4" :key="item"></el-option>
</el-select>
</el-form-item>
<el-form-item label="商品模式">
@ -70,12 +54,7 @@
</el-form-item>
<el-form-item label="尾部留空">
<el-select v-model="form.config.feet">
<el-option
:label="`${item}行`"
:value="`${item}`"
v-for="item in feets"
:key="item"
></el-option>
<el-option :label="`${item}行`" :value="`${item}`" v-for="item in feets" :key="item"></el-option>
</el-select>
</el-form-item>
</el-form>
@ -144,12 +123,7 @@
</el-button>
</div>
<div class="btn">
<el-button
type="primary"
style="width: 100%"
:loading="loading"
@click="submitHandle"
>
<el-button type="primary" style="width: 100%" :loading="loading" @click="submitHandle">
保存
</el-button>
</div>
@ -161,6 +135,7 @@
</template>
<script setup>
import dayjs from 'dayjs'
import { ipcRenderer } from "electron";
import { onMounted, ref } from "vue";
import { useRouter, useRoute } from "vue-router";
@ -211,10 +186,43 @@ function printHandle() {
ElMessage.warning("请选择打印设备");
return;
}
ipcRenderer.send(
"printStart",
JSON.stringify({ deviceName: form.value.config.deviceName })
);
// ipcRenderer.send(
// "printStart",
// JSON.stringify({ deviceName: form.value.config.deviceName })
// );
const data = {
shop_name: '溜溜',
carts: [
{
id: 1,
name: '娃哈哈矿泉水',
skuName: '500ml',
salePrice: '1.0',
number: '10',
totalAmount: '10'
},
{
id: 2,
name: '柠檬奶茶',
skuName: '加冰、加珍珠',
salePrice: '10',
number: '2',
totalAmount: '20'
}
],
amount: '30.00',
remark: '',
orderInfo: {
masterId: '#002',
orderNo: '202404021023542223445'
},
deviceName: form.value.config.deviceName,
createdAt: '2024-04-02 10:15',
printTime: '2024-04-02 10:15',
};
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
}
//

View File

@ -141,7 +141,7 @@ function checkLocalPrint(deviceName) {
}
}
if (!print.name || !print.status) {
if (!print.name) {
return false
} else {
return true

View File

@ -397,7 +397,7 @@ const ordereData = reactive({//表格数据
list: [],
size: 10,
page: 1,
status: 'cash',
status: '',
total: '',
orderNo: '',
})