ionic3+angular4动态设置入口页rootpage,根据不同的状态值来确定不同的入口页

来源:互联网 发布:php实例 百度网盘 编辑:程序博客网 时间:2024/06/05 18:54
在ionic+angular4的项目中有一个需求,就是当项目启动后先自动调一个接口,这个接口返回四个不同的状态值,然后项目根据这个四个不同的状态值来设置不同的入口页;

例如状态值为1是入口页为登录页,状态值为2时,入口页为首页,状态值为3时入口页为验证身份页等依次类推,动态的设置入口页rootpage。

实现如下:

1.将rootpage的初始值设置为空,

2.然后在app.component.ts里面设置项目启动的时候调用接口,获取返回的娥状态值,

3.根据不同的状态值来设置不同的rootpage页面

export class MyApp {  rootPage:any = "";   public AccountId=localStorage.getItem("AccountId");  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,public mineService: MineService) {    platform.ready().then(() => {//当平台准备好的时候运行      // Okay, so the platform is ready and our plugins are available.      // Here you can do any higher level native things you might need.      statusBar.styleDefault();      splashScreen.hide();      mineService.ionienter(this.Id).then((data:string)=>{//调用接口        let reslObj=JSON.parse(data);        console.log(reslObj);        console.log(0);        console.log(reslObj.Status);        if(reslObj.IsOK==1){          if(reslObj.Status=="1"){//根据返回的状态值来跳转页面            console.log(1);            this.rootPage="HomePage";          }else if(reslObj.Status=="2"){            console.log(2);            this.rootPage="MinePage1";          }else if(reslObj.Status=="3"){            console.log(3);            this.rootPage="LoginPage";          }        }        });    });  }}

阅读全文
0 0
原创粉丝点击