Skip to content

Commit bc1eabe

Browse files
committed
updates
1 parent 6f701ee commit bc1eabe

File tree

7 files changed

+447
-2
lines changed

7 files changed

+447
-2
lines changed

src/common/config/db.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export default {
1111
mysql: {
1212
host: '127.0.0.1',
1313
port: '3306',
14-
database: 'liblog',
14+
database: 'think_user',
1515
user: 'root',
16-
password: 'dxky500!',
16+
password: '123456!',
1717
prefix: 'li_',
1818
encoding: 'utf8'
1919
},

src/topic/config/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
/**
3+
* config
4+
*/
5+
export default {
6+
//key: value
7+
};

src/topic/controller/base.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
export default class extends think.controller.base {
4+
/**
5+
* some base method in here
6+
*/
7+
async __before() {
8+
9+
// assign后台设置
10+
let _web = await this.getConfig();
11+
this.assign('_web', _web);
12+
13+
//设置CSRF值
14+
let csrf = await this.session("__CSRF__");
15+
this.assign("csrf", csrf);
16+
17+
// 是否登录
18+
let uinfo = await this.session('uInfo');
19+
let islogin = (!think.isEmpty(uinfo)) ? 1 : 0;
20+
this.assign("islogin", islogin);
21+
if (!think.isEmpty(uinfo)) {
22+
let logininfo = await this.model('topic').findAll('user', { name: uinfo.name });
23+
this.assign("logininfo", logininfo[0]);
24+
}
25+
//是否登录
26+
27+
// 获取最新会员
28+
let memberList = await this.model("topic").getMemberList({ role: 4 }, 9);
29+
this.assign("memberList", memberList);
30+
31+
//获取tags
32+
let tagList = await this.model("topic").getOrderList("tags", { appear: 1 });
33+
this.assign('tagList', tagList);
34+
35+
//获取导航链接
36+
let navList = await this.model("topic").getOrderList('menu', { appear: 1 });
37+
this.assign("navList", navList);
38+
39+
//获取友情链接
40+
let linksList = await this.model("topic").getOrderList("links", { flag: 1 });
41+
this.assign("linksList", linksList);
42+
43+
// 设置主题地址
44+
this.THEME_VIEW_PATH = `${think.THEME_PATH}${think.sep}${_web.theme}${think.sep}${think.Modules_Src}${think.sep}${this.http.module}${think.sep}`;
45+
this.assign("theme_url", 'static/theme/' + _web.theme + '/res');
46+
47+
}
48+
async getConfig() {
49+
let sysdata = await this.model('topic').findOne('system', { id: 1 });
50+
return sysdata;
51+
}
52+
53+
// 渲染主题view层
54+
async displayView(name) {
55+
return this.display(this.THEME_VIEW_PATH + name + '.html');
56+
}
57+
}

src/topic/controller/create.js

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
'use strict';
2+
import fs from "fs";
3+
import path from "path";
4+
import Base from './base.js';
5+
6+
export default class extends Base {
7+
/**
8+
* index action
9+
* @return {Promise} []
10+
*/
11+
async indexAction(){
12+
this.assign("title","新建主题");
13+
let uinfo=await this.session('uInfo');
14+
if(!think.isEmpty(uinfo)){
15+
let upic=await this.model("topic").getUserPic({name:uinfo.name});
16+
let itemList=await this.model("topic").findAll("topic_item");
17+
this.assign('itemList',itemList);
18+
this.assign('uinfo',uinfo);
19+
this.assign('upic',upic.pic);
20+
return this.displayView("create_index");
21+
}else {
22+
return this.redirect('/login.html');
23+
}
24+
}
25+
26+
async doaddAction(){ //编辑或者新增主题
27+
let mycreatetime=think.datetime(this.post('createtime'));
28+
let updatetime=think.datetime(this.post('updatetime'));
29+
let data=await this.post();
30+
data.createtime=mycreatetime;
31+
data.updatetime=updatetime;
32+
if(!think.isEmpty(this.post("id"))){
33+
let rs=await this.model("topic").updateRecord("topic",{id:data.id},data);
34+
if(rs) return this.success();
35+
}else{
36+
let rs=await this.model("topic").addRecord("topic",data);
37+
let points=await this.model("topic").increpoint({name:data.author},this.config('point.addtopic'));
38+
if(rs) return this.success();
39+
}
40+
}
41+
42+
async editAction(){
43+
this.assign("title","编辑主题");
44+
let myid=this.get("tid");
45+
let uinfo=await this.session('uInfo');
46+
if(!think.isEmpty(uinfo)){
47+
let topicInfo=await this.model("topic").findOne("topic",{id:myid,author:uinfo.name});
48+
if(!think.isEmpty(topicInfo)){
49+
let upic=await this.model("topic").getUserPic({name:uinfo.name});
50+
this.assign('upic',upic.pic);
51+
let itemList=await this.model("topic").findAll("topic_item");
52+
this.assign('uinfo',uinfo);
53+
this.assign("topicInfo",topicInfo)
54+
this.assign("itemList",itemList)
55+
return this.displayView("create_edit");
56+
}else {
57+
return this.displayView("../common/error_404");
58+
}
59+
}else {
60+
return this.redirect('/login.html');
61+
}
62+
}
63+
64+
async savereplyAction(){
65+
//编辑或者新增回复
66+
let marked = require('marked');
67+
marked.setOptions({
68+
renderer: new marked.Renderer(),
69+
gfm: true,
70+
tables: true,
71+
breaks: true,
72+
pedantic: false,
73+
sanitize: true,
74+
smartLists: true,
75+
smartypants: false
76+
});
77+
let mycreatetime=think.datetime(this.post('createtime'));
78+
let data=await this.post();
79+
data.createtime=mycreatetime;
80+
if(data.text===''){
81+
return this.json({status:0,errno:1,errmsg:'回复不能为空!'});
82+
}else{
83+
// 解析markdown
84+
let html=marked(data.comment);
85+
// data.comment=html;
86+
if(!think.isEmpty(data.id)){
87+
//编辑
88+
let isexist=await this.model("topic").findOne("topic_comment",{id:data.id});
89+
let tid=await this.model("topic").findOne("topic",{id:data.tid});
90+
if(!think.isEmpty(isexist)&&!think.isEmpty(tid)){
91+
//更新最后回复数据
92+
let updata={
93+
updatetime:mycreatetime,
94+
updateauthor:data.author,
95+
updatepic:data.pic
96+
}
97+
let updatetime=await this.model("topic").updateRecord("topic",{id:data.tid},updata);
98+
//更新最后回复数据
99+
// 更新回复
100+
let rs=await this.model("topic").updateRecord("topic_comment",{id:data.id},data);
101+
if(rs) return this.success();
102+
}else{
103+
return this.fail("该主题或回复不存在或已删除!");
104+
}
105+
}else{
106+
//更新最后回复数据
107+
let updata={
108+
updatetime:mycreatetime,
109+
updateauthor:data.author,
110+
updatepic:data.pic
111+
}
112+
let updatetime=await this.model("topic").updateRecord("topic",{id:data.tid},updata);
113+
//更新最后回复数据
114+
//增加
115+
let rs=await this.model("topic_comment").add(data);
116+
// 增加积分
117+
let points=await this.model("topic").increpoint({name:data.author},this.config('point.addcomment'));
118+
// 增加回复数
119+
let replycount=await this.model("topic").where({id:data.tid}).increment('replycount',1);
120+
if(rs) return this.success();
121+
}
122+
}
123+
}
124+
125+
async postlikeAction(){
126+
let data=await this.post();
127+
let liker=data.likers;
128+
let myid=data.id;
129+
if(!think.isEmpty(myid)){
130+
let item=await this.model("topic").findOne("topic_comment",{id:myid});
131+
let arr=(!item.likers)?[]:(item.likers).split(",");
132+
let likers=arr||[];
133+
let n=likers.indexOf(liker);
134+
if(n<0){
135+
likers.push(liker);
136+
let newlikers=likers.join(",");
137+
let m=likers.length;
138+
let rs=await this.model("topic_comment").where({id:myid}).update({like:m,likers:newlikers});
139+
if(rs) return this.success({likeCount:m});
140+
}else{
141+
likers.splice(n,1);
142+
let m=likers.length;
143+
let newlikers=likers.join(",");
144+
let rs=await this.model("topic_comment").where({id:myid}).update({like:m,likers:newlikers});
145+
if(rs) return this.success({likeCount:m});
146+
}
147+
}
148+
}
149+
150+
async removereplyAction(){
151+
let data=await this.post();
152+
let myid=data.id;
153+
if(!think.isEmpty(myid)){
154+
let rs=await this.model("topic_comment").where({id:myid}).delete();
155+
// 减少回复数
156+
let replycount=await this.model("topic").where({id:data.tid}).decrement('replycount',1);
157+
if(rs) return this.success();
158+
}
159+
}
160+
161+
async removeitemAction(){
162+
let data=await this.post();
163+
let myid=data.id;
164+
if(!think.isEmpty(myid)){
165+
let rs=await this.model("topic").where({id:myid}).delete();
166+
if(rs) return this.success();
167+
}
168+
}
169+
170+
//上传图片接口
171+
async uploadeditorAction()
172+
{
173+
let IS_USE_OSS=think.config('OSS.on');
174+
if(IS_USE_OSS){
175+
//上传OSS图片接口
176+
let ALIOSS = think.service("alioss");
177+
let alioss = new ALIOSS();
178+
let file = think.extend({}, this.file('img'));
179+
let rs=await alioss.upload(file);
180+
if(rs){
181+
return this.json(think.config('OSS.domain')+"/"+rs.name);
182+
}else{
183+
return this.json("上传失败!");
184+
}
185+
}else{
186+
//上传应用服务器图片接口
187+
let file = think.extend({}, this.file('img'));
188+
let filepath = file.path;
189+
let newpath = liFormatDate(new Date().toLocaleDateString());
190+
let uploadPath = think.UPLOAD_PATH + '/pics/' + newpath;
191+
think.mkdir(uploadPath);
192+
let basename = path.basename(filepath);
193+
fs.renameSync(filepath, uploadPath + basename);
194+
this.json("/static/upload/pics/" + newpath + basename);
195+
}
196+
}
197+
198+
}

src/topic/controller/index.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
'use strict';
2+
3+
import Base from './base.js';
4+
5+
export default class extends Base {
6+
/**
7+
* index action
8+
* @return {Promise} []
9+
*/
10+
async indexAction(){
11+
let tab=this.get("tab");
12+
this.assign("title","社区");
13+
let map,menu;
14+
if(tab==='all'||tab===''){
15+
map={show:1};
16+
menu="all";
17+
}else{
18+
map={item:tab,show:1};
19+
menu=tab;
20+
}
21+
// let topicList=await this.model('topic').getTopicListJoinRecord(map);
22+
let pagenumber=this.get("page")||1;
23+
let pagesize=this.get("pagesize")||20;
24+
//分页
25+
let itemList=await this.model("topic").getPageSelect(map,pagenumber,pagesize);
26+
let result = await this.model("topic").getPageCountSelect(map,pagenumber,pagesize);
27+
var Page=think.adapter("template", "page");
28+
var page = new Page(this.http);
29+
var pageData=page.pagination(result);
30+
31+
this.assign("itemList",itemList);
32+
this.assign('pageData',pageData);
33+
this.assign('menu',"topic/"+menu);
34+
//分页
35+
// tab列表
36+
let tablist=await this.model("topic").findAll("topic_item");
37+
this.assign("tablist",tablist);
38+
// tab列表
39+
this.assign("tab",tab);
40+
return this.displayView("index_index");
41+
42+
}
43+
async itemAction(){
44+
let tid= await this.get("tid");
45+
let uinfo=await this.session('uInfo');
46+
let islogin=(!think.isEmpty(uinfo))?1:0;
47+
this.assign("islogin",islogin);
48+
if(!think.isEmpty(uinfo)){
49+
let loginuserinfo=await this.model('topic').findAll('user',{name:uinfo.name});
50+
this.assign("loginuserinfo",loginuserinfo[0]);
51+
//获取收藏信息
52+
let collectList=await this.model('topic').findAll('user_collect',{aid:tid,type:'topic',author:uinfo.name,iscollect:1});
53+
if(collectList.length>0){
54+
this.assign("cid",collectList[0].id);
55+
this.assign("iscollect",1);
56+
}else {
57+
this.assign("cid","");
58+
this.assign("iscollect",0);
59+
}
60+
}else{
61+
this.assign("loginuserinfo",{});
62+
}
63+
64+
// 获取回复列表
65+
let replyList=await this.model("topic").getReplyListInfo({tid:tid});
66+
this.assign("replyList",replyList);
67+
68+
let topicInfo=await this.model("topic").findOne("topic",{id:tid});
69+
if(!think.isEmpty(topicInfo)){
70+
let topicItem=await this.model("topic").findOne("topic_item",{name:topicInfo.item});
71+
let viewcount=await this.model("topic").where({id:tid}).increment('view',1);
72+
this.assign('topicInfo',topicInfo);
73+
this.assign("replycount",topicInfo.replycount);
74+
this.assign('topicItem',topicItem.comment);
75+
return this.displayView("index_item");
76+
77+
}else{
78+
return this.displayView("../common/error_404");
79+
}
80+
}
81+
82+
async editAction(){
83+
let tid= await this.get("tid");
84+
let replyInfo=await this.model("topic").findOne("topic_comment",{id:tid});
85+
let topicInfo=await this.model("topic").findOne("topic",{id:replyInfo.tid});
86+
this.assign("title","回复编辑");
87+
this.assign("replyInfo",replyInfo);
88+
this.assign("topicInfo",topicInfo);
89+
return this.displayView("index_edit");
90+
}
91+
}

src/topic/logic/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
/**
3+
* logic
4+
* @param {} []
5+
* @return {} []
6+
*/
7+
export default class extends think.logic.base {
8+
/**
9+
* index action logic
10+
* @return {} []
11+
*/
12+
indexAction(){
13+
14+
}
15+
}

0 commit comments

Comments
 (0)