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

This commit is contained in:
txz 2016-04-06 09:40:53 +08:00
commit 0d04f996c5
2 changed files with 25 additions and 18 deletions

View File

@ -19,6 +19,7 @@
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.js"></script>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular-route.js"></script>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular-sanitize.min.js"></script>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular-cookies.js"></script>
<script src="/javascripts/wechat/app.js"></script>
</body>

View File

@ -1,18 +1,16 @@
var app = angular.module('wechat', ['ngRoute']);
var app = angular.module('wechat', ['ngRoute','ngCookies']);
var apiUrl = 'http://wechat.trustie.net/api/v1/';
//var openid= "oCnvgvz8R7QheXE-R9Kkr39j8Ndg";
var openid = '';
var debug = false; //调试标志,如果在本地请置为true
if(debug===true){
openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg";
}
app.factory('auth', function($http,$routeParams, $cookies){
var _openid = '';
app.factory('auth', function($http,$routeParams){
var _openid = openid;
if(debug===true){
_openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg";
}
var getOpenId = function(cb) {
if (_openid.length > 0) {
if (typeof _openid !== 'undefined' && _openid.length > 0) {
cb(_openid);
return;
}
@ -23,19 +21,26 @@ app.factory('auth', function($http,$routeParams){
method: 'POST'
}).then(function successCallback(response) {
_openid = response.data.openid;
openid = _openid;
if(typeof _openid !== 'undefined' && _openid.length>0){
if(debug !== true){ //如果是生产环境,就存到cookies中
$cookies.put("openid", _openid);
}
} else {
if(debug!==true){//考虑从cookies中取出
_openid = $cookies.get('openid');
}
}
cb(_openid);
}, function errorCallback(response) {
cb(null);
});
};
var setOpenId = function(id){
_openid = id;
var openid = function(){
return _openid;
}
return {getOpenId: getOpenId, setOpenId: setOpenId};
return {getOpenId: getOpenId, openid: openid};
});
app.controller('ActivityController',function($scope, $http, auth){
@ -43,6 +48,8 @@ app.controller('ActivityController',function($scope, $http, auth){
return "http://www.trustie.net/" + url;
}
console.log("ActivityController load");
$scope.activities = [];
$scope.page = 1;
@ -51,7 +58,7 @@ app.controller('ActivityController',function($scope, $http, auth){
$http({
method: 'POST',
url: apiUrl+ "activities",
data: {openid: openid, page: page},
data: {openid: auth.openid(), page: page},
}).then(function successCallback(response) {
$scope.activities = $scope.activities.concat(response.data.data);
}, function errorCallback(response) {
@ -98,7 +105,7 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth){
var userInfo = {
type: "Issue",
content: data.comment,
openid: openid,
openid: auth.openid(),
};
$http({
@ -113,7 +120,6 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth){
});
}
console.log(auth.getOpenId());
});