@aplus-frontend/ui
Version:
164 lines (163 loc) • 5.35 kB
TypeScript
import { ModalProps, ModalFuncProps } from '@aplus-frontend/antdv';
import { ModalFunc, ModalStaticFunctions } from '@aplus-frontend/antdv/lib/modal/confirm';
import { AppContext } from 'vue';
export type CreateModalFuncProps<ContentRecord = any> = Omit<ModalProps, 'open' | 'onUpdate:open' | 'destroyOnClose' | 'onCancel' | 'onOk' | 'getContainer' | 'icon'> & Partial<{
/**
* 点击取消回调
* @param params content组件内使用defineExpose导出的对象
* @returns
*/
onCancel: (params: ContentRecord) => any | Promise<any>;
/**
* 点击确定回调
* @param params content组件内使用defineExpose导出的对象
* @returns
*/
onOk: (params: ContentRecord) => any | Promise<any>;
/**
* 指定弹框挂载的 HTML 节点
*/
getContainer: HTMLElement;
/**
* 内容
*/
content: any;
/**
* 关闭时是否销毁弹框
*/
destroyOnClose: boolean;
/**
* 自适应高度
*/
wrapperOffset: boolean | number;
/**
* 弹窗的上下文,一般用于获取全局注册组件、vuex 等内容
*/
appContext: AppContext;
}>;
export type CreateModalFuncReturn = {
/**
* 销毁弹框
* @returns
*/
destroy: () => void;
/**
* 更新弹框 props 属性
* @param newConfig
* @returns
*/
update: (newConfig: CreateModalFuncProps) => void;
/**
* 打开弹框
* @returns
*/
open: () => void;
/**
* 关闭弹框,不销毁
* @returns
*/
close: () => void;
};
export type CreateModalFunc = (props: CreateModalFuncProps) => CreateModalFuncReturn;
export type ModalStreamNextFunc<ModalType extends ModalStreamTypeKey = ModalStreamTypeKey> = (option?: {
/**
* 下一步弹框的id
*/
modalId?: string;
/**
* 下一步弹框传递的参数
*/
params?: any;
/**
* 本次弹框关闭前的回调,createModal默认关闭弹框,其他弹框类型默认销毁弹框,调用弹框实例的open方法可以不关闭弹框
*/
handleCurrentModal?: (
/**
* 本次弹框的实例方法
*/
modalExample: ModalStreamTypeExample[ModalType]) => any | Promise<any>;
/**
* 处理当前弹框流中存在的弹框
* @param option.getModal 根据modalId获取弹框实例
* @returns
*/
handleModal?: (option: {
getModal: (modalId: string) => CreateModalFuncReturn | ModalStreamFuncReturn;
}) => any | Promise<any>;
}) => any | Promise<any>;
export type ModalStreamType = {
createModal: CreateModalStream<'createModal'>;
info: ModalFuncStream<'info'>;
success: ModalFuncStream<'success'>;
error: ModalFuncStream<'error'>;
warning: ModalFuncStream<'warning'>;
confirm: ModalFuncStream<'confirm'>;
};
export type ModalStreamFuncReturn = ReturnType<ModalFunc> & {
open: () => void;
};
export type ModalStreamTypeExample = {
createModal: CreateModalFuncReturn;
info: ModalStreamFuncReturn;
success: ModalStreamFuncReturn;
error: ModalStreamFuncReturn;
warning: ModalStreamFuncReturn;
confirm: ModalStreamFuncReturn;
};
export type ModalFuncStream<ModalType extends ModalStreamTypeKey = ModalStreamTypeKey> = Omit<ModalFuncProps, 'onOk' | 'onCancel'> & {
/**
* 点击确定回调
* @param next 下一步
* @returns
*/
onOk?: (next: ModalStreamNextFunc<ModalType>) => any | Promise<any>;
/**
* 点击取消回调
* @param next 下一步
* @returns
*/
onCancel?: (next: ModalStreamNextFunc<ModalType>) => any | Promise<any>;
};
export type CreateModalStream<ModalType extends ModalStreamTypeKey = ModalStreamTypeKey> = Omit<CreateModalFuncProps, 'destroyOnClose' | 'onOk' | 'onCancel'> & {
/**
* 点击确定回调
* * @param params content组件内使用defineExpose导出的对象
* @param next 下一步
* @returns
*/
onOk?: (params: any, next: ModalStreamNextFunc<ModalType>) => any | Promise<any>;
/**
* 点击取消回调
* * @param params content组件内使用defineExpose导出的对象
* @param next 下一步
* @returns
*/
onCancel?: (params: any, next: ModalStreamNextFunc<ModalType>) => any | Promise<any>;
};
export type ModalStreamTypeKey = keyof ModalStreamType;
export type CreateModalStreamProps<ModalType extends ModalStreamTypeKey = ModalStreamTypeKey> = ModalType extends ModalStreamTypeKey ? {
/**
* 弹框id
*/
modalId: string;
/**
* 弹框类型
*/
modalType?: ModalType;
/**
* 弹框属性
* @param params 上一步弹框传递的参数
* @param next 下一步
* @returns
*/
props: (params: any, next: ModalStreamNextFunc<ModalType>) => Promise<ModalStreamType[ModalType]>;
} : never;
export type CreateModalStreamFunc<ModalType extends ModalStreamTypeKey = ModalStreamTypeKey> = (streamList: CreateModalStreamProps<ModalType>[], firstModalId?: string) => {
/** 获取弹框实例 */
getModal: (modalId: string) => CreateModalFuncReturn | ModalStreamFuncReturn;
/** 清空弹框 */
clearAllModal: () => void;
/** 下一步 */
next: ModalStreamNextFunc<ModalType>;
} | undefined;
export type ApModalType = keyof Omit<ModalStaticFunctions, 'warn'>;