UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

797 lines (796 loc) 42.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setLabelTemplateDataWithArrange = exports.setLabelTemplateData = exports.buildLabelTemplate = exports.getMaxCount = exports.buildFormTemplate = exports.buildDetailTemplate = void 0; var tslib_1 = require("tslib"); var js_base64_1 = require("js-base64"); var type_1 = require("./type"); var moment_1 = tslib_1.__importDefault(require("moment")); var buildDetailTemplate = function (settings, options, printContent, index, numberOfPage, batched) { var width = settings.width, height = settings.height, direction = settings.direction, top = settings.top, bottom = settings.bottom, defaultLeft = settings.left, defaultRight = settings.right; var showHeader = options.showHeader, showFooter = options.showFooter, showHeaderLine = options.showHeaderLine, headerTitle = options.headerTitle, showFooterLine = options.showFooterLine, titleAllPrint = options.titleAllPrint, subTitleAllPrint = options.subTitleAllPrint, showLogo = options.showLogo, headerFontSize = options.headerFontSize, headerFontFontFamily = options.headerFontFontFamily, title = options.title, showTitle = options.showTitle, showDynamicSubTitles = options.showDynamicSubTitles, dynamicSubTiltes = options.dynamicSubTiltes, titleFontSize = options.titleFontSize, titleFontFamily = options.titleFontFamily, subTitleFontSize = options.subTitleFontSize, subTitleFontFamily = options.subTitleFontFamily, footerFontSize = options.footerFontSize, footerFontFamily = options.footerFontFamily, showPrinter = options.showPrinter, showDate = options.showDate, showPageNum = options.showPageNum, showBarCode = options.showBarCode, showQRCode = options.showQRCode; var subTitle = printContent.subTitle, extraTitle = printContent.extraTitle, codeLabel = printContent.codeLabel, codeValue = printContent.codeValue, htmlContent = printContent.htmlContent, userName = printContent.userName; var pageWidth = direction == 'vertical' ? width : height; var pageHeight = ((direction == 'vertical' ? height : width)) / numberOfPage; var headerHeight = showHeader ? 16 : 0; var codeWidth = (showBarCode || showQRCode) ? showBarCode ? 60 : 15 : 0; var codeHeight = (showBarCode || showQRCode) ? showBarCode ? 13 : 15 : 0; var titleHeight = showTitle ? titleFontSize / 3 : 0; var headerTitleHeight = showHeader ? headerFontSize / 3.33333 : 0; var titleMarginTop = showHeader ? 3 : 0; var maxSubtitleRow = Math.max.apply(Math, tslib_1.__spreadArray(tslib_1.__spreadArray([], dynamicSubTiltes.map(function (item) { return item.split('\r').length; }), false), [1], false)); var subTitleHeight = showDynamicSubTitles ? (subTitleFontSize / 3 * maxSubtitleRow) + (maxSubtitleRow - 1) * 0.5 : 0; var subTitleMarginTop = showDynamicSubTitles ? 3 : 0; var subTitleCount = dynamicSubTiltes.length; var htmlMarginTop = 1.3; var htmlMarginBottom = 8; var footerHeight = footerFontSize / 3.33333; var pageNumWidth = footerFontSize; var rect = { top: pageHeight * index + top, left: defaultLeft, width: pageWidth - defaultLeft - defaultRight, height: pageHeight - top - bottom }; var headerRect = { top: rect.top, left: rect.left, width: rect.width, height: headerHeight }; var logoRect = { top: headerRect.top, left: headerRect.left, width: showLogo ? headerRect.height : 0, height: showLogo ? headerRect.height : 0, content: showLogo ? "<img src=\"./public/images/sanfu.png\"/>" : '' }; var headerTitleRect = { top: headerRect.top + (headerRect.height / 2 - 2), left: headerRect.left + logoRect.width + 5, width: headerRect.width - logoRect.width - 5, height: headerTitleHeight, content: showHeader ? headerTitle : '', itemType: 1, fontSize: headerFontSize * 3 / 4, fontFamily: headerFontFontFamily }; var headerLineRect = showHeader && showHeaderLine ? { top: headerRect.top + headerRect.height, left: rect.left, width: rect.width, height: 0 } : undefined; var codeRect = { top: headerRect.top, left: headerRect.width + headerRect.left - codeWidth, width: codeWidth, height: codeHeight, label: '', codeType: showQRCode ? 'QRCode' : 'code39', content: (showBarCode || showQRCode) ? codeValue : undefined }; var codeLabelRect = { top: headerRect.top, left: headerRect.left, width: headerRect.width - codeWidth - 1, height: 10, content: "".concat(codeLabel, ":").concat(codeValue) }; var extraTitleRect = { top: headerRect.top, left: headerRect.left + logoRect.width, width: headerRect.width - logoRect.width, height: headerRect.height, content: extraTitle }; var titleRect = { top: headerRect.top + headerRect.height + titleMarginTop + (showHeader ? 0 : 5), left: rect.left, width: rect.width, height: titleHeight, content: showTitle ? title + (subTitle ? "[".concat(subTitle, "]") : '') : '', itemType: titleAllPrint && !batched ? 1 : 0, fontSize: titleFontSize * 3 / 4, fontFamily: titleFontFamily }; var subTitleRect = { top: titleRect.top + titleRect.height + subTitleMarginTop, left: defaultLeft, width: rect.width, height: subTitleHeight }; var subTitleRect1 = { top: subTitleRect.top, left: subTitleRect.left, width: subTitleRect.width / (subTitleCount || 1), height: subTitleRect.height, content: showDynamicSubTitles ? dynamicSubTiltes[0] : undefined, itemType: subTitleAllPrint && !batched ? 1 : 0, fontSize: subTitleFontSize * 3 / 4, fontFamily: subTitleFontFamily }; var subTitleRect2 = { top: subTitleRect.top, left: subTitleCount <= 1 ? 0 : subTitleRect.left + (subTitleRect.width / subTitleCount), width: subTitleCount <= 1 ? 0 : subTitleRect.width / (subTitleCount || 1), height: subTitleRect.height, content: showDynamicSubTitles ? dynamicSubTiltes[1] : undefined, itemType: subTitleAllPrint && !batched ? 1 : 0, fontSize: subTitleFontSize * 3 / 4, fontFamily: subTitleFontFamily }; var subTitleRect3 = { top: subTitleRect.top, left: subTitleCount <= 2 ? 0 : subTitleRect.left + (subTitleRect.width / subTitleCount * (subTitleCount - 1)), width: subTitleCount <= 2 ? 0 : subTitleRect.width / (subTitleCount || 1), height: subTitleRect.height, content: showDynamicSubTitles ? dynamicSubTiltes[2] : undefined, itemType: subTitleAllPrint && !batched ? 1 : 0, fontSize: subTitleFontSize * 3 / 4, fontFamily: subTitleFontFamily }; var footerRect = { top: rect.height + rect.top - footerHeight, left: rect.left, width: rect.width, height: footerHeight > 0 ? footerHeight : 0 }; var footerLineRect = showFooter && showFooterLine ? { top: rect.height + rect.top - footerHeight - 2, left: rect.left, width: rect.width, height: 0 } : undefined; var printerRect = { top: footerRect.top, left: rect.left, width: footerRect.width * 0.3, height: showPrinter && showFooter ? footerRect.height : 0, content: showFooter && showPrinter ? "\u6253\u5370\u8005:".concat(userName) : '', itemType: 1, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var dateRect = { top: footerRect.top, left: footerRect.left + printerRect.width, width: footerRect.width * 0.4, height: showDate && showFooter ? footerRect.height : 0, content: showFooter && showDate ? "\u6253\u5370\u65F6\u95F4:".concat((0, moment_1.default)(new Date()).format('YYYY-MM-DD HH:mm:ss')) : '', itemType: 1, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var numRect = { top: footerRect.top, left: footerRect.left + printerRect.width + dateRect.width + (footerRect.width * 0.3 - pageNumWidth * 2) - 2, width: pageNumWidth, height: showFooter ? footerRect.height : 0, content: showFooter && showPageNum ? '第#页' : '', itemType: showFooter && showPageNum ? 2 : 0, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var sumRect = { top: footerRect.top, left: numRect.left + numRect.width + 1, width: pageNumWidth, height: showFooter ? footerRect.height : 0, content: showFooter && showPageNum ? '共#页' : '', itemType: showFooter && showPageNum ? 3 : 0, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var htmlRect = { top: subTitleRect.top + subTitleRect.height + htmlMarginTop, left: rect.left, width: rect.width, height: footerRect.top - (subTitleRect.top + subTitleRect.height + htmlMarginTop) - htmlMarginBottom + (showFooter ? 0 : 6), content: htmlContent, }; var divider = index > 0 ? { top: index * ((direction == 'vertical' ? height : width) / numberOfPage), left: 0, width: pageWidth, height: 0 } : undefined; return { divider: divider, header: headerRect, headerLine: headerLineRect, logo: logoRect, headerTitle: headerTitleRect, code: codeRect, codeLabel: codeLabelRect, extraTitle: extraTitleRect, title: titleRect, subTitle: subTitleRect, subTitle1: subTitleRect1, subTitle2: subTitleRect2, subTitle3: subTitleRect3, html: htmlRect, date: dateRect, printer: printerRect, footer: footerRect, footerLine: footerLineRect, num: numRect, sum: sumRect }; }; exports.buildDetailTemplate = buildDetailTemplate; var buildFormTemplate = function (settings, options) { var _a, _b; var userInfo = (_a = sessionStorage.getItem('userInfo')) !== null && _a !== void 0 ? _a : '{}'; var userObj = userInfo && JSON.parse(userInfo); var width = settings.width, height = settings.height, direction = settings.direction, defaultTop = settings.top, defaultBottom = settings.bottom, defaultLeft = settings.left, defaultRight = settings.right; var showHeaderTitle = options.showHeaderTitle, headerTitle = options.headerTitle, showHeaderLine = options.showHeaderLine, showLogo = options.showLogo, showTitle = options.showTitle, titleFontSize = options.titleFontSize, titleFontFamily = options.titleFontFamily, headerFontSize = options.headerFontSize, headerFontFamily = options.headerFontFamily, titleAllPrint = options.titleAllPrint, title = options.title, showSubTitle = options.showSubTitle, subTitleAllPrint = options.subTitleAllPrint, _c = options.subTitle, subTitle = _c === void 0 ? [] : _c, subTitleFontSize = options.subTitleFontSize, subTitleFontFamily = options.subTitleFontFamily, footerFontSize = options.footerFontSize, footerFontFamily = options.footerFontFamily, showFooterLine = options.showFooterLine, showFooterTitle = options.showFooterTitle, footerTitle = options.footerTitle, showPrinter = options.showPrinter, showDate = options.showDate, showPageNum = options.showPageNum; var pageWidth = direction == 'vertical' ? width : height; var pageHeight = direction == 'vertical' ? height : width; var headerHeight = (showLogo || showHeaderTitle || showHeaderLine) ? 18 : 0; var titleHeight = showTitle ? titleFontSize / 3 : 0; var maxSubtitleRow = Math.max.apply(Math, tslib_1.__spreadArray(tslib_1.__spreadArray([], subTitle.map(function (item) { return item.split('\r').length; }), false), [1], false)); var subTitleHeight = showSubTitle ? (subTitleFontSize / 3 * maxSubtitleRow) + (maxSubtitleRow - 1) * 0.5 : 0; var subTitleMarginTop = showSubTitle ? 3 : 0; var subTitleCount = subTitle.length; var footerHeight = footerFontSize / 3.33333; var pageNumWidth = footerFontSize; var headerRect = { top: defaultTop, left: defaultLeft, width: pageWidth - defaultLeft - defaultRight, height: headerHeight }; var headerLineRect = showHeaderLine ? { top: headerRect.top + headerRect.height + 2, left: headerRect.left, width: headerRect.width, height: 0 } : undefined; var logoRect = { top: headerRect.top, left: headerRect.left, width: showLogo ? headerRect.height : 0, height: showLogo ? headerRect.height : 0, content: showLogo ? "<img src=\"./public/images/sanfu.png\"/>" : '' }; var headerTitleRect = { top: headerRect.top + (headerRect.height / 2 - 2), left: headerRect.left + logoRect.width + 5, width: headerRect.width - logoRect.width - 5, height: titleHeight, content: showHeaderTitle ? headerTitle : '', itemType: 1, fontSize: headerFontSize * 3 / 4, fontFamily: headerFontFamily }; var footerRect = { top: pageHeight - defaultBottom - footerHeight, left: defaultLeft, width: pageWidth - defaultLeft - defaultRight, height: footerHeight }; var footerTitleRect = { top: footerRect.top - footerHeight, left: footerRect.left, width: footerRect.width, height: showFooterTitle ? footerHeight : 0, content: showFooterTitle ? footerTitle : '', itemType: 1, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var footerLineRect = showFooterLine ? { top: footerRect.top, left: footerRect.left, width: footerRect.width, height: 0 } : undefined; var printerRect = { top: footerRect.top + 2, left: footerRect.left, width: footerRect.width * 0.3, height: footerRect.height, content: showPrinter ? "\u6253\u5370\u8005:".concat((_b = userObj.user_name) !== null && _b !== void 0 ? _b : '') : '', itemType: 1, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var dateRect = { top: footerRect.top + 2, left: footerRect.left + printerRect.width, width: footerRect.width * 0.4, height: footerRect.height, content: showDate ? "\u6253\u5370\u65F6\u95F4:".concat((0, moment_1.default)(new Date()).format('YYYY-MM-DD HH:mm:ss')) : '', itemType: 1, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var numRect = { top: footerRect.top + 2, left: footerRect.left + printerRect.width + dateRect.width + (footerRect.width * 0.3 - pageNumWidth * 2) - 2, width: pageNumWidth, height: footerRect.height, content: showPageNum ? '第#页' : '', itemType: showPageNum ? 2 : 0, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var sumRect = { top: footerRect.top + 2, left: numRect.left + numRect.width + 1, width: pageNumWidth, height: footerRect.height, content: showPageNum ? '共#页' : '', itemType: showPageNum ? 3 : 0, fontSize: footerFontSize * 3 / 4, fontFamily: footerFontFamily }; var bodyRect = { top: 5 + headerRect.top + headerRect.height, left: defaultLeft, width: pageWidth - defaultLeft - defaultRight, height: pageHeight - (headerRect.top + headerRect.height + 3) - (footerRect.height + defaultBottom + 3) - (showFooterTitle ? footerHeight : 0) }; var titleRect = { top: bodyRect.top, left: bodyRect.left, width: bodyRect.width, height: titleHeight, content: showTitle ? title : '', itemType: titleAllPrint ? 1 : 0, fontSize: titleFontSize * 3 / 4, fontFamily: titleFontFamily, }; var subTitleRect = { top: titleRect.top + titleRect.height + subTitleMarginTop, left: bodyRect.left, width: bodyRect.width, height: subTitleHeight }; var subTitleRect1 = { top: subTitleRect.top, left: subTitleRect.left, width: subTitleRect.width / (subTitleCount || 1), height: subTitleCount > 0 ? subTitleRect.height : 0, content: showSubTitle ? subTitle[0] : undefined, itemType: subTitleAllPrint ? 1 : 0, fontSize: subTitleFontSize * 3 / 4, fontFamily: subTitleFontFamily }; var subTitleRect2 = { top: subTitleRect.top, left: subTitleCount <= 1 ? 0 : subTitleRect.left + (subTitleRect.width / subTitleCount), width: subTitleCount <= 1 ? 0 : subTitleRect.width / (subTitleCount || 1), height: subTitleCount > 0 ? subTitleRect.height : 0, content: showSubTitle ? subTitle[1] : undefined, itemType: subTitleAllPrint ? 1 : 0, fontSize: subTitleFontSize * 3 / 4, fontFamily: subTitleFontFamily }; var subTitleRect3 = { top: subTitleRect.top, left: subTitleCount <= 2 ? 0 : subTitleRect.left + (subTitleRect.width / subTitleCount * (subTitleCount - 1)), width: subTitleCount <= 2 ? 0 : subTitleRect.width / (subTitleCount || 1), height: subTitleCount > 0 ? subTitleRect.height : 0, content: showSubTitle ? subTitle[2] : undefined, itemType: subTitleAllPrint ? 1 : 0, fontSize: subTitleFontSize * 3 / 4, fontFamily: subTitleFontFamily }; var tableRect = { top: subTitleRect.top + subTitleRect1.height + 3, left: bodyRect.left, width: bodyRect.width, height: bodyRect.height - titleRect.height - subTitleRect.height - subTitleMarginTop - 9 }; return { header: headerRect, logo: logoRect, headerLine: headerLineRect, headerTitle: headerTitleRect, body: bodyRect, title: titleRect, subTitle: subTitleRect, subTitle1: subTitleRect1, subTitle2: subTitleRect2, subTitle3: subTitleRect3, table: tableRect, footer: footerRect, footerLine: footerLineRect, footerTitle: footerTitleRect, printer: printerRect, date: dateRect, num: numRect, sum: sumRect }; }; exports.buildFormTemplate = buildFormTemplate; // 计算每行放的个最大数 var getMaxCount = function (templateWidth, pageWidth, spacing) { var count = 1; while ((count * templateWidth + (count - 1) * spacing) <= pageWidth) { count++; if (count > 50) { break; } } return (count - 1) || 1; }; exports.getMaxCount = getMaxCount; // 解析base64内容构造标签模板 var buildLabelTemplate = function (templateContent) { var _a, _b, _c; var getParams = function (dataStr) { var start = dataStr.indexOf('(') + 1; var end = dataStr.lastIndexOf(')'); var str = dataStr.substring(start, end); var params = str.split(','); return params.map(function (value) { var left = value.startsWith('"') ? value.substring(1) : value; var right = left.endsWith('"') ? left.substring(0, left.length - 1) : left; return right.replaceAll('\\"', '"').replaceAll('\\r', '').replaceAll('\\n', ''); }); }; var getStyleParams = function (dataStr) { var isNumber = function (value) { return /^[0-9]+.?[0-9]*/.test(value); }; var params = getParams(dataStr); var id = isNumber(params[0]) ? Number(params[0]) : params[0]; var name = params[1]; var value = isNumber(params[2]) ? Number(params[2]) : params[2]; return [id, name, value]; }; var labelTemplate = { tempTop: new type_1.LabelNumber(0, 297), tempLeft: new type_1.LabelNumber(0, 210), tempWidth: new type_1.LabelNumber(0, 210), tempHeight: new type_1.LabelNumber(0, 297), labelTexts: [], labelHtmls: [], labelImages: [], labelTables: [], labelBarCodes: [], labelRects: [], labelEllipses: [], labelShapes: [], labelLines: [] }; var value = (0, js_base64_1.decode)(templateContent); var tempDatas = value.split('LODOP'); var exprs = [type_1.LabelCodeType.ADD_RECT, type_1.LabelCodeType.ADD_ELLIPSE, type_1.LabelCodeType.ADD_LINE]; var initData = tempDatas.find(function (data) { return data.includes(type_1.LabelCodeType.INITA); }); var initParams = getParams(initData); var tempWidth = new type_1.LabelNumber(initParams[2]); var tempHeight = new type_1.LabelNumber(initParams[3]); labelTemplate.tempTop = new type_1.LabelNumber(initParams[0]); labelTemplate.tempLeft = new type_1.LabelNumber(initParams[1]); labelTemplate.tempWidth = tempWidth; labelTemplate.tempHeight = tempHeight; var _loop_1 = function (i) { var data = tempDatas[i]; var j = i + 1; var params = getParams(data); // 添加文本 if (data.includes(type_1.LabelCodeType.ADD_TEXT)) { var styles = []; while (tempDatas[j] && tempDatas[j].includes(type_1.LabelCodeType.SET_STYLE)) { var param = getStyleParams(tempDatas[j]); styles.push(param); j++; } var labelText = data.includes(type_1.LabelCodeType.ADD_TEXTA) ? { fieldName: params[0], top: new type_1.LabelNumber(params[1], tempHeight.number), left: new type_1.LabelNumber(params[2], tempWidth.number), width: new type_1.LabelNumber(params[3], tempWidth.number), height: new type_1.LabelNumber(params[4], tempHeight.number), content: params[5], styles: styles } : { top: new type_1.LabelNumber(params[0], tempHeight.number), left: new type_1.LabelNumber(params[1], tempWidth.number), width: new type_1.LabelNumber(params[2], tempWidth.number), height: new type_1.LabelNumber(params[3], tempHeight.number), content: params[4], styles: styles }; labelTemplate.labelTexts.push(labelText); } // 添加富文本和图片 if (data.includes(type_1.LabelCodeType.ADD_HTML)) { var styles = []; while (tempDatas[j] && tempDatas[j].includes(type_1.LabelCodeType.SET_STYLE)) { var param = getStyleParams(tempDatas[j]); styles.push(param); j++; } var fieldName = (_a = styles.find(function (_a) { var _id = _a[0], name = _a[1]; return name === 'ItemName'; })) === null || _a === void 0 ? void 0 : _a[2]; var labelHtml = { top: new type_1.LabelNumber(params[0], tempHeight.number), left: new type_1.LabelNumber(params[1], tempWidth.number), width: new type_1.LabelNumber(params[2], tempWidth.number), height: new type_1.LabelNumber(params[3], tempHeight.number), content: params[4], fieldName: fieldName, styles: styles }; labelTemplate.labelHtmls.push(labelHtml); } // 添加图片 if (data.includes(type_1.LabelCodeType.ADD_IMAGE)) { var styles = []; while (tempDatas[j] && tempDatas[j].includes(type_1.LabelCodeType.SET_STYLE)) { var param = getStyleParams(tempDatas[j]); styles.push(param); j++; } var fieldName = (_b = styles.find(function (_a) { var _id = _a[0], name = _a[1]; return name === 'ItemName'; })) === null || _b === void 0 ? void 0 : _b[2]; var labelImage = { top: new type_1.LabelNumber(params[0], tempHeight.number), left: new type_1.LabelNumber(params[1], tempWidth.number), width: new type_1.LabelNumber(params[2], tempWidth.number), height: new type_1.LabelNumber(params[3], tempHeight.number), url: params.slice(4).join(), fieldName: fieldName, styles: styles }; labelTemplate.labelImages.push(labelImage); } // 添加表格 if (data.includes(type_1.LabelCodeType.ADD_TABLE)) { var styles = []; while (tempDatas[j] && tempDatas[j].includes(type_1.LabelCodeType.SET_STYLE)) { var param = getStyleParams(tempDatas[j]); styles.push(param); j++; } var fieldName = (_c = styles.find(function (_a) { var _id = _a[0], name = _a[1]; return name === 'ItemName'; })) === null || _c === void 0 ? void 0 : _c[2]; var labelTable = { top: new type_1.LabelNumber(params[0], tempHeight.number), left: new type_1.LabelNumber(params[1], tempWidth.number), width: new type_1.LabelNumber(params[2], tempWidth.number), height: new type_1.LabelNumber(params[3], tempHeight.number), content: params.slice(4).join(), fieldName: fieldName, styles: styles }; labelTemplate.labelTables.push(labelTable); } // 添加条码 if (data.includes(type_1.LabelCodeType.ADD_BARCODE)) { var styles = []; while (tempDatas[j] && tempDatas[j].includes(type_1.LabelCodeType.SET_STYLE)) { var param = getStyleParams(tempDatas[j]); styles.push(param); j++; } var labelBarCode = data.includes(type_1.LabelCodeType.ADD_BARCODEA) ? { fieldName: params[0], top: new type_1.LabelNumber(params[1], tempHeight.number), left: new type_1.LabelNumber(params[2], tempWidth.number), width: new type_1.LabelNumber(params[3], tempWidth.number), height: new type_1.LabelNumber(params[4], tempHeight.number), codeType: params[5], codeValue: params[6], styles: styles } : { top: new type_1.LabelNumber(params[0], tempHeight.number), left: new type_1.LabelNumber(params[1], tempWidth.number), width: new type_1.LabelNumber(params[2], tempWidth.number), height: new type_1.LabelNumber(params[3], tempHeight.number), codeType: params[4], codeValue: params[5], styles: styles }; labelTemplate.labelBarCodes.push(labelBarCode); } // 添加其它图形 if (data.includes(type_1.LabelCodeType.ADD_SHAPE)) { var labelShape = { shapeType: Number(params[0]), top: new type_1.LabelNumber(params[1], tempHeight.number), left: new type_1.LabelNumber(params[2], tempWidth.number), width: new type_1.LabelNumber(params[3], tempWidth.number), height: new type_1.LabelNumber(params[4], tempHeight.number), lineStyle: Number(params[5]), lineWidth: Number(params[6]), fillColor: params[7] }; labelTemplate.labelShapes.push(labelShape); } // 添加图形 var expr = exprs.find(function (expr) { return data.includes(expr); }); if (expr) { var label = { top: new type_1.LabelNumber(params[0], tempHeight.number), left: new type_1.LabelNumber(params[1], tempWidth.number), width: new type_1.LabelNumber(params[2], tempWidth.number), height: new type_1.LabelNumber(params[3], tempHeight.number), lineStyle: Number(params[4]), lineWidth: Number(params[5]) }; switch (expr) { case type_1.LabelCodeType.ADD_RECT: labelTemplate.labelRects.push(label); break; case type_1.LabelCodeType.ADD_ELLIPSE: labelTemplate.labelEllipses.push(label); break; case type_1.LabelCodeType.ADD_LINE: labelTemplate.labelLines.push(label); break; default: break; } } }; for (var i = 0; i < tempDatas.length; i++) { _loop_1(i); } return labelTemplate; }; exports.buildLabelTemplate = buildLabelTemplate; // 设置模板内标签的数据,一页放一个模板 var setLabelTemplateData = function (labelTemplate, printData, baseUrl, tableColumn) { var labelTexts = labelTemplate.labelTexts, labelHtmls = labelTemplate.labelHtmls, labelImages = labelTemplate.labelImages, labelBarCodes = labelTemplate.labelBarCodes, labelTables = labelTemplate.labelTables; var labelDatas = []; var _loop_2 = function (i) { var tempTexts = []; var tempHtmls = []; var tempImages = []; var tempTables = []; var tempBarCodes = []; var labelData = printData[i]; var fields = Object.keys(labelData); labelTexts.forEach(function (text) { var content = text.content; var field = fields.find(function (field) { return field === text.fieldName; }); if (field) { var data = labelData[field]; if (data) { if (content.includes("[".concat(field, "]"))) { content = content.replaceAll("[".concat(field, "]"), data); } else { content = data; } } } tempTexts.push(tslib_1.__assign(tslib_1.__assign({}, text), { content: content })); }); labelHtmls.forEach(function (html) { var content = html.content; var field = fields.find(function (field) { return field === html.fieldName; }); if (field) { var data = labelData[field]; if (data) { var info = data.info; if (info) { var url = baseUrl ? (baseUrl + info[0].addr) : info[0].addr; content = "<img style=\"width:100%\" src=".concat(url, " alt=\"\" />"); } else if (typeof data === 'string') { content = data.replaceAll('text-decoration-line', 'text-decoration'); } else { content = data; } } } tempHtmls.push(tslib_1.__assign(tslib_1.__assign({}, html), { content: content })); }); labelImages.forEach(function (image) { var url = image.url; var field = fields.find(function (field) { return field === image.fieldName; }); if (field) { var data = labelData[field]; if (data) { url = "<img style=\"width:100%\" src=".concat(data, " alt=\"\" />"); } } tempImages.push(tslib_1.__assign(tslib_1.__assign({}, image), { url: url })); }); labelTables.forEach(function (table) { var content = table.content; var field = fields.find(function (field) { return field === table.fieldName; }); if (field) { var data = labelData[field]; if (typeof data !== 'string' && tableColumn) { content = buildTableData(tableColumn[field], data); } } tempTables.push(tslib_1.__assign(tslib_1.__assign({}, table), { content: content })); }); labelBarCodes.forEach(function (barCode) { var codeValue = barCode.codeValue; var field = fields.find(function (field) { return field === barCode.fieldName; }); if (field) { var data = labelData[field]; if (data) { codeValue = data; } } tempBarCodes.push(tslib_1.__assign(tslib_1.__assign({}, barCode), { codeValue: codeValue })); }); labelDatas.push([ tslib_1.__assign(tslib_1.__assign({}, labelTemplate), { labelTexts: tempTexts, labelHtmls: tempHtmls, labelTables: tempTables, labelBarCodes: tempBarCodes }) ]); }; for (var i = 0; i < printData.length; i++) { _loop_2(i); } return labelDatas; }; exports.setLabelTemplateData = setLabelTemplateData; // 设置模板内标签的数据,一页放多个模板 var setLabelTemplateDataWithArrange = function (labelTemplate, printData, printerParam, countOfPage, countOfColumn, baseUrl) { var labelCount = printData.length; var tempWidth = labelTemplate.tempWidth, tempHeight = labelTemplate.tempHeight, labelTexts = labelTemplate.labelTexts, labelHtmls = labelTemplate.labelHtmls, labelImages = labelTemplate.labelImages, labelBarCodes = labelTemplate.labelBarCodes, labelRects = labelTemplate.labelRects, labelEllipses = labelTemplate.labelEllipses, labelLines = labelTemplate.labelLines, labelShapes = labelTemplate.labelShapes; var colSpacing = printerParam.colSpacing, rowSpacing = printerParam.rowSpacing; var pageParams = []; var _loop_3 = function (i) { var labelData = printData[i]; var tempTexts = []; var tempHtmls = []; var tempImages = []; var tempBarCodes = []; var tempShapes = []; var tempRects = []; var tempEllipses = []; var tempLines = []; var pageIndex = Math.floor(i / countOfPage); var column = i % countOfColumn; var row = Math.floor(i % countOfPage / countOfColumn); var left = tempWidth.number * column + column * colSpacing; var top = tempHeight.number * row + row * rowSpacing; var fields = Object.keys(labelData); labelTexts.forEach(function (text) { var content = text.content; var field = fields.find(function (field) { return field === text.fieldName; }); if (field) { var data = labelData[field]; if (data) { if (content.includes("[".concat(field, "]"))) { content = content.replaceAll("[".concat(field, "]"), data); } else { content = data; } } } var textLeft = new type_1.LabelNumber(left + text.left.number); var textTop = new type_1.LabelNumber(top + text.top.number); tempTexts.push(tslib_1.__assign(tslib_1.__assign({}, text), { content: content, left: textLeft, top: textTop })); }); labelHtmls.forEach(function (html) { var content = html.content; var field = fields.find(function (field) { return field === html.fieldName; }); if (field) { var data = labelData[field]; if (data) { var info = data.info; if (info) { var url = baseUrl ? (baseUrl + info[0].addr) : info[0].addr; content = "<img style=\"width:100%\" src=".concat(url, " alt=\"\" />"); } else if (typeof data === 'string') { content = data.replaceAll('text-decoration-line', 'text-decoration'); } else { content = data; } } } var htmlLeft = new type_1.LabelNumber(left + html.left.number); var htmlTop = new type_1.LabelNumber(top + html.top.number); tempHtmls.push(tslib_1.__assign(tslib_1.__assign({}, html), { content: content, left: htmlLeft, top: htmlTop })); }); labelImages.forEach(function (image) { var url = image.url; var field = fields.find(function (field) { return field === image.fieldName; }); if (field) { var data = labelData[field]; if (url) { url = "<img style=\"width:100%\" src=".concat(data, " alt=\"\" />"); } } var imageLeft = new type_1.LabelNumber(left + image.left.number); var imageTop = new type_1.LabelNumber(top + image.top.number); tempImages.push(tslib_1.__assign(tslib_1.__assign({}, image), { url: url, left: imageLeft, top: imageTop })); }); labelBarCodes.forEach(function (barCode) { var codeValue = barCode.codeValue; var field = fields.find(function (field) { return field === barCode.fieldName; }); if (field) { var data = labelData[field]; if (data) { codeValue = data; } } var barCodeLeft = new type_1.LabelNumber(left + barCode.left.number); var barCodeTop = new type_1.LabelNumber(top + barCode.top.number); tempBarCodes.push(tslib_1.__assign(tslib_1.__assign({}, barCode), { codeValue: codeValue, left: barCodeLeft, top: barCodeTop })); }); labelShapes.forEach(function (shape) { var shapeLeft = new type_1.LabelNumber(left + shape.left.number); var shapeTop = new type_1.LabelNumber(top + shape.top.number); tempShapes.push(tslib_1.__assign(tslib_1.__assign({}, shape), { left: shapeLeft, top: shapeTop })); }); labelEllipses.forEach(function (ellipse) { var ellipseLeft = new type_1.LabelNumber(left + ellipse.left.number); var ellipseTop = new type_1.LabelNumber(top + ellipse.top.number); tempEllipses.push(tslib_1.__assign(tslib_1.__assign({}, ellipse), { left: ellipseLeft, top: ellipseTop })); }); labelRects.forEach(function (rect) { var rectLeft = new type_1.LabelNumber(left + rect.left.number); var rectTop = new type_1.LabelNumber(top + rect.top.number); tempRects.push(tslib_1.__assign(tslib_1.__assign({}, rect), { left: rectLeft, top: rectTop })); }); labelLines.forEach(function (line) { var lineLeft = new type_1.LabelNumber(left + line.left.number); var lineTop = new type_1.LabelNumber(top + line.top.number); tempLines.push(tslib_1.__assign(tslib_1.__assign({}, line), { left: lineLeft, top: lineTop })); }); pageParams.push([pageIndex, tslib_1.__assign(tslib_1.__assign({}, labelTemplate), { tempTop: new type_1.LabelNumber(top), tempLeft: new type_1.LabelNumber(left), labelTexts: tempTexts, labelHtmls: tempHtmls, labelBarCodes: tempBarCodes, labelShapes: tempShapes, labelEllipses: tempEllipses, labelRects: tempRects, labelLines: tempLines })]); }; for (var i = 0; i < labelCount; i++) { _loop_3(i); } var pageIndexs = Array.from(new Set(pageParams.map(function (rect) { return rect[0]; }))); var labelDatas = []; for (var i = 0; i < pageIndexs.length; i++) { var pageIndex = pageIndexs[i]; var tempDatas = []; for (var j = 0; j < pageParams.length; j++) { var pageParam = pageParams[j]; var pageTemplate = pageParam[1]; if (pageParam[0] === pageIndex) { tempDatas.push(pageTemplate); } } labelDatas.push(tempDatas); } return labelDatas; }; exports.setLabelTemplateDataWithArrange = setLabelTemplateDataWithArrange; var buildTableData = function (columnInfo, rowDatas) { var _a, _b, _c; var columns = columnInfo.columns, statistics = columnInfo.statistics; columns.forEach(function (column) { var stastic = statistics === null || statistics === void 0 ? void 0 : statistics.find(function (stastic) { return stastic.field === column.name; }); column.statistics = stastic === null || stastic === void 0 ? void 0 : stastic.property; }); var div = document.createElement('div'); var table = document.createElement('table'); table.setAttribute('border', '1'); table.setAttribute('cellSpacing', '0'); table.setAttribute('width', '100%'); table.setAttribute('style', 'border-collapse:collapse'); table.setAttribute('bordercolor', '#333333'); var thead = document.createElement('thead'); var tr = document.createElement('tr'); for (var i = 0; i < columns.length; i++) { var th = document.createElement('th'); var column = columns[i]; th.textContent = column.label; tr.appendChild(th); } thead.appendChild(tr); table.appendChild(thead); var tbody = document.createElement('tbody'); for (var i = 0; i < rowDatas.length; i++) { var row = rowDatas[i]; var tr_1 = document.createElement('tr'); for (var j = 0; j < columns.length; j++) { var td = document.createElement('td'); var column = columns[j]; td.textContent = row[column.name]; tr_1.appendChild(td); } tbody.appendChild(tr_1); } table.appendChild(tbody); if (statistics) { var tfoot = document.createElement('tfoot'); var maxRow = (_b = (_a = statistics.map(function (item) { return item.property.length; }).sort(function (a, b) { return b - a; })) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 0; for (var i = 0; i < maxRow; i++) { var tr_2 = document.createElement('tr'); for (var j = 0; j < columns.length; j++) { var column = columns[j]; var statistic = (_c = column.statistics) === null || _c === void 0 ? void 0 : _c[i]; var td = document.createElement('td'); if (statistic) { td.textContent = statistic.label; td.setAttribute('format', statistic.format); td.setAttribute('tdata', statistic.tdata); } tr_2.appendChild(td); } tfoot.appendChild(tr_2); } table.appendChild(tfoot); } div.appendChild(table); return div.innerHTML; }; //# sourceMappingURL=./utils/print/util.js.map