Browse Source

报错提示输出bug修复

ellisran 5 months ago
parent
commit
79bcfd03ea
3 changed files with 8 additions and 7 deletions
  1. 1 1
      app/base/base_controller.js
  2. 1 0
      app/controller/measure_controller.js
  3. 6 6
      app/view/layout/layout.ejs

+ 1 - 1
app/base/base_controller.js

@@ -93,7 +93,7 @@ class BaseController extends Controller {
             const renderData = {
                 min: this.app.config.min,
                 content: viewString,
-                message: JSON.stringify(message),
+                message: message ? message : '',
                 modal: modalString,
                 dropDownMenu: data.dropDownMenu === undefined ? [] : data.dropDownMenu,
                 breadCrumb: data.breadCrumb === undefined ? '' : data.breadCrumb,

+ 1 - 0
app/controller/measure_controller.js

@@ -317,6 +317,7 @@ module.exports = app => {
             } catch (err) {
                 this.log(err);
                 console.log(err);
+                ctx.session.postError = err.toString();
                 ctx.redirect(ctx.request.header.referer);
             }
         }

+ 6 - 6
app/view/layout/layout.ejs

@@ -67,12 +67,12 @@
         "showMethod": "fadeIn",
         "hideMethod": "fadeOut"
     };
-    let toastInfo = '<%- message %>';
-    try {
-        toastInfo = toastInfo !== '' && toastInfo !== 'null' ? JSON.parse(toastInfo) : '';
-    } catch (error) {
-        toastInfo = '';
-    }
+    const toastInfo = JSON.parse(unescape('<%- escape(JSON.stringify(message)) %>'));
+    // try {
+    //     toastInfo = toastInfo !== '' && toastInfo !== 'null' ? JSON.parse(toastInfo) : '';
+    // } catch (error) {
+    //     toastInfo = '';
+    // }
 
     if (toastInfo !== '') {
         toastr[toastInfo.type](toastInfo.message);