1

嗨,我需要在我的 sencha touch 应用程序中实现保持登录

请在下面查看我的代码:

Login.js - 一旦用户点击登录,它会在本地存储“sessionToken”。然后它会去主页面

   onBtnLoginClick: function(){

            var loginviewGetValue =  Ext.getCmp('loginview').getValues();
            var bbid =  Ext.getCmp('bbID').getValue();
            var bbpassword =  Ext.getCmp('bbPassword').getValue();
                var LoginLS =   Ext.getStore('LoginLS');





                                    LoginLS.add({
                                        sessionId: 'sadsadsadasd'
                                       ,deviceId:'1'
                                       ,bb_id :bbid
                                       });

                                       LoginLS.sync();      

                                   var mainForm= Ext.create('bluebutton.view.Main');
                                    Ext.Viewport.setActiveItem(mainForm);

App.js~每次启动函数都会检查localStorage中的sessionToken。如果 Localstorage 为空,则进入登录页面。否则进入主页面

        launch: function() {




        // Destroy the #appLoadingIndicator element
        Ext.fly('appLoadingIndicator').destroy();


        // Initialize the main view

             var LoginLS = Ext.getStore('LoginLS');
             LoginLS.load();

             var record =  LoginLS.getAt(0);


            if(record != undefined){
                var sessionId = record.get('sessionId');
               if (sessionId !=undefined){
                     Ext.Viewport.add(Ext.create('bluebutton.view.Main'));
               }
               else
                   Ext.Viewport.add(Ext.create('bluebutton.view.Login'));

            }
            else{
               Ext.Viewport.add(Ext.create('bluebutton.view.Login'));
               }

//        Ext.create('bluebutton.view.TopMenuList');

    },

Logout.js~Logout 会清除 sessionToken 并再次进入登录页面

onLogoutClick: function scan() {
                var LoginLS = Ext.getStore('LoginLS');


                     Ext.Viewport.setMasked({
                        xtype: 'loadmask',
                        message: 'Loading...'
                    });



                 LoginLS.load();

                 var record =  LoginLS.getAt(0);
                   LoginLS.removeAll();
                    LoginLS.sync();
                   //Load a new view


//                   Ext.getCmp('tabpanel').destroy();






                var loginForm = Ext.create('bluebutton.view.Login');
                Ext.Viewport.setActiveItem(loginForm);   

                Ext.Viewport.setMasked(false); // hide the load screen

但我现在有问题。我无法返回登录页面。它进入空白页。请给我一些解决方案。谢谢。

这是我得到的错误

    [WARN][Ext.data.Batch#runOperation] Your identifier generation strategy for the model does not ensure unique id's. Please use the UUID strategy, or implement your own identifier strategy with the flag isUnique. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`loginview`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`bbID`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`bbPassword`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[WARN][Ext.Component#constructor] Registering a component with a id (`btnLogin`) which has already been used. Please ensure the existing component has been destroyed (`Ext.Component#destroy()`. Console.js:35
[DEPRECATE][bluebutton.view.Login#show] Call show() on a component that doesn't currently belong to any container. Please add it to the the Viewport first, i.e: Ext.Viewport.add(component); 
4

2 回答 2

3

查看错误消息很明显,您正在尝试再次创建登录面板而不破坏现有组件。错误是因为您不允许id在应用程序中多次使用相同的。

为避免这种情况,您不应多次创建相同的视图,您应该重用对性能也有好处的视图。还有一件事,id当且仅当你不能没有它时,你应该给 n 元素。

假设你不能避免id属性,你应该做以下两件事之一:

  1. 仅当它不存在时才创建新视图

    var loginView = Ext.getCmp("loginview");
    if(!loginView){
        loginView = Ext.create('bluebutton.view.Login');
    }
    
  2. 通过调用以下方法销毁登录视图,一旦它离开(隐藏/删除)视口:

    var loginView = Ext.getCmp("loginview");
    loginView.destroy();
    
于 2013-03-12T10:56:25.843 回答
0

用于itemId您的组件,而不是id在您中相应地引用它们Controller。检查这个问题:警告说“Id”存在并且应该被销毁

于 2013-03-12T05:47:50.220 回答