UNPKG

yuang-framework-ui-pc

Version:

yuang-framework-ui-pc Library

93 lines (92 loc) 3.08 kB
import { defineComponent, computed, resolveComponent, createElementBlock, openBlock, normalizeClass, normalizeStyle, createVNode, normalizeProps, guardReactiveProps } from "vue"; import { CellRender } from "../../ele-virtual-table/util"; const _sfc_main = defineComponent({ name: "ToolPrintHeaderCell", components: { CellRender }, props: { /** 列数据 */ col: { type: Object, required: true }, /** 列索引 */ columnIndex: Number, /** 单元格样式 */ headerCellStyle: [Object, Function], /** 单元格类名自定义 */ headerCellClass: [String, Function] }, setup(props, { slots }) { const renderOpt = computed(() => { const { text, column } = props.col; const params = [{ column, $index: props.columnIndex }]; const slotName = column ? column.printHeaderSlot || column.headerSlot : void 0; if (column && slotName && typeof slots[slotName] === "function") { return { render: slots[slotName], params }; } return { render: () => text, params }; }); const cellParam = computed(() => { return { column: props.col.column, columnIndex: props.columnIndex, rowIndex: props.col.index }; }); const cellStyle = computed(() => { if (typeof props.headerCellStyle === "function") { if (cellParam.value.column == null) { return; } return props.headerCellStyle(cellParam.value); } return props.headerCellStyle; }); const cellClass = computed(() => { const classes = []; const column = cellParam.value.column; if (column) { const align = column.headerAlign || column.align; if (align) { classes.push("is-align-" + align); } if (typeof props.headerCellClass === "function") { const temp = props.headerCellClass(cellParam.value); if (temp) { classes.push(temp); } } else if (props.headerCellClass) { classes.push(props.headerCellClass); } if (column.labelClassName) { classes.push(column.labelClassName); } } return classes.join(" "); }); return { renderOpt, cellStyle, cellClass }; } }); const _export_sfc = (sfc, props) => { const target = sfc.__vccOpts || sfc; for (const [key, val] of props) { target[key] = val; } return target; }; const _hoisted_1 = ["colspan", "rowspan"]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { const _component_CellRender = resolveComponent("CellRender"); return openBlock(), createElementBlock("th", { colspan: _ctx.col.colspan, rowspan: _ctx.col.rowspan, style: normalizeStyle(_ctx.cellStyle), class: normalizeClass(_ctx.cellClass) }, [ createVNode(_component_CellRender, normalizeProps(guardReactiveProps(_ctx.renderOpt)), null, 16) ], 14, _hoisted_1); } const toolPrintHeaderCell = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { toolPrintHeaderCell as default };