Skip to content

Commit 5062ce9

Browse files
committed
完善个人界面,修复bug
1 parent 6643ee5 commit 5062ce9

File tree

6 files changed

+207
-78
lines changed

6 files changed

+207
-78
lines changed

models/topic.js

+31-38
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,16 @@ topic.myTopic=function(name,size,num,callback){
5757
global.db.collection('topic',function(err,collection){
5858
collection.find({name:name,hide:false}).sort({_id: -1}).skip(num).limit(size).toArray(function(err,items){
5959
if(err){
60-
client.hmset("myTopic", {isOk:false},function(error, res){
61-
if(error) {
62-
console.log(error);
63-
} else {
64-
console.log(res);
65-
}
66-
});
6760
callback({isOk:false});
6861
}else{
6962
var json=JSON.stringify(items);
70-
client.hmset("myTopic", {isOk:true,data:json},function(error, res){
63+
var key="myTopic"+name;
64+
client.hmset(key, {isOk:true,data:json},function(error, res){
7165
if(error) {
72-
console.log(error);
73-
} else {
74-
console.log(res);
75-
}
66+
console.log(error);
67+
} else {
68+
console.log(res);
69+
}
7670
});
7771
callback({isOk:true,data:items});
7872
}
@@ -81,32 +75,31 @@ topic.myTopic=function(name,size,num,callback){
8175
}
8276

8377
//插入redis判断
84-
//这边redis存储需要详细命名,目前有bug
85-
client.hgetall("myTopic", function (err, res) {
86-
if(err) {
87-
console.log(err);
88-
} else {
89-
//首先判断缓存中是否有值,就是用缓存中内容
90-
if(res){
91-
//然后需要判断下是否有更新
92-
var l=redisCache;
93-
if(!redisCache.myTopic){//redisCache.myTopic为false表示缓存没有更新
94-
if(res.isOk=="true"){
95-
var obj={isOk:true,data:JSON.parse(res.data)};
96-
callback(obj);
97-
}
98-
}else{
99-
getFromDB();
100-
redisCache.myTopic=false;//更新缓存后,设置为false
101-
}
102-
}else{
103-
//到数据库中获取最新的值
104-
getFromDB();
105-
redisCache.myTopic=false;//更新缓存后,设置为false
106-
}
107-
108-
}
109-
});
78+
client.hgetall("myTopic"+name, function (err, res) {
79+
if(err) {
80+
console.log(err);
81+
} else {
82+
//首先判断缓存中是否有值,就是用缓存中内容
83+
if(res){
84+
//然后需要判断下是否有更新
85+
var l=redisCache;
86+
if(!redisCache.myTopic){//redisCache.myTopic为false表示缓存没有更新
87+
if(res.isOk=="true"){
88+
var obj={isOk:true,data:JSON.parse(res.data)};
89+
callback(obj);
90+
}
91+
}else{
92+
getFromDB();
93+
redisCache.myTopic=false;//更新缓存后,设置为false
94+
}
95+
}else{
96+
//到数据库中获取最新的值
97+
getFromDB();
98+
redisCache.myTopic=false;//更新缓存后,设置为false
99+
}
100+
101+
}
102+
});
110103
};
111104

112105
//用户关注对象的话题

public/app/app.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner" ng-controller='headerCtrl'>
2222
<div class="container">
2323
<div class="navbar-header">
24-
<a href="/" class="navbar-brand">Money</a>
24+
<a href="/app/app.html#index" class="navbar-brand">Money</a>
2525
</div>
2626
<nav class="navbar-collapse bs-navbar-collapse" role="navigation">
2727
<ul class="nav navbar-nav">
2828
<li>
29-
<a href="/">首页</a>
29+
<a href="/app/app.html#index">首页</a>
3030
</li>
3131
<li class="dropdown">
3232
<a href="#" class="dropdown-toggle" data-toggle="dropdown">广场<b class="caret"></b></a>

public/app/people.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h3 id="pageName" pName="{{name}}">{{name}}的信息</h3>
66
<img ng-src="{{people.info.pic.big}}" style="width:100%"/>
77
</div>
88
<div class="col-md-8">
9-
<p isWatch="iswatch" id="watchP" ng-hide="myself">
9+
<p isWatch="iswatch" id="watchP" ng-hide="myself" ng-controller="watchPeople">
1010
<button type="button" class="btn btn-info col-md-offset-4" ng-hide="iswatch" ng-click="watchPeo()" id="watchOk">关注</button>
1111
<button type="button" class="btn btn-info col-md-offset-4" ng-show="iswatch" ng-click="unwatchPeo()" id="watchNo">取消关注</button>
1212
</p>
@@ -16,7 +16,7 @@ <h3 id="pageName" pName="{{name}}">{{name}}的信息</h3>
1616

1717
<div class="clearfix"></div>
1818
<h3>我的选择</h3>
19-
<table class="table table-bordered table-hover table-condensed" ng-controller="timeStock">
19+
<table class="table table-bordered table-hover table-condensed" ng-controller="timeStockUser">
2020
<thead>
2121
<tr>
2222
<th>股票</th>
@@ -51,14 +51,14 @@ <h3>我的选择</h3>
5151
</ul>
5252

5353
<div class="tab-content">
54-
<div class="tab-pane active" id="home" ng-include="'app/mode/mytopic.html'" ng-controller="mytopic">
54+
<div class="tab-pane active" id="home" ng-include="'app/mode/mytopic.html'" ng-controller="mytopicUser">
5555
</div>
5656
<div class="tab-pane" id="profile">
5757
<ul class="list-group">
5858
<li>Profile</li>
5959
</ul>
6060
</div>
61-
<div class="tab-pane" id="messages">
61+
<div class="tab-pane" id="messages" ng-controller="lookname">
6262
<ul class="list-group">
6363
<li class="list-group-item col-md-3 col-md-offset-1" ng-repeat="look in looks">
6464
{{look.name}}
@@ -67,7 +67,7 @@ <h3>我的选择</h3>
6767
</li>
6868
</ul>
6969
</div>
70-
<div class="tab-pane" id="settings">
70+
<div class="tab-pane" id="settings" ng-controller="fenname">
7171
<ul class="list-group">
7272
<li class="list-group-item col-md-3 col-md-offset-1" ng-repeat="fen in fens">
7373
{{fen.name}}

public/js/app/controllers.js

+62
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,69 @@ app.factory('User', [function() {
4949
return User;
5050
}]);
5151

52+
//处理关注和粉丝的数据
53+
app.factory('watchAndFens', [function() {
54+
var watchAndFens={};
55+
watchAndFens.fn=function(data){
56+
for(var i=0,l=data.length;i<l;i++){
57+
if(data[i].myself){
58+
data[i].watch=false;
59+
data[i].unwatch=false;
60+
}else{
61+
if(data[i].haveWatch){//false表示没有关注
62+
data[i].watch=false;
63+
data[i].unwatch=true;
64+
}else{
65+
data[i].watch=true;
66+
data[i].unwatch=false;
67+
}
68+
}
69+
}
70+
};
71+
return watchAndFens;
72+
}]);
5273

74+
app.factory('textExtract', [function() {
75+
var textExtract=function(comment,name){
76+
//正则获取@ 的用户,用户名3-15个英文或数字
77+
var aboutPeople=comment.match(/@\w{3,15}\s|@\w{3,15}$/g);
78+
if(!!aboutPeople){
79+
for(var i1=0,l1=aboutPeople.length;i1<l1;i1++){
80+
aboutPeople[i1]=aboutPeople[i1].replace(" ","").replace(/@/,"");
81+
}
82+
}else{
83+
aboutPeople=[];
84+
}
85+
//正则获取$$ 的股票代码/sh[0-9]{6}|sz[0-9]{6}/i
86+
var aboutStockcode=comment.match(/\$sh[0-9]{6}\$|\$sz[0-9]{6}\$/ig);
87+
if(!!aboutStockcode){
88+
for(var i2=0,l2=aboutStockcode.length;i2<l2;i2++){
89+
aboutStockcode[i2]=aboutStockcode[i2].replace(/\$/g,"");
90+
}
91+
}else{
92+
aboutStockcode=[];
93+
}
94+
//正则获取股票名称
95+
var aboutStockName=comment.match(/\$[\u4e00-\u9fa5]{2,6}\$/ig);
96+
if(!!aboutStockName){
97+
for(var i3=0,l3=aboutStockName.length;i3<l3;i3++){
98+
aboutStockName[i3]=aboutStockName[i3].replace(/\$/g,"");
99+
}
100+
}else{
101+
aboutStockName=[];
102+
}
103+
//前端解析的对象
104+
var commentObj={
105+
topic:comment,
106+
name:name,
107+
aboutPeople:aboutPeople,
108+
aboutStockcode:aboutStockcode,
109+
aboutStockName:aboutStockName
110+
};
111+
return commentObj;
112+
};
113+
return textExtract;
114+
}]);
53115

54116

55117

public/js/app/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//index页面父控制器
2-
function indexCtrl ($scope, $http, $location ,User) {
2+
function indexCtrl ($scope, $http, $location ,User,textExtract) {
33
$scope.userInfo=User.get();
44
if(!$scope.userInfo){
55
$location.path("/login");
@@ -22,6 +22,26 @@ function indexCtrl ($scope, $http, $location ,User) {
2222
$scope.$on("delStockTime",function (event,msg) {
2323
$scope.$broadcast("delTopStock", msg);
2424
});
25+
26+
$scope.submitCom=function(){
27+
if(!$scope.sayCom){
28+
alert("请填写内容");
29+
}else{
30+
var commentObj=textExtract($scope.sayCom,$scope.userInfo.name);
31+
$http.post("/submitTopic", commentObj).success(function(data,status){
32+
if(data.isOk){
33+
$scope.sayCom="";
34+
// if(!!$scope.myTopicList){//已经加载了我的评论页面
35+
// //插入到第一个
36+
// $scope.myTopicList.unshift(data.data[0]);
37+
// }
38+
$scope.$broadcast("addMyTopic", data.data[0]);
39+
}else{
40+
alert("提交失败!");
41+
}
42+
});
43+
}
44+
}
2545
}
2646

2747
//定时刷新控制器

public/js/app/people.js

+86-32
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function peopleCtrl($scope, $routeParams, $http, $location ,User){
1313
$http({method: "GET", url: "/peopleAjax?name="+lookName}).success(function(data,status){
1414
data.user.info.pic.big="/images/"+data.user.info.pic.big;
1515
$scope.people=data.user;
16+
$scope.lookPeople=data.people;
17+
//发出加载消息
18+
$scope.$broadcast("openTimeStock");
19+
1620
if(data.isWatch=="myself"){
1721
$scope.myself=true;
1822
}else{
@@ -21,40 +25,90 @@ function peopleCtrl($scope, $routeParams, $http, $location ,User){
2125
});
2226
}
2327

24-
function timeStock($scope, $http){
28+
function watchPeople($scope, $http){
29+
var myName=$scope.$parent.name;
30+
$scope.watchPeo=function(){
31+
$http({method: "GET", url: "/watchPeople?name="+myName}).success(function(data,status){
32+
if(data.ok){
33+
$scope.iswatch=true;
34+
}else{
35+
alert(data.message);
36+
}
37+
});
38+
}
39+
$scope.unwatchPeo=function(){
40+
$http({method: "GET", url: "/unwatchPeople?name="+myName}).success(function(data,status){
41+
if(data.ok){
42+
$scope.iswatch=false;
43+
}
44+
});
45+
}
46+
}
47+
48+
function lookname($scope, $http,watchAndFens){
49+
var pageNum=0;
50+
var pageSize=10;
51+
var name=$scope.$parent.name;
52+
$http({method: "GET", url: "/peopleWatchTab?name="+name+"&pageNum="+pageNum+"&pageSize="+pageSize}).success(function(data,status){
53+
if(data.ok){
54+
watchAndFens.fn(data.list);
55+
$scope.looks=data.list;
56+
}
57+
});
58+
}
59+
function fenname($scope, $http,watchAndFens){
60+
var pageNum2=0;
61+
var pageSize2=10;
62+
var name=$scope.$parent.name;
63+
$http({method: "GET", url: "/peopleFensTab?name="+name+"&pageNum="+pageNum2+"&pageSize="+pageSize2}).success(function(data,status){
64+
if(data.ok){
65+
watchAndFens.fn(data.list);
66+
$scope.fens=data.list;
67+
}
68+
});
69+
}
70+
71+
function timeStockUser($scope, $http){
2572
//股票实时数据
26-
var userInfo=$scope.$parent.userInfo;
2773
var time;
2874
function ajaxStock(){
29-
stockCode=userInfo.stock.join(",");
30-
//$scope.url = 'http://xueqiu.com/stock/quote.json?code='+pathUrl+'&callback=JSON_CALLBACK';
31-
if(stockCode!==""){
32-
//如果没有信息,就不请求
33-
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
34-
$http({ method: "JSONP", url: $scope.url }).success(function(data, status) {
35-
for(var i=0,l=data.quotes.length;i<l;i++){
36-
data.quotes[i].volume=(data.quotes[i].volume/10000).toFixed(2);
37-
data.quotes[i].marketCapital=(data.quotes[i].marketCapital/100000000).toFixed(2);
38-
if(Number(data.quotes[i].change)>0){
39-
data.quotes[i].zdClass="red";
40-
data.quotes[i].zdBack="danger";
41-
data.quotes[i].change="+"+data.quotes[i].change;
42-
data.quotes[i].percentage="+"+data.quotes[i].percentage+"%";
43-
}else if(Number(data.quotes[i].change)===0){
44-
data.quotes[i].zdClass="";
45-
data.quotes[i].zdBack="";
46-
data.quotes[i].percentage=data.quotes[i].percentage+"%";
47-
}else{
48-
data.quotes[i].zdClass="green";
49-
data.quotes[i].zdBack="success";
50-
data.quotes[i].percentage=data.quotes[i].percentage+"%";
51-
}
52-
}
53-
$scope.stocks=data.quotes;
54-
});
55-
}
75+
var userInfo=$scope.$parent.lookPeople;
76+
stockCode=userInfo.stock.join(",");
77+
//$scope.url = 'http://xueqiu.com/stock/quote.json?code='+pathUrl+'&callback=JSON_CALLBACK';
78+
if(stockCode!==""){
79+
//如果没有信息,就不请求
80+
$scope.url = 'http://xueqiu.com/stock/quote.json?code='+stockCode+'&'+xueqiuUrl+'&callback=JSON_CALLBACK';
81+
$http({ method: "JSONP", url: $scope.url }).success(function(data, status) {
82+
for(var i=0,l=data.quotes.length;i<l;i++){
83+
data.quotes[i].volume=(data.quotes[i].volume/10000).toFixed(2);
84+
data.quotes[i].marketCapital=(data.quotes[i].marketCapital/100000000).toFixed(2);
85+
if(Number(data.quotes[i].change)>0){
86+
data.quotes[i].zdClass="red";
87+
data.quotes[i].zdBack="danger";
88+
data.quotes[i].change="+"+data.quotes[i].change;
89+
data.quotes[i].percentage="+"+data.quotes[i].percentage+"%";
90+
}else if(Number(data.quotes[i].change)===0){
91+
data.quotes[i].zdClass="";
92+
data.quotes[i].zdBack="";
93+
data.quotes[i].percentage=data.quotes[i].percentage+"%";
94+
}else{
95+
data.quotes[i].zdClass="green";
96+
data.quotes[i].zdBack="success";
97+
data.quotes[i].percentage=data.quotes[i].percentage+"%";
98+
}
99+
}
100+
$scope.stocks=data.quotes;
101+
});
102+
}
56103
}
57-
ajaxStock();
104+
105+
//订阅消息
106+
$scope.$on("openTimeStock",function (event) {
107+
ajaxStock();
108+
start();
109+
});
110+
111+
58112
var hours;
59113
var now;
60114
function start(){
@@ -65,7 +119,7 @@ function timeStock($scope, $http){
65119
time=setTimeout(start,10000);
66120
}
67121
}
68-
start();
122+
69123

70124
//路由跳转后暂停加载
71125
$scope.$on('$routeChangeStart', function(next, current) {
@@ -76,7 +130,7 @@ function timeStock($scope, $http){
76130
/*
77131
话题模块
78132
*/
79-
function mytopic($scope, $http, topicFun){
133+
function mytopicUser($scope, $http, topicFun){
80134

81135
//初始化stock.angular函数,传入这个作用域内需要用到的函数
82136
//var selfName=myName;//selfName登陆用户

0 commit comments

Comments
 (0)