Remove company banner from printed asset labels
This commit is contained in:
parent
1e28279749
commit
af8dc675d9
@ -70,21 +70,18 @@ assert.ok(splitCode[0].endsWith('-'), '第一行编码应尽量在分隔符处
|
||||
assert.equal(splitCode.join(''), 'JS-DESIGN-2026-ULTRA-09', '拆分后编码内容必须完整保留')
|
||||
|
||||
const industrialCard = buildIndustrialCardDisplay({
|
||||
companyName: '常州简尚家具有限公司',
|
||||
equipmentCode: 'JS-PC-2040',
|
||||
equipmentType: '显示器',
|
||||
purchaseDate: '2026-03-24T12:38:58.000Z',
|
||||
organizationName: '设计中心'
|
||||
})
|
||||
|
||||
assert.equal(industrialCard.companyName, '常州简尚家具有限公司', '工业卡片版必须保留公司名')
|
||||
assert.equal(industrialCard.typeText, '显示器', '工业卡片版必须显示资产类别')
|
||||
assert.equal(industrialCard.purchaseDateText, '2026-03-24', '工业卡片版必须显示格式化后的采购日期')
|
||||
assert.equal(industrialCard.organizationText, '设计中心', '工业卡片版必须显示所属组织')
|
||||
assert.deepEqual(industrialCard.codeLines, ['JS-PC-2040'], '较短编码应保持单行显示')
|
||||
|
||||
const blankDateCard = buildIndustrialCardDisplay({
|
||||
companyName: '常州简尚家具有限公司',
|
||||
equipmentCode: 'JS-PC-2041',
|
||||
equipmentType: '显示器',
|
||||
purchaseDate: '',
|
||||
|
||||
@ -161,10 +161,8 @@ const LABEL_PRESET = {
|
||||
canvasWidthPx: 709,
|
||||
canvasHeightPx: 472,
|
||||
outerInsetPx: 10,
|
||||
headerHeightPx: 82,
|
||||
qrPanelWidthPx: 324,
|
||||
qrCodeSizePx: 286,
|
||||
companyName: '常州简尚家居有限公司'
|
||||
qrCodeSizePx: 286
|
||||
} as const
|
||||
|
||||
const equipmentList = ref<EquipmentBarcode[]>([])
|
||||
@ -419,13 +417,11 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
canvasWidthPx,
|
||||
canvasHeightPx,
|
||||
outerInsetPx,
|
||||
headerHeightPx,
|
||||
qrPanelWidthPx,
|
||||
qrCodeSizePx
|
||||
} = LABEL_PRESET
|
||||
|
||||
const display = buildIndustrialCardDisplay({
|
||||
companyName: LABEL_PRESET.companyName,
|
||||
equipmentCode: equipment.equipment_code || '-',
|
||||
equipmentType: equipment.equipment_type,
|
||||
purchaseDate: equipment.purchase_date,
|
||||
@ -438,46 +434,14 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
ctx.lineWidth = 8
|
||||
ctx.strokeRect(4, 4, canvasWidthPx - 8, canvasHeightPx - 8)
|
||||
|
||||
const contentX = outerInsetPx
|
||||
const contentY = outerInsetPx
|
||||
const contentWidth = canvasWidthPx - outerInsetPx * 2
|
||||
|
||||
ctx.fillStyle = '#000000'
|
||||
ctx.fillRect(contentX, contentY, contentWidth, headerHeightPx)
|
||||
|
||||
const whiteBodyMeasure = createMeasureText(ctx, '700', BODY_FONT)
|
||||
const companyFit = fitSingleLineText(
|
||||
{
|
||||
text: display.companyName,
|
||||
maxWidth: contentWidth - 110,
|
||||
maxFontSize: 32,
|
||||
minFontSize: 22,
|
||||
allowTruncate: true
|
||||
},
|
||||
whiteBodyMeasure
|
||||
)
|
||||
drawTextLine(ctx, {
|
||||
text: companyFit.text,
|
||||
x: contentX + 18,
|
||||
y: contentY + Math.round((headerHeightPx - companyFit.fontSize) / 2) - 1,
|
||||
fontSize: companyFit.fontSize,
|
||||
weight: '900',
|
||||
family: BODY_FONT,
|
||||
color: '#FFFFFF'
|
||||
})
|
||||
|
||||
ctx.fillStyle = '#FFFFFF'
|
||||
ctx.fillRect(contentX + contentWidth - 52, contentY + 16, 24, 24)
|
||||
ctx.fillRect(contentX + contentWidth - 20, contentY + 16, 5, 24)
|
||||
|
||||
const mainY = contentY + headerHeightPx + 10
|
||||
const mainHeight = canvasHeightPx - mainY - outerInsetPx
|
||||
const qrPanelX = contentX
|
||||
const mainY = outerInsetPx + 10
|
||||
const qrPanelX = outerInsetPx
|
||||
const qrPanelY = mainY
|
||||
const qrPanelHeight = mainHeight
|
||||
const qrPanelHeight = canvasHeightPx - mainY - outerInsetPx
|
||||
const qrPanelInnerSize = qrPanelWidthPx - 20
|
||||
const qrCaptionHeight = 32
|
||||
const qrFrameX = qrPanelX + 10
|
||||
const qrFrameY = qrPanelY + Math.round((qrPanelHeight - qrPanelInnerSize) / 2)
|
||||
const qrFrameY = qrPanelY + Math.round((qrPanelHeight - qrPanelInnerSize - qrCaptionHeight) / 2)
|
||||
|
||||
ctx.fillStyle = '#FFFFFF'
|
||||
ctx.fillRect(qrPanelX, qrPanelY, qrPanelWidthPx, qrPanelHeight)
|
||||
@ -519,7 +483,7 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
drawTextLine(ctx, {
|
||||
text: leftCaptionFit.text,
|
||||
x: qrPanelX + 16,
|
||||
y: qrPanelY + qrPanelHeight - 32,
|
||||
y: qrFrameY + qrPanelInnerSize + 10,
|
||||
fontSize: leftCaptionFit.fontSize,
|
||||
weight: '900',
|
||||
family: COMPACT_FONT,
|
||||
@ -529,7 +493,7 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
const rightX = qrPanelX + qrPanelWidthPx + 10
|
||||
const rightWidth = canvasWidthPx - rightX - outerInsetPx
|
||||
const blackCompactMeasure = createMeasureText(ctx, '900', COMPACT_FONT)
|
||||
const headerFit = fitSingleLineText(
|
||||
const typeFit = fitSingleLineText(
|
||||
{
|
||||
text: display.typeText,
|
||||
maxWidth: Math.floor(rightWidth * 0.86),
|
||||
@ -539,16 +503,16 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
},
|
||||
blackCompactMeasure
|
||||
)
|
||||
const typeBadgeWidth = Math.ceil(blackCompactMeasure(headerFit.text, headerFit.fontSize)) + 40
|
||||
const typeBadgeHeight = headerFit.fontSize + 22
|
||||
const typeBadgeWidth = Math.ceil(blackCompactMeasure(typeFit.text, typeFit.fontSize)) + 40
|
||||
const typeBadgeHeight = typeFit.fontSize + 22
|
||||
|
||||
ctx.fillStyle = '#000000'
|
||||
ctx.fillRect(rightX, mainY, typeBadgeWidth, typeBadgeHeight)
|
||||
drawTextLine(ctx, {
|
||||
text: headerFit.text,
|
||||
text: typeFit.text,
|
||||
x: rightX + typeBadgeWidth / 2,
|
||||
y: mainY + typeBadgeHeight / 2 + 1,
|
||||
fontSize: headerFit.fontSize,
|
||||
fontSize: typeFit.fontSize,
|
||||
weight: '900',
|
||||
family: COMPACT_FONT,
|
||||
color: '#FFFFFF',
|
||||
@ -590,7 +554,8 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
const codeBottomY = codeY + codeLines.length * codeLineHeight
|
||||
drawRule(ctx, rightX, codeBottomY + 10, rightWidth, 4)
|
||||
|
||||
const purchaseDateLabelY = codeBottomY + 18
|
||||
const detailGap = 32
|
||||
const purchaseDateLabelY = codeBottomY + detailGap
|
||||
drawLabelCell(ctx, '采购日期', rightX, purchaseDateLabelY, 142, 40, 16)
|
||||
|
||||
let purchaseDateBottomY = purchaseDateLabelY + 40
|
||||
@ -621,7 +586,7 @@ const renderCardToCanvas = async (equipment: EquipmentBarcode) => {
|
||||
purchaseDateBottomY = purchaseDateTextY + purchaseDateFit.fontSize
|
||||
}
|
||||
|
||||
const organizationLabelY = purchaseDateBottomY + 12
|
||||
const organizationLabelY = purchaseDateBottomY + detailGap
|
||||
drawLabelCell(ctx, '所属组织', rightX, organizationLabelY, 160, 40, 16)
|
||||
|
||||
const organizationMeasure = createMeasureText(ctx, '700', BODY_FONT)
|
||||
|
||||
@ -33,7 +33,6 @@ export interface FittedMultilineText {
|
||||
}
|
||||
|
||||
export interface IndustrialCardDisplayInput {
|
||||
companyName: string
|
||||
equipmentCode: string
|
||||
equipmentType?: string | null
|
||||
purchaseDate?: string | null
|
||||
@ -41,7 +40,6 @@ export interface IndustrialCardDisplayInput {
|
||||
}
|
||||
|
||||
export interface IndustrialCardDisplayModel {
|
||||
companyName: string
|
||||
codeLines: string[]
|
||||
typeText: string
|
||||
purchaseDateText: string
|
||||
@ -192,7 +190,6 @@ export const splitCodeForDisplay = (code: string) => {
|
||||
export const buildIndustrialCardDisplay = (
|
||||
input: IndustrialCardDisplayInput
|
||||
): IndustrialCardDisplayModel => ({
|
||||
companyName: normalizeText(input.companyName),
|
||||
codeLines: splitCodeForDisplay(input.equipmentCode),
|
||||
typeText: normalizeText(input.equipmentType || '未分类资产'),
|
||||
purchaseDateText: formatDisplayDate(input.purchaseDate),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user