message.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import store from "@/store";
  2. export type MessageType = {
  3. txt: string;
  4. type: "info" | "success" | "error" | "warning";
  5. duration: number;
  6. };
  7. export const MessageFu = {
  8. info: (txt: string, duration?: number) => {
  9. store.dispatch({
  10. type: "layout/message",
  11. payload: {
  12. txt,
  13. type: "info",
  14. duration: duration === undefined ? 3 : duration,
  15. },
  16. });
  17. },
  18. success: (txt: string, duration?: number) => {
  19. store.dispatch({
  20. type: "layout/message",
  21. payload: {
  22. txt,
  23. type: "success",
  24. duration: duration === undefined ? 3 : duration,
  25. },
  26. });
  27. },
  28. error: (txt: string, duration?: number) => {
  29. store.dispatch({
  30. type: "layout/message",
  31. payload: {
  32. txt,
  33. type: "error",
  34. duration: duration === undefined ? 3 : duration,
  35. },
  36. });
  37. },
  38. warning: (txt: string, duration?: number) => {
  39. store.dispatch({
  40. type: "layout/message",
  41. payload: {
  42. txt,
  43. type: "warning",
  44. duration: duration === undefined ? 3 : duration,
  45. },
  46. });
  47. },
  48. };