Files
gdt-tool/src/renderer/store/snackbar.ts
T
2025-11-05 14:46:49 +08:00

49 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia';
import { ref } from 'vue';
export interface SnackbarAction {
text: string;
color?: string;
handler?: () => void;
}
export const useSnackbarStore = defineStore('snackbar', () => {
const isVisible = ref(false);
const message = ref('');
const color = ref('info');
const timeout = ref(3000);
const actions = ref<SnackbarAction[]>([]);
const show = (msg: string, clr = 'info', tout = 3000, actionList: SnackbarAction[] = []) => {
message.value = msg;
color.value = clr;
timeout.value = tout;
actions.value = actionList;
isVisible.value = true;
};
const success = (msg: string, tout = 3000) => show(msg, 'success', tout);
const error = (msg: string, tout = 3000) => show(msg, 'error', tout);
const warning = (msg: string, tout = 3000) => show(msg, 'warning', tout);
const info = (msg: string, tout = 3000) => show(msg, 'info', tout);
const hide = () => {
isVisible.value = false;
actions.value = [];
};
return {
isVisible,
message,
color,
timeout,
actions,
show,
success,
error,
warning,
info,
hide,
};
});