UNPKG

birdpaper-ui

Version:

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

34 lines (33 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const useTableSelect = (props, emit, tableHeaderRef) => { const selectedData = vue.ref([]); const onSelectChange = (record) => { emit("select", selectedData.value, record[props.rowKey], record); }; const onSelectAll = (isSelectAll) => { emit("select-all", isSelectAll); if (!isSelectAll) { selectedData.value = []; return; } selectedData.value = []; for (let i = 0; i < props.data.length; i++) { const element = props.data[i]; selectedData.value.push(element[props.rowKey]); } }; vue.watch(selectedData, () => { var _a; tableHeaderRef.value && (tableHeaderRef.value.isSelectAll = props.data.length !== 0 && ((_a = selectedData.value) == null ? void 0 : _a.length) === props.data.length); emit("selection-change", selectedData.value); emit("update:selectedKey", selectedData.value); }); return { onSelectChange, onSelectAll, selectedData }; }; exports.useTableSelect = useTableSelect;