edit-tags
This commit is contained in:
parent
f68a930812
commit
f3da92ba8f
@ -97,7 +97,7 @@ class Article extends BaseController
|
|||||||
//获取文章ID
|
//获取文章ID
|
||||||
//$id = Request::param('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){
|
'cate' => function($query){
|
||||||
$query->where('delete_time',0)->field('id,catename');
|
$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_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();
|
$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]);
|
View::assign(['article'=>$article,'comments'=>$comments,'artHot'=>$artHot,'ad_art'=>$ad_article,'ad_comm'=>$ad_comm]);
|
||||||
return View::fetch();
|
return View::fetch();
|
||||||
}
|
}
|
||||||
@ -156,13 +156,13 @@ class Article extends BaseController
|
|||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
if(Request::isAjax()){
|
if(Request::isAjax()){
|
||||||
$data = Request::post();
|
$data = Request::only(['cate_id','title','user_id','content','upzip','tags','captcha']);
|
||||||
$validate = new \app\common\validate\Article; //调用验证器
|
$validate = new \app\common\validate\Article; //调用验证器
|
||||||
$result = $validate->scene('Artadd')->check($data); //进行数据验证
|
$result = $validate->scene('Artadd')->check($data); //进行数据验证
|
||||||
if(true !==$result){
|
if(true !==$result){
|
||||||
return $this->error($validate->getError());
|
return $this->error($validate->getError());
|
||||||
} else {
|
} else {
|
||||||
$article = new \app\common\model\Article;
|
$article = new \app\common\model\Article();
|
||||||
$result = $article->add($data);
|
$result = $article->add($data);
|
||||||
if($result == 1) {
|
if($result == 1) {
|
||||||
$aid = Db::name('article')->max('id');
|
$aid = Db::name('article')->max('id');
|
||||||
@ -176,27 +176,27 @@ class Article extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
//添加tag
|
//添加tag
|
||||||
public function tags(){
|
public function tags()
|
||||||
|
{
|
||||||
$data = Request::only(['tags']);
|
$data = Request::only(['tags']);
|
||||||
$att = explode(',',$data['tags']);
|
$att = explode(',',$data['tags']);
|
||||||
$tags = [];
|
$tags = [];
|
||||||
foreach($att as $v){
|
foreach($att as $v){
|
||||||
if ($v !='') {
|
if ($v !='') {
|
||||||
$tags = $v;
|
|
||||||
|
$tags[] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//var_dump($tags);
|
|
||||||
return json(['code'=>0,'data'=>$tags]);
|
return json(['code'=>0,'data'=>$tags]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//编辑文章
|
//编辑文章
|
||||||
public function edit()
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$aid = input('id');
|
$article = Db::name('article')->find($id);
|
||||||
$article = Db::name('article')->find($aid);
|
|
||||||
|
|
||||||
if(Request::isAjax()){
|
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(); //调用验证器
|
$validate = new \app\common\validate\Article(); //调用验证器
|
||||||
$res = $validate->scene('Artadd')->check($data); //进行数据验证
|
$res = $validate->scene('Artadd')->check($data); //进行数据验证
|
||||||
|
|
||||||
@ -207,14 +207,23 @@ class Article extends BaseController
|
|||||||
$article = new \app\common\model\Article();
|
$article = new \app\common\model\Article();
|
||||||
$result = $article->edit($data);
|
$result = $article->edit($data);
|
||||||
if($result == 1) {
|
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 {
|
} else {
|
||||||
$this->error($result);
|
$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();
|
return View::fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class Sign extends BaseController
|
|||||||
public function lists()
|
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();
|
$time = time();
|
||||||
$start_stime = strtotime(date('Y-m-d 0:0:0', $time)) - 1;
|
$start_stime = strtotime(date('Y-m-d 0:0:0', $time)) - 1;
|
||||||
$end_stime = strtotime(date('Y-m-d 23:59:59', $time)) + 1;
|
$end_stime = strtotime(date('Y-m-d 23:59:59', $time)) + 1;
|
||||||
|
@ -138,15 +138,15 @@
|
|||||||
|
|
||||||
layui.use('form', function(){
|
layui.use('form', function(){
|
||||||
var form = layui.form;
|
var form = layui.form;
|
||||||
|
|
||||||
|
//发布文章
|
||||||
form.on('submit(article-add)', function(data){
|
form.on('submit(article-add)', function(data){
|
||||||
var field = data.field;
|
var field = data.field;
|
||||||
var numArr = new Array();
|
var numArr = new Array();
|
||||||
$('.layui-btn-container').children('button').each(function(){
|
$('.layui-btn-container').children('button').each(function(){
|
||||||
numArr.push($(this).val());//添加至数组
|
numArr.push($(this).val());//添加至数组
|
||||||
});
|
});
|
||||||
tags = numArr.join(',');
|
tags = numArr.join(',');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:"post",
|
type:"post",
|
||||||
url:"{:url('article/add')}",
|
url:"{:url('article/add')}",
|
||||||
@ -174,12 +174,25 @@ layui.use('form', function(){
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//添加tags
|
||||||
$('#article-tags-button').on('click',function(){
|
$('#article-tags-button').on('click',function(){
|
||||||
var tags = $("input[name='tags']").val();
|
var tags = $("input[name='tags']").val();
|
||||||
if(tags == ''){
|
if(tags == ''){
|
||||||
layer.msg('不能为空');
|
layer.msg('不能为空');
|
||||||
return false;
|
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);
|
//console.log(tags);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:"post",
|
type:"post",
|
||||||
@ -188,7 +201,9 @@ layui.use('form', function(){
|
|||||||
daType:"json",
|
daType:"json",
|
||||||
success:function (data){
|
success:function (data){
|
||||||
if (data.code == 0) {
|
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("");
|
$("input[name='tags']").val("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{extend name="public/base" /}
|
{extend name="public/base" /}
|
||||||
{block name="title"}帖子编辑{/block}
|
{block name="title"}编辑帖子{/block}
|
||||||
{block name="column"}{/block}
|
{block name="column"}{/block}
|
||||||
{block name="content"}
|
{block name="content"}
|
||||||
<div class="layui-container fly-marginTop">
|
<div class="layui-container fly-marginTop">
|
||||||
@ -8,11 +8,11 @@
|
|||||||
<div class="layui-form layui-form-pane">
|
<div class="layui-form layui-form-pane">
|
||||||
<div class="layui-tab layui-tab-brief" lay-filter="user">
|
<div class="layui-tab layui-tab-brief" lay-filter="user">
|
||||||
<ul class="layui-tab-title">
|
<ul class="layui-tab-title">
|
||||||
<li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
|
<li class="layui-this">编辑帖子</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
|
<div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
|
||||||
<div class="layui-tab-item layui-show">
|
<div class="layui-tab-item layui-show">
|
||||||
<form action="" method="post">
|
|
||||||
<input type="hidden" name="id" value="{$article.id}">
|
<input type="hidden" name="id" value="{$article.id}">
|
||||||
<div class="layui-row layui-col-space15 layui-form-item">
|
<div class="layui-row layui-col-space15 layui-form-item">
|
||||||
<div class="layui-col-md3">
|
<div class="layui-col-md3">
|
||||||
@ -81,6 +81,32 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="layui-form-mid layui-word-aux">发表后无法更改飞吻</div>
|
<div class="layui-form-mid layui-word-aux">发表后无法更改飞吻</div>
|
||||||
</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>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label for="L_vercode" class="layui-form-label">验证码</label>
|
<label for="L_vercode" class="layui-form-label">验证码</label>
|
||||||
@ -92,9 +118,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<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>
|
</div>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -106,12 +132,28 @@
|
|||||||
{block name="script"}
|
{block name="script"}
|
||||||
|
|
||||||
<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({
|
$.ajax({
|
||||||
type:"post",
|
type:"post",
|
||||||
url:"{:url('article/edit')}",
|
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",
|
daType:"json",
|
||||||
success:function (data){
|
success:function (data){
|
||||||
if (data.code == 1) {
|
if (data.code == 1) {
|
||||||
@ -134,6 +176,52 @@ $(function() {
|
|||||||
});
|
});
|
||||||
return false;
|
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>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user