Browse Source

showPage / showDialog

luoyifan 4 years ago
parent
commit
a5bb16d757
2 changed files with 71 additions and 12 deletions
  1. 68 10
      src/Scope.ts
  2. 3 2
      src/controls/MainTab.js

+ 68 - 10
src/Scope.ts

@@ -16,7 +16,7 @@ export class Scope {
     /**
      * 一个 ExtJS 能接受的配置对象
      */
-    config
+    vjson
 
     /**
      * 双向绑定的模型对象
@@ -47,26 +47,84 @@ export class Scope {
         })
     }
 
-    constructor({model, vjson}) {
-        this.viewModel = new Ext.app.ViewModel(model);
-        this.viewModel.yvanScope = this
-        this._applyWatchList()
+    /**
+     * 以对话框模式打开当前模块
+     * @param sender 发送者(按钮或Scope对象)
+     * @param option 覆盖选项(可以为空)
+     */
+    showDialog(sender, option) {
+        const that = this
 
+        const config = _.defaultsDeep({
+            animateTarget: sender,
+            listeners: {
+                show(sender) {
+                    // 记录句柄
+                    if (sender && !that._handle) {
+                        that._handle = sender
+                    }
+
+                    // 调用onLoad回调
+                    that.onLoad()
+
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(that.vjson.listeners?.show, that, arguments)
+                }
+            },
+
+        }, option, that.vjson)
+
+        const win = new Ext.Window(config);
+        win.show();
+    }
+
+    /**
+     * 以标签模式打开当前模块
+     * @param option 覆盖选项(可以为空)
+     */
+    showPage(option) {
         const that = this
-        this.config = _.defaultsDeep({
-            closable: true,
+
+        const config = _.defaultsDeep({
             listeners: {
                 added(sender) {
                     // 记录句柄
                     if (sender && !that._handle) {
                         that._handle = sender
                     }
+
                     // 调用onLoad回调
                     that.onLoad()
 
                     // 如果vjson中配置了 afterrender ,需要恢复状态
-                    invokeMethod(vjson.listeners?.added, that, arguments)
-                },
+                    invokeMethod(that.vjson.listeners?.show, that, arguments)
+                }
+            },
+
+        }, option, that.vjson)
+
+        const tt = Ext.getCmp('TT')
+        tt.addScope(this, config)
+
+        return config
+    }
+
+    /**
+     * 关闭对话框(或标签页)
+     */
+    close() {
+        this._handle.close()
+    }
+
+    constructor({model, vjson}) {
+        this.viewModel = new Ext.app.ViewModel(model);
+        this.viewModel.yvanScope = this
+        this._applyWatchList()
+
+        const that = this
+        this.vjson = _.defaultsDeep({
+            closable: true,
+            listeners: {
                 afterrender(sender) {
                     // 记录句柄
                     if (sender && !that._handle) {
@@ -115,7 +173,7 @@ export class Scope {
                     // 销毁 viewModel
                     that.viewModel.destroy()
                     delete that.viewModel
-                    delete that.config
+                    delete that.vjson
                     delete that._watchList
                     delete that._handle
 

+ 3 - 2
src/controls/MainTab.js

@@ -35,8 +35,9 @@ export default function () {
         /**
          * 添加一个业务模块实例到选项卡
          * @param scopeInstance 业务对象实例
+         * @param config ExtJS配置对象
          */
-        addScope(scopeInstance) {
+        addScope(scopeInstance, config) {
             if (scopeInstance.path) {
                 for (let i = 0; i < this.items.items.length; i++) {
                     // 找到当前 tabs 里有没有已经打开过
@@ -53,7 +54,7 @@ export default function () {
             this.add({
                 uuid: scopeInstance.path,
                 closable: true,
-                ...scopeInstance.config,
+                ...config,
             })
 
             this.setActiveTab(scopeInstance._handle);