feat: 重构 ToastService,添加消息管理功能并更新按钮事件处理
This commit is contained in:
@ -1,10 +1,23 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// @ts-expect-error - Ignore missing types
|
// @ts-expect-error - Ignore missing types
|
||||||
import ToastEventBus from 'primevue/toasteventbus';
|
import ToastEventBus from 'primevue/toasteventbus';
|
||||||
|
import type { ToastServiceMethods } from 'primevue/toastservice';
|
||||||
|
|
||||||
function showToast() {
|
// https://github.com/primefaces/primevue/blob/61929eae7526015af0362fc5889f2af7527403d1/packages/primevue/src/toastservice/ToastService.js
|
||||||
ToastEventBus.emit('add', { severity: 'info', summary: 'Info', detail: 'Message Content', life: 3000 });
|
const ToastService: ToastServiceMethods = {
|
||||||
}
|
add: (message) => {
|
||||||
|
ToastEventBus.emit('add', message);
|
||||||
|
},
|
||||||
|
remove: (message) => {
|
||||||
|
ToastEventBus.emit('remove', message);
|
||||||
|
},
|
||||||
|
removeGroup: (group) => {
|
||||||
|
ToastEventBus.emit('remove-group', group);
|
||||||
|
},
|
||||||
|
removeAllGroups: () => {
|
||||||
|
ToastEventBus.emit('remove-all-groups');
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -26,6 +39,14 @@ function showToast() {
|
|||||||
|
|
||||||
<DatePicker dateFormat="dd/mm/yy" />
|
<DatePicker dateFormat="dd/mm/yy" />
|
||||||
|
|
||||||
<Button @click="showToast">ToastService</Button>
|
<Button @click="ToastService.add({ severity: 'info', summary: 'Info', detail: 'Message Content', life: 3000 })">
|
||||||
|
ToastService
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.p-toast {
|
||||||
|
max-width: calc(100% - 50px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
Reference in New Issue
Block a user