vxe-table
Version:
A PC-end table component based on Vxe UI, supporting copy-paste, data pivot table, and high-performance virtual list table solution.
424 lines (423 loc) • 18.6 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var footer_exports = {};
__export(footer_exports, {
default: () => footer_default
});
module.exports = __toCommonJS(footer_exports);
var import_vue = require("vue");
var import_comp = require("../../ui/src/comp");
var import_xe_utils = __toESM(require("xe-utils"));
var import_core = require("@vxe-ui/core");
var import_dom = require("../../ui/src/dom");
var import_util = require("./util");
var import_utils = require("../../ui/src/utils");
const { renderer, renderEmptyElement } = import_core.VxeUI;
const sourceType = "table";
const renderType = "footer";
var footer_default = (
/* define-vxe-component start */
(0, import_comp.defineVxeComponent)({
name: "VxeTableFooter",
props: {
footerTableData: {
type: Array,
default: () => []
},
tableColumn: {
type: Array,
default: () => []
},
fixedColumn: {
type: Array,
default: () => []
},
fixedType: {
type: String,
default: null
}
},
setup(props) {
const $xeTable = (0, import_vue.inject)("$xeTable", {});
const { xID, props: tableProps, reactData: tableReactData, internalData: tableInternalData } = $xeTable;
const { computeFooterTooltipOpts, computeColumnOpts, computeCellOpts, computeFooterCellOpts, computeDefaultRowHeight, computeResizableOpts, computeVirtualXOpts, computeIsFooterRenderOptimize, computeRendererOpts } = $xeTable.getComputeMaps();
const refElem = (0, import_vue.ref)();
const refFooterScroll = (0, import_vue.ref)();
const refFooterTable = (0, import_vue.ref)();
const refFooterColgroup = (0, import_vue.ref)();
const refFooterTFoot = (0, import_vue.ref)();
const refFooterXSpace = (0, import_vue.ref)();
const renderRows = (isOptimizeMode, tableColumn, footerTableData, row, $rowIndex, _rowIndex) => {
const $xeGrid = $xeTable.xeGrid;
const $xeGantt = $xeTable.xeGantt;
const { fixedType } = props;
const { resizable: allResizable, border, footerCellClassName, footerCellStyle, footerAlign: allFooterAlign, footerSpanMethod, align: allAlign, columnKey, showFooterOverflow: allColumnFooterOverflow } = tableProps;
const { scrollXLoad, scrollYLoad, overflowX, mergeFootFlag, currColFlag } = tableReactData;
const { fullColumnIdData, mergeFooterList, mergeFooterCellMaps, scrollXStore, currentCol } = tableInternalData;
const virtualXOpts = computeVirtualXOpts.value;
const footerTooltipOpts = computeFooterTooltipOpts.value;
const resizableOpts = computeResizableOpts.value;
const { isAllColumnDrag } = resizableOpts;
const columnOpts = computeColumnOpts.value;
const defaultRowHeight = computeDefaultRowHeight.value;
const cellOpts = computeCellOpts.value;
const footerCellOpts = computeFooterCellOpts.value;
const currCellHeight = (0, import_util.getCalcHeight)(footerCellOpts.height) || defaultRowHeight;
const rendererOpts = computeRendererOpts.value;
return tableColumn.map((column, $columnIndex) => {
const { type, showFooterOverflow, footerAlign, align, footerClassName, editRender, cellRender } = column;
const colid = column.id;
const colRest = fullColumnIdData[colid] || {};
const renderOpts = editRender || cellRender;
const compConf = renderOpts && renderOpts.name ? rendererOpts[renderOpts.name] || renderer.get(renderOpts.name) : null;
const showAllTip = footerTooltipOpts.showAll;
const fixedHiddenColumn = overflowX && (fixedType ? column.fixed !== fixedType : !!column.fixed);
const cellPadding = (0, import_utils.getDefaultConfig)(footerCellOpts.padding, cellOpts.padding);
const isAllCellPadding = cellPadding === true;
const isCellPaddingTop = cellPadding ? isAllCellPadding || cellPadding.top !== false : false;
const isCellPaddingBottom = cellPadding ? isAllCellPadding || cellPadding.bottom !== false : false;
const isCellPaddingLeft = cellPadding ? isAllCellPadding || cellPadding.left !== false : false;
const isCellPaddingRight = cellPadding ? isAllCellPadding || cellPadding.right !== false : false;
const footOverflow = (0, import_utils.getDefaultConfig)(showFooterOverflow, allColumnFooterOverflow);
const footAlign = footerAlign || (compConf ? compConf.tableFooterCellAlign : "") || allFooterAlign || align || (compConf ? compConf.tableCellAlign : "") || allAlign;
const showEllipsis = (footOverflow === true ? footerTooltipOpts.mode : footOverflow) === "ellipsis";
const showTitle = (footOverflow === true ? footerTooltipOpts.mode : footOverflow) === "title";
const showTooltip = (footOverflow === true ? footerTooltipOpts.mode : footOverflow) === "tooltip";
const hasEllipsis = showTitle || showTooltip || showEllipsis;
const showResizable = import_xe_utils.default.isBoolean(column.resizable) ? column.resizable : columnOpts.resizable || allResizable;
const attrs = { colid };
const tfOns = {};
const columnIndex = colRest.index;
const _columnIndex = colRest._index;
const itemIndex = _columnIndex;
const cellParams = {
$table: $xeTable,
$grid: $xeGrid,
$gantt: $xeGantt,
row,
rowIndex: _rowIndex,
_rowIndex,
$rowIndex,
column,
columnIndex,
$columnIndex,
_columnIndex,
itemIndex,
items: row,
fixed: fixedType,
source: sourceType,
type: renderType,
data: footerTableData
};
if (showTitle || showTooltip || showAllTip) {
tfOns.onMouseenter = (evnt) => {
if (showTitle) {
(0, import_dom.updateCellTitle)(evnt.currentTarget, column);
} else if (showTooltip || showAllTip) {
$xeTable.triggerFooterTooltipEvent(evnt, cellParams);
}
};
}
if (showTooltip || showAllTip) {
tfOns.onMouseleave = (evnt) => {
if (showTooltip || showAllTip) {
$xeTable.handleTargetLeaveEvent(evnt);
}
};
}
tfOns.onClick = (evnt) => {
$xeTable.triggerFooterCellClickEvent(evnt, cellParams);
};
tfOns.onDblclick = (evnt) => {
$xeTable.triggerFooterCellDblclickEvent(evnt, cellParams);
};
let isMergeCell = false;
if (mergeFootFlag && mergeFooterList.length) {
const spanRest = mergeFooterCellMaps[`${_rowIndex}:${_columnIndex}`];
if (spanRest) {
const { rowspan, colspan } = spanRest;
if (!rowspan || !colspan) {
return null;
}
if (rowspan > 1) {
isMergeCell = true;
attrs.rowspan = rowspan;
}
if (colspan > 1) {
isMergeCell = true;
attrs.colspan = colspan;
}
}
} else if (footerSpanMethod) {
const { rowspan = 1, colspan = 1 } = footerSpanMethod(cellParams) || {};
if (!rowspan || !colspan) {
return null;
}
if (rowspan > 1) {
attrs.rowspan = rowspan;
}
if (colspan > 1) {
attrs.colspan = colspan;
}
}
const isLastColumn = $columnIndex === tableColumn.length - 1;
const isAutoCellWidth = !column.resizeWidth && (column.minWidth === "auto" || column.width === "auto");
let isVNPreEmptyStatus = false;
if (isOptimizeMode && overflowX && !isMergeCell) {
if (scrollXLoad && tableColumn.length > 10 && !column.fixed && !virtualXOpts.immediate && (_columnIndex < scrollXStore.visibleStartIndex - scrollXStore.preloadSize || _columnIndex > scrollXStore.visibleEndIndex + scrollXStore.preloadSize)) {
isVNPreEmptyStatus = true;
}
}
const tcStyle = {};
if (hasEllipsis) {
tcStyle.height = `${currCellHeight}px`;
} else {
tcStyle.minHeight = `${currCellHeight}px`;
}
return (0, import_vue.h)(
"td",
{
class: [
"vxe-table--column vxe-footer--column",
column.id,
{
[`col--${footAlign}`]: footAlign,
[`col--${type}`]: type,
"col--last": isLastColumn,
"fixed--width": !isAutoCellWidth,
"fixed--hidden": fixedHiddenColumn,
"is--pg-top": isCellPaddingTop,
"is--pg-bottom": isCellPaddingBottom,
"is--pg-left": isCellPaddingLeft,
"is--pg-right": isCellPaddingRight,
"col--ellipsis": hasEllipsis,
"col--current": currColFlag && currentCol === column
},
(0, import_dom.getPropClass)(footerClassName, cellParams),
(0, import_dom.getPropClass)(footerCellClassName, cellParams)
],
...attrs,
style: footerCellStyle ? import_xe_utils.default.isFunction(footerCellStyle) ? footerCellStyle(cellParams) : footerCellStyle : null,
...tfOns,
key: columnKey || scrollXLoad || scrollYLoad || columnOpts.useKey || columnOpts.drag ? column.id : $columnIndex
},
[
(0, import_vue.h)(
"div",
{
class: [
"vxe-cell",
{
"c--title": showTitle,
"c--tooltip": showTooltip,
"c--ellipsis": showEllipsis
}
],
style: tcStyle
},
isVNPreEmptyStatus ? [] : [
(0, import_vue.h)(
"div",
{
colid,
class: "vxe-cell--wrapper vxe-footer-cell--wrapper"
},
column.renderFooter(cellParams)
)
]
),
/**
* 列宽拖动
*/
!fixedHiddenColumn && showResizable && isAllColumnDrag ? (0, import_vue.h)("div", {
class: [
"vxe-cell--col-resizable",
{
"is--line": !border || border === "none"
}
],
onMousedown: (evnt) => $xeTable.handleColResizeMousedownEvent(evnt, fixedType, cellParams),
onDblclick: (evnt) => $xeTable.handleColResizeDblclickEvent(evnt, cellParams)
}) : renderEmptyElement($xeTable)
]
);
});
};
const renderHeads = (isOptimizeMode, renderColumnList) => {
const { fixedType, footerTableData } = props;
const { footerRowClassName, footerRowStyle } = tableProps;
return footerTableData.map((row, _rowIndex) => {
const $rowIndex = _rowIndex;
const rowParams = { $table: $xeTable, row, rowIndex: _rowIndex, _rowIndex, $rowIndex, fixed: fixedType, type: renderType };
return (0, import_vue.h)(
"tr",
{
key: _rowIndex,
class: ["vxe-footer--row", footerRowClassName ? import_xe_utils.default.isFunction(footerRowClassName) ? footerRowClassName(rowParams) : footerRowClassName : ""],
style: footerRowStyle ? import_xe_utils.default.isFunction(footerRowStyle) ? footerRowStyle(rowParams) : footerRowStyle : null
},
renderRows(isOptimizeMode, renderColumnList, footerTableData, row, _rowIndex, _rowIndex)
);
});
};
const renderVN = () => {
const { fixedType, fixedColumn, tableColumn } = props;
const { visibleColumn, fullColumnIdData } = tableInternalData;
const { isGroup, isColLoading, overflowX, scrollXLoad, dragCol } = tableReactData;
const isFooterRenderOptimize = computeIsFooterRenderOptimize.value;
let renderColumnList = tableColumn;
const isOptimizeMode = isFooterRenderOptimize;
if (!isOptimizeMode || !isColLoading && (fixedType || !overflowX)) {
renderColumnList = visibleColumn;
}
if (fixedType) {
if (isOptimizeMode) {
renderColumnList = fixedColumn || [];
}
}
if (!fixedType && !isGroup) {
if (scrollXLoad && dragCol) {
if (renderColumnList.length > 2) {
const dCowRest = fullColumnIdData[dragCol.id];
if (dCowRest) {
const dcIndex = dCowRest._index;
const firstCol = renderColumnList[0];
const lastCol = renderColumnList[renderColumnList.length - 1];
const firstColRest = fullColumnIdData[firstCol.id];
const lastColRest = fullColumnIdData[lastCol.id];
if (firstColRest && lastColRest) {
const fcIndex = firstColRest._index;
const lcIndex = lastColRest._index;
if (dcIndex < fcIndex) {
renderColumnList = [dragCol].concat(renderColumnList);
} else if (dcIndex > lcIndex) {
renderColumnList = renderColumnList.concat([dragCol]);
}
}
}
}
}
}
return (0, import_vue.h)(
"div",
{
ref: refElem,
class: ["vxe-table--footer-wrapper", fixedType ? `fixed-${fixedType}--wrapper` : "body--wrapper"],
xid: xID
},
[
(0, import_vue.h)(
"div",
{
ref: refFooterScroll,
class: "vxe-table--footer-inner-wrapper",
onScroll(evnt) {
$xeTable.triggerFooterScrollEvent(evnt, fixedType);
}
},
[
fixedType ? renderEmptyElement($xeTable) : (0, import_vue.h)("div", {
ref: refFooterXSpace,
class: "vxe-body--x-space"
}),
(0, import_vue.h)(
"table",
{
ref: refFooterTable,
class: "vxe-table--footer",
xid: xID,
cellspacing: 0,
cellpadding: 0,
border: 0,
xvm: isOptimizeMode ? "1" : null
},
[
/**
* 列宽
*/
(0, import_vue.h)(
"colgroup",
{
ref: refFooterColgroup
},
renderColumnList.map((column, $columnIndex) => {
return (0, import_vue.h)("col", {
name: column.id,
key: $columnIndex,
style: {
width: `${column.renderWidth}px`
}
});
})
),
/**
* 底部
*/
(0, import_vue.h)(
"tfoot",
{
ref: refFooterTFoot
},
renderHeads(isOptimizeMode, renderColumnList)
)
]
)
]
)
]
);
};
(0, import_vue.onMounted)(() => {
(0, import_vue.nextTick)(() => {
const { fixedType } = props;
const { elemStore } = tableInternalData;
const prefix = `${fixedType || "main"}-footer-`;
elemStore[`${prefix}wrapper`] = refElem;
elemStore[`${prefix}scroll`] = refFooterScroll;
elemStore[`${prefix}table`] = refFooterTable;
elemStore[`${prefix}colgroup`] = refFooterColgroup;
elemStore[`${prefix}list`] = refFooterTFoot;
elemStore[`${prefix}xSpace`] = refFooterXSpace;
});
});
(0, import_vue.onUnmounted)(() => {
const { fixedType } = props;
const { elemStore } = tableInternalData;
const prefix = `${fixedType || "main"}-footer-`;
elemStore[`${prefix}wrapper`] = null;
elemStore[`${prefix}scroll`] = null;
elemStore[`${prefix}table`] = null;
elemStore[`${prefix}colgroup`] = null;
elemStore[`${prefix}list`] = null;
elemStore[`${prefix}xSpace`] = null;
});
return renderVN;
}
})
);