UNPKG

birdpaper-ui

Version:

一个通用的 vue3 UI组件库。A common vue3 UI component library.

81 lines (80 loc) 2.42 kB
import { defineComponent, Comment, ref, watch, createVNode, resolveComponent, mergeProps, Fragment } from "vue"; import { getAllElements } from "../../../utils/dom.js"; import TableSelect from "./table-select.vue.js"; const TableBody = /* @__PURE__ */ defineComponent({ name: "TableBody", props: { /** 表格数据 */ data: { type: Array, default: () => [] }, /** 已选数据 key */ modelValue: { type: Array, default: () => [] }, /** 选择器配置 */ selection: { type: Object }, /** 行 Key 字段名称 */ rowKey: { type: String } }, components: { TableSelect }, emits: ["update:modelValue", "change"], setup(props, { slots, emit }) { var _a; const children = getAllElements((_a = slots.default) == null ? void 0 : _a.call(slots), true).filter((item) => item.type !== Comment); const val = ref(props.modelValue || []); watch(val, () => { emit("update:modelValue", val.value); }); watch(() => props.modelValue, () => { val.value = props.modelValue; }); const onChange = (record) => { emit("change", record); }; const bodyRender = () => { return createVNode("tbody", { "class": "bp-table-body-tbody" }, [props.data.map((record, rowIndex) => { var _a2, _b; return createVNode("tr", null, [["radio", "checkbox"].includes((_a2 = props.selection) == null ? void 0 : _a2.type) ? createVNode("td", { "class": "bp-table-td" }, [createVNode(resolveComponent("table-select"), { "modelValue": val.value, "onUpdate:modelValue": ($event) => val.value = $event, "record": record, "type": (_b = props.selection) == null ? void 0 : _b.type, "value": record[props.rowKey], "onChange": onChange }, null)]) : null, children.map((child, childIndex) => { const { dataIndex = childIndex } = child == null ? void 0 : child.props; const column = Object.assign({}, child); column.props = mergeProps(child.props, { record, rowIndex }); return createVNode(Fragment, { "key": `bp-table-column-${rowIndex}-${dataIndex}` }, [column]); })]); })]); }; return bodyRender; } }); export { TableBody as default };