UNPKG

wui-print

Version:

前端打印插件,包含打印设计器、打印表单、打印API

97 lines (96 loc) 3.58 kB
import printGlobalStyle from "./print-global-style/index.js"; import { camelToKebab } from "./print-designer-utils"; import createBaseComponentStyle from "./create-style/create-base-component-style.js"; import createTableStyle from "./create-style/create-table-style.js"; import createComplexTableStyle from "./create-style/create-complex-table-style.js"; import createFormComponentStyle from "./create-style/create-form-component-style.js"; import createFormItemStyle from "./create-style/create-form-item-style.js"; import createGridStyle from "./create-style/create-grid-style.js"; import createTableLayoutStyle from "./create-style/create-table-layout-style.js"; export const createPrintStyle = ({ printConfig } = {}) => { if (!printConfig) { printConfig = {}; } let printStyleConfig = !!printConfig.style ? printConfig.style : {}; let styleText = `:root { --wui-printing-background: ${printStyleConfig.backgroundColor}; --wui-printing-page-padding-top: ${!!printStyleConfig.paddingTop ? printStyleConfig.paddingTop : "0px"}; --wui-printing-page-padding-bottom: ${!!printStyleConfig.paddingBottom ? printStyleConfig.paddingBottom : "0px"}; --wui-printing-page-padding-left: ${!!printStyleConfig.paddingLeft ? printStyleConfig.paddingLeft : "0px"}; --wui-printing-page-padding-right: ${!!printStyleConfig.paddingRight ? printStyleConfig.paddingRight : "0px"}; }`; let printSize = printConfig.pageSize; if (!!printConfig.landscape) { printSize += " landscape"; } let printStyleText = `@media print { @page { size:${printSize} } }`; styleText += printGlobalStyle; styleText += printStyleText; return styleText; }; export const createPageSizeStyle = ({ printConfig } = {}) => { if (!printConfig) { printConfig = {}; } let styleObj = {}; let styleText = ""; if (printConfig.pageSize == "custom") { let customHeight = !!printConfig.customHeight ? printConfig.customHeight : 0; let customWidth = !!printConfig.customWidth ? printConfig.customWidth : 0; styleObj.minHeight = customHeight + "mm"; styleObj.width = customWidth + "mm"; } Object.keys(styleObj).forEach((key, index) => { styleText += `${camelToKebab(key)}:${styleObj[key]};`; }); return styleText; }; export const createContainerStyle = ({ styleConfig } = {}) => { if (!styleConfig) { styleConfig = {}; } let styleObj = {}; let styleText = ""; Object.keys(styleConfig).forEach((key, index) => { if (!!styleConfig[key] || styleConfig[key] === 0) { styleObj[key] = styleConfig[key]; } }); Object.keys(styleObj).forEach((key, index) => { styleText += `${camelToKebab(key)}:${styleObj[key]};`; }); return styleText; }; export const createContainerScaleStyle = ({ printConfig } = {}) => { if (!printConfig) { printConfig = {}; } if (!printConfig.previewScale) { return ""; } let styleObj = {}; let styleText = ""; styleObj.transform = `scale(${printConfig.previewScale})`; styleObj.transformOrigin = "0 0"; Object.keys(styleObj).forEach((key, index) => { styleText += `${camelToKebab(key)}:${styleObj[key]};`; }); return styleText; }; export default { createPrintStyle, createPageSizeStyle, createContainerStyle, createContainerScaleStyle, ...createBaseComponentStyle, ...createTableStyle, ...createComplexTableStyle, ...createFormComponentStyle, ...createFormItemStyle, ...createGridStyle, ...createTableLayoutStyle };