yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
133 lines (132 loc) • 4.8 kB
JavaScript
import { defineComponent, computed, resolveComponent, createElementBlock, openBlock, normalizeClass, normalizeStyle, Fragment, createBlock, createTextVNode, toDisplayString, withCtx, createVNode, createCommentVNode, normalizeProps, guardReactiveProps } from "vue";
import { ElIcon } from "element-plus";
import { ArrowDown } from "../../icons";
import { CellRender } from "../../ele-virtual-table/util";
const _sfc_main = defineComponent({
name: "ToolPrintBodyCell",
components: { ElIcon, ArrowDown, CellRender },
props: {
/** 列数据 */
col: {
type: Object,
required: true
},
/** 列索引 */
columnIndex: Number,
/** 单元格样式 */
bodyCellStyle: [Object, Function],
/** 单元格类名自定义 */
bodyCellClass: [String, Function]
},
setup(props, { slots }) {
const renderOpt = computed(() => {
const { text, row, column, index: $index } = props.col;
const params = [{ row, column, $index }];
const slotName = column ? column.printSlot || column.slot : void 0;
if (column && "expand" !== column.type && 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,
row: props.col.row
};
});
const cellStyle = computed(() => {
if (typeof props.bodyCellStyle === "function") {
if (cellParam.value.column == null) {
return;
}
return props.bodyCellStyle(cellParam.value);
}
return props.bodyCellStyle;
});
const cellClass = computed(() => {
const classes = [];
const column = cellParam.value.column;
if (column) {
if (column.align) {
classes.push("is-align-" + column.align);
}
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 (column.className) {
classes.push(column.className);
}
}
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) {
var _a;
const _component_ArrowDown = resolveComponent("ArrowDown");
const _component_ElIcon = resolveComponent("ElIcon");
const _component_CellRender = resolveComponent("CellRender");
return openBlock(), createElementBlock("td", {
colspan: _ctx.col.colspan,
rowspan: _ctx.col.rowspan,
style: normalizeStyle(_ctx.cellStyle),
class: normalizeClass(_ctx.cellClass)
}, [
"expand" === ((_a = _ctx.col.column) == null ? void 0 : _a.type) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
_ctx.col.text ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
createTextVNode(toDisplayString(_ctx.col.text), 1)
], 64)) : (openBlock(), createBlock(_component_ElIcon, {
key: 1,
style: { "vertical-align": "middle" },
class: "ele-print-expand-icon"
}, {
default: withCtx(() => [
createVNode(_component_ArrowDown)
]),
_: 1
}))
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
_ctx.col.isTreeCell ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
_ctx.col.indent ? (openBlock(), createElementBlock("span", {
key: 0,
style: normalizeStyle({ paddingLeft: `${_ctx.col.indent * 16}px` }),
class: "ele-print-tree-indent"
}, null, 4)) : createCommentVNode("", true),
createVNode(_component_ElIcon, {
style: normalizeStyle({
verticalAlign: "middle",
marginRight: "2px",
visibility: _ctx.col.isTreeLeaf ? "hidden" : void 0
}),
class: "ele-print-tree-icon"
}, {
default: withCtx(() => [
createVNode(_component_ArrowDown)
]),
_: 1
}, 8, ["style"])
], 64)) : createCommentVNode("", true),
createVNode(_component_CellRender, normalizeProps(guardReactiveProps(_ctx.renderOpt)), null, 16)
], 64))
], 14, _hoisted_1);
}
const toolPrintBodyCell = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
toolPrintBodyCell as default
};