tav-ui
Version:
59 lines (56 loc) • 1.71 kB
JavaScript
import { ref, computed, unref, toRaw } from 'vue';
import { ROW_KEY } from '../const2.mjs';
function useTableExpand(propsRef, tableData, emit) {
const expandedRowKeys = ref([]);
const getAutoCreateKey = computed(() => {
return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey;
});
const getRowKey = computed(() => {
const { rowKey } = unref(propsRef);
return unref(getAutoCreateKey) ? ROW_KEY : rowKey;
});
const getExpandOption = computed(() => {
const { isTreeTable } = unref(propsRef);
if (!isTreeTable)
return {};
return {
expandedRowKeys: unref(expandedRowKeys),
onExpandedRowsChange: (keys) => {
expandedRowKeys.value = keys;
emit("expanded-rows-change", keys);
}
};
});
function expandAll() {
const keys = getAllKeys();
expandedRowKeys.value = keys;
}
function expandRows(keys, cover = false) {
const { isTreeTable } = unref(propsRef);
if (!isTreeTable)
return;
if (cover) {
expandedRowKeys.value = keys;
} else {
expandedRowKeys.value = [...expandedRowKeys.value, ...keys];
}
}
function getAllKeys(data) {
const keys = [];
const { childrenColumnName } = unref(propsRef);
toRaw(data || unref(tableData)).forEach((item) => {
keys.push(item[unref(getRowKey)]);
const children = item[childrenColumnName || "children"];
if (children?.length) {
keys.push(...getAllKeys(children));
}
});
return keys;
}
function collapseAll() {
expandedRowKeys.value = [];
}
return { getExpandOption, expandAll, expandRows, collapseAll };
}
export { useTableExpand };
//# sourceMappingURL=useTableExpand2.mjs.map