Просмотр исходного кода

feat(miniprogram): add pound QR label helpers and node checks.

Co-authored-by: Cursor <cursoragent@cursor.com>
wuzilong 2 месяцев назад
Родитель
Сommit
b1719fab23
2 измененных файлов с 59 добавлено и 0 удалено
  1. 26 0
      miniprogram/scripts/test_db_pound_qr.mjs
  2. 33 0
      miniprogram/utils/dbPoundQr.js

+ 26 - 0
miniprogram/scripts/test_db_pound_qr.mjs

@@ -0,0 +1,26 @@
+import assert from 'node:assert/strict'
+import {
+  poundQrDialogTitle,
+  formatPoundQrProductLine,
+  normalizePoundQrRemarks
+} from '../utils/dbPoundQr.js'
+
+assert.equal(poundQrDialogTitle('出库'), '出库磅单二维码')
+assert.equal(poundQrDialogTitle('入库'), '入库磅单二维码')
+assert.equal(poundQrDialogTitle(''), '入库磅单二维码')
+
+assert.equal(formatPoundQrProductLine({ product: '尿素', specification: '', quantity: 32 }, '吨'), '尿素(32 吨)')
+assert.equal(
+  formatPoundQrProductLine({ product: '尿素颗粒', specification: '颗粒', quantity: 10 }, '吨'),
+  '尿素 颗粒(10 吨)'
+)
+assert.equal(
+  formatPoundQrProductLine({ product: '尿素', specification: '46%', quantity: 1 }, '吨'),
+  '尿素 46%(1 吨)'
+)
+
+assert.equal(normalizePoundQrRemarks({ remarks: '急单' }), '急单')
+assert.equal(normalizePoundQrRemarks({ remark: '备货' }), '备货')
+assert.equal(normalizePoundQrRemarks({ remarks: '  ', remark: '' }), '')
+
+console.log('test_db_pound_qr: ok')

+ 33 - 0
miniprogram/utils/dbPoundQr.js

@@ -0,0 +1,33 @@
+/**
+ * 磅单二维码弹窗文案工具(与 web-admin PoundSlipQrcodeView / DbPoundSlipQrcodeDialog 对齐)
+ */
+
+export function poundQrDialogTitle(businessType) {
+  return String(businessType || '').trim() === '出库' ? '出库磅单二维码' : '入库磅单二维码'
+}
+
+/** 与 DbPoundSlipQrcodeDialog.formatQrcodeProductLabel 一致 */
+export function formatQrcodeProductLabel(row) {
+  const product = String(row?.product || '').trim()
+  const specification = String(row?.specification || '').trim()
+  if (!specification) return product
+  if (product.endsWith(specification)) {
+    const base = product.slice(0, -specification.length).trimEnd()
+    return base ? `${base} ${specification}` : specification
+  }
+  return `${product} ${specification}`.trim()
+}
+
+export function formatPoundQrProductLine(row, quantityUnit = '吨') {
+  const unit = String(quantityUnit || '').trim() || '吨'
+  const label = formatQrcodeProductLabel(row)
+  const qty = row?.quantity
+  const qtyText = qty === 0 || qty ? String(qty) : '--'
+  return `${label}(${qtyText} ${unit})`
+}
+
+export function normalizePoundQrRemarks(row) {
+  const a = String(row?.remarks ?? '').trim()
+  if (a) return a
+  return String(row?.remark ?? '').trim()
+}