modal.ts 755 B

123456789101112131415161718192021222324252627282930
  1. import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
  2. let loadingInstance: ReturnType<typeof ElLoading.service> | null = null
  3. export const $modal = {
  4. msgSuccess(msg: string) {
  5. ElMessage.success(msg)
  6. },
  7. msgError(msg: string) {
  8. ElMessage.error(msg)
  9. },
  10. msgWarning(msg: string) {
  11. ElMessage.warning(msg)
  12. },
  13. confirm(msg: string, title = '提示') {
  14. return ElMessageBox.confirm(msg, title, {
  15. type: 'warning',
  16. confirmButtonText: '确定',
  17. cancelButtonText: '取消'
  18. })
  19. },
  20. loading(text: string) {
  21. loadingInstance?.close()
  22. loadingInstance = ElLoading.service({ text, background: 'rgba(0,0,0,0.05)' })
  23. },
  24. closeLoading() {
  25. loadingInstance?.close()
  26. loadingInstance = null
  27. }
  28. }