diff --git a/src/utils/src/index.ts b/src/utils/src/index.ts index a351fca..538f536 100644 --- a/src/utils/src/index.ts +++ b/src/utils/src/index.ts @@ -4,6 +4,7 @@ export * from "./color"; export * from "./config"; export * from "./dateUtil"; export * from "./domUtils"; +export * from "./messageUtils"; export * from "./mitt"; export * from "./moduleHelper"; export * from "./router"; diff --git a/src/utils/src/messageUtils.ts b/src/utils/src/messageUtils.ts new file mode 100644 index 0000000..347edf6 --- /dev/null +++ b/src/utils/src/messageUtils.ts @@ -0,0 +1,58 @@ +import { showDialog, showFailToast, showNotify, showSuccessToast, showToast } from "vant"; +import type { MessageMode } from "#/httpClient"; + +export const messageUtils = { + showMessage(message: string, mode: MessageMode = "toast") { + if (mode === "toast") { + showToast(message); + } else if (mode === "dialog") { + showDialog({ + title: "信息", + message, + theme: "round-button", + }).then(() => { + // on close + }); + } else if (mode === "notification") { + showNotify({ type: "primary", message }); + } else if (mode === "none") { + // Handle as needed + } + }, + + showSuccessMessage(message: string, mode: MessageMode = "toast") { + if (mode === "toast") { + showSuccessToast(message); + } else if (mode === "dialog") { + showDialog({ + title: "成功", + message, + theme: "round-button", + }).then(() => { + // on close + }); + } else if (mode === "notification") { + showNotify({ type: "success", message }); + } else if (mode === "none") { + // Handle as needed + } + }, + + showErrorMessage(message: string, mode: MessageMode = "toast") { + if (mode === "toast") { + showFailToast(message); + } else if (mode === "dialog") { + showDialog({ + title: "错误", + message, + theme: "round-button", + }).then(() => { + // on close + }); + } else if (mode === "notification") { + showNotify({ type: "danger", message }); + } else if (mode === "none") { + // Handle as needed + } + }, +};