diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index cba125e..22f0a35 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -40,7 +40,7 @@ class Article extends BaseController switch ($type) { //查询文章,15个分1页 case 'jie': - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -51,7 +51,7 @@ class Article extends BaseController break; case 'hot': - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -62,7 +62,7 @@ class Article extends BaseController break; case 'top': - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -73,7 +73,7 @@ class Article extends BaseController break; default: - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -113,7 +113,7 @@ class Article extends BaseController $query->field('id,name,nickname,user_img,area_id,vip'); } ])->find($id); - Cache::set('article_'.$id,$article,3600); + Cache::tag('tagArtDetail')->set('article_'.$id,$article,3600); } $comments = $article->comments()->where('status',1)->paginate(10); $article->inc('pv')->update(); @@ -317,7 +317,24 @@ class Article extends BaseController $res = ['status'=>0,'msg'=>'精贴已取消']; } } + //清除文章缓存 + Cache::tag('tagArtDetail')->clear(); return json($res); } + //改变标题颜色 + public function titleColor() + { + $data = Request::param(); + $result = ArticleModel::update($data); + if($result){ + //清除文章缓存 + Cache::tag(['tagArt','tagArtDetail'])->clear(); + $res = ['code'=> 0, 'msg'=>'标题颜色设置成功']; + }else{ + $res = ['code'=> -1, 'msg'=>'标题颜色设置失败']; + } + return json($res); + } + } \ No newline at end of file diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 66ef248..e83bed2 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -34,13 +34,13 @@ class Index extends BaseController $query->field('id,name,nickname,user_img,area_id,vip'); } ])->withCount(['comments'])->order('create_time','desc')->limit(5)->select(); - Cache::set('arttop',$artTop,60); + Cache::tag('tagArtDetail')->set('arttop',$artTop,60); } //首页文章显示20条 $artList = Cache::get('artlist'); if(!$artList){ - $artList = Article::field('id,title,cate_id,user_id,create_time,is_hot')->with([ + $artList = Article::field('id,title,title_color,cate_id,user_id,create_time,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -48,7 +48,7 @@ class Index extends BaseController $query->field('id,name,nickname,user_img,area_id,vip'); } ])->withCount(['comments'])->where(['status'=>1,'delete_time'=>0])->order('create_time','desc')->limit(20)->select(); - Cache::set('artlist',$artList,60); + Cache::tag('tagArt')->set('artlist',$artList,60); } //热议文章 diff --git a/view/index/article/add.html b/view/index/article/add.html index e98eb87..8e15866 100644 --- a/view/index/article/add.html +++ b/view/index/article/add.html @@ -33,9 +33,11 @@ -
+ {if ($user.auth == 1)} +
+ {/if}
diff --git a/view/index/article/cate.html b/view/index/article/cate.html index cba51e8..b0d2036 100644 --- a/view/index/article/cate.html +++ b/view/index/article/cate.html @@ -19,7 +19,7 @@

{$art.cate.catename} - {$art.title} + {$art.title}

diff --git a/view/index/article/detail.html b/view/index/article/detail.html index 9449362..7d3ad36 100644 --- a/view/index/article/detail.html +++ b/view/index/article/detail.html @@ -8,7 +8,10 @@
-

{$article.title}

+

{$article.title} + {if ($user.auth == 1)}{/if} +

+
{$article.cate.catename} @@ -38,6 +41,7 @@ 取消加精 {/if} {/if} +
@@ -267,11 +271,45 @@ layui.config({ ,base: '/static/res/mods/' }).extend({ fly: 'index' -}).use(['fly', 'face'], function(){ +}).use(['fly', 'face','colorpicker'], function(){ var $ = layui.$ - ,fly = layui.fly; - //如果你是采用模版自带的编辑器,你需要开启以下语句来解析。 + ,fly = layui.fly + ,colorpicker = layui.colorpicker; + //预定义颜色项 + colorpicker.render({ + elem: '#color' + ,color: '#393d49' + ,predefine: true // 开启预定义颜色 + ,size: 'xs' + ,done: function(color){ + //改变标题颜色 + $('h1').css("color", color); + var id = {$article.id}; + $.ajax({ + type:'post', + url:"{:url('Article/titleColor')}", + data:{id: id,title_color: color}, + dataType:'json', + success:function(data){ + if(data.code == 0){ + layer.msg(data.msg,{ + icon:6, + time:2000 + }); + } else { + layer.open({ + content:data.msg, + icon:5, + adim:6 + }) + } + } + }); + } + }); + + //如果你是采用模版自带的编辑器,你需要开启以下语句来解析。 $('.detail-body').each(function(){ var othis = $(this), html = othis.html(); othis.html(fly.content(html)); diff --git a/view/index/article/edit.html b/view/index/article/edit.html index 4f68766..88f732f 100644 --- a/view/index/article/edit.html +++ b/view/index/article/edit.html @@ -35,10 +35,12 @@
+ {if ($user.auth == 1)}
+ {/if}