import { defineStore } from 'pinia' import { ref } from 'vue' export interface ToastItem { id: number type: 'success' | 'error' | 'info' message: string } /** 全局 toast 通知(后台各页统一反馈) */ export const useToastStore = defineStore('toast', () => { const toasts = ref([]) let seq = 0 const remove = (id: number) => { toasts.value = toasts.value.filter((t) => t.id !== id) } const show = (type: ToastItem['type'], message: string) => { const id = ++seq toasts.value.push({ id, type, message }) setTimeout(() => remove(id), 3200) return id } const success = (message: string) => show('success', message) const error = (message: string) => show('error', message) const info = (message: string) => show('info', message) return { toasts, show, success, error, info, remove } })