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