From 1f3c44bbf34faf7a49834c520453b2da78f1814d Mon Sep 17 00:00:00 2001 From: toogee Date: Mon, 13 Apr 2020 15:51:24 +0800 Subject: [PATCH] article title color --- app/index/controller/Article.php | 7 +- app/index/controller/Index.php | 2 +- view/index/article/add.html | 177 +++++++++++++++++-------------- view/index/article/detail.html | 2 +- view/index/article/edit.html | 32 +++++- view/index/index/index.html | 2 +- 6 files changed, 132 insertions(+), 90 deletions(-) diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index c754c8c..28bf73a 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -105,7 +105,7 @@ class Article extends BaseController $article = Cache::get('article_'.$id); if(!$article){ //查询文章 - $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([ + $article = ArticleModel::field('id,title,content,status,cate_id,user_id,is_top,is_hot,is_reply,pv,jie,tags,title_color,create_time')->where('status',1)->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -183,7 +183,8 @@ class Article extends BaseController public function add() { if(Request::isAjax()){ - $data = Request::only(['cate_id','title','user_id','content','upzip','tags','captcha']); + $data = Request::only(['cate_id','title','title_color','user_id','content','upzip','tags','captcha']); + halt($data); $validate = new \app\common\validate\Article; //调用验证器 $result = $validate->scene('Artadd')->check($data); //进行数据验证 if(true !==$result){ @@ -223,7 +224,7 @@ class Article extends BaseController $article = Db::name('article')->find($id); if(Request::isAjax()){ - $data = Request::only(['id','cate_id','title','user_id','content','upzip','tags','captcha']); + $data = Request::only(['id','cate_id','title','title_color','user_id','content','upzip','tags','captcha']); $validate = new \app\common\validate\Article(); //调用验证器 $res = $validate->scene('Artadd')->check($data); //进行数据验证 diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 338b42c..66ef248 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -26,7 +26,7 @@ class Index extends BaseController //置顶文章 $artTop = Cache::get('arttop'); if(!$artTop){ - $artTop = Article::field('id,title,cate_id,user_id,create_time,is_top')->where(['is_top'=>1,'status'=>1,'delete_time'=>0])->with([ + $artTop = Article::field('id,title,title_color,cate_id,user_id,create_time,is_top')->where(['is_top'=>1,'status'=>1,'delete_time'=>0])->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, diff --git a/view/index/article/add.html b/view/index/article/add.html index 1498263..e98eb87 100644 --- a/view/index/article/add.html +++ b/view/index/article/add.html @@ -25,13 +25,17 @@ -
+
+
+
+
+
@@ -134,83 +138,6 @@ $(this).remove(); }); }); - -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(','); - $.ajax({ - type:"post", - url:"{:url('article/add')}", - data:{"cate_id":field.cate_id,"title":field.title,"user_id":field.user_id,"content":field.content,"upzip":field.upzip,"tags":tags,"captcha":field.captcha}, - dataType:"json", - success:function (data){ - if (data.code == 1) { - layer.msg(data.msg,{ - icon:6, - time:2000 - }, function(){ - location.href = data.url; - }); - } else { - layer.open({ - tiele:'发布失败', - content:data.msg, - icon:5, - anim:6 - }); - layui.jquery('#captcha').attr('src', '{:captcha_src()}?'+Math.random()); - } - } - }); - 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", - url:"{:url('article/tags')}", - data:{"tags":tags}, - daType:"json", - success:function (data){ - if (data.code == 0) { - for(var i=0; i'+data.data[i]+''); - } - $("input[name='tags']").val(""); - } - } - }); - return false; - }); - -}); {/block} \ No newline at end of file diff --git a/view/index/article/detail.html b/view/index/article/detail.html index cc8ecd1..9449362 100644 --- a/view/index/article/detail.html +++ b/view/index/article/detail.html @@ -8,7 +8,7 @@
-

{$article.title}

+

{$article.title}

{$article.cate.catename} diff --git a/view/index/article/edit.html b/view/index/article/edit.html index 93fd1d6..4f68766 100644 --- a/view/index/article/edit.html +++ b/view/index/article/edit.html @@ -27,13 +27,18 @@
-
+
- + +
+
+
+
+
@@ -153,7 +158,7 @@ layui.use('form', function(){ $.ajax({ type:"post", url:"{:url('article/edit')}", - data:{"id":field.id,"cate_id":field.cate_id,"title":field.title,"user_id":field.user_id,"content":field.content,"upzip":field.upzip,"tags":tags,"captcha":field.captcha}, + data:{"id":field.id,"cate_id":field.cate_id,"title":field.title,"title_color":field.title_color,"user_id":field.user_id,"content":field.content,"upzip":field.upzip,"tags":tags,"captcha":field.captcha}, daType:"json", success:function (data){ if (data.code == 1) { @@ -239,7 +244,24 @@ layui.use('form', function(){ ,base: '/static/res/mods/' }).extend({ fly: 'index' - }).use('fly'); - }); + }).use(['fly','colorpicker'], function(){ + var $ = layui.$ + ,colorpicker = layui.colorpicker; + + //预定义颜色项 + colorpicker.render({ + elem: '#color' + ,color: '{$article.title_color}' + ,predefine: true // 开启预定义颜色 + ,done: function(color){ + //console.log(color); + //譬如你可以在回调中把得到的 color 赋值给表单 + $('#L_title_color').val(color); + //改变标题颜色 + $('#L_title').css("color", color); + } + }); + }); + {/block} \ No newline at end of file diff --git a/view/index/index/index.html b/view/index/index/index.html index bb01588..d92912f 100644 --- a/view/index/index/index.html +++ b/view/index/index/index.html @@ -38,7 +38,7 @@

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