app.js 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. (function () {
  2. angular.module('app', ['ionic', 'app.controllers', 'app.services', 'app.filters', 'app.directives'])
  3. .config(["$ionicConfigProvider", function ($ionicConfigProvider) {
  4. //ionic全局配置
  5. $ionicConfigProvider.views.maxCache(10);
  6. // $ionicConfigProvider.views.swipeBackEnabled(false);
  7. $ionicConfigProvider.platform.android.tabs.position('bottom');
  8. $ionicConfigProvider.platform.android.navBar.alignTitle("center");
  9. $ionicConfigProvider.backButton.text('返回');
  10. $ionicConfigProvider.form.checkbox("circle");
  11. // $ionicConfigProvider.templates.maxPrefetch(0);
  12. }])
  13. .config(["$httpProvider", function ($httpProvider) {
  14. var token = window.localStorage['token'];
  15. if (token) {
  16. $httpProvider.defaults.headers.common['Authorization'] = 'Bearer ' + token;
  17. }
  18. $httpProvider.interceptors.push('authHttpInterceptor');
  19. }])
  20. .run(["$ionicPlatform", "msg", "$rootScope", "$timeout", "$http", "userService", "$state", "$ionicLoading","jpushService",
  21. function ($ionicPlatform, msg, $rootScope, $timeout, $http, userService, $state, $ionicLoading, jpushService) {
  22. $ionicPlatform.registerBackButtonAction(function (e) {
  23. if ($rootScope.backButtonPressedOnceToExit) {
  24. ionic.Platform.exitApp();
  25. $rootScope.$destroy()
  26. } else {
  27. $rootScope.backButtonPressedOnceToExit = true;
  28. $ionicLoading.show({ template: '再按一次退出系统', duration: 500 });
  29. $timeout(function () {
  30. $rootScope.backButtonPressedOnceToExit = false
  31. }, 2000)
  32. }
  33. $ionicPlatform.preventDefault();
  34. $ionicPlatform.stopPropagation();
  35. return false
  36. }, 101);
  37. // userService.isLogin().then(null, function (error) {
  38. // console.log(JSON.stringify(error));
  39. // localStorage.removeItem('user');
  40. // localStorage.removeItem('token');
  41. // $http.defaults.headers.common["Authorization"] = undefined;
  42. // $state.go('login');
  43. // });
  44. $ionicPlatform.ready(function () {
  45. if (window.cordova && cordova.platformId === 'ios' && window.cordova.plugins && window.cordova.plugins.Keyboard) {
  46. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  47. cordova.plugins.Keyboard.disableScroll(true);
  48. }
  49. if (window.StatusBar) {
  50. StatusBar.styleLightContent();
  51. }
  52. var receiveNotification = function (event) {
  53. // alert("receiveMessageIniOSCallback是" + +JSON.stringify(event));
  54. };
  55. var setTagsWithAliasCallback = function (event) {
  56. // window.alert('result code:' + event.resultCode + ' tags:' + event.tags + ' alias:' + event.alias);
  57. };
  58. if (window.cordova) {
  59. jpushService.init({
  60. stac: setTagsWithAliasCallback,
  61. oniac: receiveNotification,
  62. notify: receiveNotification
  63. });
  64. //启动极光推送服务
  65. var onGetRegistrationID = function (registrationID) {
  66. try {
  67. if (registrationID.length == 0) {
  68. var t1 = window.setTimeout(getRegistrationID, 1000);
  69. } else {
  70. // alert("RegistrationID是" + registrationID);
  71. localStorage.setItem('jpush', registrationID);
  72. }
  73. } catch (exception) {
  74. // alert("onGetRegistrationID err:" + JSON.stringify(exception));
  75. }
  76. };
  77. var getRegistrationID = function () {
  78. window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
  79. };
  80. getRegistrationID();
  81. }
  82. });
  83. }]);
  84. angular.module("app.controllers", []);
  85. angular.module("app.services", []);
  86. angular.module("app.filters", []);
  87. angular.module("app.directives", []);
  88. })();