luoyifan 4 vuotta sitten
vanhempi
commit
f18e6fcf27
3 muutettua tiedostoa jossa 80 lisäystä ja 8 poistoa
  1. 74 2
      src/Scope.ts
  2. 4 5
      src/controls/MainTab.js
  3. 2 1
      src/init.ts

+ 74 - 2
src/Scope.ts

@@ -31,14 +31,50 @@ export class Scope {
         this.config = _.defaultsDeep({
             closable: true,
             listeners: {
-                afterrender(sender) {
+                added(sender) {
                     // 记录句柄
                     that._handle = sender
                     // 调用onLoad回调
                     that.onLoad()
                     // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(vjson.listeners?.added, that, arguments)
+                },
+                afterrender(sender) {
+                    // 调用 onRender 回调
+                    that.onRender()
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
                     invokeMethod(vjson.listeners?.afterrender, that, arguments)
-                }
+                },
+                activate(sender) {
+                    // 调用 onActivate 回调
+                    that.onActivate()
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(vjson.listeners?.activate, that, arguments)
+                },
+                deactivate(sender) {
+                    // 调用 onActivate 回调
+                    that.onDeactivate()
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(vjson.listeners?.deactivate, that, arguments)
+                },
+                beforedestroy(sender) {
+                    // 调用 onBeforeDestroy 回调
+                    that.onBeforeDestroy()
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(vjson.listeners?.beforedestroy, that, arguments)
+                },
+                beforeclose(sender) {
+                    // 调用 onActivate 回调
+                    that.onBeforeClose()
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(vjson.listeners?.beforeclose, that, arguments)
+                },
+                destroy(sender) {
+                    // 调用 onActivate 回调
+                    that.onDestroy()
+                    // 如果vjson中配置了 afterrender ,需要恢复状态
+                    invokeMethod(vjson.listeners?.destroy, that, arguments)
+                },
             },
             yvanScope: this,
             viewModel: this.viewModel,
@@ -52,6 +88,42 @@ export class Scope {
     }
 
     /**
+     * 渲染完成之后的回调
+     */
+    onRender() {
+    }
+
+    /**
+     * 被激活时的回调(可能执行多次)
+     */
+    onActivate() {
+    }
+
+    /**
+     * 进入未激活状态之前回调的函数
+     */
+    onDeactivate() {
+    }
+
+    /**
+     * 关闭之前的回调(只有 tab 选项卡有这个选项)
+     */
+    onBeforeClose() {
+    }
+
+    /**
+     * 组件被卸载之前的回调
+     */
+    onBeforeDestroy() {
+    }
+
+    /**
+     * 组件卸载之后的回调
+     */
+    onDestroy() {
+    }
+
+    /**
      * 产生一个当前模块有效的唯一id
      * @param key 唯一编号
      */

+ 4 - 5
src/controls/MainTab.js

@@ -27,17 +27,16 @@ export default function () {
         },
 
         /**
-         * 添加一个业务模块到选项卡
+         * 添加一个业务模块实例到选项卡
          * @param scopeInstance 业务对象实例
          */
         addScope(scopeInstance) {
-            const handle = this.add({
-                ...scopeInstance.config,
+            this.add({
                 closable: true,
+                ...scopeInstance.config,
             })
-            scopeInstance._invokeLoad(handle)
 
-            this.setActiveTab(handle);
+            this.setActiveTab(scopeInstance._handle);
         }
     });
 

+ 2 - 1
src/init.ts

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 import initMainTab from './controls/MainTab'
 
 export function init() {
@@ -36,7 +37,7 @@ export function init() {
      */
     const _doAddListener = Ext.mixin.Observable.prototype.doAddListener
     Ext.mixin.Observable.prototype.doAddListener = function (ename, fn, scope, options, order, caller, manager) {
-        if (typeof fn === 'string' && fn.startsWith('scope.')) {
+        if (typeof fn === 'string' && _.startsWith(fn, 'scope.')) {
             // console.log('doAddListener', ename, fn, scope, options, order, caller, manager)
             const vm = this.lookupViewModel()
             if (vm && vm.yvanScope) {