import {reactive} from "@peryl/react-compose"; import {createCounter} from "@peryl/utils/createCounter"; import {iTableHooks} from "../utils/createTableHooks"; import {LoadingMask} from "../../../LoadingMask"; import {iTablePropsType} from "../utils/table.utils"; /** * 管理Table加载状态 * @author 韦胜健 * @date 2023.1.25 23:36 */ export function useTableLoading({ props, hooks }: { props: iTablePropsType, hooks: iTableHooks }) { const nextLoadingId = createCounter('table_loading'); const state = reactive({ ids: [] as string[] }); const loading = () => { const id = nextLoadingId(); state.ids.push(id); return () => { const index = state.ids.indexOf(id); index > -1 && (state.ids.splice(index, 1)); }; }; hooks.onRender.use({ processor: ({ list, render }) => {(!!state.ids.length || props.loading) && list.push({ render, seq: -1, key: 'loading' });}, render: () => ( ) }); return { loading }; } export type iTableLoading = ReturnType