From 5873cebcfdf6eeef3addc36addab8da9beaacdcc Mon Sep 17 00:00:00 2001 From: toogee Date: Fri, 24 Apr 2020 15:07:26 +0800 Subject: [PATCH] url bind --- app/index/controller/Article.php | 36 +++--- app/index/controller/Comment.php | 41 +++--- app/index/controller/User.php | 4 +- app/middleware/LoginCheck.php | 2 +- public/static/res/mods/index.js | 10 +- public/static/res/mods/jie.js | 27 ++-- public/static/res/mods/user.js | 6 +- view/index/article/add.html | 208 +++++++++++++++-------------- view/index/article/detail.html | 116 ++++++++--------- view/index/article/edit.html | 216 +++++++++++++++---------------- view/index/public/js.html | 6 +- view/index/user/set.html | 88 +++++++------ 12 files changed, 373 insertions(+), 387 deletions(-) diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 87fb0f0..6a3ed63 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -6,14 +6,14 @@ use think\facade\View; use think\facade\Request; use think\facade\Db; use think\facade\Cache; -use app\common\model\Cate; -use app\common\model\User; use app\common\model\Comment; -use app\common\model\Collection; use app\common\model\Article as ArticleModel; use think\exception\ValidateException; use think\facade\Config; use taoler\com\Message; +use app\common\model\Cate; +use app\common\model\User; +use app\common\model\Collection; class Article extends BaseController { @@ -172,14 +172,12 @@ class Article extends BaseController $data = ['title'=>$title,'content'=>'评论通知','link'=>$link,'user_id'=>$sendId,'type'=>1]; Message::sendMsg($sendId,$receveId,$data); - $res = ['code'=>1, 'msg'=>'留言成功']; + $res = ['code'=>0, 'msg'=>'留言成功']; } else { - $res = ['code'=>0, 'msg'=>'留言失败']; + $res = ['code'=>-1, 'msg'=>'留言失败']; } return json($res); } - - //添加文章 public function add() @@ -195,7 +193,8 @@ class Article extends BaseController $result = $article->add($data); if($result == 1) { $aid = Db::name('article')->max('id'); - return json(['code'=>1,'msg'=>'发布成功','url'=>'/'.app('http')->getName().'/jie/'.$aid.'.html']); + $link = (string) url('article/detail',['id'=> $aid]); + return json(['code'=>1,'msg'=>'发布成功','url'=> $link]); } else { $this->error($result); } @@ -212,7 +211,6 @@ class Article extends BaseController $tags = []; foreach($att as $v){ if ($v !='') { - $tags[] = $v; } } @@ -235,7 +233,10 @@ class Article extends BaseController $article = new \app\common\model\Article; $result = $article->edit($data); if($result == 1) { - return json(['code'=>1,'msg'=>'修改成功','url'=>'/'.app('http')->getName().'/jie/'.$id.'.html']); + //删除缓存显示编辑后内容 + Cache::delete('article_'.$id); + $link = (string) url('article/detail',['id'=> $id]); + return json(['code'=>0,'msg'=>'修改成功','url'=> $link]); } else { $this->error($result); } @@ -255,21 +256,21 @@ class Article extends BaseController return View::fetch(); } - //删除文章 + //删除帖子 public function delete() { $article = ArticleModel::find(input('id')); $result = $article->together(['comments'])->delete(); if($result) { - $res = ['code'=>1,'msg'=>'删除文章成功','url'=>'/index/user/post']; + $res = ['code'=>0,'msg'=>'删除文章成功','url'=>'/index/user/post']; } else { - $res = ['code'=>0,'msg'=>'删除文章失败']; + $res = ['code'=>-1,'msg'=>'删除文章失败']; } return json($res); } //文本编辑器图片上传 - public function text_img_upload() + public function textImgUpload() { $file = request()->file('file'); try { @@ -317,8 +318,11 @@ class Article extends BaseController $res = ['status'=>0,'msg'=>'精贴已取消']; } } - //清除文章缓存 - Cache::tag('tagArtDetail')->clear(); + + //删除本贴设置缓存显示编辑后内容 + Cache::delete('article_'.$data['id']); + //清除文章tag缓存 + //Cache::tag('tagArtDetail')->clear(); return json($res); } diff --git a/app/index/controller/Comment.php b/app/index/controller/Comment.php index 2b93acb..d7bb359 100644 --- a/app/index/controller/Comment.php +++ b/app/index/controller/Comment.php @@ -6,14 +6,12 @@ use think\facade\Session; use app\common\model\Comment as CommentModel; use app\common\model\Article; use app\common\model\UserZan; -use think\facade\Request; -use think\Db; class Comment extends BaseController { //采纳评论 - public function jiedaCai(){ - + public function jiedaCai() + { $id = input('id'); $comms = CommentModel::find($id); $result = $comms->save(['cai' =>1]); @@ -29,33 +27,30 @@ class Comment extends BaseController } //删除评论 - public function jiedaDelete(){ - + public function jiedaDelete() + { $id = input('id'); //$arid = intval($id); $comms = CommentModel::find($id); $result = $comms->delete(); - //$result = Db::name('collection')->where('article_id',$arid)->delete(); if($result){ - //$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功']; - $res = [ - 'status' => 0, - ]; + $res = ['status' => 0,'msg' => '删除成功']; + } else { + $res = ['status' => -1,'msg' => '删除失败']; } return json($res); } - - + //编辑评论 public function getDa() { + //获取原评论 $this->isLogin(); $id = input('id'); $comms = CommentModel::find($id); $res['rows'] = []; if($comms) { - $res['status'] = 0; $res['rows']['content'] = $comms['content']; } return json($res); @@ -78,7 +73,7 @@ class Comment extends BaseController return json($res); } - //点赞评论 + //评论点赞 public function jiedaZan() { $this->isLogin(); @@ -90,20 +85,20 @@ class Comment extends BaseController if(!$zan ){ //如果没有点过赞执行点赞操作 $coms = CommentModel::find(input('post.id')); if($coms['user_id'] == session('user_id')){ - return $res=['msg' => '不能给自己点赞哦']; + $res = ['msg' => '不能给自己点赞哦']; } else { - $res = UserZan::create($data); - if($res){ + $result = UserZan::create($data); + if($result){ //评论点赞数加1 $coms->save(['zan' => $coms['zan']+1]); - return $res=['status' => 0, 'msg' => '点赞成功']; + $res = ['status' => 0, 'msg' => '点赞成功']; }else { - $this->error('点赞失败'); + $res = ['status' => -1, 'msg' => '点赞失败']; } } - } else { - return $res=['status'=>1,'msg' => '你已赞过了']; + $res = ['status'=>-1,'msg' => '你已赞过了']; } - } + return json($res); + } } \ No newline at end of file diff --git a/app/index/controller/User.php b/app/index/controller/User.php index aff645b..8ec5614 100644 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -81,7 +81,7 @@ class User extends BaseController $user = new \app\common\model\User; $result = $user->setNew($data); if($result==1){ - return ['code'=>0,'msg'=>'资料更新成功','url'=>'/index/user/set']; + return ['code'=>0,'msg'=>'资料更新成功']; } else { $this->error($result); } @@ -180,7 +180,7 @@ class User extends BaseController $result = $user->setpass($data); if($result == 1) { Session::clear(); - return $this->success('密码修改成功 请登录', '/index/user/login'); + return $this->success('密码修改成功 请登录', '/login'); } else { return $this->error($result); } diff --git a/app/middleware/LoginCheck.php b/app/middleware/LoginCheck.php index 91e4d7e..7581880 100644 --- a/app/middleware/LoginCheck.php +++ b/app/middleware/LoginCheck.php @@ -11,7 +11,7 @@ class LoginCheck if(Session::has('user_id')){ return $next($request); } else { - return redirect('/index/login'); + return redirect((string) url('login/index')); } } } diff --git a/public/static/res/mods/index.js b/public/static/res/mods/index.js index b9508ac..cd733ea 100644 --- a/public/static/res/mods/index.js +++ b/public/static/res/mods/index.js @@ -167,7 +167,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function( elem: '#uploadImg' ,acceptMime: 'image/*' ,exts: 'jpg|png|gif|bmp|jpeg' - ,url: '/index/article/text_img_upload' + ,url: textImgUpload ,size: 2048 ,done: function(res){ if(res.status == 0){ @@ -705,7 +705,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function( ,shadeClose: true ,maxWidth: 10000 ,skin: 'fly-layer-search' - ,content: ['
' + ,content: ['' ,'' ,'
'].join('') ,success: function(layero){ @@ -819,13 +819,13 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function( loading = layer.load(2, { shade: [0.2, '#000'] }); - location.href = '/index/add'; + location.href = articleAdd; } else { layer.msg('请先登陆',{ icon:5, time:2000 },function () { - location.href = '/index/login'; + location.href = login; }); } return false; @@ -858,7 +858,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function( ,click: function(type){ if(type === 'bar1'){ //slayer.msg('打开 index.js,开启发表新帖的路径'); - location.href = '/index/add'; + location.href = articleAdd; } } }); diff --git a/public/static/res/mods/jie.js b/public/static/res/mods/jie.js index 2328285..8767a56 100644 --- a/public/static/res/mods/jie.js +++ b/public/static/res/mods/jie.js @@ -70,20 +70,19 @@ layui.define('fly', function(exports){ }); }; - - //求解管理 + //帖子管理 gather.jieAdmin = { - //删求解 + //删帖子 del: function(div){ layer.confirm('确认删除该贴么?', function(index){ layer.close(index); $.ajax({ type:'get', - url:"/index/article/delete", + url:articleDelete, data:{id: div.data('id')}, dataType:'json', success:function(data){ - if(data.code == 1){ + if(data.code == 0){ layer.msg(data.msg,{ icon:6, time:2000 @@ -106,7 +105,7 @@ layui.define('fly', function(exports){ //设置置顶、状态 ,set: function(div){ var othis = $(this); - fly.json('/index/article/jieset/', { + fly.json(articleJieset, { id: div.data('id') ,rank: othis.attr('rank') ,field: othis.attr('field') @@ -121,7 +120,7 @@ layui.define('fly', function(exports){ //收藏 ,collect: function(div){ var othis = $(this), type = othis.data('type'); - fly.json('/index/collection/'+ type +'/', { + fly.json(collection+ type +'/', { cid: div.data('id') }, function(res){ if(type === 'add'){ @@ -155,7 +154,7 @@ layui.define('fly', function(exports){ gather.jiedaActive = { zan: function(li){ //赞 var othis = $(this), ok = othis.hasClass('zanok'); - fly.json('/index/comment/jiedaZan', { + fly.json(commentJiedaZan, { ok: ok ,id: li.data('id') }, function(res){ @@ -179,7 +178,7 @@ layui.define('fly', function(exports){ var othis = $(this); layer.confirm('是否采纳该回答为最佳答案?', function(index){ layer.close(index); - fly.json('/index/comment/jiedaCai', { + fly.json(commentJiedaCai, { id: li.data('id') }, function(res){ if(res.status === 0){ @@ -193,8 +192,8 @@ layui.define('fly', function(exports){ }); }); } - ,edit: function(li){ //编辑 - fly.json('/index/comment/getDa', { + ,edit: function(li){ //编辑评论 + fly.json(commentGetDa, { id: li.data('id') }, function(res){ var data = res.rows; @@ -211,7 +210,7 @@ layui.define('fly', function(exports){ }); } }, function(value, index){ - fly.json('/index/comment/updateDa/', { + fly.json(commentUpdateDa, { id: li.data('id') ,content: value }, function(res){ @@ -222,10 +221,10 @@ layui.define('fly', function(exports){ }); }); } - ,del: function(li){ //删除 + ,del: function(li){ //删除评论 layer.confirm('确认删除该回答么?', function(index){ layer.close(index); - fly.json('/index/comment/jiedaDelete/', { + fly.json(commentJiedaDelete, { id: li.data('id') }, function(res){ if(res.status === 0){ diff --git a/public/static/res/mods/user.js b/public/static/res/mods/user.js index f40f117..dda315a 100644 --- a/public/static/res/mods/user.js +++ b/public/static/res/mods/user.js @@ -25,8 +25,6 @@ layui.define(['laypage', 'fly', 'element', 'flow'], function(exports){ }; - - //我的相关数据 var elemUC = $('#LAY_uc'), elemUCM = $('#LAY_ucm'); gather.minelog = {}; @@ -171,14 +169,14 @@ layui.define(['laypage', 'fly', 'element', 'flow'], function(exports){ upload.render({ elem: '.upload-img' - ,url: '/index/user/uploadHeadImg/' + ,url: uploadHeadImg ,size: 300 ,before: function(){ avatarAdd.find('.loading').show(); } ,done: function(res){ if(res.status == 0){ - $.post('/index/user/set/', { + $.post(userSet, { avatar: res.url }, function(res){ location.reload(); diff --git a/view/index/article/add.html b/view/index/article/add.html index 8e15866..a9d4440 100644 --- a/view/index/article/add.html +++ b/view/index/article/add.html @@ -133,7 +133,6 @@ {block name="script"} {/block} \ No newline at end of file diff --git a/view/index/article/detail.html b/view/index/article/detail.html index ab5579c..fb96825 100644 --- a/view/index/article/detail.html +++ b/view/index/article/detail.html @@ -26,7 +26,6 @@ {if ($article.is_hot == 1)} 精帖 {/if} -
{if ($user.auth == 1)} 删除 @@ -41,7 +40,6 @@ 取消加精 {/if} {/if} -
@@ -64,20 +62,13 @@ {$article.create_time|date='Y-m-d H:d'} -
{if(session('user_name')==$article.user.name || $user.auth == 1)} 编辑此贴 {/if}
- -
{$article.content|raw}
@@ -140,7 +131,7 @@ {/volist} - +
{$comments|raw}
@@ -199,7 +190,7 @@ @@ -216,57 +207,23 @@ {/block} {block name="script"} - - - {/block} \ No newline at end of file diff --git a/view/index/public/js.html b/view/index/public/js.html index b8e79d9..b6675b2 100644 --- a/view/index/public/js.html +++ b/view/index/public/js.html @@ -3,5 +3,9 @@ diff --git a/view/index/user/set.html b/view/index/user/set.html index 5dabfae..cbcfdc2 100644 --- a/view/index/user/set.html +++ b/view/index/user/set.html @@ -116,11 +116,13 @@ {block name="script"} {/block} \ No newline at end of file