wui-print
Version:
前端打印插件,包含打印设计器、打印表单、打印API
112 lines (111 loc) • 4.15 kB
JavaScript
import { deepCopy } from "../../print-designer-utils";
import printDesignerStyleHelper from "../../print-designer-style-helper";
import complexTableTools from "./complex-table-tools";
const getHeaderCellHtml = ({ rowIndex, colIndex, spanHeaderCellList, complexTableDetails } = {}) => {
let cellShow = complexTableTools.getHeaderCellShow({ rowIndex, colIndex, spanHeaderCellList });
let headerCellHtml = "";
if (!cellShow) {
return "";
}
let headerLayout = complexTableDetails.headerLayout;
let propsConfig = complexTableDetails.props;
let styleConfig = complexTableDetails.style;
let headerRules = complexTableDetails.headerRules;
let headerRulesId = printDesignerStyleHelper.getComplexTableHeaderRulesId({
rowIndex,
colIndex
});
let tdPropsConfig = {};
let tdStyleConfig = {};
if (!!headerRules && !!headerRules[headerRulesId]) {
tdPropsConfig = headerRules[headerRulesId].props;
tdStyleConfig = headerRules[headerRulesId].style;
}
if (!!tdPropsConfig.slash) {
// 有斜线
headerCellHtml = `<td rowspan="${complexTableTools.getRowspan({
rowIndex,
colIndex,
headerLayout
})}" colspan="${complexTableTools.getColspan({
rowIndex,
colIndex,
headerLayout
})}" style="${printDesignerStyleHelper.createComplexTableHeaderTdStyle({
complexTablePropsConfig: propsConfig,
complexTableStyleConfig: styleConfig,
tdPropsConfig,
tdStyleConfig
})}">${_createHeaderCellSlashHtml({
complexTableId: complexTableDetails.id,
rowIndex,
colIndex,
complexTableStyleConfig: complexTableDetails.style,
tdPropsConfig
})}</td>`;
} else {
// 无斜线
headerCellHtml = `<td rowspan="${complexTableTools.getRowspan({
rowIndex,
colIndex,
headerLayout
})}" colspan="${complexTableTools.getColspan({
rowIndex,
colIndex,
headerLayout
})}" style="${printDesignerStyleHelper.createComplexTableHeaderTdStyle({
complexTablePropsConfig: propsConfig,
complexTableStyleConfig: styleConfig,
tdPropsConfig,
tdStyleConfig
})}"><div style="${printDesignerStyleHelper.createComplexTableHeaderTdContainerStyle({
complexTablePropsConfig: propsConfig,
complexTableStyleConfig: styleConfig,
tdPropsConfig,
tdStyleConfig
})}">${_createHeaderTdText({ rowIndex, colIndex, complexTableDetails })}</div></td>`;
}
return headerCellHtml;
};
function _createHeaderTdText({ rowIndex, colIndex, complexTableDetails } = {}) {
let headerRules = complexTableDetails.headerRules;
let headerRulesId = printDesignerStyleHelper.getComplexTableHeaderRulesId({
rowIndex,
colIndex
});
let tdPropsConfig = false;
if (!!headerRules && !!headerRules[headerRulesId]) {
tdPropsConfig = headerRules[headerRulesId].props;
}
if (!!tdPropsConfig) {
return tdPropsConfig.title;
}
return "";
}
function _createHeaderCellSlashHtml({ complexTableId, rowIndex, colIndex, complexTableStyleConfig, tdPropsConfig } = {}) {
let slashContainerHtml = "";
let slashHtml = "";
let slashTextLeftHtml = "";
let slashTexRightHtml = "";
let slashTexLeft = "";
let slashTexRight = "";
if (!!tdPropsConfig && !!tdPropsConfig.slashTextLeft) {
slashTexLeft = tdPropsConfig.slashTextLeft;
}
if (!!tdPropsConfig && !!tdPropsConfig.slashTextRight) {
slashTexRight = tdPropsConfig.slashTextRight;
}
slashHtml = `<div class="_p-c-t_td-slash_slash"></div>`;
slashTextLeftHtml = `<div class="_p-c-t_td-slash_left">${slashTexLeft}</div>`;
slashTexRightHtml = `<div class="_p-c-t_td-slash_right">${slashTexRight}</div>`;
slashContainerHtml = `<div name="${complexTableId}_header_${complexTableTools.getHeaderCellId({
rowIndex,
colIndex
})}_slash" class="print-complex-table_td-slash print-complex-table_td-slash--${
tdPropsConfig.slashDirection
}">${slashTextLeftHtml}${slashHtml}${slashTexRightHtml}</div>`;
return slashContainerHtml;
}
export default {
getHeaderCellHtml
};