44 lines
843 B
TypeScript
44 lines
843 B
TypeScript
import { ref, type Ref } from "vue";
|
|
|
|
enum color {
|
|
Red,
|
|
Yellow,
|
|
Blue,
|
|
Green,
|
|
}
|
|
|
|
type ErrorMessageContent = {
|
|
message: string;
|
|
color: color;
|
|
id: number;
|
|
timeout: number;
|
|
};
|
|
|
|
let id: number = 0;
|
|
const getId = () => {
|
|
id = id + 1;
|
|
return id;
|
|
};
|
|
|
|
function addNewMessage(errorMessage: string, type?: color, timeout?: number) {
|
|
if (timeout == null) {
|
|
timeout = 5000;
|
|
}
|
|
if (type == null) {
|
|
type = color.Red;
|
|
}
|
|
|
|
const data: ErrorMessageContent = {
|
|
message: errorMessage,
|
|
timeout: timeout,
|
|
color: type,
|
|
id: getId(),
|
|
};
|
|
errorList.value.push(data);
|
|
setTimeout(() => errorList.value.slice(0, 1), timeout);
|
|
}
|
|
|
|
const errorList: Ref<ErrorMessageContent[]> = ref([]);
|
|
|
|
export { addNewMessage, errorList, color, type ErrorMessageContent };
|