diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index f87af796f..f0f8e9c92 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -1,6 +1,7 @@
+
diff --git a/public/assets/wechat/app.html b/public/assets/wechat/app.html index 187439468..6fcaa76f5 100644 --- a/public/assets/wechat/app.html +++ b/public/assets/wechat/app.html @@ -14,11 +14,6 @@
-
-
- 加载中... -
-
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index a15e94014..3dcc0e6c1 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -3,6 +3,7 @@ var apiUrl = '/api/v1/'; var debug = false; //调试标志,如果在本地请置为true if(debug===true){ + //apiUrl = 'http://localhost:3000/api/v1/'; apiUrl = 'https://www.trustie.net/api/v1/'; } @@ -399,6 +400,25 @@ app.directive('textAutoHeight', function($timeout){ } }); +app.directive('loadingSpinner', function ($http) { + return { + restrict: 'A', + replace: true, + template: '
加载中...
', + link: function (scope, element, attrs) { + + scope.$watch('activeCalls', function (newVal, oldVal) { + if (newVal == 0) { + $(element).hide(); + } + else { + $(element).show(); + } + }); + } + }; +}); + app.config(['$routeProvider',"$httpProvider",function ($routeProvider, $httpProvider) { $routeProvider .when('/activities', { @@ -436,22 +456,30 @@ app.config(['$routeProvider',"$httpProvider",function ($routeProvider, $httpProv .otherwise({ redirectTo: '/activities' }); - //$httpProvider.interceptors.push('timestampMarker'); -}]); -//loading -app.factory('timestampMarker', ["$rootScope", function ($rootScope) { - var timestampMarker = { - request: function (config) { - $rootScope.loading = true; - config.requestTimestamp = new Date().getTime(); - return config; - }, - response: function (response) { - // $rootScope.loading = false; - response.config.responseTimestamp = new Date().getTime(); - return response; - } - }; - return timestampMarker; + //监听异步请求 + $httpProvider.interceptors.push(function ($q, $rootScope) { + if ($rootScope.activeCalls == undefined) { + $rootScope.activeCalls = 0; + } + + return { + request: function (config) { + $rootScope.activeCalls += 1; + return config; + }, + requestError: function (rejection) { + $rootScope.activeCalls -= 1; + return rejection; + }, + response: function (response) { + $rootScope.activeCalls -= 1; + return response; + }, + responseError: function (rejection) { + $rootScope.activeCalls -= 1; + return rejection; + } + }; + }); }]); diff --git a/public/stylesheets/weui/weixin.css b/public/stylesheets/weui/weixin.css index 21fde54bb..fffa7a214 100644 --- a/public/stylesheets/weui/weixin.css +++ b/public/stylesheets/weui/weixin.css @@ -76,4 +76,4 @@ a.underline {text-decoration:underline;} .loading-bg {position:fixed; width:100%; height:100%; left:0; top:0; z-index:99; background:rgba(206, 206, 206, 0.3); overflow:hidden;} .loading-box {position:absolute; top:50%; background:white; width:160px; height:72px; left:50%; margin-top:-36px; margin-left:-80px; text-align:center;} .loading-box img {margin-top: 3px; text-align: center;} -.loading-box span {display: block;} +.loading-box span {display: block; font-size:12px;}