Pārlūkot izejas kodu

pda-client 多级子页面回退到上一级页面问题,支持页面切换动画

lizw 3 gadi atpakaļ
vecāks
revīzija
9b0c2c46bc
1 mainītis faili ar 32 papildinājumiem un 26 dzēšanām
  1. 32 26
      src/Scope.ts

+ 32 - 26
src/Scope.ts

@@ -94,6 +94,8 @@ export class Scope {
             handle.setStyle({'z-index': 1})
             Ext.Viewport.getLayout().setAnimation({type: 'slide', direction: 'right', duration: 300})
             Ext.Viewport.setActiveItem(handle)
+            Scope.SHOW_PAGE_STACK.length = 0
+            Scope.SHOW_PAGE_STACK.push((window as any).mainWindow)
         }
     }
 
@@ -126,8 +128,6 @@ export class Scope {
                 vjsonOption,
                 dataOption
             } = option
-
-
             this._vjsonOption = vjsonOption;
             this._dataOption = dataOption;
             const vmodel = _.defaultsDeep({
@@ -167,7 +167,6 @@ export class Scope {
                 }, config)
             }
             that._handle = Ext.create(config)
-
             this.viewModel = that._handle.getViewModel()
             this.viewModel.yvanScope = this
             that._handle.on({
@@ -186,31 +185,35 @@ export class Scope {
                         const $back = $(sender.el.dom)
                             .find('.navbar>.x-panelheader')
                             .find('.x-body-el>.fa-angle-left')
+                        $back.off('click');
                         $back.on('click', () => {
-                            // // 显示前一个页面
-                            // const index = Scope.SHOW_PAGE_STACK.findIndex(scope => scope === this);
-                            // if (index >= 0) {
-                            //     Scope.SHOW_PAGE_STACK.splice(index, 1);
-                            // }
-                            // const scopeArr = _.sortBy(Scope.SHOW_PAGE_STACK, scope => scope._lastShowTime)
-                            // if (scopeArr.length > 0) {
-                            //     const scope = scopeArr[scopeArr.length - 1]
-                            //     scope._handle.setStyle({'z-index': 1})
-                            //     let actived = false;
-                            //     (Ext.Viewport.getItems().items as []).forEach((item, idx) => {
-                            //         if (!actived && item === scope._handle) {
-                            //             actived = true
-                            //             Ext.Viewport.getLayout().setAnimation({type: 'slide', direction: 'right', duration: 300})
-                            //             Ext.Viewport.setActiveItem(idx)
-                            //             scope._lastShowTime = new Date().getTime()
-                            //         }
-                            //     })
-                            // }
+                            const handle = Ext.Viewport.getActiveItem();
+                            // 显示前一个页面
+                            const index = Scope.SHOW_PAGE_STACK.findIndex(scope => scope._handle === handle);
+                            // console.log("###### remove", index)
+                            if (index >= 0) {
+                                Scope.SHOW_PAGE_STACK.splice(index, 1);
+                            }
+                            const scopeArr = _.sortBy(Scope.SHOW_PAGE_STACK, scope => scope._lastShowTime)
+                            if (scopeArr.length > 0) {
+                                const scope = scopeArr[scopeArr.length - 1]
+                                scope._handle.setStyle({'z-index': 1})
+                                let actived = false;
+                                (Ext.Viewport.getItems().items as []).forEach((item, idx) => {
+                                    if (!actived && item === scope._handle) {
+                                        actived = true
+                                        Ext.Viewport.getLayout().setAnimation({type: 'slide', direction: 'right', duration: 300})
+                                        Ext.Viewport.setActiveItem(idx)
+                                        scope._lastShowTime = new Date().getTime()
+                                        // console.log("###### show", idx, Scope.SHOW_PAGE_STACK)
+                                    }
+                                })
+                            }
                             // 关闭
-                            that._handle.setStyle({'z-index': 0})
-                            Ext.Viewport.getLayout().setAnimation({type: 'slide', direction: 'right', duration: 300})
-                            Ext.Viewport.remove(that._handle)
-                            that.close()
+                            handle.setStyle({'z-index': 0})
+                            // Ext.Viewport.getLayout().setAnimation({type: 'slide', direction: 'right', duration: 300})
+                            Ext.Viewport.remove(handle)
+                            handle.close()
                         })
                     }
                 },
@@ -230,6 +233,9 @@ export class Scope {
             }
         }
         Ext.Viewport.add(that._handle)
+        if ((window as any).mainWindow === that) {
+            Scope.SHOW_PAGE_STACK.length = 0
+        }
         that._handle.setStyle({'z-index': 1})
         let actived = false;
         (Ext.Viewport.getItems().items as []).forEach((item, idx) => {