【问题标题】:Sqlite ionic framework Active sessionSqlite 离子框架活动会话
【发布时间】:2016-04-07 21:15:14
【问题描述】:

我正在尝试根据 sqlite 数据库打开一个视图。我的代码很好,因为当数据库中存在“Session_activa”时,它会显示我想要的视图。 但我的问题是当我打开我的应用程序时,首先显示登录视图,然后在 1 或 2 秒后转到相应的视图。

我该如何解决这个问题? 当用户登录时,我想默认放置他的 html 视图

这是我的代码:

App.js

var db = null;//paso 1 BD

angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers'])

.run(function($ionicPlatform, $cordovaSQLite,$state) {//paso 2 agrego cordovaSqlite
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
      //creo la tabla tutoria
      db = $cordovaSQLite.openDB({ name: 'tuto.db' });//paso 3 creo  la BD
      $cordovaSQLite.execute(db,"CREATE TABLE IF NOT EXISTS tutoria (id integer primary key, estado text, rolUs text, pNombre text, Inicial text, sNombre text, pApellido text, sApellido text, cedula text)");
      //fin creo la tabla tutoria
      //comprobar sesion
      var query = "SELECT * FROM tutoria";
      $cordovaSQLite.execute(db,query).then(function(result) {
        for ( j=0; j < result.rows.length; j++) { 
          if(result.rows.item(j).estado=="Sesion_Activa" && result.rows.item(j).rolUs=="docente"){
            $state.go('tabs.perfilDocente');//HERE GOES TO THE VIEW
          }else{
            if(result.rows.item(j).estado=="Sesion_Activa" && result.rows.item(j).rolUs=="estudiante"){
              $state.go('tabsEst.perfilEstudiante');//HERE GOES TO THE 2cond VIEW
            }
          }               
        }
      });
      //fin comprobar sesion
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
//VISTAS
.config(function($stateProvider, $urlRouterProvider) {  
  $stateProvider
    //Login de la APP
    .state('login',{
      cache: false,
      url:'/login',
      templateUrl:'templates/login.html',
      controller: 'LoginCtrl'
    })
    // PADRE DE VISTAS TABS DOCENTE
    .state('tabs',{
      cache: false,
      url:'/Gtuto',
      abstract:true,
      templateUrl:'templates/tabs.html'
    })
    //Hijos de TABS
    .state('tabs.perfilDocente', {
      cache: false,
      url:'/perfil',
      views:{
        'perfil-tab':{
          templateUrl:'templates/perfilDocente.html',
          controller:'SalirCtrl'
        }
      }
    })
    .state('tabs.CompDocente', {
      cache: false,
      url:'/componentes',
      views:{
        'componentes-tab':{
          templateUrl:'templates/CompDocente.html',
          controller:'DocenteCtrl'
        }
      }
    })    
    .state('tabs.ListaTutoDocente', {
      cache: false,
      url:'/componentes/:nom_coe',
      views:{
        'componentes-tab':{
          templateUrl:'templates/ListaTutoDocente.html',
          controller:'DocenteCtrl'
        }
      }
    })
    .state('tabs.CrearTutoria', {
      cache: false,
      url:'/componentes/:nom_coe/:paralelo',
      views:{
        'componentes-tab':{
          templateUrl:'templates/CrearTutoria.html',
          controller:'DocenteCtrl'
        }
      }
    })
    .state('tabs.ContEdicionTuto', {
      cache: false,
      url:'/componentes/:Nom_coe/EdicionTutorias/:id',
      views:{
        'componentes-tab':{
          templateUrl:'templates/ContEdicionTuto.html',
          controller:'DocenteCtrl'
        }
      }
    })
    .state('tabs.comentarios', {
      cache: false,
      url:'/componentes/:componentesId/:c/:f/:d',
      views:{
        'componentes-tab':{
          templateUrl:'templates/comentarios.html',
          controller:'DocenteCtrl'
        }
      }
    })
    .state('tabs.participantes', {
      cache: false,
      url:'/componentes/:componentesId/:c/:f/:d/:e',
      views:{
        'componentes-tab':{
          templateUrl:'templates/participantes.html',
          controller:'DocenteCtrl'
        }
      }
    })
    .state('tabs.notDoc', {
      cache: false,
      url:'/notificaciones',
      views:{
        'notificaciones-tab':{
          templateUrl:'templates/NotDoc.html'
        }
      }
    })
    // PADRE DE VISTAS TABSEST ESTUDIANTE
    .state('tabsEst',{
      cache: false,
      url:'/Gtuto',
      abstract:true,
      templateUrl:'templates/tabsEst.html'
    })
    //Hijos de TABSEST
    .state('tabsEst.perfilEstudiante', {
      cache: false,
      url:'/perfilEst',
      views:{
        'perfil-tabsEst':{
          templateUrl:'templates/perfilEstudiante.html',
          controller:'SalirCtrl'
        }
      }
    })
    .state('tabsEst.CompEstudiante', {
      cache: false,
      url:'/componentesEst',
      views:{
        'componentes-tabsEst':{
          templateUrl:'templates/CompEstudiante.html',
          controller:'AlumnoCtrl'
        }
      }
    })    
    .state('tabsEst.ListaTutoEstudiante', {
      cache: false,
      url:'/componentesEst/:nombre',
      views:{
        'componentes-tabsEst':{
          templateUrl:'templates/ListaTutoEstudiante.html',
          controller:'AlumnoCtrl'
        }
      }
    })
    .state('tabsEst.notificaciones', {
      cache: false,
      url:'/notificacionesEst',
      views:{
        'notificaciones-tabsEst':{
          templateUrl:'templates/NotEst.html'
        }
      }
    })
  $urlRouterProvider.otherwise('/login');
})

【问题讨论】:

    标签: angularjs sqlite ionic-framework


    【解决方案1】:

    angular.run 方法是异步的,这会导致所谓的竞争条件。

    如果我不得不猜测,我会说您的 $cordova.execute 花费的时间太长,此时您的应用程序已经导航到您列为 /login 的默认视图。由于 angular.run 即使在您导航后仍在处理中,所以它会在完成后导航您。这就是您看到 2 秒延迟的原因。

    对此的解决方案是不在您的angular.run 方法中运行任何查询或导航逻辑。而是为应用程序初始化创建一个控制器。让这个控制器成为第一个屏幕并抛出一个加载指示器。完成初始化逻辑后,导航到您需要去的地方。

    最好的,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 2017-05-10
      • 1970-01-01
      • 2019-07-25
      • 2016-11-12
      • 2015-05-12
      • 2014-06-17
      相关资源
      最近更新 更多