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,9 +138,39 @@
$(this).remove();
});
});
</script>
<script>
layui.cache.page = 'jie';
layui.cache.user = {
username: '游客'
,uid: -1
,avatar: '/static/res/images/avatar/00.jpg'
,experience: 83
,sex: '男'
};
layui.config({
version: "3.0.0"
,base: '/static/res/mods/'
}).extend({
fly: 'index'
}).use(['fly','form','colorpicker'], function(){
var $ = layui.$
,form = layui.form
,colorpicker = layui.colorpicker;
layui.use('form', function(){
var form = layui.form;
//预定义颜色项
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){
@ -149,7 +183,7 @@ layui.use('form', function(){
$.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},
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) {
@ -210,23 +244,8 @@ layui.use('form', function(){
return false;
});
});
</script>
<script>
layui.cache.page = 'jie';
layui.cache.user = {
username: '游客'
,uid: -1
,avatar: '/static/res/images/avatar/00.jpg'
,experience: 83
,sex: '男'
};
layui.config({
version: "3.0.0"
,base: '/static/res/mods/'
}).extend({
fly: 'index'
}).use(['fly']);
</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" 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>