您好我需要在我的sencha touch应用程序中实现keep login
请参阅下面的代码:
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);
答案 0 :(得分:3)
查看错误消息,很明显您正在尝试再次创建登录面板而不会破坏现有组件。出现错误是因为您不允许在应用程序中多次使用相同的id
。
为避免这种情况,您不应多次创建相同的视图,您应该重复使用对性能有益的视图。还有一件事,当且仅当你不能没有它时,你应该给{n}元素{/ 1}}。
假设你无法避免id
属性,你应该做以下两件事之一:
仅在新视图不存在时才创建
id
通过调用以阻止登录视图(隐藏/删除)视口:
var loginView = Ext.getCmp("loginview");
if(!loginView){
loginView = Ext.create('bluebutton.view.Login');
}
答案 1 :(得分:0)
使用itemId
代替id
而不是Controller
,并在{{1}}中相应地引用它们。请查看此问题:Warning saying `Id` exist and should be destroyed