edit-tags

This commit is contained in:
zhao 2020-02-19 14:59:09 +08:00
parent f68a930812
commit f3da92ba8f
4 changed files with 144 additions and 32 deletions

View File

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

View File

@ -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;

View File

@ -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<numArr.length; i++){
if(tags.indexOf(numArr[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('<button type="button" class="layui-btn" value='+data.data+'>'+data.data+'</button>');
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("");
}
}

View File

@ -1,5 +1,5 @@
{extend name="public/base" /}
{block name="title"}帖子编辑{/block}
{block name="title"}编辑帖子{/block}
{block name="column"}{/block}
{block name="content"}
<div class="layui-container fly-marginTop">
@ -8,11 +8,11 @@
<div class="layui-form layui-form-pane">
<div class="layui-tab layui-tab-brief" lay-filter="user">
<ul class="layui-tab-title">
<li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
<li class="layui-this">编辑帖子</li>
</ul>
<div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
<div class="layui-tab-item layui-show">
<form action="" method="post">
<input type="hidden" name="id" value="{$article.id}">
<div class="layui-row layui-col-space15 layui-form-item">
<div class="layui-col-md3">
@ -81,6 +81,32 @@
</div>
<div class="layui-form-mid layui-word-aux">发表后无法更改飞吻</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">上传附件</label>
<div class="layui-input-inline" style="width: 190px;">
<input type="text" class="layui-input" name="upzip" value="" placeholder="下一版本再开发这个" title="上传附件"/>
</div>
<div class="layui-form-mid layui-word-aux">是否回复可下载或者密码下载</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">添加标签</label>
<div class="layui-input-inline" style="width: 190px;">
<input type="text" class="layui-input" name="tags" placeholder="多个标签用,号隔开" title="添加标签"/>
</div>
<button type="button" class="layui-btn" id="article-tags-button">添加</button>
</div>
</div>
<div class="layui-form-item">
<div class="layui-btn-container">
{volist name="tags" id="vo" }
<button type="button" class="layui-btn" value="{$vo.0}">{$vo.0}</button>
{/volist}
</div>
</div>
<div class="layui-form-item">
<label for="L_vercode" class="layui-form-label">验证码</label>
@ -92,9 +118,9 @@
</div>
</div>
<div class="layui-form-item">
<button type="submit" class="layui-btn" lay-filter="user" lay-submit id="edit">立即发布</button>
<button type="submit" class="layui-btn" lay-filter="article-edit" lay-submit id="edit">立即发布</button>
</div>
</form>
</div>
</div>
</div>
@ -106,12 +132,28 @@
{block name="script"}
<script>
$(function() {
$('#edit').click(function() {
//删除tag
$(document).ready(function(){
$('.layui-btn-container').on('click','button',function(){
$(this).remove();
});
});
layui.use('form', function(){
var form = layui.form;
form.on('submit(article-edit)', 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/edit')}",
data:$('form').serialize(),
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},
daType:"json",
success:function (data){
if (data.code == 1) {
@ -134,6 +176,52 @@ $(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<numArr.length; i++){
if(tags.indexOf(numArr[i])>=0){
layer.msg('不能重复添加'+numArr[i]);
return false;
}
}
$.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("");
} else {
layer.open({
tiele:'添加失败',
content:data.msg,
icon:5,
anim:6
});
};
}
});
return false;
});
});
</script>