import { useState } from "react"; export type BasicCrudType = 'add' | 'edit' | 'view'; export const CRUD_NAMES = { add: '新增', edit: '编辑' } export type CrudContext = { mode: modes | null; record: any; goto: (mode: modes | null, r: any) => void; loading: boolean; setLoading: (val: boolean) => void; } export default function useCrud(params?: { mode?: modes; record?: any; }): CrudContext { const [loading, setLoading] = useState(false); const [state, setState] = useState<{ mode: modes | null; record: any; }>({ mode: params?.mode || null, record: params?.record, }) const goto = (mode: modes | null, record: any) => { setState({ mode, record }) }; return { ...state, goto, loading, setLoading, } }