From ada15b42123536486f0e62f76cb5f3072ccebd06 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Tue, 14 Jun 2016 16:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=B8=8A=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4,=20=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5=E5=88=86?= =?UTF-8?q?=E5=BC=80=E5=86=99,=E4=BD=86=E5=8F=91=E5=B8=83=E6=97=B6?= =?UTF-8?q?=E6=89=93=E6=88=90=E4=B8=80=E4=B8=AAjs=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/wechats/user_activities.html.erb | 4 +- public/assets/wechat/app.html | 13 ++++- public/javascripts/wechat/app.js | 7 --- public/javascripts/wechat/build/app.min.js | 14 +++++ .../wechat/controllers/activity.js | 6 +- public/javascripts/wechat/controllers/blog.js | 6 +- .../wechat/controllers/course_notice.js | 5 +- .../wechat/controllers/discussion.js | 4 +- .../wechat/controllers/homework.js | 4 +- .../javascripts/wechat/controllers/issue.js | 4 +- .../wechat/controllers/journals.js | 4 +- public/javascripts/wechat/others/factory.js | 12 ++-- public/javascripts/wechat/others/filter.js | 4 +- public/javascripts/wechat/others/routes.js | 4 +- public/javascripts/wechat/wechat_dev.js | 57 ------------------- script/assets | 3 + 16 files changed, 59 insertions(+), 92 deletions(-) create mode 100644 public/javascripts/wechat/build/app.min.js delete mode 100644 public/javascripts/wechat/wechat_dev.js create mode 100644 script/assets diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index 3d61d8fcf..073d45495 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -13,6 +13,8 @@ @@ -21,7 +23,7 @@ - + \ No newline at end of file diff --git a/public/assets/wechat/app.html b/public/assets/wechat/app.html index d88efe50f..cabd224c4 100644 --- a/public/assets/wechat/app.html +++ b/public/assets/wechat/app.html @@ -2,7 +2,7 @@ - 我的动态 + 仅供本地调试使用 @@ -17,7 +17,15 @@
+ + + + @@ -33,6 +41,9 @@ + + + \ No newline at end of file diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index adf445b51..4d947e440 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -1,8 +1 @@ var app = angular.module('wechat', ['ngRoute']); -var apiUrl = '/api/v1/'; -var debug = true; //调试标志,如果在本地请置为true - -if(debug===true){ - apiUrl = 'http://localhost:3000/api/v1/'; - //apiUrl = 'http://www.trustie.net/api/v1/'; -} diff --git a/public/javascripts/wechat/build/app.min.js b/public/javascripts/wechat/build/app.min.js new file mode 100644 index 000000000..d8eacbf1b --- /dev/null +++ b/public/javascripts/wechat/build/app.min.js @@ -0,0 +1,14 @@ +var app=angular.module("wechat",["ngRoute"]); +app.factory("auth",["$http","$routeParams","$q",function(e,n,t){var o="";"undefined"!=typeof g_openid&&(o=g_openid);var a=function(){var a=t.defer();if("undefined"!=typeof o&&o.length>0)a.resolve(o);else{var i=n.code;e({url:"/wechat/get_open_id",data:{code:i},method:"POST"}).then(function(e){o=e.data.openid,a.resolve(o)},function(e){a.reject(e)})}return a.promise},i=function(){return o};return{getOpenId:a,openid:i}}]),app.factory("rms",function(){var e={},n=function(n,t){e[n]=t},t=function(n){return e[n]};return{save:n,get:t}}),app.factory("common",["$http","auth","$routeParams",function(e,n,t){var o=function(t,o,a,i){if(a.comment&&!(a.comment.length<=0)){var r=a.comment.replace(/\n/g,"
"),d={type:o,content:r,openid:n.openid()};a.disabled=!0,e({method:"POST",url:apiUrl+"new_comment/"+t,data:d}).then(function(e){a.disabled=!1,"function"==typeof i&&i()},function(e){})}},a=function(t,o){return e({method:"GET",url:apiUrl+o+"/"+t+"?openid="+n.openid()})},i=function(t){t.praise_count+=1,t.has_praise=!0,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})},r=function(t){t.praise_count-=1,t.has_praise=!1,e({method:"POST",url:apiUrl+"praise/"+t.act_id,data:{openid:n.openid(),type:t.act_type}}).then(function(e){console.log(e.data)},function(e){})};return{addCommonReply:o,loadCommonData:a,addCommonPraise:i,decreaseCommonPraise:r}}]); +app.filter("safeHtml",["$sce",function(t){return function(n){return t.trustAsHtml(n)}}]); +app.controller("ActivityController",["$anchorScroll","$location","$scope","$http","$timeout","auth","rms","common",function(t,a,e,o,i,n,c,s){e.replaceUrl=function(t){return t},console.log("ActivityController load"),e.page=c.get("page")||0,e.activities=c.get("activities")||[],e.has_more=c.get("has_more"),e.loadActData=function(t){e.page=t,o({method:"POST",url:apiUrl+"activities",data:{openid:n.openid(),page:t}}).then(function(t){t.data.page>0?e.activities=e.activities.concat(t.data.data):e.activities=t.data.data,c.save("activities",e.activities),e.has_more=t.data.count+10*t.data.page
加载中...
'}}]); +app.config(["$routeProvider","$httpProvider","$locationProvider",function(e,r,t){var o="/assets/wechat/";e.when("/activites",{templateUrl:o+"activities.html",controller:"ActivityController"}).when("/issues/:id",{templateUrl:o+"issue_detail.html",controller:"IssueController"}).when("/project_discussion/:id",{templateUrl:o+"project_discussion.html",controller:"DiscussionController"}).when("/homework/:id",{templateUrl:o+"homework_detail.html",controller:"HomeworkController"}).when("/course_notice/:id",{templateUrl:o+"course_notice.html",controller:"CourseNoticeController"}).when("/course_discussion/:id",{templateUrl:o+"course_discussion.html",controller:"DiscussionController"}).when("/journal_for_message/:id",{templateUrl:o+"jour_message_detail.html",controller:"JournalsController"}).when("/blog_comment/:id",{templateUrl:o+"blog_detail.html",controller:"BlogController"}).when("/add_class",{templateUrl:o+"add_class.html",controller:"AddClassController"}).otherwise({redirectTo:"/activites"}),r.interceptors.push(["$q","$rootScope",function(e,r){return void 0==r.activeCalls&&(r.activeCalls=0),{request:function(e){return r.activeCalls+=1,e},requestError:function(e){return r.activeCalls-=1,e},response:function(e){return r.activeCalls-=1,e},responseError:function(e){return r.activeCalls-=1,e}}}])}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/activity.js b/public/javascripts/wechat/controllers/activity.js index 732772e13..e17b7c5b3 100644 --- a/public/javascripts/wechat/controllers/activity.js +++ b/public/javascripts/wechat/controllers/activity.js @@ -1,5 +1,7 @@ -app.controller('ActivityController',function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){ +app.controller('ActivityController', + ['$anchorScroll', '$location','$scope', '$http', '$timeout', 'auth', 'rms', 'common', + function($anchorScroll, $location,$scope, $http, $timeout, auth, rms, common){ $scope.replaceUrl = function(url){ return url; }; @@ -63,4 +65,4 @@ app.controller('ActivityController',function($anchorScroll, $location,$scope, $h $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/blog.js b/public/javascripts/wechat/controllers/blog.js index 56589122a..8eb45b604 100644 --- a/public/javascripts/wechat/controllers/blog.js +++ b/public/javascripts/wechat/controllers/blog.js @@ -1,5 +1,7 @@ -app.controller('BlogController', function($scope, $http, $routeParams, auth, common){ +app.controller('BlogController', + ['$scope', '$http', '$routeParams', 'auth', 'common', + function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -35,4 +37,4 @@ app.controller('BlogController', function($scope, $http, $routeParams, auth, com console.log(act); common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/course_notice.js b/public/javascripts/wechat/controllers/course_notice.js index 9a60d2222..24b0fdbe1 100644 --- a/public/javascripts/wechat/controllers/course_notice.js +++ b/public/javascripts/wechat/controllers/course_notice.js @@ -1,4 +1,5 @@ -app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){ +app.controller('CourseNoticeController', ['$scope', '$http', '$routeParams', 'auth', 'common', + function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -32,4 +33,4 @@ app.controller('CourseNoticeController', function($scope, $http, $routeParams, a $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/discussion.js b/public/javascripts/wechat/controllers/discussion.js index 479f473bf..4828cb39a 100644 --- a/public/javascripts/wechat/controllers/discussion.js +++ b/public/javascripts/wechat/controllers/discussion.js @@ -1,5 +1,5 @@ -app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){ +app.controller('DiscussionController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -33,4 +33,4 @@ app.controller('DiscussionController', function($scope, $http, $routeParams, aut $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/homework.js b/public/javascripts/wechat/controllers/homework.js index 5fb890741..795bf30e9 100644 --- a/public/javascripts/wechat/controllers/homework.js +++ b/public/javascripts/wechat/controllers/homework.js @@ -1,5 +1,5 @@ -app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){ +app.controller('HomeworkController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -33,4 +33,4 @@ app.controller('HomeworkController', function($scope, $http, $routeParams, auth, $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); +}]); diff --git a/public/javascripts/wechat/controllers/issue.js b/public/javascripts/wechat/controllers/issue.js index 53bdbf265..09602f9e1 100644 --- a/public/javascripts/wechat/controllers/issue.js +++ b/public/javascripts/wechat/controllers/issue.js @@ -1,4 +1,4 @@ -app.controller('IssueController', function($scope, $http, $routeParams, auth, common){ +app.controller('IssueController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -33,4 +33,4 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth, co $scope.decreasePraise = function(act){ common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/journals.js b/public/javascripts/wechat/controllers/journals.js index c292b1932..f379525d7 100644 --- a/public/javascripts/wechat/controllers/journals.js +++ b/public/javascripts/wechat/controllers/journals.js @@ -1,4 +1,4 @@ -app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){ +app.controller('JournalsController', ['$scope', '$http', '$routeParams', 'auth', 'common', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ @@ -34,4 +34,4 @@ app.controller('JournalsController', function($scope, $http, $routeParams, auth, console.log(act); common.decreaseCommonPraise(act); }; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index 955ca2faf..cefef3ab9 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -1,14 +1,10 @@ -app.factory('auth', function($http,$routeParams, $q){ +app.factory('auth', ['$http','$routeParams', '$q', function($http,$routeParams, $q){ var _openid = ''; if(typeof g_openid !== 'undefined'){ _openid = g_openid; } - if(debug===true){ - _openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg"; //guange的帐号 - } - var getOpenId = function() { var deferred = $q.defer(); if (typeof _openid !== 'undefined' && _openid.length > 0){ @@ -32,7 +28,7 @@ app.factory('auth', function($http,$routeParams, $q){ return _openid; }; return {getOpenId: getOpenId, openid: openid}; -}); +}]); app.factory('rms', function(){ @@ -48,7 +44,7 @@ app.factory('rms', function(){ return {save: save, get: get}; }); -app.factory('common', function($http, auth, $routeParams){ +app.factory('common', ['$http', 'auth', '$routeParams', function($http, auth, $routeParams){ var addCommonReply = function(id, type, data, cb){ if(!data.comment || data.comment.length<=0){ @@ -117,4 +113,4 @@ app.factory('common', function($http, auth, $routeParams){ }; return {addCommonReply: addCommonReply, loadCommonData: loadCommonData, addCommonPraise: addCommonPraise, decreaseCommonPraise: decreaseCommonPraise}; -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/others/filter.js b/public/javascripts/wechat/others/filter.js index 2f57c2417..dcb8e9e6a 100644 --- a/public/javascripts/wechat/others/filter.js +++ b/public/javascripts/wechat/others/filter.js @@ -1,5 +1,5 @@ -app.filter('safeHtml', function ($sce) { +app.filter('safeHtml', ['$sce',function ($sce) { return function (input) { return $sce.trustAsHtml(input); } -}); \ No newline at end of file +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index 270c16edd..7ea270c6e 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -43,7 +43,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($rou }); //监听异步请求,实现加载中显隐标记 - $httpProvider.interceptors.push(function ($q, $rootScope) { + $httpProvider.interceptors.push(['$q', '$rootScope', function ($q, $rootScope) { if ($rootScope.activeCalls == undefined) { $rootScope.activeCalls = 0; } @@ -66,5 +66,5 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",function ($rou return rejection; } }; - }); + }]); }]); \ No newline at end of file diff --git a/public/javascripts/wechat/wechat_dev.js b/public/javascripts/wechat/wechat_dev.js deleted file mode 100644 index 36529e0b8..000000000 --- a/public/javascripts/wechat/wechat_dev.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Created by root on 3/25/16. - */ -$(document).ready(function(){ - - var bt=baidu.template; - bt.LEFT_DELIMITER=''; - - var apiUrl = '/api/v1/'; - var loadDataFromServer = function(id, page){ - getOpenId(function(openid){ - $.ajax({ - url: apiUrl + 'activities', - data: {openid: openid, page: page}, - type: 'POST', - dataType: 'json', - success: function(data){ - setTemplate(data.data, data.all_count, data.count, data.page); - }, - error: function(xhr,status,err){ - console.log(err); - } - }); - }) - - }; - var setTemplate = function(data, all_count, count, page){ - console.log(data); - var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page}); - if (page == 0) { - $('#container').prepend(html); - } else { - $("#more_activities").remove(); - $('#container').append(html); - } - descToggle(); - }; - //内容全部显示与部分隐藏 - var descToggle = function(){ - $(".post-all-content").each(function(){ - var postHeight = $(this).height(); - if (postHeight > 90){ - $(this).parent().next().css("display","block"); - $(this).parent().next().toggle(function(){ - $(this).text("点击隐藏"); - $(this).prev().css("height",postHeight); - },function(){ - $(this).text("点击展开"); - $(this).prev().css("height",90); - }); - } - }); - } - - loadDataFromServer(8686, 0); -}); diff --git a/script/assets b/script/assets new file mode 100644 index 000000000..bf4501127 --- /dev/null +++ b/script/assets @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cd public/javascripts/wechat && gulp && gulp minify