UNPKG

wui-print

Version:

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

94 lines (93 loc) 2.91 kB
import { camelToKebab } from "../print-designer-utils"; const createTableStyle = ({ styleConfig } = {}) => { if (!styleConfig) { styleConfig = {}; } let styleText = ""; Object.keys(styleConfig).forEach((key, index) => { if (key.indexOf("_") >= 0) { return false; } if (!!styleConfig[key] || styleConfig[key] === 0) { styleText += `${camelToKebab(key)}:${styleConfig[key]};`; } }); return styleText; }; const createTableHeaderStyle = ({ tableStyleConfig, columnStyleConfig } = {}) => { if (!tableStyleConfig) { tableStyleConfig = {}; } if (!columnStyleConfig) { columnStyleConfig = {}; } let styleText = ""; let styleObj = {}; styleObj.width = columnStyleConfig.width; Object.keys(tableStyleConfig).forEach((key, index) => { if (key.indexOf("header_") < 0) { return false; } let newKey = key.replace("header_", ""); if (!!tableStyleConfig[key] || tableStyleConfig[key] === 0) { styleObj[newKey] = tableStyleConfig[key]; } }); Object.keys(columnStyleConfig).forEach((key, index) => { if (key.indexOf("header_") < 0) { return false; } let newKey = key.replace("header_", ""); if (!!columnStyleConfig[newKey] || columnStyleConfig[newKey] === 0) { styleObj[newKey] = columnStyleConfig[newKey]; } if (!!columnStyleConfig[key] || columnStyleConfig[key] === 0) { styleObj[newKey] = columnStyleConfig[key]; } }); Object.keys(styleObj).forEach((key, index) => { styleText += `${camelToKebab(key)}:${styleObj[key]};`; }); return styleText; }; const createTableCellStyle = ({ tableStyleConfig, columnStyleConfig } = {}) => { if (!tableStyleConfig) { tableStyleConfig = {}; } if (!columnStyleConfig) { columnStyleConfig = {}; } let styleText = ""; let styleObj = {}; styleObj.width = columnStyleConfig.width; Object.keys(tableStyleConfig).forEach((key, index) => { if (key.indexOf("cell_") < 0) { return false; } let newKey = key.replace("cell_", ""); if (!!tableStyleConfig[key] || tableStyleConfig[key] === 0) { styleObj[newKey] = tableStyleConfig[key]; } }); Object.keys(columnStyleConfig).forEach((key, index) => { if (key.indexOf("cell_") < 0) { return false; } let newKey = key.replace("cell_", ""); if (!!columnStyleConfig[newKey] || columnStyleConfig[newKey] === 0) { styleObj[newKey] = columnStyleConfig[newKey]; } if (!!columnStyleConfig[key] || columnStyleConfig[key] === 0) { styleObj[newKey] = columnStyleConfig[key]; } }); Object.keys(styleObj).forEach((key, index) => { styleText += `${camelToKebab(key)}:${styleObj[key]};`; }); return styleText; }; export default { createTableStyle, createTableHeaderStyle, createTableCellStyle };