Yue 2 лет назад
Родитель
Сommit
c218917210
2 измененных файлов с 23 добавлено и 13 удалено
  1. 3 3
      package.json
  2. 20 10
      src/core/utils/message.ts

+ 3 - 3
package.json

@@ -4,9 +4,9 @@
   "private": true,
   "scripts": {
     "dev": "vite",
-    "build": "run-p type-check build-only",
     "preview": "vite preview",
-    "build-only": "vite build",
+    "build": "vite build",
+    "build-check": "run-p type-check build-only",
     "type-check": "vue-tsc --noEmit",
     "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
   },
@@ -81,4 +81,4 @@
     "vite": "^3.1.8",
     "vue-tsc": "^1.0.8"
   }
-}
+}

+ 20 - 10
src/core/utils/message.ts

@@ -1,11 +1,5 @@
 import Swal from "sweetalert2"
 
-export const Toast = Swal.mixin({
-  toast: true,
-  position: "top-end",
-  showConfirmButton: false,
-})
-
 const DEFAULT_MESSAGE_BOX_CONFIG = {
   defalut: {
     buttonsStyling: false,
@@ -105,19 +99,35 @@ export const showToast = (type: string, message: string | undefined, callback?:
   const messageContent = {} as any
   messageContent.type = type
 
+  let opt: any = {
+    toast: true,
+    position: "top-end",
+    width: "360px",
+    showConfirmButton: false,
+  }
+  if (type == "success") {
+    opt.timer = 2000
+    opt.timerProgressBar = true
+    opt.didOpen = (toast: any) => {
+      toast.addEventListener("mouseenter", Swal.stopTimer)
+      toast.addEventListener("mouseleave", Swal.resumeTimer)
+    }
+    message = message || "操作成功"
+  }
   if (message) {
     messageContent.title = message
   }
-
-  const opt = Object.assign(
-    {},
+  opt = Object.assign(
+    opt,
     //DEFAULT_MESSAGE_BOX_CONFIG.defalut,
     DEFAULT_MESSAGE_BOX_CONFIG[type],
     messageContent,
     options || {}
   )
+  //console.log("TOAST", opt)
+
   return new Promise((resolve, reject) => {
-    Toast.fire(opt)
+    Swal.fire(opt)
       .then((isConfirmed) => {
         callback && callback(isConfirmed)
         resolve(isConfirmed)