微信点赞保证各个切换之间点赞状态保持一致

This commit is contained in:
yuanke 2016-07-13 14:06:56 +08:00
parent 5ea4eff876
commit a5acc2641e
2 changed files with 52 additions and 5 deletions

View File

@ -144,10 +144,54 @@ app.controller('ActivityController',
}
$scope.addPraise = function(act){
for(var i in $scope.activities){
if($scope.activities[i].act_id == act.act_id){
$scope.activities[i].praise_count += 1;
$scope.activities[i].has_praise = true;
break;
}
}
for(var i in $scope.course_activities){
if($scope.course_activities[i].act_id == act.act_id){
$scope.course_activities[i].praise_count += 1;
$scope.course_activities[i].has_praise = true;
break;
}
}
for(var i in $scope.project_activities){
if($scope.project_activities[i].act_id == act.act_id){
$scope.project_activities[i].praise_count += 1;
$scope.project_activities[i].has_praise = true;
break;
}
}
common.addCommonPraise(act);
};
$scope.decreasePraise = function(act){
for(var i in $scope.activities){
if($scope.activities[i].act_id == act.act_id){
$scope.activities[i].praise_count -= 1;
$scope.activities[i].has_praise = false;
break;
}
}
for(var i in $scope.course_activities){
if($scope.course_activities[i].act_id == act.act_id){
$scope.course_activities[i].praise_count -= 1;
$scope.course_activities[i].has_praise = false;
break;
}
}
for(var i in $scope.project_activities){
if($scope.project_activities[i].act_id == act.act_id){
$scope.project_activities[i].praise_count -= 1;
$scope.project_activities[i].has_praise = false;
break;
}
}
common.decreaseCommonPraise(act);
};
}]);

View File

@ -126,8 +126,8 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms', function($http, au
};
var addCommonPraise = function(act){
act.praise_count += 1;
act.has_praise = true;
// act.praise_count += 1;
// act.has_praise = true;
$http({
method: 'POST',
@ -141,9 +141,8 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms', function($http, au
};
var decreaseCommonPraise = function(act){
act.praise_count -= 1;
act.has_praise = false;
// act.praise_count -= 1;
// act.has_praise = false;
$http({
method: 'POST',
url: apiUrl + "praise/" + act.act_id,
@ -205,6 +204,8 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms', function($http, au
rms.save("course_activities",course_activities);
rms.save("project_activities",project_activities);
act.praise_count += 1;
act.has_praise = true;
addCommonPraise(act);
};
@ -237,6 +238,8 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms', function($http, au
rms.save("course_activities",course_activities);
rms.save("project_activities",project_activities);
act.praise_count -= 1;
act.has_praise = false;
decreaseCommonPraise(act);
};
}