28 lines
608 B
TypeScript
28 lines
608 B
TypeScript
import type { AppContext } from "vue";
|
|
|
|
type MessageType = "info" | "success" | "warning" | "error";
|
|
|
|
type MessageHandler = (content: string) => unknown | Promise<unknown>;
|
|
|
|
type MessageApi = {
|
|
[type in MessageType]?: MessageHandler;
|
|
};
|
|
|
|
export const showTDesignMessage = async (
|
|
appContext: AppContext | undefined,
|
|
type: MessageType,
|
|
content: string
|
|
) => {
|
|
const handler = (appContext?.config.globalProperties.$message as MessageApi | undefined)?.[type];
|
|
if (handler) {
|
|
await handler(content);
|
|
return;
|
|
}
|
|
if ("error" === type) {
|
|
console.error(content);
|
|
return;
|
|
}
|
|
console.warn(content);
|
|
};
|
|
|