feat: 添加 useDialogRef 函数,优化对话框引用管理,更新对话框组件逻辑
This commit is contained in:
@ -1,3 +1,13 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useDialogRef } from '@/utils/primevue';
|
||||||
|
|
||||||
|
const dialogRef = useDialogRef();
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>dialog-content.vue</div>
|
<div mb-8>dialog-content.vue</div>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<Button type="button" label="关闭" severity="secondary" @click="dialogRef?.close"></Button>
|
||||||
|
<Button type="button" label="关闭" @click="dialogRef?.close"></Button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts"></script>
|
<script lang="ts"></script>
|
||||||
|
|
||||||
<script setup lang="tsx">
|
<script setup lang="tsx">
|
||||||
import { ConfirmationService, DialogService, ToastService } from '@/utils/primevue';
|
import { ConfirmationService, DialogService, ToastService, useDialogRef } from '@/utils/primevue';
|
||||||
import dialogContent from './dialog-content.vue';
|
import dialogContent from './dialog-content.vue';
|
||||||
|
|
||||||
const dynamicComponent = defineComponent({
|
const dynamicComponent = defineComponent({
|
||||||
@ -12,7 +12,7 @@ const dynamicComponent = defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props, ctx) {
|
setup(props, ctx) {
|
||||||
const dialogRef = inject<ComputedRef<DynamicDialogOptions>>('dialogRef');
|
const dialogRef = useDialogRef();
|
||||||
return () => (
|
return () => (
|
||||||
<div>
|
<div>
|
||||||
<button onClick={() => ctx.emit('close')}>emit('close')</button> <hr />
|
<button onClick={() => ctx.emit('close')}>emit('close')</button> <hr />
|
||||||
@ -55,7 +55,6 @@ const openDialog = async () => {
|
|||||||
DialogService.open(dialogContent, {
|
DialogService.open(dialogContent, {
|
||||||
props: {
|
props: {
|
||||||
header: '对话框2',
|
header: '对话框2',
|
||||||
position: 'bottomright',
|
|
||||||
// draggable: false, // Header1的 draggable: true 会影响 Header2,如果指定 draggable: false,则不会受到影响。
|
// draggable: false, // Header1的 draggable: true 会影响 Header2,如果指定 draggable: false,则不会受到影响。
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -68,6 +68,7 @@ export const DialogService: DialogServiceMethods = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
export function useDialogRef() {
|
||||||
type DynamicDialogOptions = import('primevue/dynamicdialogoptions').DynamicDialogOptions;
|
type DialogRef = ComputedRef<import('primevue/dynamicdialogoptions').DynamicDialogInstance>;
|
||||||
|
return inject<DialogRef>('dialogRef');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user