2023-12-07 13:28:59 +00:00
|
|
|
import { escapeHtml } from "@/utils/html";
|
2022-07-12 08:55:28 +00:00
|
|
|
import { App } from "vue";
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
export class Notifier {
|
2022-07-12 08:55:28 +00:00
|
|
|
private app: App;
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2022-07-12 08:55:28 +00:00
|
|
|
constructor(app: App) {
|
|
|
|
this.app = app;
|
2019-06-17 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:39:59 +00:00
|
|
|
success(message: string): void {
|
2022-08-26 14:08:58 +00:00
|
|
|
this.notification(message, "success");
|
2019-06-17 15:15:27 +00:00
|
|
|
}
|
2019-09-11 07:59:01 +00:00
|
|
|
|
2020-10-13 18:39:59 +00:00
|
|
|
error(message: string): void {
|
2022-08-26 14:08:58 +00:00
|
|
|
this.notification(message, "danger");
|
2019-12-03 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:39:59 +00:00
|
|
|
info(message: string): void {
|
2022-08-26 14:08:58 +00:00
|
|
|
this.notification(message, "info");
|
2019-12-03 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 08:55:28 +00:00
|
|
|
private notification(message: string, type: string) {
|
|
|
|
this.app.config.globalProperties.$oruga.notification.open({
|
2023-12-07 13:28:59 +00:00
|
|
|
message: escapeHtml(message),
|
2019-09-11 07:59:01 +00:00
|
|
|
duration: 5000,
|
2022-08-26 14:08:58 +00:00
|
|
|
position: "bottom-right",
|
2019-12-03 10:29:51 +00:00
|
|
|
type,
|
2019-09-11 07:59:01 +00:00
|
|
|
});
|
|
|
|
}
|
2019-06-17 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 08:55:28 +00:00
|
|
|
export const notifierPlugin = {
|
|
|
|
install(app: App) {
|
|
|
|
const notifier = new Notifier(app);
|
|
|
|
app.config.globalProperties.$notifier = notifier;
|
|
|
|
app.provide("notifier", notifier);
|
|
|
|
},
|
|
|
|
};
|