app.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. (function () {
  2. angular.module('app', ['ionic', 'app.controllers', 'app.services', 'app.filters', 'app.directives', 'ionic-citypicker'])
  3. .config(["$ionicConfigProvider", function ($ionicConfigProvider) {
  4. //ionic全局配置
  5. $ionicConfigProvider.views.maxCache(10);
  6. $ionicConfigProvider.platform.android.tabs.position('bottom');
  7. $ionicConfigProvider.platform.android.navBar.alignTitle("center");
  8. $ionicConfigProvider.backButton.text('后退').icon('ion-chevron-left');
  9. $ionicConfigProvider.form.checkbox("circle");
  10. $ionicConfigProvider.templates.maxPrefetch(0);
  11. $ionicConfigProvider.scrolling.jsScrolling(true);
  12. }]).factory('myHttpInterceptor', ["$q", 'data', function ($q, data) { //$http拦截器定义
  13. var initInjector = angular.injector(['ng']);
  14. var $http = initInjector.get('$http');
  15. return {
  16. 'request': function (config) {
  17. return config;
  18. },
  19. 'requestError': function (rejection) {
  20. return $q.reject(rejection);
  21. },
  22. 'response': function (response) {
  23. return response;
  24. },
  25. 'responseError': function (rejection) {
  26. if (rejection.status == 401) {
  27. data.remove('user');
  28. data.remove('token');
  29. $http.defaults.headers.common["Authorization"] = undefined;
  30. window.location.href = '#/account/login';
  31. return $q.reject('');
  32. }
  33. return $q.reject(rejection);
  34. }
  35. }
  36. }])
  37. .config(["$httpProvider", "$windowProvider", function ($httpProvider, $windowProvider) {
  38. var win = $windowProvider.$get();
  39. var token=win.localStorage['token'];
  40. if (token) {
  41. $httpProvider.defaults.headers.common['Authorization'] = 'Bearer ' + token;
  42. }
  43. $httpProvider.interceptors.push('myHttpInterceptor');
  44. }])
  45. .run(["$ionicPlatform", "$location", "msg", "$rootScope", "$timeout", "$ionicHistory", "userService", "$state", "$http", "map",
  46. function ($ionicPlatform, $location, msg, $rootScope, $timeout, $ionicHistory, userService, $state, $http, map) {
  47. $ionicPlatform.registerBackButtonAction(function (e) {
  48. if ($location.path().indexOf("wl/") != -1) {
  49. if ($rootScope.backButtonPressedOnceToExit) {
  50. ionic.Platform.exitApp();
  51. $rootScope.$destroy()
  52. } else {
  53. $rootScope.backButtonPressedOnceToExit = true;
  54. msg.text("再按一次退出系统",true);
  55. $timeout(function () {
  56. $rootScope.backButtonPressedOnceToExit = false
  57. }, 3000)
  58. }
  59. } else if ($ionicHistory.backView()) {
  60. $ionicHistory.goBack()
  61. }
  62. $ionicPlatform.preventDefault();
  63. $ionicPlatform.stopPropagation();
  64. return false
  65. }, 101);
  66. $ionicPlatform.ready(function () {
  67. if (window.cordova && cordova.platformId === 'ios' && window.cordova.plugins && window.cordova.plugins.Keyboard) {
  68. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  69. cordova.plugins.Keyboard.disableScroll(true);
  70. }
  71. // if (window.StatusBar) {
  72. // StatusBar.styleDefault();
  73. // }
  74. navigator.splashscreen.hide();
  75. if (!$rootScope.location) {
  76. map.getLocation().then(function (result) {
  77. $rootScope.location = result;
  78. });
  79. }
  80. if (!userService.isLogin()) {
  81. $state.go('login');
  82. }
  83. });
  84. }]);
  85. angular.module("app.controllers", []);
  86. angular.module("app.services", []);
  87. angular.module("app.filters", []);
  88. angular.module('app.directives', []);
  89. })();