UNPKG

birdpaper-ui

Version:

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

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