changes
This commit is contained in:
7
package-lock.json
generated
7
package-lock.json
generated
@@ -19,6 +19,7 @@
|
||||
"es-toolkit": "^1.42.0",
|
||||
"highcharts": "^12.2.0",
|
||||
"highcharts-vue": "^2.0.1",
|
||||
"jsbarcode": "^3.12.3",
|
||||
"mammoth": "^1.9.1",
|
||||
"nuxt-qrcode": "^0.4.8",
|
||||
"pdfjs-dist": "^3.11.174",
|
||||
@@ -8637,6 +8638,12 @@
|
||||
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/jsbarcode": {
|
||||
"version": "3.12.3",
|
||||
"resolved": "https://registry.npmjs.org/jsbarcode/-/jsbarcode-3.12.3.tgz",
|
||||
"integrity": "sha512-CuHU9hC6dPsHF5oVFMo8NW76uQVjH4L22CsP4hW+dNnGywJHC/B0ThA1CTDVLnxKLrrpYdicBLnd2xsgTfRnvg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/jsesc": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"es-toolkit": "^1.42.0",
|
||||
"highcharts": "^12.2.0",
|
||||
"highcharts-vue": "^2.0.1",
|
||||
"jsbarcode": "^3.12.3",
|
||||
"mammoth": "^1.9.1",
|
||||
"nuxt-qrcode": "^0.4.8",
|
||||
"pdfjs-dist": "^3.11.174",
|
||||
|
||||
32
print/print_barcode.py
Normal file
32
print/print_barcode.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import win32print
|
||||
import sys
|
||||
import json
|
||||
|
||||
def print_barcode(tspl_content, printer_name="Xprinter XP-350BM"):
|
||||
h = win32print.OpenPrinter(printer_name)
|
||||
try:
|
||||
win32print.StartDocPrinter(h, 1, ("Print Barcode", None, "RAW"))
|
||||
win32print.StartPagePrinter(h)
|
||||
win32print.WritePrinter(h, tspl_content.encode('utf-8'))
|
||||
win32print.EndPagePrinter(h)
|
||||
win32print.EndDocPrinter(h)
|
||||
finally:
|
||||
win32print.ClosePrinter(h)
|
||||
|
||||
if __name__ == "__main__":
|
||||
data = json.loads(sys.argv[1])
|
||||
|
||||
tspl = f'''
|
||||
SIZE 50 mm,40 mm
|
||||
GAP 2 mm,0
|
||||
DIRECTION 1
|
||||
DENSITY 8
|
||||
CLS
|
||||
TEXT 20,15,"3",0,1,1,"{data['name']}"
|
||||
TEXT 20,70,"1",0,1,1,"Price: {data['price']} VND"
|
||||
BARCODE 20,140,"128",50,1,0,2,2,"{data['imei']}"
|
||||
PRINT 1,1
|
||||
'''.strip()
|
||||
|
||||
print_barcode(tspl)
|
||||
print("Sent to printer.")
|
||||
17
print/test_barcode.txt
Normal file
17
print/test_barcode.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
SIZE 50 mm,40 mm
|
||||
GAP 2 mm,0
|
||||
DIRECTION 1
|
||||
DENSITY 8
|
||||
CLS
|
||||
|
||||
TEXT 20,15,"3",0,1,1,"CellphoneS Store"
|
||||
TEXT 20,45,"2",0,1,1,"iPhone 15 Pro Max 256GB"
|
||||
TEXT 20,70,"2",0,1,1,"Color: Natural Titanium"
|
||||
TEXT 20,95,"1",0,1,1,"Price: 29,990,000 VND"
|
||||
TEXT 20,115,"1",0,1,1,"Warranty: 12 months"
|
||||
|
||||
BARCODE 20,140,"128",50,1,0,2,2,"SKU123456789"
|
||||
|
||||
QRCODE 280,140,"L",4,"A",0,"https://example.com/p/123456789"
|
||||
|
||||
PRINT 1,1
|
||||
20
server/api/print/barcode.post.ts
Normal file
20
server/api/print/barcode.post.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { execFile } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import path from "path";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
const { name, imei, price } = body;
|
||||
|
||||
const scriptPath = path.join(process.cwd(), "print", "print_barcode.py");
|
||||
const payload = JSON.stringify({ name, imei, price });
|
||||
|
||||
try {
|
||||
const { stdout } = await execFileAsync("python", [scriptPath, payload]);
|
||||
return { success: true, output: stdout };
|
||||
} catch (err) {
|
||||
throw createError({ statusCode: 500, statusMessage: "Print failed", data: String(err) });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user