Selaa lähdekoodia

全局捕获异常

CzRger 6 kuukautta sitten
vanhempi
commit
1a430b0c2e
2 muutettua tiedostoa jossa 11 lisäystä ja 1 poistoa
  1. 10 1
      src/main.ts
  2. 1 0
      src/style/cus.scss

+ 10 - 1
src/main.ts

@@ -10,13 +10,22 @@ import initDirect from '@/plugins/initDirect'
 import 'default-passive-events'
 import 'default-passive-events'
 import './browerPatch'
 import './browerPatch'
 import { createPinia } from 'pinia'
 import { createPinia } from 'pinia'
-import ElementPlus from 'element-plus'
+import ElementPlus, {ElNotification} from 'element-plus'
 import 'element-plus/dist/index.css'
 import 'element-plus/dist/index.css'
 
 
 
 
 // repeatFileValid()
 // repeatFileValid()
 await initMainRouter()  //  路由挂载前初始化路由表
 await initMainRouter()  //  路由挂载前初始化路由表
 const app = createApp(App)
 const app = createApp(App)
+app.config.errorHandler = (err, instance, info) => {
+  const path = instance?.$options.__file
+  ElNotification({
+    duration: 0,
+    title: `系统异常(${path?.match(/smart-search-web(.*)/)?.[1] || path})`,
+    message: err.stack,
+    type: 'error',
+  })
+};
 app.use(createPinia())
 app.use(createPinia())
 await initProperties(app)
 await initProperties(app)
 initComponent(app)
 initComponent(app)

+ 1 - 0
src/style/cus.scss

@@ -9,6 +9,7 @@
   --cus-main-color: #2E81FF;
   --cus-main-color: #2E81FF;
   --cus-main-color-rgb: 46, 129, 255;
   --cus-main-color-rgb: 46, 129, 255;
   --cus-main-color-hex-2: #273A58;
   --cus-main-color-hex-2: #273A58;
+  --el-notification-width: min-content;
 }
 }
 
 
 .__hover {
 .__hover {