article title color

This commit is contained in:
toogee 2020-04-13 15:51:24 +08:00
parent b8e8221140
commit 1f3c44bbf3
6 changed files with 132 additions and 90 deletions

View File

@ -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); //进行数据验证

View File

@ -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');
},

View File

@ -25,13 +25,17 @@
</select>
</div>
</div>
<div class="layui-col-md9">
<div class="layui-col-md8">
<label for="L_title" class="layui-form-label">标题</label>
<div class="layui-input-block">
<input type="text" id="L_title" name="title" required lay-verify="required" autocomplete="off" class="layui-input">
<input type="hidden" id="L_title_color" name="title_color" autocomplete="off" class="layui-input">
<input type="hidden" name="user_id" value="{:session('user_id')}">
</div>
</div>
<div class="layui-col-md2">
<div id="color"></div>
</div>
</div>
<div class="layui-row layui-col-space15 layui-form-item layui-hide" id="LAY_quiz">
<div class="layui-col-md3">
@ -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<numArr.length; i++){
if(tags.indexOf(numArr[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.length; i++){
$('.layui-btn-container').append('<button type="button" class="layui-btn" value='+data.data[i]+'>'+data.data[i]+'</button>');
}
$("input[name='tags']").val("");
}
}
});
return false;
});
});
</script>
<script>
layui.cache.page = 'jie';
@ -226,7 +153,99 @@ layui.use('form', function(){
,base: '/static/res/mods/'
}).extend({
fly: 'index'
}).use(['fly']);
}).use(['fly','form','colorpicker'], function(){
var $ = layui.$
,form = layui.form
,colorpicker = layui.colorpicker;
//预定义颜色项
colorpicker.render({
elem: '#color'
,color: '#393d49'
,predefine: true // 开启预定义颜色
,done: function(color){
console.log(color);
//譬如你可以在回调中把得到的 color 赋值给表单
$('#L_title_color').val(color);
//改变标题颜色
$('#L_title').css("color", color);
}
});
//发布文章
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,"title_color":field.title_color,"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<numArr.length; i++){
if(tags.indexOf(numArr[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.length; i++){
$('.layui-btn-container').append('<button type="button" class="layui-btn" value='+data.data[i]+'>'+data.data[i]+'</button>');
}
$("input[name='tags']").val("");
}
}
});
return false;
});
});
</script>
{/block}

View File

@ -8,7 +8,7 @@
<div class="layui-row layui-col-space15">
<div class="layui-col-md8 content detail">
<div class="fly-panel detail-box">
<h1>{$article.title}</h1>
<h1 style="color:{$article.title_color} ;font-weight:bold">{$article.title}</h1>
<div class="fly-detail-info">
<!-- <span class="layui-badge">审核中</span> -->
<span class="layui-badge layui-bg-green fly-detail-column">{$article.cate.catename}</span>

View File

@ -27,13 +27,18 @@
</select>
</div>
</div>
<div class="layui-col-md9">
<div class="layui-col-md8">
<label for="L_title" class="layui-form-label">标题</label>
<div class="layui-input-block">
<input type="text" id="L_title" name="title" required lay-verify="required" autocomplete="off" class="layui-input" value="{$article.title}">
<input type="hidden" name="user_id" value="{$article.user_id}">
<input type="hidden" id="L_title_color" name="title_color" autocomplete="off" class="layui-input">
<input type="hidden" name="user_id" value="{$article.user_id}">
</div>
</div>
<div class="layui-col-md1">
<div id="color"></div>
<div id="test9" style="margin-left: 30px;"></div>
</div>
</div>
<div class="layui-row layui-col-space15 layui-form-item layui-hide" id="LAY_quiz">
<div class="layui-col-md3">
@ -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);
}
});
});
</script>
{/block}

View File

@ -38,7 +38,7 @@
</a>
<h2>
<a class="layui-badge">{$top.cate.catename}</a>
<a href="{:url('article/detail',['id' => $top.id])}">{$top.title}</a>
<a href="{:url('article/detail',['id' => $top.id])}" style="color:{$top.title_color};font-weight:bold">{$top.title}</a>
</h2>
<div class="fly-list-info">
<a href="{:url('user/home',['id'=>$top.user_id])}" link>