UNPKG

comic-plus

Version:

<p align="center"> <img width="200px" src="./logo.png"/> </p>

80 lines (79 loc) 2.58 kB
import { defineComponent, inject, h } from "vue"; import { TABLE_PROVIDE } from "../type.mjs"; import { CuCheckbox } from "../../../checkbox/index.mjs"; import TableColgroup from "../components/table-colgroup.mjs"; import "../../../../utils/config.mjs"; import { isFunction } from "../../../../utils/typescript.mjs"; import "@vueuse/core"; const TableHeader = defineComponent({ name: "TableHeader", setup() { const { props, columns, isAllSelected, indeterminate, getFixedIndex, selectAll, getCellClass } = inject(TABLE_PROVIDE); const helpRender = (col) => { const type = col.props.type; if (type === "selection") { return h(CuCheckbox, { modelValue: isAllSelected.value, indeterminate: indeterminate.value, onChange: selectAll }); } else if (type === "index") { return col.props.label; } else if (type === "default") { return col.header ? col.header({ column: "内容待定" }) : col.props.label; } }; return () => { return h( "div", { class: "cu-table__header" }, h( "table", { cellspacing: 0, cellpadding: 0 }, [ h(TableColgroup), h( "thead", h( "tr", { class: ["cu-table__row", props.headerRowClass], style: props.headerRowStyle }, [ columns.value.map((col, colIdx) => { return h( "th", { key: col.uid, class: [ "cu-table__th", col.fixed ? "fixed-" + col.fixed : void 0, { "fixed-shadow-left": getFixedIndex.value.left == colIdx }, { "fixed-shadow-right": getFixedIndex.value.right == colIdx }, isFunction(props.headerCellClass) ? props.headerCellClass({ col, colIndex: colIdx }) : props.headerCellClass ], style: col.style, rowspan: 1, colspan: 1 }, h("div", { class: ["cu-table__cell", ...getCellClass(col)] }, helpRender(col)) ); }) ] ) ) ] ) ); }; } }); export { TableHeader as default };