Skip to content

Commit

Permalink
feat: modal confirm 开放 closable
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Apr 1, 2022
1 parent 41e8c78 commit 5c04bcd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions components/modal/modalApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface ModalConfig {
type VNodeProperty = 'title' | 'content' | 'footer';

const forceProps = {
closable: false,
maskClosable: false,
forGlobal: true,
displayDirective: 'if',
Expand All @@ -43,6 +42,7 @@ function create(type: ModalType, config: ModalConfig) {
} = {
width: 400,
show: true,
closable: false,
};
let cbFuncEnd = false;

Expand All @@ -60,22 +60,27 @@ function create(type: ModalType, config: ModalConfig) {
render(<Modal {...props} v-slots={slots} />, div);
}

async function handleCallBack(event: MouseEvent, cbFunc?: (event: MouseEvent) => void | Promise<any>) {
async function handleCallBack(
event: MouseEvent,
cbFunc?: (event: MouseEvent) => void | Promise<any>,
) {
if (cbFuncEnd) return;
cbFuncEnd = true;
try {
if (isFunction(cbFunc)) await cbFunc(event);
mergeProps.show = false;
renderModal();
} catch (error) { }
} catch (error) {}
cbFuncEnd = false;
}

function updateProps(options: ModalConfig) {
// 更新 props
Object.assign(mergeProps, options || {});
mergeProps.onOk = (event: MouseEvent) => handleCallBack(event, options.onOk);
mergeProps.onCancel = (event: MouseEvent) => handleCallBack(event, options.onCancel);
mergeProps.onOk = (event: MouseEvent) =>
handleCallBack(event, options.onOk);
mergeProps.onCancel = (event: MouseEvent) =>
handleCallBack(event, options.onCancel);

// 更新 slots
['title', 'content', 'footer'].forEach((key) => {
Expand Down

0 comments on commit 5c04bcd

Please sign in to comment.