common.ts 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { ElMessage } from "element-plus";
  2. let msgBoxInstance: any = null;
  3. /**
  4. * [showMessage 统一封装消息]
  5. *
  6. * @return {[params]} [return description]
  7. */
  8. export const showMessage = (params: {
  9. type: string;
  10. message: string;
  11. icon?: string;
  12. duration?: number;
  13. }) => {
  14. if (msgBoxInstance) {
  15. msgBoxInstance.close();
  16. }
  17. msgBoxInstance = ElMessage(params as any);
  18. };
  19. /**
  20. * [倒计时]
  21. *
  22. * @return {[params]} [return description]
  23. */
  24. export function startCountdown(
  25. duration: number,
  26. onTick?: (args: number) => void,
  27. onComplete?: () => void
  28. ) {
  29. let time = duration;
  30. const timer = setInterval(() => {
  31. time--;
  32. if (typeof onTick === "function") {
  33. onTick(time);
  34. }
  35. if (time <= 0) {
  36. clearInterval(timer);
  37. if (typeof onComplete === "function") {
  38. onComplete();
  39. }
  40. }
  41. }, 1000);
  42. }