You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.2 KiB
116 lines
3.2 KiB
app.factory('auth', ['$http','$routeParams', '$q', function($http,$routeParams, $q){
|
|
var _openid = '';
|
|
|
|
if(typeof g_openid !== 'undefined'){
|
|
_openid = g_openid;
|
|
}
|
|
|
|
var getOpenId = function() {
|
|
var deferred = $q.defer();
|
|
if (typeof _openid !== 'undefined' && _openid.length > 0){
|
|
deferred.resolve(_openid);
|
|
} else {
|
|
var code = $routeParams.code;
|
|
$http({
|
|
url: '/wechat/get_open_id',
|
|
data: {code: code},
|
|
method: 'POST'
|
|
}).then(function successCallback(response) {
|
|
_openid = response.data.openid;
|
|
deferred.resolve(_openid);
|
|
}, function errorCallback(response) {
|
|
deferred.reject(response);
|
|
});
|
|
}
|
|
return deferred.promise;
|
|
};
|
|
var openid = function(){
|
|
return _openid;
|
|
};
|
|
return {getOpenId: getOpenId, openid: openid};
|
|
}]);
|
|
|
|
|
|
app.factory('rms', function(){
|
|
var _saveStorage = {};
|
|
var save = function(key, value){
|
|
_saveStorage[key] = value;
|
|
};
|
|
|
|
var get = function(key){
|
|
return _saveStorage[key];
|
|
};
|
|
|
|
return {save: save, get: get};
|
|
});
|
|
|
|
app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $routeParams){
|
|
var addCommonReply = function(id, type, data, cb){
|
|
|
|
if(!data.comment || data.comment.length<=0){
|
|
return;
|
|
}
|
|
|
|
var temp = data.comment.replace(/\n/g,'<br/>');
|
|
|
|
var userInfo = {
|
|
type: type,
|
|
content: temp,
|
|
openid: auth.openid()
|
|
};
|
|
//回复按钮禁用
|
|
data.disabled = true;
|
|
|
|
$http({
|
|
method: 'POST',
|
|
url: apiUrl+ "new_comment/"+id,
|
|
data: userInfo
|
|
}).then(function successCallback(response) {
|
|
//alert("提交成功");
|
|
//数据提交完成,回复按钮启用
|
|
data.disabled = false;
|
|
if(typeof cb === 'function'){
|
|
cb();
|
|
}
|
|
}, function errorCallback(response) {
|
|
});
|
|
};
|
|
|
|
var loadCommonData = function(id, type){
|
|
return $http({
|
|
method: 'GET',
|
|
url: apiUrl+ type + "/" + id+"?openid="+auth.openid()
|
|
})
|
|
};
|
|
|
|
var addCommonPraise = function(act){
|
|
act.praise_count += 1;
|
|
act.has_praise = true;
|
|
|
|
$http({
|
|
method: 'POST',
|
|
url: apiUrl + "praise/" + act.act_id,
|
|
data:{openid:auth.openid(),type:act.act_type}
|
|
}).then(function successCallback(response) {
|
|
console.log(response.data);
|
|
}, function errorCallback(response) {
|
|
});
|
|
|
|
};
|
|
|
|
var decreaseCommonPraise = function(act){
|
|
act.praise_count -= 1;
|
|
act.has_praise = false;
|
|
|
|
$http({
|
|
method: 'POST',
|
|
url: apiUrl + "praise/" + act.act_id,
|
|
data:{openid:auth.openid(),type:act.act_type}
|
|
}).then(function successCallback(response) {
|
|
console.log(response.data);
|
|
}, function errorCallback(response) {
|
|
});
|
|
};
|
|
|
|
return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise};
|
|
}]); |