From f3da92ba8f6f8e7811d5cb470a88272446c74658 Mon Sep 17 00:00:00 2001 From: zhao Date: Wed, 19 Feb 2020 14:59:09 +0800 Subject: [PATCH] edit-tags --- app/index/controller/Article.php | 37 ++++++----- app/index/controller/Sign.php | 2 +- view/index/article/add.html | 33 +++++++--- view/index/article/edit.html | 104 ++++++++++++++++++++++++++++--- 4 files changed, 144 insertions(+), 32 deletions(-) diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index bf4e6cc..6f9bb51 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -97,7 +97,7 @@ class Article extends BaseController //获取文章ID //$id = Request::param('id'); //查询文章 - $article = ArticleModel::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,create_time')->where('status',1)->with([ + $article = ArticleModel::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,tags,create_time')->where('status',1)->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -129,7 +129,7 @@ class Article extends BaseController $ad_article = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',4)->whereTime('slid_over','>=',time())->select(); //通用右栏 $ad_comm = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',2)->whereTime('slid_over','>=',time())->select(); - + View::assign(['article'=>$article,'comments'=>$comments,'artHot'=>$artHot,'ad_art'=>$ad_article,'ad_comm'=>$ad_comm]); return View::fetch(); } @@ -156,13 +156,13 @@ class Article extends BaseController public function add() { if(Request::isAjax()){ - $data = Request::post(); + $data = Request::only(['cate_id','title','user_id','content','upzip','tags','captcha']); $validate = new \app\common\validate\Article; //调用验证器 $result = $validate->scene('Artadd')->check($data); //进行数据验证 if(true !==$result){ return $this->error($validate->getError()); } else { - $article = new \app\common\model\Article; + $article = new \app\common\model\Article(); $result = $article->add($data); if($result == 1) { $aid = Db::name('article')->max('id'); @@ -176,27 +176,27 @@ class Article extends BaseController } //添加tag - public function tags(){ + public function tags() + { $data = Request::only(['tags']); $att = explode(',',$data['tags']); $tags = []; foreach($att as $v){ if ($v !='') { - $tags = $v; + + $tags[] = $v; } } - //var_dump($tags); return json(['code'=>0,'data'=>$tags]); } //编辑文章 - public function edit() + public function edit($id) { - $aid = input('id'); - $article = Db::name('article')->find($aid); + $article = Db::name('article')->find($id); if(Request::isAjax()){ - $data = Request::post(); + $data = Request::only(['id','cate_id','title','user_id','content','upzip','tags','captcha']); $validate = new \app\common\validate\Article(); //调用验证器 $res = $validate->scene('Artadd')->check($data); //进行数据验证 @@ -207,14 +207,23 @@ 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/'.$aid.'.html']); + return json(['code'=>1,'msg'=>'修改成功','url'=>'/'.app('http')->getName().'/jie/'.$id.'.html']); } else { $this->error($result); } } } - - View::assign('article',$article); + + $tag = Db::name('article')->where('id',$id)->value('tags'); + $attr = explode(',',$tag); + $tags = []; + foreach($attr as $key=>$v){ + if ($v !='') { + $tags[] = $v; + } + } + + View::assign(['article'=>$article,'tags'=>$tags]); return View::fetch(); } diff --git a/app/index/controller/Sign.php b/app/index/controller/Sign.php index 94cacc3..496b14a 100644 --- a/app/index/controller/Sign.php +++ b/app/index/controller/Sign.php @@ -23,7 +23,7 @@ class Sign extends BaseController public function lists() { //总榜 - $list = Db::name('user_sign')->alias('s')->leftJoin('user u', 's.uid=u.id')->field('uid,s.id as id,max(days) as days,name,user_img')->group('uid')->order('days desc')->limit(20)->select(); + $totallist = Db::name('user_sign')->alias('s')->leftJoin('user u', 's.uid=u.id')->field('uid,s.id as id,max(days) as days,name,user_img')->group('uid')->order('days desc')->limit(20)->select(); $time = time(); $start_stime = strtotime(date('Y-m-d 0:0:0', $time)) - 1; $end_stime = strtotime(date('Y-m-d 23:59:59', $time)) + 1; diff --git a/view/index/article/add.html b/view/index/article/add.html index deb8889..0334126 100644 --- a/view/index/article/add.html +++ b/view/index/article/add.html @@ -138,15 +138,15 @@ layui.use('form', function(){ var form = layui.form; - + +//发布文章 form.on('submit(article-add)', function(data){ - var field = data.field; - var numArr = new Array(); - $('.layui-btn-container').children('button').each(function(){ - numArr.push($(this).val());//添加至数组 - }); - tags = numArr.join(','); - + var field = data.field; + var numArr = new Array(); + $('.layui-btn-container').children('button').each(function(){ + numArr.push($(this).val());//添加至数组 + }); + tags = numArr.join(','); $.ajax({ type:"post", url:"{:url('article/add')}", @@ -174,12 +174,25 @@ layui.use('form', function(){ return false; }); + //添加tags $('#article-tags-button').on('click',function(){ var tags = $("input[name='tags']").val(); if(tags == ''){ layer.msg('不能为空'); return false; } + + var numArr = new Array(); + $('.layui-btn-container').children('button').each(function(){ + numArr.push($(this).val());//添加至数组 + }); + + for(var i=0; i=0){ + layer.msg('不能重复添加'+numArr[i]); + return false; + } + } //console.log(tags); $.ajax({ type:"post", @@ -188,7 +201,9 @@ layui.use('form', function(){ daType:"json", success:function (data){ if (data.code == 0) { - $('.layui-btn-container').append(''); + for(var i=0; i'+data.data[i]+''); + } $("input[name='tags']").val(""); } } diff --git a/view/index/article/edit.html b/view/index/article/edit.html index 39a3ea6..b90b49f 100644 --- a/view/index/article/edit.html +++ b/view/index/article/edit.html @@ -1,5 +1,5 @@ {extend name="public/base" /} -{block name="title"}帖子编辑{/block} +{block name="title"}编辑帖子{/block} {block name="column"}{/block} {block name="content"}
@@ -8,11 +8,11 @@
    -
  • 发表新帖
  • +
  • 编辑帖子
-
+
@@ -81,6 +81,32 @@
发表后无法更改飞吻
+
+
+
+ +
+ +
+
是否回复可下载或者密码下载
+
+
+ +
+
+ +
+ +
+ +
+
+
+
+ {volist name="tags" id="vo" } + + {/volist} +
@@ -92,9 +118,9 @@
- +
- +
@@ -106,12 +132,28 @@ {block name="script"}