Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange

chenlw_dev
txz 9 years ago
commit 6115e374bf

@ -412,7 +412,7 @@ module ApiHelper
#课程动态的更新 #课程动态的更新
def update_course_activity_api type, id def update_course_activity_api type, id
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id).first course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id.to_i).first
if course_activity if course_activity
course_activity.updated_at = Time.now course_activity.updated_at = Time.now
course_activity.save course_activity.save
@ -420,7 +420,7 @@ module ApiHelper
end end
#首页动态更新 #首页动态更新
def update_user_activity_api type, id def update_user_activity_api type, id
user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id).first user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id.to_i).first
if user_activity if user_activity
user_activity.updated_at = Time.now user_activity.updated_at = Time.now
user_activity.save user_activity.save
@ -428,7 +428,7 @@ module ApiHelper
end end
#项目动态更新 #项目动态更新
def update_forge_activity_api type, id def update_forge_activity_api type, id
forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id).first forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id.to_i).first
if forge_activity if forge_activity
forge_activity.updated_at = Time.now forge_activity.updated_at = Time.now
forge_activity.save forge_activity.save
@ -436,7 +436,7 @@ module ApiHelper
end end
#组织动态更新 #组织动态更新
def update_org_activity_api type , id def update_org_activity_api type , id
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id).first org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id.to_i).first
if org_activity if org_activity
org_activity.updated_at = Time.now org_activity.updated_at = Time.now
org_activity.save org_activity.save
@ -444,7 +444,7 @@ module ApiHelper
end end
#个人动态更新 #个人动态更新
def update_principal_activity_api type, id def update_principal_activity_api type, id
principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id).first principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id.to_i).first
if principal_activity if principal_activity
principal_activity.updated_at = Time.now principal_activity.updated_at = Time.now
principal_activity.save principal_activity.save

@ -1,41 +1,45 @@
var app = angular.module('wechat', ['ngRoute','ngCookies']); var app = angular.module('wechat', ['ngRoute','ngCookies']);
var apiUrl = 'http://localhost:3000/api/v1/'; var apiUrl = 'http://wechat.trustie.net/api/v1/';
var debug = true; //调试标志,如果在本地请置为true var debug = false; //调试标志,如果在本地请置为true
app.factory('auth', function($http,$routeParams, $cookies){ if(debug===true){
apiUrl = 'http://localhost:3000/api/v1/';
}
app.factory('auth', function($http,$routeParams, $cookies, $q){
var _openid = ''; var _openid = '';
if(debug===true){ if(debug===true){
_openid = "1"; _openid = "1";
} }
var getOpenId = function(cb) { var getOpenId = function() {
var deferred = $q.defer();
if (typeof _openid !== 'undefined' && _openid.length > 0) { if (typeof _openid !== 'undefined' && _openid.length > 0) {
cb(_openid); deferred.resolve(_openid);
return; } else {
} var code = $routeParams.code;
var code = $routeParams.code; $http({
$http({ url: '/wechat/get_open_id',
url: '/wechat/get_open_id', data: {code: code},
data: {code: code}, method: 'POST'
method: 'POST' }).then(function successCallback(response) {
}).then(function successCallback(response) { _openid = response.data.openid;
_openid = response.data.openid; if(typeof _openid !== 'undefined' && _openid.length>0){
if(typeof _openid !== 'undefined' && _openid.length>0){ if(debug !== true){ //如果是生产环境,就存到cookies中
if(debug !== true){ //如果是生产环境,就存到cookies中 $cookies.put("openid", _openid);
$cookies.put("openid", _openid); }
} } else {
} else { if(debug!==true){//考虑从cookies中取出
if(debug!==true){//考虑从cookies中取出 _openid = $cookies.get('openid');
_openid = $cookies.get('openid'); }
} }
} deferred.resolve(_openid);
}, function errorCallback(response) {
cb(_openid); deferred.reject(response);
}, function errorCallback(response) { });
cb(null); }
}); return deferred.promise;
}; };
var openid = function(){ var openid = function(){
return _openid; return _openid;
@ -43,14 +47,28 @@ app.factory('auth', function($http,$routeParams, $cookies){
return {getOpenId: getOpenId, openid: openid}; return {getOpenId: getOpenId, openid: openid};
}); });
app.controller('ActivityController',function($scope, $http, auth){
$scope.replaceUrl = function(url){ 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.controller('ActivityController',function($scope, $http, auth, rms){
$scope.repaceUrl = function(url){
return "http://www.trustie.net/" + url; return "http://www.trustie.net/" + url;
} }
console.log("ActivityController load"); console.log("ActivityController load");
$scope.activities = []; $scope.activities = rms.get("activities") || [];
$scope.page = 1; $scope.page = 1;
var loadActData = function(page){ var loadActData = function(page){
@ -61,17 +79,18 @@ app.controller('ActivityController',function($scope, $http, auth){
data: {openid: auth.openid(), page: page}, data: {openid: auth.openid(), page: page},
}).then(function successCallback(response) { }).then(function successCallback(response) {
$scope.activities = $scope.activities.concat(response.data.data); $scope.activities = $scope.activities.concat(response.data.data);
rms.save('activities', $scope.activities);
}, function errorCallback(response) { }, function errorCallback(response) {
}); });
} }
auth.getOpenId().then(
auth.getOpenId(function(oid){ function successCallback(response){
if(!oid){
alert("获取openid出错");
} else {
loadActData($scope.page); loadActData($scope.page);
}, function errorCallback(response) {
alert("获取openid出错:"+response);
} }
}); );
$scope.loadActData = loadActData; $scope.loadActData = loadActData;
}); });

Loading…
Cancel
Save