common.ts 545 B

123456789101112131415161718192021222324252627
  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. export const safeJsonParse = (val: string, defaultValue?: any) => {
  20. try {
  21. return JSON.parse(val);
  22. } catch {
  23. return defaultValue ?? {};
  24. }
  25. };