UNPKG

hongluan-ui

Version:
37 lines (32 loc) 1.24 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); function useExpand({ expandRowKeys, defaultExpandAll, getRowKey }) { const allExpandKeys = vue.ref(expandRowKeys.value.reduce((prev, cur) => (prev[cur] = true, prev), {})); const { emit } = vue.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); }; vue.watch(expandRowKeys, () => { allExpandKeys.value = expandRowKeys.value.reduce((prev, cur) => (prev[cur] = true, prev), {}); }); return { expandedKeyExisted, toggleExpandRow, toggleExpand }; } exports.useExpand = useExpand; //# sourceMappingURL=use-expand.js.map