提交 46557d23 编写于 作者: tony001's avatar tony001

全局导航服务

上级 904d9329
export interface NavDataElement {
/**
* 主键标识
*
* @memberof NavDataElement
*/
id: string;
/**
* 视图标题
*
* @memberof NavDataElement
*/
title: any;
/**
* 上下文
*
* @memberof NavDataElement
*/
context:any;
/**
* 视图参数
*
* @memberof NavDataElement
*/
viewparams:any;
/**
* 视图数据
*
* @memberof NavDataElement
*/
data:any;
}
/**
* 导航数据服务
*
* @export
* @class CodeListService
*/
export default class NavDataService {
/**
* 导航数据栈
*
* @memberof NavDataService
*/
public navDataStack:Array<NavDataElement> = [];
/**
* 导航数据存储仓库
*
* @memberof NavDataService
*/
public sessionStore:any;
/**
* 初始化实例
*
* @memberof NavDataService
*/
constructor(opts:any = {}){
this.sessionStore = window.sessionStorage;
this.initNavData();
}
/**
* 初始化基础导航数据
*
* @memberof NavDataService
*/
public initNavData(){
if(this.sessionStore && this.sessionStore.getItem('srfnavdata')){
this.navDataStack = JSON.parse(this.sessionStore.getItem('srfnavdata'));
}
}
/**
* 添加基础导航数据到栈中
*
* @memberof NavDataService
*/
public addNavData(curNavData:NavDataElement){
if(this.navDataStack.length >0){
let tempIndex:number = this.navDataStack.findIndex((element:NavDataElement) =>{
return Object.is(element.id,curNavData.id);
})
if(tempIndex === -1){
this.navDataStack.push(curNavData);
this.sessionStore.setItem('srfnavdata',JSON.stringify(this.navDataStack));
return curNavData;
}else{
this.setNavDataById(curNavData.id,curNavData);
}
}else{
this.navDataStack.push(curNavData);
this.sessionStore.setItem('srfnavdata',JSON.stringify(this.navDataStack));
return curNavData;
}
console.log(this.navDataStack);
}
/**
* 设置指定数据到基础导航数据栈中
*
* @memberof NavDataService
*/
public setNavDataById(id:string,curNavData:NavDataElement){
if(this.navDataStack.length >0){
let tempIndex:number = this.navDataStack.findIndex((element:NavDataElement) =>{
return Object.is(element.id,id);
})
this.navDataStack[tempIndex] = curNavData;
this.sessionStore.setItem('srfnavdata',JSON.stringify(this.navDataStack));
return curNavData;
}else{
return null;
}
}
/**
* 从导航数据栈中删除指定数据
*
* @memberof NavDataService
*/
public removeNavData(id:string){
if(this.navDataStack.length >0){
let tempIndex:number = this.navDataStack.findIndex((element:NavDataElement) =>{
return Object.is(element.id,id);
})
let removeNavData = this.navDataStack.splice(tempIndex);
this.sessionStore.setItem('srfnavdata',JSON.stringify(this.navDataStack));
return removeNavData;
}else{
return null;
}
}
/**
* 从导航数据栈中获取指定数据
*
* @memberof NavDataService
*/
public getNavDataById(id:string){
if(this.navDataStack.length >0){
let tempIndex:number = this.navDataStack.findIndex((element:NavDataElement) =>{
return Object.is(element.id,id);
})
return this.navDataStack[tempIndex];
}else{
return null;
}
}
/**
* 从导航数据栈中获取指定数据的前一条数据
*
* @memberof NavDataService
*/
public getPreNavDataById(id:string){
if(this.navDataStack.length >0){
let tempIndex:number = this.navDataStack.findIndex((element:NavDataElement) =>{
return Object.is(element.id,id);
})
return this.navDataStack[tempIndex-1];
}else{
return null;
}
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册