Browse Source

底层命令栈增加命令日志导出

haojianlong 5 years ago
parent
commit
773dbe8581

+ 1 - 1
saga-web-base/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/base",
-    "version": "2.1.16",
+    "version": "2.1.18",
     "description": "上格云Web基础库。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 14 - 0
saga-web-base/src/undo/SCommandLog.ts

@@ -0,0 +1,14 @@
+/**
+ *  命令日志接口
+ *
+ *  @author haojianlong
+ * */
+
+export interface SCommandLog {
+    /** 命令名称    */
+    command: string;
+    /** 命令描述    */
+    desc: string;
+    /** 命令细节    */
+    detail: string;
+} // interface SCommandLog

+ 14 - 3
saga-web-base/src/undo/SUndoCommand.ts

@@ -4,14 +4,17 @@
  * @author  庞利祥(sybotan@126.com)
  */
 export abstract class SUndoCommand {
+    /** 命令名称    */
+    abstract get command(): string;
+    /** 命令描述    */
+    desc: string = "undefined";
+
     /**
      * 构造函数
      *
      * @param   parent      指向父命令
      */
-    protected constructor(parent: SUndoCommand | null = null) {
-
-    } // Constructor
+    protected constructor(parent: SUndoCommand | null = null) {} // Constructor
 
     /**
      * undo回调
@@ -39,4 +42,12 @@ export abstract class SUndoCommand {
     id(): number {
         return -1;
     } // Function id()
+
+    /**
+     * 命令转为描述谢姐
+     *
+     * */
+    toString(): string {
+        return "";
+    } // toString()
 } // Class SUndoCommand

+ 18 - 1
saga-web-base/src/undo/SUndoStack.ts

@@ -1,5 +1,6 @@
 import { SObject } from "../SObject";
 import { SUndoCommand } from "./SUndoCommand";
+import { SCommandLog } from "./SCommandLog";
 
 /**
  * Undo操作堆栈
@@ -90,7 +91,7 @@ export class SUndoStack extends SObject {
      */
     count(): number {
         return this.cmdStack.length;
-    } // Function cout()
+    } // Function count()
 
     /**
      * 将命令添加到命令栈
@@ -106,4 +107,20 @@ export class SUndoStack extends SObject {
         this.cmdStack.push(cmd);
         this._index = this.cmdStack.length - 1;
     } // Function push()
+
+    /**
+     * 将命令堆栈转为日志(命令数组)
+     *
+     * */
+    toLog(): SCommandLog[] {
+        let stackList: SCommandLog[] = [];
+        for (let i = 0; i <= this.index; i++) {
+            stackList.push({
+                command: this.cmdStack[i].command,
+                desc: this.cmdStack[i].desc,
+                detail: this.cmdStack[i].toString()
+            });
+        }
+        return stackList;
+    } // Function toLog()
 } // Class SUndoStack