UNPKG

yanzhen-design-vue

Version:

67 lines (66 loc) 1.54 kB
import { toRefs, computed, unref } from "vue"; import { isArray, omit } from "lodash-es"; import { isEmptyValue } from "@yanzhen-libs/utils"; function useVxeTableProps(props) { const { rowConfig: rowConfigRef } = toRefs(props); const dataSource = computed({ get: () => { return isArray(props.data) ? props.data : []; }, set(value) { } }); const loading = computed(() => props.loading); const rowKey = computed(() => { const rowConfig = unref(rowConfigRef); const keyField = (rowConfig == null ? void 0 : rowConfig.useKey) ? rowConfig == null ? void 0 : rowConfig.keyField : void 0; if (!isEmptyValue(keyField)) { return keyField; } return "key"; }); const vxeIgnoreTableProps = { data: unref(dataSource) }; const vxeTableProps = computed(() => { const tableProps = {}; const _props = omit( props, "data", ...Object.keys(tableProps), ...Object.keys(vxeIgnoreTableProps) ); return { ..._props, ...tableProps }; }); const elTableProps = computed(() => { return { data: unref(dataSource), border: true, rowKey: unref(rowKey) }; }); const aTableProps = computed(() => { return { dataSource: unref(dataSource), scroll: { scrollToFirstRowOnChange: true, x: "max-content" }, pagination: false }; }); return { rowKey, dataSource, loading, elTableProps, aTableProps, vxeTableProps }; } export { useVxeTableProps };