tav-ui
Version:
63 lines (58 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var _const = require('../const2.js');
function useTableExpand(propsRef, tableData, emit) {
const expandedRowKeys = vue.ref([]);
const getAutoCreateKey = vue.computed(() => {
return vue.unref(propsRef).autoCreateKey && !vue.unref(propsRef).rowKey;
});
const getRowKey = vue.computed(() => {
const { rowKey } = vue.unref(propsRef);
return vue.unref(getAutoCreateKey) ? _const.ROW_KEY : rowKey;
});
const getExpandOption = vue.computed(() => {
const { isTreeTable } = vue.unref(propsRef);
if (!isTreeTable)
return {};
return {
expandedRowKeys: vue.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 } = vue.unref(propsRef);
if (!isTreeTable)
return;
if (cover) {
expandedRowKeys.value = keys;
} else {
expandedRowKeys.value = [...expandedRowKeys.value, ...keys];
}
}
function getAllKeys(data) {
const keys = [];
const { childrenColumnName } = vue.unref(propsRef);
vue.toRaw(data || vue.unref(tableData)).forEach((item) => {
keys.push(item[vue.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 };
}
exports.useTableExpand = useTableExpand;
//# sourceMappingURL=useTableExpand2.js.map