Skip to content

Commit fa65fef

Browse files
committed
all
1 parent 6e402db commit fa65fef

File tree

15 files changed

+150
-34
lines changed

15 files changed

+150
-34
lines changed

models/base.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ var Server = require('mongodb').Server;
1313

1414
//数据库初始化
1515
var jixiang = function(){
16+
// var db = db || config.db;
1617
this.db = new Db(config.db,new Server(config.host,Connection.DEFAULT_PORT,{
1718
auto_reconnect:true
18-
},
19-
{}));
20-
this.db.open(function(){});
19+
},{}));
20+
this.db.open(function(err,db){
21+
if(err)console.log(err)
22+
// db.auth('mm','mmm');
23+
});
2124
}
2225
//获取聚集操作
2326
jixiang.prototype.getCollection = function(collection,callback){

models/init.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
db.dropDatabase();
2+
db.users.insert({
3+
accounts:"admintest@tuer.me",
4+
created_at:new Date(),
5+
pwd:hex_md5("1234qwer"),
6+
nick:"admin",
7+
avatar:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACO0lEQVR42u2ZaXOCMBCG/f9/TRFw6jHO9LDlEKQqrdyF7S697UwhkEDo+OH9mOR9shuSXUZhGMKQNboA/DcAcx/ByklAtTJQzBfQ7AL0bQGqncPaTeQCOAUh3HgxTK380+jMgT+1dNJybPA+vleAxTYtjVeZ/i4NIXX7LTokHSPVBqQxwM6PmIxXQZmHuFuAlZuCjovz0sLNugOg3SpTgSMAzdcZwLXHd/c7B1hiuAcNsHBeBABAdwBXwwfIuQOQLgB1Nd9iCmHIeUqzoeNDPFQA5xjhS7MQAFDADucWDjClJ/IWhEgxc/EAqg3CAEj+88ABXD8aNsBOPEAhFODpJDiFNMEAwg9xgOUfvRx5G6fbvbOLzD9FsN7x+5wu3bxxXdyqqOcFEAQ9dSXKfg8aaKWGTwhuja37fdrYvO4UZTr23plz/Zg9Gi13nntrkSBYAIxDIhfAEd8wUzRWRwreJawXlnAAMsQCEASSAZChKeZ1Hc2wopOuvV6mUE2AuWwAtPszO6sNMMGKznuK5AAg8xOspOqa/w7B4yC3ArAPEWhWxmz+U0YGD48dXWSuH8LGi0A3UxgbOe560dz4mRSMBs2p4tx3uIbDUNxXAmy8GGbWl2lajJfx3yBQrkFr6RbBxM0BaIIxGaaJe9QYN0wxM3aAcmDP5j9EB54JgAprCqdMuvWSegD0WZzTX0TJABQ8F8fnGgAq/f6Uzfy7xkZRDTAxQVoAUlAFILN5knfW+PoBYB1i6QGu7J+f1FebMjmuZa3kQAAAAABJRU5ErkJggg==",
8+
profile:'nothing yet',
9+
firends:[],
10+
isadmin:true,
11+
notebook:0,
12+
todocount:0,
13+
pageurl:''
14+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "lili's ask",
2+
"name": "lili",
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {

public/css/model.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@
103103
background: #7BAFA7;
104104
color: #fff;
105105
}
106+
107+
/*pac-box*/
108+
.package-box{
109+
background: #e5e1d0;
110+
}

public/js/index.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define(function(require){
1515
,format : 'YYYY-MM-DD'
1616
});
1717
}
18-
if(document.getElementById('charts')){
18+
if(document.getElementById('charts') && document.getElementById('data-charts')){
1919
require('./lib/highcharts');
2020
var datalist = JSON.parse( $('#data-charts').val() );
2121
var show = {
@@ -149,7 +149,30 @@ define(function(require){
149149
//选择&搜索
150150
$('#thecat').on('change',function(){
151151
var $this = $(this);
152-
var url = window.location.pathname+'?tag='+$this.val();
153-
window.location.href = url;
152+
if(!parseInt($this.val(),10)){//如果是全部跳转
153+
window.location.href = window.location.pathname;
154+
return;
155+
}
156+
var url = window.location.pathname+'/cat/get?cat='+$this.val();
157+
$.get(url,function(res){
158+
// console.log(res)
159+
if(res.success){
160+
var list = '';
161+
var name;
162+
for(var i=0,len=res.list.length;i<len;i++){
163+
name = res.list[i].name;
164+
list += '<option value="'+name+'">'+name+'</option>';
165+
}
166+
var pa = $this.parent();
167+
pa.find('#getCat').remove();
168+
if(list)
169+
pa.append('<select name="getCat" id="getCat"><option value="0">请选择..</option>'+list+'</select>')
170+
}else{
171+
alert('服务器卖萌了!')
172+
}
173+
})
154174
});
175+
$('#select-cat').delegate('#getCat','change',function(){
176+
window.location.href = window.location.pathname + '?cat='+$('#thecat').val()+'&tag='+this.value;
177+
})
155178
})

public/js/models/ajax.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ define(function(require,exports,module){
1515
}
1616
var formId = this.id;
1717
var data = $(this).serialize();
18+
if(formId == 'toteacher' && data.indexOf('toteacher') < 0){
19+
new popbox.tinyTips('error','请选择老师');
20+
return false;
21+
}
22+
1823
var tips = new popbox.tinyTips();
1924
$.ajax({
2025
url : $(this).attr('action')
@@ -32,7 +37,7 @@ define(function(require,exports,module){
3237
window.location.href = res.redirect;
3338
else
3439
window.location.reload();
35-
},2000);
40+
},500);
3641
}else if(res.flg === 2){
3742
tips.close();
3843
$('#answers').html('<div class="grey-tips">'+res.answers.a+'</div>');

routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function(app){
1717
/*===================
1818
前台路由
1919
===================*/
20+
app.get('/test',login.test);
2021
//-------------------
2122
// 登陆
2223
//-------------------
@@ -114,6 +115,7 @@ module.exports = function(app){
114115
//分类&章节&专题
115116
app.get('/admin/question/cat',adminQuestion.cat);
116117
app.post('/admin/question/cat',adminQuestion.cat);
118+
app.get('/admin/question/cat/get',adminQuestion.getCat);
117119
//------------------
118120
// 友情链接
119121
//------------------

routes/admin/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ var config = require('../../config')
66

77
var index = function(req,res){
88
if(req.method == 'GET'){
9-
// if(req.session.user.cat !==3){
10-
// return res.redirect('/');
11-
// }
12-
res.render('./admin/index',
13-
{
14-
title : config.name+'管理后台'
15-
,user : req.session.user
16-
});
9+
res.redirect('/admin/notice')
1710
}else if(req.method == 'POST'){
1811

1912
}

routes/admin/question.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,26 @@ exports.index = function(req,res){
3636
return;
3737
}
3838
var tag = req.query.tag || '';
39+
result.catCat = parseInt(req.query.cat,10) || null;
3940
var query = {};
40-
if(tag.length){
41-
switch(tag){
42-
case '分类' :
41+
if(result.catCat){
42+
switch(result.catCat){
43+
case 1 :
4344
query.catCat = tag;
4445
break;
45-
case '章节' :
46+
case 2 :
4647
query.catChapter = tag;
4748
break;
48-
case '专题' :
49+
case 3 :
4950
query.catTopic = tag;
5051
break;
5152
}
5253
}
5354
result.search = tag;
55+
56+
if(req.query.keyword){
57+
query.q = new RegExp(req.query.keyword,'gi');
58+
}
5459
jixiang.count(query,'qa',function(err,count){
5560
if(err)return res.json({flg:0,msg:err});
5661
// 分页
@@ -67,12 +72,26 @@ exports.index = function(req,res){
6772
}
6873
condition.query = query;
6974
if(pageNum.cur > pageNum.max)return;
75+
76+
var n = 2;
77+
jixiang.get({
78+
query : {
79+
cat:result.catCat
80+
}
81+
,get : {
82+
name: 1
83+
}
84+
},'qcat',function(err,doc){
85+
if(err)doc=[];
86+
result.catTag = doc;
87+
--n || render(pageNum);
88+
})
7089
jixiang.get(condition,'qa',function(err,doc){
71-
console.log(doc)
7290
if(err)doc=[];
7391
result.qa = doc;
74-
render(pageNum);
92+
--n || render(pageNum);
7593
});
94+
7695
});
7796

7897
function render(){
@@ -222,4 +241,23 @@ exports.cat = function(req,res){
222241
});
223242
}
224243
}
244+
}
245+
246+
exports.getCat = function(req,res){
247+
if(req.method === 'GET'){
248+
var cat = parseInt(req.query.cat,10) || null;
249+
jixiang.get({
250+
query : {
251+
cat : cat
252+
}
253+
,get : {
254+
name : 1
255+
}
256+
},'qcat',function(err,doc){
257+
if(err)doc=[];
258+
return res.json({success: true,list:doc})
259+
})
260+
}else if(req.method === 'POST'){
261+
262+
}
225263
}

routes/login.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ var index = function(req,res){
5858
var list = {};
5959
var first = new Date(doc[0].askdate);
6060
var firstDate = utils.format.call(first,'yyyy-MM-dd');
61-
list[firstDate] = 1;
61+
list[firstDate] = 0;
6262
doc.forEach(function(item,index){
6363
var date = new Date(item.askdate);
6464
if(date.getFullYear() === first.getFullYear()
6565
&& date.getMonth() === first.getMonth()
6666
&& date.getDate() === first.getDate() ){
67-
++list[firstDate];
67+
list[firstDate]++;
68+
console.log('after')
69+
console.log(list[firstDate])
6870
}else{
6971
first = new Date(item.askdate);
7072
firstDate = utils.format.call(first,'yyyy-MM-dd');
@@ -88,6 +90,7 @@ var index = function(req,res){
8890
var md5 = crypto.createHash('md5');
8991
var password = md5.update(req.body.password).digest('base64');
9092
var cat = parseInt(req.body.cat,10) || 1;
93+
9194
jixiang.getOne({username:req.body.username,cat : cat},'users',function(err,user){
9295
if(!user){
9396
return res.json({flg:0,msg:'用户名或者密码错误!'});
@@ -119,4 +122,17 @@ var index = function(req,res){
119122
}
120123
}
121124

122-
exports.index = index;
125+
exports.index = index;
126+
127+
//测试
128+
exports.test = function(req,res){
129+
// var jixiang1 = new jixiang();
130+
if(req.method == 'GET'){
131+
res.render('./index/test',{
132+
title : '测试'
133+
,user : req.session.user
134+
});
135+
}else if(req.method == 'POST'){
136+
137+
}
138+
}

routes/question.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ exports.toslove = function(req,res){
152152
}
153153
}
154154
jixiang.getOne({_id:condition.query._id},'qa',function(err,doc){
155-
console.log(doc)
156155
if(err)console.log(err);
157156
jixiang.getOne({username:doc.askuser},'users',function(err,user){
158157
if(err)console.log(err);

views/admin/question.jade

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ block content
1212
th(colspan="5")
1313
tr
1414
th(colspan="5",style="text-align:left;padding:5px")
15-
.form-inline
15+
#select-cat.form-inline.fl-l
1616
select.fl-l(id="thecat",name="thecat")
1717
- var cats = ['全部','分类','章节','专题'];
18-
each item in cats
18+
each item,index in cats
1919
-var selected = false
20-
if item == result.search
20+
if index == result.catCat
2121
-selected = true
22-
option(value=item,selected=selected)= item
22+
option(value=index,selected=selected)= item
23+
if result.catCat
24+
select(id="getCat",name="getCat")
25+
option(value="0") 请选择..
26+
each item in result.catTag
27+
-var selected = false
28+
if result.search == item.name
29+
-selected = true
30+
option(value=item.name,selected=selected)= item.name
2331
form.form-inline.fl-r
2432
input(id="keyword",name="keyword",type="text")
2533
button(type="submit",class="btn") 搜索
@@ -74,6 +82,7 @@ block content
7482
-list += '<option value="'+item.name+'">'+item.name+'</option>';
7583
if !!list
7684
select(name=key)
85+
option(value="无")
7786
!{list}
7887
else
7988
| 还没有#{catArray[key].name}
@@ -120,6 +129,7 @@ block content
120129
-list += ' value="'+item.name+'">'+item.name+'</option>';
121130
if !!list
122131
select(name=key)
132+
option(value="无")
123133
!{list}
124134
else
125135
| 还没有#{catArray[key].name}

views/index/index.jade

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ block content
3636
//公告处
3737
if !!result.notice
3838
.grey-tips.red 公告:#{result.notice}
39-
input(id="data-charts",value="#{result.total}",type="hidden")
40-
#charts
39+
if result.total
40+
input(id="data-charts",value="#{result.total}",type="hidden")
41+
#charts
42+
else
43+
#charts 还没有数据支持生成图表,开始你的提问之旅吧~
4144

4245
block link
4346
if result.links && result.links.length

views/index/question.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ block content
88
button.btn 提交
99
#answers
1010
if template === 2
11-
form.form-inline.ajax-form(action="/question?add=1",method="post")
11+
form#toteacher.form-inline.ajax-form(action="/question?add=1",method="post")
1212
table.table.order-table
1313
caption.bread
1414
a.parent 提问老师

views/index/test.jade

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.container
2+
.header 我擦
3+
4+
5+

0 commit comments

Comments
 (0)