Ver código fonte

frontend: use toast instead of alert() to notify error

wangweimin 4 anos atrás
pai
commit
2e398d5834
3 arquivos alterados com 19 adições e 4 exclusões
  1. 2 2
      webiojs/src/handlers/input.ts
  2. 4 2
      webiojs/src/session.ts
  3. 13 0
      webiojs/src/utils.ts

+ 2 - 2
webiojs/src/handlers/input.ts

@@ -1,5 +1,5 @@
 import {Command, Session} from "../session";
-import {body_scroll_to, LRUMap, make_set} from "../utils";
+import {body_scroll_to, error_alert, LRUMap, make_set} from "../utils";
 import {InputItem} from "../models/input/base"
 import {state} from '../state'
 import {all_input_items} from "../models/input"
@@ -211,7 +211,7 @@ class FormController {
 
             for (let name in that.name2input)
                 if (!that.name2input[name].check_valid())
-                    return alert('输入项存在错误,请修复错误后再提交');
+                    return error_alert('输入项存在错误,请消除错误后再提交');
 
             let data: { [i: string]: any } = {};
             $.each(that.name2input, (name, ctrl) => {

+ 4 - 2
webiojs/src/session.ts

@@ -1,3 +1,5 @@
+import {error_alert} from "./utils";
+
 export interface Command {
     command: string
     task_id: string
@@ -94,7 +96,7 @@ export class WebSocketSession implements Session {
 
     send_message(msg: ClientEvent, onprogress?: (loaded: number, total: number) => void): void {
         if (this.closed())
-            return alert("与服务器连接已断开,请刷新页面重新操作");
+            return error_alert("与服务器连接已断开,请刷新页面重新操作");
 
         if (this.ws === null)
             return console.error('WebSocketWebIOSession.ws is null when invoke WebSocketWebIOSession.send_message. ' +
@@ -191,7 +193,7 @@ export class HttpSession implements Session {
 
     send_message(msg: ClientEvent, onprogress?: (loaded: number, total: number) => void): void {
         if (this.closed())
-            return alert("与服务器连接已断开,请刷新页面重新操作");
+            return error_alert("与服务器连接已断开,请刷新页面重新操作");
 
         if (this.debug) console.info('<<<', msg);
         $.ajax({

+ 13 - 0
webiojs/src/utils.ts

@@ -1,4 +1,6 @@
 // Indexable Types
+import {state} from "./state";
+
 interface Dict {
     [index: string]: any;
 }
@@ -135,4 +137,15 @@ export function openApp(name: string, new_window: boolean) {
         window.open(url.href);
     else
         window.location.href = url.href;
+}
+
+
+export function error_alert(text: string, duration: number = 1.5) {
+    Toastify({
+        text: text,
+        duration: duration * 1000,
+        gravity: "top",
+        position: 'center',
+        backgroundColor: '#e53935',
+    }).showToast();
 }