common.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }
  43. export const webSiteFlagRelation: Record<string, string> = {
  44. 'user': '1', // 海外用户
  45. 'distributor': '2' // 国内分销商
  46. }
  47. const webSiteContactRelation: Record<string, string> = {
  48. 'user': 'email', // 海外用户
  49. 'distributor': 'mobile' // 国内分销商
  50. }
  51. export const webSiteLanguageRelation: Record<string, string> = {
  52. 'user': 'en', // 海外用户
  53. 'distributor': 'zh' // 国内分销商
  54. }
  55. export const getContactType = () => {
  56. const config = useRuntimeConfig()
  57. const contactType = webSiteContactRelation[config.public.appType];
  58. return contactType;
  59. }