Ionic / MobileFirst应用程序自动重定向页面

时间:2017-08-17 14:49:50

标签: ionic2 ibm-mobilefirst ionic3 mobilefirst-adapters

我的Ionic 3应用程序中有以下流程,该应用程序由MobileFirst Platform V8驱动:

WelcomePage --> HomePage --> ViewReportPage

当用户打开应用程序时,他将登陆WelcomePage并输入他的凭据。验证凭据后,他将被带到HomePage,然后点击View按钮转到ViewReportPage

ViewReportPage用户点击搜索按钮搜索报告。

我的问题是,当用户点击搜索按钮时,一旦服务代码发送请求从服务器获取数据,我就会被重定向到HomePage。不知道问题是什么。以下是代码。

奇怪的是,只有当我关闭应用并打开它然后按照上面给出的步骤时才会发生这种情况。如果我在重定向到HomePage后再转到ViewReportPage然后单击搜索按钮,那么我就不会遇到这个问题,应用程序正常运行。

ViewReportPage HTML

<ion-card>
    <ion-list no-lines>
      <ion-item>
        <ion-label>Year</ion-label>
        <ion-select [(ngModel)]="year">
          <ion-option value="{{yearToSearch}}" *ngFor="let yearToSearch of years">{{yearToSearch}}</ion-option>
        </ion-select>
      </ion-item>
      <ion-item>
        <button round center padding class="align-center" color="secondary" ion-button (click)="search()">
          <ion-icon ios="ios-search" md="md-search" class="ion-lable-icon-padding"></ion-icon>
          Search
        </button>
      </ion-item>
    </ion-list>
  </ion-card>

ViewReport TS

@IonicPage()
@Component({
  selector: 'page-view-report',
  templateUrl: 'view-report.html',
})
export class ViewReportPage {
  public years : number[] = null; 
  public year = null;
  public corrData : any[] = null;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public loginSrvc : LoginService,
              public corrSrvc : ReportService,
              public events: Events) {
    let currentYear = new Date().getFullYear();
    this.year =  currentYear;
    this.years = [
      currentYear,
      currentYear -1 ,
      currentYear - 2
    ];

    this.events.subscribe('corrResults',(value)=>{
      this.corrData = this.corrSrvc.getReportData();
    });
  }

  ionViewDidLoad() {
    console.log('Hello ViewReportPage Page');
  }

  search(){
    let searchData : ReportSearchModel = new ReportSearchModel(
      this.loginSrvc.getUserId(),
      this.loginSrvc.getEncodedSignature(),
      this.year,
      null
    );  
    let invocationData = {
        procedure : 'getReports',
        parameters : searchData,
        navController : this.navCtrl
      };
      this.corrSrvc.search(invocationData);
  }
}

ReportService TS

search(invocationData){        
    let procedureName = invocationData.procedure;
    let parameters = invocationData.parameters;
    let nav : NavController = invocationData.navController;
    this.nav = nav;
    let isuserLoggedIn = this.loginService.checkForLoggedInUser();
    this.ngZone.run(
     () => {
        let reqToSend = new WLResourceRequest('/adapters/MyMFPAdapter'+procedureName, WLResourceRequest.GET);
        let jsonToStingData = JSON.stringify(parameters);
        reqToSend.setQueryParameter("params", `[${jsonToStingData}]`);
        reqToSend.send().then((response) => {
          let invocationResponse = response.responseJSON;
          //resolve(response.responseJSON);
          console.log(invocationResponse);
          this.corrData = invocationResponse['reportBeans'];
          if(this.corrData == null || this.corrData == undefined || this.corrData.length < 1){
            alert('No Report Found');
          }
          this.events.publish('corrResults','results');
        });
      }
    );        
  }

  getCorrespondenceData(){
    return this.corrData;
  }

0 个答案:

没有答案