api.ts 671 B

123456789101112131415161718192021222324252627282930313233
  1. import { confirmStore } from "./store";
  2. const createId = () =>{
  3. return typeof crypto !== "undefined" && crypto.randomUUID
  4. ? crypto.randomUUID()
  5. : `${Date.now()}_${Math.random()}`;
  6. }
  7. // let id = createId();
  8. export function confirmDialog(options: {
  9. title?: string;
  10. content?: string | string[];
  11. noOk?: boolean;
  12. noCancel?: boolean;
  13. okBtnTxt?: string;
  14. cancelBtnTxt?: string;
  15. }) {
  16. return new Promise<boolean>((resolve) => {
  17. const state = confirmStore.getSnapshot();
  18. confirmStore.setState({
  19. queue: [
  20. ...state.queue,
  21. {
  22. id: createId(),
  23. ...options,
  24. resolve,
  25. },
  26. ],
  27. });
  28. });
  29. }