first commit
This commit is contained in:
55
src/hooks/modal.ts
Normal file
55
src/hooks/modal.ts
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* @Author: 田鑫
|
||||
* @Date: 2023-02-21 15:11:01
|
||||
* @LastEditors: 田鑫
|
||||
* @LastEditTime: 2023-02-21 15:11:02
|
||||
* @Description:
|
||||
*/
|
||||
import type { AppContext, Component, DefineComponent } from 'vue';
|
||||
import type { ModalConfig } from '@arco-design/web-vue';
|
||||
|
||||
import { ModalSimple } from '@/components/_base';
|
||||
|
||||
type CompType = DefineComponent | Component;
|
||||
interface SlotsType {
|
||||
default?: CompType;
|
||||
header?: CompType;
|
||||
close?: CompType;
|
||||
}
|
||||
|
||||
export const useModal = () => {
|
||||
const instance = getCurrentInstance();
|
||||
|
||||
const Modal = AModal;
|
||||
|
||||
Modal._context = instance?.appContext as AppContext;
|
||||
|
||||
Modal.simple = (config: ModalConfig, slots: SlotsType) => {
|
||||
const { title, content, ..._config } = config || {};
|
||||
|
||||
const modal = Modal.open({
|
||||
..._config,
|
||||
simple: false,
|
||||
footer: false,
|
||||
closable: false,
|
||||
content: () =>
|
||||
h(
|
||||
ModalSimple,
|
||||
{
|
||||
title,
|
||||
content,
|
||||
onClose: modal.close,
|
||||
},
|
||||
{
|
||||
default: slots?.default,
|
||||
header: slots?.header,
|
||||
close: slots?.close,
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
return modal;
|
||||
};
|
||||
|
||||
return { Modal };
|
||||
};
|
||||
Reference in New Issue
Block a user