You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/manager/ui.ts

42 lines
916 B
TypeScript

import { buildRegFn } from './buildRegFn';
/**
* 通用UI api设置
*/
type ToastsType = 'info' | 'success' | 'error' | 'warning';
export const [showToasts, setToasts] =
buildRegFn<(message: string, type?: ToastsType) => void>('toasts');
/**
* 一个封装方法, 用于直接抛出错误
* @param error 错误信息
*/
export function showErrorToasts(error: unknown) {
let msg = '';
if (error instanceof Error) {
msg = error.message;
} else {
msg = String(error);
}
showToasts(msg, 'error');
}
interface AlertOptions {
message: React.ReactNode;
onConfirm?: () => void | Promise<void>;
}
export const [showAlert, setAlert] =
buildRegFn<(options: AlertOptions) => void>('alert');
/**
* 全局Loading提示
* 返回移除函数
*/
export const [showGlobalLoading, setGlobalLoading] = buildRegFn<
(text: string) => () => void
>('global-loading', () => {
return () => {};
});