Skip to content

Commit

Permalink
Merge branch 'ExtWebpages'
Browse files Browse the repository at this point in the history
  • Loading branch information
DynastyKids committed Dec 28, 2023
2 parents ed2880f + 441c8a0 commit bce8b81
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 56 deletions.
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<li><a class="dropdown-item" href="labelgenerator.html">Generate Labels</a></li>
<li><a class="dropdown-item" href="#">Check prefill labels (Unavailable)</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="stocks.html">Stock Management</a></li>
<li><a class="dropdown-item" href="stocks/stocks.html">Stock Management</a></li>
<li><a class="dropdown-item" href="#">Add Stock (Unavailable)</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Scan QR Code(Unavailable)</a></li>
Expand All @@ -55,7 +55,7 @@ <h1>Welcome to Warehouse Electron</h1>
<ul>
<li class="httpLink"><a href="labelgenerator.html"><i class="ti ti-tag"></i>Generate Labels</a></li>
<li class="httpsLink"><a href="#" data-bs-toggle="modal" data-bs-target="#httpsModal"><i class="ti ti-tag"></i>Generate Labels over HTTPS</a></li>
<li><a href="stocks.html"><i class="ti ti-packages"></i>Check Current Stocks</a></li>
<li><a href="stocks/stocks.html"><i class="ti ti-packages"></i>Check Current Stocks</a></li>
</ul>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions public/labelgenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<li><a class="dropdown-item" href="labelgenerator.html">Generate Labels</a></li>
<li><a class="dropdown-item" href="#">Check prefill labels (Unavailable)</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="stocks.html">Stock Management</a></li>
<li><a class="dropdown-item" href="stocks/stocks.html">Stock Management</a></li>
<li><a class="dropdown-item" href="#">Add Stock (Unavailable)</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Scan QR Code(Unavailable)</a></li>
Expand Down Expand Up @@ -123,7 +123,7 @@ <h5>Optional</h5>
<script src="/library/jspdf.umd.min.js"></script> <!--用于生成PDF,从ChromeEXT项目引入-->
<script src="/library/qrious.min.js"></script>
<!--JS.PDF用于生成PDF文件,而PDF.js用于读取PDF文件-->

<script src="/library/sha1.min.js"></script>
<script src="labelgenerator.js"></script>

<style>
Expand Down
105 changes: 64 additions & 41 deletions public/labelgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,29 @@ document.querySelector("#table_submit").addEventListener("click", function (ev)
// console.log(doc.internal.pageSize.width,doc.internal.pageSize.height) // Line Height在A4横向下总高度约为210
let prefillArray = []
let productLists = document.querySelectorAll(".rowRecords")
let sequence = 0;
for (let i = 0; i < productLists.length; i++) {
let rowInput = productLists[i].querySelectorAll("input")
for (let copy = 0; copy < rowInput[4].value; copy++) { // Looping when require multiple copies
sequence++
var stockInfo = {
POnumber: "",
productCode: "",
productName: "",
quantity: 1,
quantityUnit: "",
bestbefore: "",
productLabel: (new Date()).toISOString().replaceAll("-", "").split("T")[0] + getRandomXHexdigits(7),
productLabel: (new Date()).toISOString().replaceAll("-", "").split("T")[0],
seq: sequence,
removed: 0,
loggingTime: new Date(),
createTime: new Date()
}


if (String(stockInfo.POnumber).length <= 0){
stockInfo.loggingTime = new Date()
}

// 验证输入的productName是否在库中, 替换rowInput[0].value中的名称为产品Code,通过搜索原datalist的列表
document.querySelectorAll("#productSuggestions option").forEach(eachItem =>{
if (eachItem.value === rowInput[0].value){
Expand All @@ -118,42 +125,59 @@ document.querySelector("#table_submit").addEventListener("click", function (ev)
stockInfo.bestbefore = rowInput[3].value
stockInfo.POnumber = document.querySelector("#input_purchaseorder").value ? document.querySelector("#input_purchaseorder").value : ""

var initTextSize = 120
doc.setFontSize(initTextSize).setFont(undefined, 'normal')
var initTextSize = 110
doc.setFontSize(initTextSize).setFont("Helvetica", 'normal')
var part1Text = stockInfo.productName.slice(0,30);
while (doc.getTextDimensions(part1Text).w > doc.internal.pageSize.getWidth() - 20) {
initTextSize -= 5;
doc.setFontSize(initTextSize).setFont(undefined, 'normal')
doc.setFontSize(initTextSize).setFont("Helvetica", 'normal')
}

if (stockInfo.productName.length <= 30) {
while (doc.getTextDimensions(part1Text).w > doc.internal.pageSize.getWidth() - 40) {
initTextSize -= 5;
doc.setFontSize(initTextSize).setFont("Helvetica", 'normal')
}
doc.text(stockInfo.productName, doc.internal.pageSize.getWidth() / 2, 100, {lineHeightFactor: 0.9, align: "center"})
} else {
while (doc.getTextDimensions(part1Text).w > doc.internal.pageSize.getWidth() - 40) {
initTextSize -= 5;
doc.setFontSize(initTextSize).setFont("Helvetica", 'normal')
}
doc.text(`${stockInfo.productCode} - ${stockInfo.productName.slice(0, 40)}...`, 15, 80,
{lineHeightFactor: 1.1, align: "left", maxWidth: doc.internal.pageSize.width - 30})
stockInfo.productName = `${stockInfo.productCode} - ${stockInfo.productName.slice(0, 40)}...`
}
doc.text((stockInfo.productName.length<=50 ? stockInfo.productName : stockInfo.productName.slice(0,50)+"..."),
(stockInfo.productName.length<=25 ? doc.internal.pageSize.getWidth()/2 : 15),
(stockInfo.productName.length<=25 ? 110 : 70), {
lineHeightFactor: 1.1,
align: (stockInfo.productName.length<=25 ? "center" : 'left'),
maxWidth: doc.internal.pageSize.width-30});
// 新增内容,如果字段过长,拆分成2行,每行限制30字符,至多60字符,两行使用相同配置,左对齐

doc.setFontSize(90).setFont(undefined, 'normal'); //Quantity Text
doc.text(stockInfo.quantity + " " + stockInfo.quantityUnit, 25, doc.internal.pageSize.getHeight() - 190, {lineHeightFactor: 0.8});
let labelHash = generateProductHashString(stockInfo)
stockInfo.productLabel = (new Date()).toISOString().replaceAll("-", "").split("T")[0] + labelHash.substring(0,7)

doc.setFontSize(90).setFont("Helvetica", 'normal');
doc.text(stockInfo.quantity + " " + stockInfo.quantityUnit, 15, doc.internal.pageSize.getHeight() - 180, {lineHeightFactor: 1});

doc.setFontSize(90).setFont(undefined, 'normal'); // bestbefore Text
doc.text(stockInfo.bestbefore, 20, doc.internal.pageSize.getHeight() - 75, {lineHeightFactor: 0.8});
doc.setFontSize(90).setFont("Helvetica", 'normal')
doc.text(stockInfo.bestbefore, 15, doc.internal.pageSize.getHeight() - 90, {lineHeightFactor: 1});

doc.addImage(qrCodeGenerateV3(stockInfo.POnumber, stockInfo.productCode, stockInfo.productName,
stockInfo.quantity, stockInfo.quantityUnit, stockInfo.bestbefore, stockInfo.productLabel)
, "PNG", doc.internal.pageSize.getWidth() - 255, doc.internal.pageSize.getHeight() - 255, 250, 250)
doc.addImage(QRCodeObjectGenerateV3(stockInfo), "PNG", doc.internal.pageSize.getWidth() - 255, doc.internal.pageSize.getHeight() - 255, 250, 250)

//新增右上角标签号标记
doc.setFontSize(28).setFont(undefined, 'normal')
doc.text(stockInfo.productLabel.slice(-7), doc.internal.pageSize.getWidth()-20, 32, {lineHeightFactor: 0.75, align: "right"});
doc.setFontSize(48).setFont("courier", 'bold')
doc.text(`${stockInfo.productLabel.slice(-7)}`, 20, doc.internal.pageSize.getHeight() - 50, {lineHeightFactor: 0.75,});

doc.setFontSize(36).setFont("courier", 'bold')
doc.text(`${stockInfo.productLabel.slice(-7)}`, doc.internal.pageSize.getWidth() - 20, 36, {lineHeightFactor: 0.75, align: "right"});

doc.setFontSize(10).setFont(undefined, 'normal')
let bottomVerfiyText = ["V3", stockInfo.productLabel, stockInfo.POnumber, stockInfo.productCode,
stockInfo.quantity + stockInfo.quantityUnit, (stockInfo.bestbefore ? "Exp:" + stockInfo.bestbefore : "*")]
let bottomVerfiyText = ["V3_Electron", "P:"+stockInfo.POnumber,
"C:"+stockInfo.productCode, "Q:"+stockInfo.quantity + stockInfo.quantityUnit,
"E:" + (stockInfo.bestbefore ? stockInfo.bestbefore.replaceAll("-", "") : "*")]
doc.text(bottomVerfiyText.toString(), 20, doc.internal.pageSize.getHeight() - 30, {lineHeightFactor: 0.8});
doc.text("L:"+stockInfo.productLabel, 20, doc.internal.pageSize.getHeight() - 20, {lineHeightFactor: 0.8});

if (document.querySelector("#preloadCheckbox").checked) {
prefillItem({item: stockInfo})
}
doc.text(bottomVerfiyText.toString(), 20, doc.internal.pageSize.getHeight() - 30, {lineHeightFactor: 0.6});
prefillArray.push(stockInfo);
doc.addPage("a4","landscape");
}
Expand Down Expand Up @@ -195,24 +219,23 @@ function checkProductNameInDatabase(productsData, productCode){
return false;
}

function getRandomXHexdigits(bit) {
return (Math.random() * 0xfffffffff * 1000000000).toString(16).slice(0, bit)
// 2024-01-01预更新
/* 从2024.1.1开始,产品编号不在使用随机数,将改成使用SHA1信息摘要, 根据传入的数组生成对应的HASH值
* 为了避免信息重复,由收货单传入的值要有PTL#板位号,或者箱数编号范围x-xxx~x-xxx,,手动生成的多个label用自编号1~100...
* */
function generateProductHashString(qrObject){
let targetObject = qrObject
delete targetObject.productLabel
return sha1(JSON.stringify(targetObject))
}

// QR代码生成部分沿用Chrome EXT项目中的方法,默认使用V3,等后续按照产品需要引入V5
function qrCodeGenerateV3(purchaseNo = "", productCode = "", productName = "", quantity = 1, unit = "", bestbefore = "", labelId = "") {
var qrText = "https://yourAddress.local/?item=" + btoa(
JSON.stringify({
Build: 3,
POnumber: purchaseNo, //Purchase Order Reference
productCode: productCode,
productName: productName,
quantity: quantity,
quantityUnit: unit,
bestbefore: (bestbefore !== null ? bestbefore : ""), // bestbefore by YYYYMMDD
productLabel: labelId
})
);
var qrcode = new QRious({level: "M", size: 300, value: qrText, padding: 3});
return qrcode.toDataURL("image/png")
function QRCodeObjectGenerateV3(qrObject){
let remoteServerAddress = "http://192.168.0.254:3000/qrstock?item="
try {
var qrText = remoteServerAddress + btoa(JSON.stringify(qrObject))
var qrcode = new QRious({level: "L", size: 300, value: qrText, padding: 5});
return qrcode.toDataURL("image/png")
} catch (e) {
return null
}
}
48 changes: 48 additions & 0 deletions public/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layout - Warehouse Electron</title>
<link href="/library/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="/library/tabler/tabler-icons.min.css">
<link href="/library/datatables/datatables.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="../index.html">Stock-take Electron</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="../index.html"><i class="ti ti-home"></i>Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="ti ti-tools"></i>Features
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="labelgenerator.html">Generate Labels</a></li>
<li><a class="dropdown-item" href="#">Check prefill labels (Unavailable)</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="stocks/stocks.html">Stock Management</a></li>
<li><a class="dropdown-item" href="#">Add Stock (Unavailable)</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Scan QR Code(Unavailable)</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="/api"><i class="ti ti-api"></i>Swagger Portal (OpenAPI)</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</body>
</html>
Loading

0 comments on commit bce8b81

Please sign in to comment.