UNPKG

hongluan-ui

Version:
33 lines (30 loc) 1.17 kB
import { ref, getCurrentInstance, watch } from 'vue'; function useExpand({ expandRowKeys, defaultExpandAll, getRowKey }) { const allExpandKeys = ref(expandRowKeys.value.reduce((prev, cur) => (prev[cur] = true, prev), {})); const { emit } = getCurrentInstance(); const expandedKeyExisted = (row, slotName) => { if (!slotName) return false; const rowKey = getRowKey(row) + slotName; return rowKey in allExpandKeys.value ? allExpandKeys.value[rowKey] : defaultExpandAll.value; }; const toggleExpandRow = (row, slotName) => { const key = getRowKey(row); toggleExpand(key, slotName); }; const toggleExpand = (key, slotName) => { const rowKey = key + slotName; allExpandKeys.value[rowKey] = rowKey in allExpandKeys.value ? !allExpandKeys.value[rowKey] : !defaultExpandAll.value; emit("expand", allExpandKeys.value[rowKey], rowKey, slotName); }; watch(expandRowKeys, () => { allExpandKeys.value = expandRowKeys.value.reduce((prev, cur) => (prev[cur] = true, prev), {}); }); return { expandedKeyExisted, toggleExpandRow, toggleExpand }; } export { useExpand }; //# sourceMappingURL=use-expand.mjs.map