yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
386 lines (385 loc) • 13.2 kB
JavaScript
;
const vue = require("vue");
const elementPlus = require("element-plus");
const core = require("../../utils/core");
const icons = require("../../icons");
const CellCheckbox = require("./cell-checkbox");
const util = require("../util");
const _sfc_main = vue.defineComponent({
name: "BodyCell",
components: {
ElIcon: elementPlus.ElIcon,
ArrowDown: icons.ArrowDown,
LoadingDotOutlined: icons.LoadingDotOutlined,
CellCheckbox,
CellRender: util.CellRender
},
props: {
/** 列配置 */
column: {
type: Object,
required: true
},
/** 列索引 */
columnIndex: {
type: Number,
required: true
},
/** 行索引 */
rowIndex: {
type: Number,
required: true
},
/** 行数据 */
rowData: {
type: Object,
required: true
},
/** 所有列的列宽 */
colSizes: {
type: Array,
required: true
},
/** 单元格类名自定义 */
bodyCellClass: [String, Function],
/** 单元格样式自定义 */
bodyCellStyle: [Object, Function],
/** 单元格合并行列方法 */
spanMethod: Function,
/** 溢出提示组件全局属性 */
tableTooltipProps: [Boolean, Object],
/** 序号列起始编号 */
pageIndex: Number,
/** 表格行高 */
rowHeight: Number,
/** 多选当前行是否选中 */
isChecked: Boolean,
/** 多选当前行是否禁用 */
isDisabled: Boolean,
/** 表格尺寸 */
tableSize: String,
/** 树表格展开图标的列 */
expandColumnKey: String,
/** 树表格当前行是否有子级 */
hasChildren: Boolean,
/** 树表格当前行缩进 */
rowIndent: String,
/** 树表格当前行是否折叠 */
isCollapse: Boolean,
/** 树表格子级加载状态 */
loading: Boolean,
/** 是否需要固定单元格高度 */
fixedCellHeight: Boolean,
/** 表格是否是自适应行高 */
autoRowHeight: Boolean
},
emits: {
/** 多选框选中改变事件 */
checkedChange: (_checked) => true,
/** 展开状态改变事件 */
expandChange: (_expanded) => true,
/** 点击事件 */
click: (_col, _e) => true,
/** 双击事件 */
dblclick: (_col, _e) => true,
/** 右键事件 */
contextmenu: (_col, _e) => true,
/** 鼠标移入事件 */
mouseenter: (_col, _e) => true,
/** 鼠标移出事件 */
mouseleave: (_col, _e) => true
},
setup(props, { emit, slots }) {
const originalCol = vue.computed(() => props.column.originalCol);
const colType = vue.computed(() => originalCol.value.type ?? "");
const cellParam = vue.computed(() => {
return {
column: originalCol.value,
columnIndex: props.columnIndex,
rowIndex: props.rowIndex,
row: props.rowData
};
});
const cellSpan = vue.computed(() => {
const span = util.getCellSpan(cellParam.value, props.spanMethod);
if (["indedx", "selection", "expand"].includes(colType.value)) {
span.rowspan = 1;
}
return span;
});
const isEllipsis = vue.computed(() => {
if (colType.value === "selection" || colType.value === "expand") {
return true;
}
const col = originalCol.value;
if (col && col.showOverflowTooltip != null) {
return col.showOverflowTooltip !== false;
}
return !!props.tableTooltipProps;
});
const cellClass = vue.computed(() => {
const classes = ["el-table-v2__row-cell", "ele-table-td"];
if (!cellSpan.value.colspan) {
classes.push("is-none");
} else if (cellSpan.value.colspan > 1) {
classes.push("is-multi-cell");
}
if (!cellSpan.value.rowspan) {
classes.push("is-placeholder");
} else if (cellSpan.value.rowspan > 1) {
classes.push("is-multi-row");
}
if (colType.value === "index") {
classes.push("is-index");
}
if (colType.value === "selection") {
classes.push("is-selection");
}
if (colType.value === "expand") {
classes.push("is-expand");
}
const col = originalCol.value;
if (col) {
if (col.align) {
classes.push("is-align-" + col.align);
}
if (isEllipsis.value) {
classes.push("is-ellipsis");
}
if (col.fixed === "right") {
classes.push("is-fixed-right");
} else if (col.fixed === "left" || col.fixed === true) {
classes.push("is-fixed-left");
}
if (props.column) {
if (props.column.isFixedLeftLast) {
classes.push("is-fixed-left-last");
}
if (props.column.isFixedRightFirst) {
classes.push("is-fixed-right-first");
}
}
if (typeof props.bodyCellClass === "function") {
const temp = props.bodyCellClass(cellParam.value);
if (temp) {
classes.push(temp);
}
} else if (props.bodyCellClass) {
classes.push(props.bodyCellClass);
}
if (col.className) {
classes.push(col.className);
}
}
return classes.join(" ");
});
const cellWidth = vue.computed(() => {
const colspan = cellSpan.value.colspan;
if (colspan === 0) {
return "0px";
}
let width = props.colSizes[props.columnIndex].width || 0;
if (colspan && colspan > 1) {
const end = props.columnIndex + colspan;
for (let i = props.columnIndex; i < end; i++) {
if (props.colSizes[i] && props.colSizes[i].width != null) {
width += props.colSizes[i].width;
}
}
}
return width + "px";
});
const cellHeight = vue.computed(() => {
if (props.fixedCellHeight && props.rowHeight != null) {
return props.rowHeight + "px";
}
const rowspan = cellSpan.value.rowspan;
if (props.rowHeight == null || rowspan == null || rowspan <= 1) {
return;
}
return rowspan * props.rowHeight + "px";
});
const cellMinHeight = vue.computed(() => {
if (!props.autoRowHeight || !props.rowHeight) {
return;
}
return props.rowHeight + "px";
});
const colSize = vue.computed(() => {
if (!props.colSizes || props.columnIndex == null) {
return;
}
return props.colSizes[props.columnIndex];
});
const cellStyle = vue.computed(() => {
const userStyle = props.bodyCellStyle;
const param = cellParam.value;
return [
{
width: cellWidth.value,
height: cellHeight.value,
minHeight: cellMinHeight.value,
left: colSize.value ? colSize.value.fixedLeft : void 0,
right: colSize.value ? colSize.value.fixedRight : void 0
},
(typeof userStyle === "function" ? userStyle(param) : userStyle) || {}
];
});
const cellText = vue.computed(() => {
const col = originalCol.value;
if (col && col.type === "index") {
if (typeof col.index === "function") {
return;
}
return util.getIndexValue(props.rowIndex, col.index, props.pageIndex);
}
const prop = props.column ? props.column.dataKey : void 0;
const { rowspan, colspan } = cellSpan.value;
if (rowspan === 0 || colspan === 0 || prop == null || !props.rowData) {
return;
}
return core.getValue(props.rowData, prop);
});
const isExpandCol = vue.computed(() => {
return props.column != null && props.expandColumnKey != null && props.expandColumnKey === props.column.key;
});
const renderOpt = vue.computed(() => {
const col = originalCol.value;
const { rowspan, colspan } = cellSpan.value;
if (col && rowspan !== 0 && colspan !== 0) {
const { rowIndex, rowData } = props;
if (col.type === "index") {
if (typeof col.index === "function") {
return { render: col.index, params: [rowIndex] };
}
return {};
}
if (col.slot && typeof slots[col.slot] === "function") {
return {
render: slots[col.slot],
params: [{ row: rowData, column: col, $index: rowIndex }]
};
}
if (typeof col.formatter === "function") {
return {
render: col.formatter,
params: [rowData, col, cellText.value, rowIndex]
};
}
}
return {};
});
const handleTextClick = (e) => {
if (colType.value === "selection") {
e.stopPropagation();
}
};
const handleCheckedChange = (checked) => {
emit("checkedChange", checked);
};
const handleExpandChange = () => {
if (!props.loading) {
emit("expandChange", props.isCollapse);
}
};
const handleClick = (e) => {
emit("click", originalCol.value, e);
};
const handleDblclick = (e) => {
emit("dblclick", originalCol.value, e);
};
const handleContextmenu = (e) => {
emit("contextmenu", originalCol.value, e);
};
const handleMouseenter = (e) => {
emit("mouseenter", originalCol.value, e);
};
const handleMouseleave = (e) => {
emit("mouseleave", originalCol.value, e);
};
return {
colType,
cellClass,
cellStyle,
cellText,
isExpandCol,
renderOpt,
handleTextClick,
handleCheckedChange,
handleExpandChange,
handleClick,
handleDblclick,
handleContextmenu,
handleMouseenter,
handleMouseleave
};
}
});
const _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
const _hoisted_1 = {
key: 2,
class: "ele-table-placeholder"
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_LoadingDotOutlined = vue.resolveComponent("LoadingDotOutlined");
const _component_ArrowDown = vue.resolveComponent("ArrowDown");
const _component_ElIcon = vue.resolveComponent("ElIcon");
const _component_CellCheckbox = vue.resolveComponent("CellCheckbox");
const _component_CellRender = vue.resolveComponent("CellRender");
return vue.openBlock(), vue.createElementBlock("div", {
class: vue.normalizeClass(_ctx.cellClass),
style: vue.normalizeStyle(_ctx.cellStyle),
onClick: _cache[2] || (_cache[2] = (...args) => _ctx.handleClick && _ctx.handleClick(...args)),
onDblclick: _cache[3] || (_cache[3] = (...args) => _ctx.handleDblclick && _ctx.handleDblclick(...args)),
onContextmenu: _cache[4] || (_cache[4] = (...args) => _ctx.handleContextmenu && _ctx.handleContextmenu(...args)),
onMouseenter: _cache[5] || (_cache[5] = (...args) => _ctx.handleMouseenter && _ctx.handleMouseenter(...args)),
onMouseleave: _cache[6] || (_cache[6] = (...args) => _ctx.handleMouseleave && _ctx.handleMouseleave(...args))
}, [
vue.createElementVNode("div", {
class: "ele-table-cell",
onClick: _cache[1] || (_cache[1] = (...args) => _ctx.handleTextClick && _ctx.handleTextClick(...args))
}, [
_ctx.isExpandCol ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
_ctx.rowIndent ? (vue.openBlock(), vue.createElementBlock("div", {
key: 0,
class: "ele-table-indent",
style: vue.normalizeStyle({ width: _ctx.rowIndent })
}, null, 4)) : vue.createCommentVNode("", true),
_ctx.hasChildren ? (vue.openBlock(), vue.createElementBlock("div", {
key: 1,
class: vue.normalizeClass(["ele-table-expand", { "is-collapse": _ctx.isCollapse }]),
onClick: _cache[0] || (_cache[0] = vue.withModifiers((...args) => _ctx.handleExpandChange && _ctx.handleExpandChange(...args), ["stop"]))
}, [
vue.createVNode(_component_ElIcon, {
class: vue.normalizeClass({ "is-loading": _ctx.loading })
}, {
default: vue.withCtx(() => [
_ctx.loading ? (vue.openBlock(), vue.createBlock(_component_LoadingDotOutlined, { key: 0 })) : (vue.openBlock(), vue.createBlock(_component_ArrowDown, { key: 1 }))
]),
_: 1
}, 8, ["class"])
], 2)) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1))
], 64)) : vue.createCommentVNode("", true),
_ctx.colType === "selection" ? (vue.openBlock(), vue.createBlock(_component_CellCheckbox, {
key: 1,
checked: _ctx.isChecked,
disabled: _ctx.isDisabled,
size: _ctx.tableSize,
onChange: _ctx.handleCheckedChange
}, null, 8, ["checked", "disabled", "size", "onChange"])) : _ctx.colType !== "expand" ? (vue.openBlock(), vue.createBlock(_component_CellRender, vue.normalizeProps(vue.mergeProps({ key: 2 }, _ctx.renderOpt)), {
default: vue.withCtx(() => [
vue.createTextVNode(vue.toDisplayString(_ctx.cellText), 1)
]),
_: 1
}, 16)) : vue.createCommentVNode("", true)
])
], 38);
}
const bodyCell = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
module.exports = bodyCell;