优化桌面端

This commit is contained in:
gyq
2024-05-16 16:55:55 +08:00
parent 43ccf82177
commit 6f378cc3c0
6 changed files with 141 additions and 239 deletions

View File

@@ -1,86 +1 @@
"use strict"; "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()});
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();
});

View File

@@ -1,72 +1,72 @@
{ {
"name": "vite-electron", "name": "vite-electron",
"private": true, "private": true,
"version": "1.0.25", "version": "1.1.2",
"main": "dist-electron/main.js", "main": "dist-electron/main.js",
"scripts": { "scripts": {
"dev": "chcp 65001 && vite", "dev": "chcp 65001 && vite",
"build": "node ./addVersion.js && vite build && electron-builder", "build": "node ./addVersion.js && vite build && electron-builder",
"preview": "vite preview", "preview": "vite preview",
"build:win": "node ./addVersion.js && vite build && electron-builder --w" "build:win": "node ./addVersion.js && vite build && electron-builder --w"
}, },
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"axios": "^1.6.2", "axios": "^1.6.2",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"electron-pos-printer": "^1.3.6", "electron-pos-printer": "^1.3.6",
"electron-pos-printer-vue": "^1.0.9", "electron-pos-printer-vue": "^1.0.9",
"element-plus": "^2.4.3", "element-plus": "^2.4.3",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"swiper": "^11.1.1", "swiper": "^11.1.1",
"vue": "^3.3.8", "vue": "^3.3.8",
"vue-router": "^4.2.5" "vue-router": "^4.2.5"
}, },
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "^4.5.0", "@vitejs/plugin-vue": "^4.5.0",
"electron": "^28.2.3", "electron": "^28.2.3",
"electron-builder": "^24.13.3", "electron-builder": "^24.13.3",
"electron-rebuild": "^3.2.9", "electron-rebuild": "^3.2.9",
"path": "^0.12.7", "path": "^0.12.7",
"sass": "^1.69.5", "sass": "^1.69.5",
"sass-loader": "^13.3.2", "sass-loader": "^13.3.2",
"tree-kill": "^1.2.2", "tree-kill": "^1.2.2",
"vite": "^5.0.0", "vite": "^5.0.0",
"vite-plugin-electron": "^0.15.4", "vite-plugin-electron": "^0.15.4",
"vite-plugin-electron-renderer": "^0.14.5" "vite-plugin-electron-renderer": "^0.14.5"
}, },
"build": { "build": {
"appId": "com.cashierdesktop.app", "appId": "com.cashierdesktop.app",
"productName": "银收客", "productName": "银收客",
"asar": true, "asar": true,
"files": [ "files": [
"./dist/**/*", "./dist/**/*",
"./dist-electron/**/*" "./dist-electron/**/*"
], ],
"directories": { "directories": {
"buildResources": "build", "buildResources": "build",
"output": "release" "output": "release"
}, },
"win": { "win": {
"icon": "./public/logo.ico", "icon": "./public/logo.ico",
"target": [ "target": [
{ {
"target": "nsis", "target": "nsis",
"arch": [ "arch": [
"ia32" "ia32"
] ]
} }
] ]
}, },
"nsis": { "nsis": {
"oneClick": false, "oneClick": false,
"allowElevation": true, "allowElevation": true,
"allowToChangeInstallationDirectory": true, "allowToChangeInstallationDirectory": true,
"installerIcon": "./public/logo.ico", "installerIcon": "./public/logo.ico",
"uninstallerIcon": "./public/logo.ico", "uninstallerIcon": "./public/logo.ico",
"installerHeaderIcon": "./public/logo.ico", "installerHeaderIcon": "./public/logo.ico",
"createDesktopShortcut": true, "createDesktopShortcut": true,
"createStartMenuShortcut": true "createStartMenuShortcut": true
} }
} }
} }

View File

@@ -26,6 +26,19 @@ export function productqueryCommodityInfo(params) {
}); });
} }
/**
* 查询商品信息
* @param {*} params
* @returns
*/
export function queryNewCommodityInfo(params) {
return request({
method: "get",
url: "product/queryNewCommodityInfo",
params
});
}
/** /**
* 通过选中的商品规格查询价格 * 通过选中的商品规格查询价格
* @param {*} params * @param {*} params

View File

@@ -30,11 +30,12 @@
<el-input placeholder="请输入商品名称查询" prefix-icon="Search" v-model="commdityName" clearable <el-input placeholder="请输入商品名称查询" prefix-icon="Search" v-model="commdityName" clearable
@input="inputChange"></el-input> @input="inputChange"></el-input>
</div> </div>
<el-button :icon="shopListType == 'text' ? 'PictureRounded' : 'PriceTag'" <!-- <el-button :icon="shopListType == 'text' ? 'PictureRounded' : 'PriceTag'"
@click="changeShopListType"></el-button> @click="changeShopListType"></el-button> -->
</div> </div>
<div class="shop_list" :class="{ img: shopListType == 'img' }" v-loading="loading"> <div class="shop_list" :class="{ img: shopListType == 'img' }" v-loading="loading">
<swiper class="swiper_box" direction="vertical" @slideChange="onSlideChange"> <!-- <swiper class="swiper_box" direction="vertical" @slideChange="onSlideChange"> -->
<swiper class="swiper_box" direction="vertical">
<swiper-slide class="slide_item" v-for="(goods, index) in goodsList" :key="index"> <swiper-slide class="slide_item" v-for="(goods, index) in goodsList" :key="index">
<div class="item_wrap" v-for="item in goods" :key="item.id" @click="showSkuHandle(item)"> <div class="item_wrap" v-for="item in goods" :key="item.id" @click="showSkuHandle(item)">
<div class="item"> <div class="item">
@@ -42,7 +43,7 @@
<div class="cover" v-if="shopListType == 'img'"> <div class="cover" v-if="shopListType == 'img'">
<el-image :src="item.coverImg" class="el_img" fit="cover"></el-image> <el-image :src="item.coverImg" class="el_img" fit="cover"></el-image>
</div> </div>
<div class="name"><el-text line-clamp="2">{{ item.name }}</el-text></div> <div class="name"><el-text line-clamp="1">{{ item.name }}</el-text></div>
<div class="item_empty" v-if="shopListType == 'text'"></div> <div class="item_empty" v-if="shopListType == 'text'"></div>
<div class="price"> <div class="price">
<el-text>{{ item.lowPrice }}</el-text> <el-text>{{ item.lowPrice }}</el-text>
@@ -66,7 +67,7 @@ import useStorage from "@/utils/useStorage";
import skuModal from '@/components/skuModal.vue' import skuModal from '@/components/skuModal.vue'
import { queryCategory, productqueryCommodityInfo, queryProductSku } from '@/api/product' import { queryCategory, queryNewCommodityInfo, queryProductSku } from '@/api/product'
import { useUser } from "@/store/user.js" import { useUser } from "@/store/user.js"
import { Swiper, SwiperSlide } from 'swiper/vue' import { Swiper, SwiperSlide } from 'swiper/vue'
@@ -183,6 +184,7 @@ function changeCategory(index) {
finish.value = false finish.value = false
currentGoodsIndex.value = 0 currentGoodsIndex.value = 0
loopMax.value = 0 loopMax.value = 0
clearInterval(loopTimer.value)
loopTimer.value = null loopTimer.value = null
updataGoods() updataGoods()
@@ -221,7 +223,7 @@ async function queryCategoryAjax() {
async function productqueryCommodityInfoAjax() { async function productqueryCommodityInfoAjax() {
try { try {
// loading.value = true // loading.value = true
const res = await productqueryCommodityInfo({ const res = await queryNewCommodityInfo({
shopId: store.userInfo.shopId, shopId: store.userInfo.shopId,
categoryId: categorys.value[categorysActive.value].id, categoryId: categorys.value[categorysActive.value].id,
commdityName: commdityName.value, commdityName: commdityName.value,
@@ -234,11 +236,15 @@ async function productqueryCommodityInfoAjax() {
} }
// loading.value = false // loading.value = false
if (res.total > (goodsPageSize.value * 2)) { if (res.pages > 2 && loopTimer.value == null) {
// 启动循环任务 // 启动循环任务
loopMax.value = parseInt(res.total / goodsPageSize.value) // loopMax.value = parseInt(res.total / goodsPageSize.value)
loopGetGoods() loopGetGoods()
} }
if (goodsPage.value >= res.pages) {
clearInterval(loopTimer.value)
loopTimer.value = null
}
return res.list return res.list
} catch (error) { } catch (error) {
loading.value = false loading.value = false
@@ -250,14 +256,9 @@ async function productqueryCommodityInfoAjax() {
function loopGetGoods() { function loopGetGoods() {
loopTimer.value = setInterval(async () => { loopTimer.value = setInterval(async () => {
goodsPage.value++ goodsPage.value++
if (goodsPage.value > loopMax.value) {
clearInterval(loopTimer.value)
loopTimer.value = null
return
}
const res = await productqueryCommodityInfoAjax() const res = await productqueryCommodityInfoAjax()
goodsList.value.push(res) goodsList.value.push(res)
}, 2000) }, 1000)
} }
// 更新商品数据 // 更新商品数据

View File

@@ -1,12 +1,7 @@
<!-- 结算订单 --> <!-- 结算订单 -->
<template> <template>
<el-drawer <el-drawer size="100%" :with-header="false" direction="btt" v-model="dialogVisible">
size="100%"
:with-header="false"
direction="btt"
v-model="dialogVisible"
>
<div class="drawer_wrap"> <div class="drawer_wrap">
<div class="cart_list"> <div class="cart_list">
<div class="nav_wrap card"> <div class="nav_wrap card">
@@ -18,9 +13,7 @@
<div class="info"> <div class="info">
<div class="master_id">{{ props.masterId }}</div> <div class="master_id">{{ props.masterId }}</div>
<div class="btm"> <div class="btm">
<span class="p" <span class="p">服务员{{ store.userInfo.shopName || "暂无" }}</span>
>服务员{{ store.userInfo.shopName || "暂无" }}</span
>
<span class="t">{{ <span class="t">{{
props.orderInfo.createdAt && props.orderInfo.createdAt &&
dayjs(props.orderInfo.createdAt).format("MM-DD HH:mm") dayjs(props.orderInfo.createdAt).format("MM-DD HH:mm")
@@ -28,10 +21,7 @@
</div> </div>
</div> </div>
</div> </div>
<div <div class="list_wrap card" style="margin-top: var(--el-font-size-base)">
class="list_wrap card"
style="margin-top: var(--el-font-size-base)"
>
<div class="item" v-for="item in props.cart" :key="item.id"> <div class="item" v-for="item in props.cart" :key="item.id">
<div class="top"> <div class="top">
<span class="name">{{ item.name }}</span> <span class="name">{{ item.name }}</span>
@@ -48,11 +38,7 @@
</div> </div>
</div> </div>
<div class="packge_Wrap" v-if="item.isPack == 'true'"> <div class="packge_Wrap" v-if="item.isPack == 'true'">
<div <div class="icon_item" v-if="item.isPack == 'true'" @click="giftPackHandle('isPack', item)">
class="icon_item"
v-if="item.isPack == 'true'"
@click="giftPackHandle('isPack', item)"
>
<el-icon class="icon" style="color: var(--primary-color)"> <el-icon class="icon" style="color: var(--primary-color)">
<Box /> <Box />
</el-icon> </el-icon>
@@ -63,29 +49,15 @@
<div class="footer"> <div class="footer">
<!-- <el-button icon="Edit"></el-button> --> <!-- <el-button icon="Edit"></el-button> -->
<div class="button"> <div class="button">
<el-checkbox <el-checkbox v-model="isPrint" border label="打印结算小票" style="width: 100%" />
v-model="isPrint"
border
label="打印结算小票"
style="width: 100%"
/>
</div> </div>
<div class="print"> <div class="print">
<el-button <el-button type="primary" v-loading="printLoading" @click="printHandle">打印预结单</el-button>
type="primary"
v-loading="printLoading"
@click="printHandle"
>打印预结单</el-button
>
</div> </div>
</div> </div>
</div> </div>
<div class="pay_wrap"> <div class="pay_wrap">
<payCard <payCard :amount="props.amount" :orderId="props.orderInfo.id" @paySuccess="paySuccess" />
:amount="props.amount"
:orderId="props.orderInfo.id"
@paySuccess="paySuccess"
/>
</div> </div>
</div> </div>
</el-drawer> </el-drawer>
@@ -150,40 +122,41 @@ async function bySubTypeAjax() {
} }
} }
// 打印操作
async function printHandle() { async function printHandle() {
// try {
// if (!isPrint.value) return;
// if (printList.value.length) {
// const data = {
// shop_name: store.userInfo.merchantName,
// carts: props.cart,
// amount: props.amount,
// remark: props.remark,
// orderInfo: props.orderInfo,
// deviceName: printList.value[0].config.deviceName,
// createdAt: dayjs(props.orderInfo.createdAt).format(
// "YYYY-MM-DD HH:mm:ss"
// ),
// printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
// };
// ipcRenderer.send("printerInfoSync", JSON.stringify(data));
// } else {
// ElMessage.error("您还没有添加打印设备");
// }
// } catch (error) {
// console.log(error);
// }
try { try {
printLoading.value = true; if (!isPrint.value) return;
await print({ if (printList.value.length) {
type: "normal", const data = {
ispre: true, shop_name: store.userInfo.merchantName,
orderId: props.orderInfo.id, carts: props.cart,
}); amount: props.amount,
printLoading.value = false; remark: props.remark,
ElMessage.success("打印成功"); orderInfo: props.orderInfo,
deviceName: printList.value[0].config.deviceName,
createdAt: dayjs(props.orderInfo.createdAt).format(
"YYYY-MM-DD HH:mm:ss"
),
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
} else {
ElMessage.error("您还没有添加本地打印设备,将使用网络打印");
try {
printLoading.value = true;
await print({
type: "normal",
ispre: true,
orderId: props.orderInfo.id,
});
printLoading.value = false;
ElMessage.success("打印成功");
} catch (error) {
printLoading.value = false;
console.log(error);
}
}
} catch (error) { } catch (error) {
printLoading.value = false;
console.log(error); console.log(error);
} }
} }

View File

@@ -9,8 +9,8 @@ export default defineConfig({
server: { server: {
proxy: { proxy: {
'/api': { '/api': {
// target: 'https://cashierclient.sxczgkj.cn/cashier-client', // 线上 target: 'https://cashierclient.sxczgkj.cn/cashier-client', // 线上
target: 'http://192.168.2.116:10587/cashier-client', // 国成 // target: 'http://192.168.2.116:10587/cashier-client', // 国成
// target: 'http://192.168.2.128:10587/cashier-client', // target: 'http://192.168.2.128:10587/cashier-client',
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '') rewrite: (path) => path.replace(/^\/api/, '')