Skip to content

Commit

Permalink
feat: add message utils
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklin committed Oct 25, 2023
1 parent 1784776 commit e8cd16d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
58 changes: 58 additions & 0 deletions src/utils/src/messageUtils.ts
Original file line number Diff line number Diff line change
@@ -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
}
},
};

0 comments on commit e8cd16d

Please sign in to comment.