This commit is contained in:
toogee 2020-04-24 15:07:26 +08:00
parent 943a11bdbf
commit 5873cebcfd
12 changed files with 373 additions and 387 deletions

View File

@ -6,14 +6,14 @@ use think\facade\View;
use think\facade\Request; use think\facade\Request;
use think\facade\Db; use think\facade\Db;
use think\facade\Cache; use think\facade\Cache;
use app\common\model\Cate;
use app\common\model\User;
use app\common\model\Comment; use app\common\model\Comment;
use app\common\model\Collection;
use app\common\model\Article as ArticleModel; use app\common\model\Article as ArticleModel;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Config; use think\facade\Config;
use taoler\com\Message; use taoler\com\Message;
use app\common\model\Cate;
use app\common\model\User;
use app\common\model\Collection;
class Article extends BaseController class Article extends BaseController
{ {
@ -172,15 +172,13 @@ class Article extends BaseController
$data = ['title'=>$title,'content'=>'评论通知','link'=>$link,'user_id'=>$sendId,'type'=>1]; $data = ['title'=>$title,'content'=>'评论通知','link'=>$link,'user_id'=>$sendId,'type'=>1];
Message::sendMsg($sendId,$receveId,$data); Message::sendMsg($sendId,$receveId,$data);
$res = ['code'=>1, 'msg'=>'留言成功']; $res = ['code'=>0, 'msg'=>'留言成功'];
} else { } else {
$res = ['code'=>0, 'msg'=>'留言失败']; $res = ['code'=>-1, 'msg'=>'留言失败'];
} }
return json($res); return json($res);
} }
//添加文章 //添加文章
public function add() public function add()
{ {
@ -195,7 +193,8 @@ class Article extends BaseController
$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');
return json(['code'=>1,'msg'=>'发布成功','url'=>'/'.app('http')->getName().'/jie/'.$aid.'.html']); $link = (string) url('article/detail',['id'=> $aid]);
return json(['code'=>1,'msg'=>'发布成功','url'=> $link]);
} else { } else {
$this->error($result); $this->error($result);
} }
@ -212,7 +211,6 @@ class Article extends BaseController
$tags = []; $tags = [];
foreach($att as $v){ foreach($att as $v){
if ($v !='') { if ($v !='') {
$tags[] = $v; $tags[] = $v;
} }
} }
@ -235,7 +233,10 @@ 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/'.$id.'.html']); //删除缓存显示编辑后内容
Cache::delete('article_'.$id);
$link = (string) url('article/detail',['id'=> $id]);
return json(['code'=>0,'msg'=>'修改成功','url'=> $link]);
} else { } else {
$this->error($result); $this->error($result);
} }
@ -255,21 +256,21 @@ class Article extends BaseController
return View::fetch(); return View::fetch();
} }
//删除文章 //删除帖子
public function delete() public function delete()
{ {
$article = ArticleModel::find(input('id')); $article = ArticleModel::find(input('id'));
$result = $article->together(['comments'])->delete(); $result = $article->together(['comments'])->delete();
if($result) { if($result) {
$res = ['code'=>1,'msg'=>'删除文章成功','url'=>'/index/user/post']; $res = ['code'=>0,'msg'=>'删除文章成功','url'=>'/index/user/post'];
} else { } else {
$res = ['code'=>0,'msg'=>'删除文章失败']; $res = ['code'=>-1,'msg'=>'删除文章失败'];
} }
return json($res); return json($res);
} }
//文本编辑器图片上传 //文本编辑器图片上传
public function text_img_upload() public function textImgUpload()
{ {
$file = request()->file('file'); $file = request()->file('file');
try { try {
@ -317,8 +318,11 @@ class Article extends BaseController
$res = ['status'=>0,'msg'=>'精贴已取消']; $res = ['status'=>0,'msg'=>'精贴已取消'];
} }
} }
//清除文章缓存
Cache::tag('tagArtDetail')->clear(); //删除本贴设置缓存显示编辑后内容
Cache::delete('article_'.$data['id']);
//清除文章tag缓存
//Cache::tag('tagArtDetail')->clear();
return json($res); return json($res);
} }

View File

@ -6,14 +6,12 @@ use think\facade\Session;
use app\common\model\Comment as CommentModel; use app\common\model\Comment as CommentModel;
use app\common\model\Article; use app\common\model\Article;
use app\common\model\UserZan; use app\common\model\UserZan;
use think\facade\Request;
use think\Db;
class Comment extends BaseController class Comment extends BaseController
{ {
//采纳评论 //采纳评论
public function jiedaCai(){ public function jiedaCai()
{
$id = input('id'); $id = input('id');
$comms = CommentModel::find($id); $comms = CommentModel::find($id);
$result = $comms->save(['cai' =>1]); $result = $comms->save(['cai' =>1]);
@ -29,33 +27,30 @@ class Comment extends BaseController
} }
//删除评论 //删除评论
public function jiedaDelete(){ public function jiedaDelete()
{
$id = input('id'); $id = input('id');
//$arid = intval($id); //$arid = intval($id);
$comms = CommentModel::find($id); $comms = CommentModel::find($id);
$result = $comms->delete(); $result = $comms->delete();
//$result = Db::name('collection')->where('article_id',$arid)->delete();
if($result){ if($result){
//$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功']; $res = ['status' => 0,'msg' => '删除成功'];
$res = [ } else {
'status' => 0, $res = ['status' => -1,'msg' => '删除失败'];
];
} }
return json($res); return json($res);
} }
//编辑评论 //编辑评论
public function getDa() public function getDa()
{ {
//获取原评论
$this->isLogin(); $this->isLogin();
$id = input('id'); $id = input('id');
$comms = CommentModel::find($id); $comms = CommentModel::find($id);
$res['rows'] = []; $res['rows'] = [];
if($comms) { if($comms) {
$res['status'] = 0;
$res['rows']['content'] = $comms['content']; $res['rows']['content'] = $comms['content'];
} }
return json($res); return json($res);
@ -78,7 +73,7 @@ class Comment extends BaseController
return json($res); return json($res);
} }
//点赞评论 //评论点赞
public function jiedaZan() public function jiedaZan()
{ {
$this->isLogin(); $this->isLogin();
@ -90,20 +85,20 @@ class Comment extends BaseController
if(!$zan ){ //如果没有点过赞执行点赞操作 if(!$zan ){ //如果没有点过赞执行点赞操作
$coms = CommentModel::find(input('post.id')); $coms = CommentModel::find(input('post.id'));
if($coms['user_id'] == session('user_id')){ if($coms['user_id'] == session('user_id')){
return $res=['msg' => '不能给自己点赞哦']; $res = ['msg' => '不能给自己点赞哦'];
} else { } else {
$res = UserZan::create($data); $result = UserZan::create($data);
if($res){ if($result){
//评论点赞数加1 //评论点赞数加1
$coms->save(['zan' => $coms['zan']+1]); $coms->save(['zan' => $coms['zan']+1]);
return $res=['status' => 0, 'msg' => '点赞成功']; $res = ['status' => 0, 'msg' => '点赞成功'];
}else { }else {
$this->error('点赞失败'); $res = ['status' => -1, 'msg' => '点赞失败'];
} }
} }
} else { } else {
return $res=['status'=>1,'msg' => '你已赞过了']; $res = ['status'=>-1,'msg' => '你已赞过了'];
} }
return json($res);
} }
} }

View File

@ -81,7 +81,7 @@ class User extends BaseController
$user = new \app\common\model\User; $user = new \app\common\model\User;
$result = $user->setNew($data); $result = $user->setNew($data);
if($result==1){ if($result==1){
return ['code'=>0,'msg'=>'资料更新成功','url'=>'/index/user/set']; return ['code'=>0,'msg'=>'资料更新成功'];
} else { } else {
$this->error($result); $this->error($result);
} }
@ -180,7 +180,7 @@ class User extends BaseController
$result = $user->setpass($data); $result = $user->setpass($data);
if($result == 1) { if($result == 1) {
Session::clear(); Session::clear();
return $this->success('密码修改成功 请登录', '/index/user/login'); return $this->success('密码修改成功 请登录', '/login');
} else { } else {
return $this->error($result); return $this->error($result);
} }

View File

@ -11,7 +11,7 @@ class LoginCheck
if(Session::has('user_id')){ if(Session::has('user_id')){
return $next($request); return $next($request);
} else { } else {
return redirect('/index/login'); return redirect((string) url('login/index'));
} }
} }
} }

View File

@ -167,7 +167,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function(
elem: '#uploadImg' elem: '#uploadImg'
,acceptMime: 'image/*' ,acceptMime: 'image/*'
,exts: 'jpg|png|gif|bmp|jpeg' ,exts: 'jpg|png|gif|bmp|jpeg'
,url: '/index/article/text_img_upload' ,url: textImgUpload
,size: 2048 ,size: 2048
,done: function(res){ ,done: function(res){
if(res.status == 0){ if(res.status == 0){
@ -705,7 +705,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function(
,shadeClose: true ,shadeClose: true
,maxWidth: 10000 ,maxWidth: 10000
,skin: 'fly-layer-search' ,skin: 'fly-layer-search'
,content: ['<form action="/index/index/search">' ,content: ['<form action="/index/search">'
,'<input autocomplete="off" placeholder="搜索内容,回车跳转" type="text" name="keywords">' ,'<input autocomplete="off" placeholder="搜索内容,回车跳转" type="text" name="keywords">'
,'</form>'].join('') ,'</form>'].join('')
,success: function(layero){ ,success: function(layero){
@ -819,13 +819,13 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function(
loading = layer.load(2, { loading = layer.load(2, {
shade: [0.2, '#000'] shade: [0.2, '#000']
}); });
location.href = '/index/add'; location.href = articleAdd;
} else { } else {
layer.msg('请先登陆',{ layer.msg('请先登陆',{
icon:5, icon:5,
time:2000 time:2000
},function () { },function () {
location.href = '/index/login'; location.href = login;
}); });
} }
return false; return false;
@ -858,7 +858,7 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function(
,click: function(type){ ,click: function(type){
if(type === 'bar1'){ if(type === 'bar1'){
//slayer.msg('打开 index.js开启发表新帖的路径'); //slayer.msg('打开 index.js开启发表新帖的路径');
location.href = '/index/add'; location.href = articleAdd;
} }
} }
}); });

View File

@ -70,20 +70,19 @@ layui.define('fly', function(exports){
}); });
}; };
//帖子管理
//求解管理
gather.jieAdmin = { gather.jieAdmin = {
//删求解 //删帖子
del: function(div){ del: function(div){
layer.confirm('确认删除该贴么?', function(index){ layer.confirm('确认删除该贴么?', function(index){
layer.close(index); layer.close(index);
$.ajax({ $.ajax({
type:'get', type:'get',
url:"/index/article/delete", url:articleDelete,
data:{id: div.data('id')}, data:{id: div.data('id')},
dataType:'json', dataType:'json',
success:function(data){ success:function(data){
if(data.code == 1){ if(data.code == 0){
layer.msg(data.msg,{ layer.msg(data.msg,{
icon:6, icon:6,
time:2000 time:2000
@ -106,7 +105,7 @@ layui.define('fly', function(exports){
//设置置顶、状态 //设置置顶、状态
,set: function(div){ ,set: function(div){
var othis = $(this); var othis = $(this);
fly.json('/index/article/jieset/', { fly.json(articleJieset, {
id: div.data('id') id: div.data('id')
,rank: othis.attr('rank') ,rank: othis.attr('rank')
,field: othis.attr('field') ,field: othis.attr('field')
@ -121,7 +120,7 @@ layui.define('fly', function(exports){
//收藏 //收藏
,collect: function(div){ ,collect: function(div){
var othis = $(this), type = othis.data('type'); var othis = $(this), type = othis.data('type');
fly.json('/index/collection/'+ type +'/', { fly.json(collection+ type +'/', {
cid: div.data('id') cid: div.data('id')
}, function(res){ }, function(res){
if(type === 'add'){ if(type === 'add'){
@ -155,7 +154,7 @@ layui.define('fly', function(exports){
gather.jiedaActive = { gather.jiedaActive = {
zan: function(li){ //赞 zan: function(li){ //赞
var othis = $(this), ok = othis.hasClass('zanok'); var othis = $(this), ok = othis.hasClass('zanok');
fly.json('/index/comment/jiedaZan', { fly.json(commentJiedaZan, {
ok: ok ok: ok
,id: li.data('id') ,id: li.data('id')
}, function(res){ }, function(res){
@ -179,7 +178,7 @@ layui.define('fly', function(exports){
var othis = $(this); var othis = $(this);
layer.confirm('是否采纳该回答为最佳答案?', function(index){ layer.confirm('是否采纳该回答为最佳答案?', function(index){
layer.close(index); layer.close(index);
fly.json('/index/comment/jiedaCai', { fly.json(commentJiedaCai, {
id: li.data('id') id: li.data('id')
}, function(res){ }, function(res){
if(res.status === 0){ if(res.status === 0){
@ -193,8 +192,8 @@ layui.define('fly', function(exports){
}); });
}); });
} }
,edit: function(li){ //编辑 ,edit: function(li){ //编辑评论
fly.json('/index/comment/getDa', { fly.json(commentGetDa, {
id: li.data('id') id: li.data('id')
}, function(res){ }, function(res){
var data = res.rows; var data = res.rows;
@ -211,7 +210,7 @@ layui.define('fly', function(exports){
}); });
} }
}, function(value, index){ }, function(value, index){
fly.json('/index/comment/updateDa/', { fly.json(commentUpdateDa, {
id: li.data('id') id: li.data('id')
,content: value ,content: value
}, function(res){ }, function(res){
@ -222,10 +221,10 @@ layui.define('fly', function(exports){
}); });
}); });
} }
,del: function(li){ //删除 ,del: function(li){ //删除评论
layer.confirm('确认删除该回答么?', function(index){ layer.confirm('确认删除该回答么?', function(index){
layer.close(index); layer.close(index);
fly.json('/index/comment/jiedaDelete/', { fly.json(commentJiedaDelete, {
id: li.data('id') id: li.data('id')
}, function(res){ }, function(res){
if(res.status === 0){ if(res.status === 0){

View File

@ -25,8 +25,6 @@ layui.define(['laypage', 'fly', 'element', 'flow'], function(exports){
}; };
//我的相关数据 //我的相关数据
var elemUC = $('#LAY_uc'), elemUCM = $('#LAY_ucm'); var elemUC = $('#LAY_uc'), elemUCM = $('#LAY_ucm');
gather.minelog = {}; gather.minelog = {};
@ -171,14 +169,14 @@ layui.define(['laypage', 'fly', 'element', 'flow'], function(exports){
upload.render({ upload.render({
elem: '.upload-img' elem: '.upload-img'
,url: '/index/user/uploadHeadImg/' ,url: uploadHeadImg
,size: 300 ,size: 300
,before: function(){ ,before: function(){
avatarAdd.find('.loading').show(); avatarAdd.find('.loading').show();
} }
,done: function(res){ ,done: function(res){
if(res.status == 0){ if(res.status == 0){
$.post('/index/user/set/', { $.post(userSet, {
avatar: res.url avatar: res.url
}, function(res){ }, function(res){
location.reload(); location.reload();

View File

@ -133,7 +133,6 @@
{block name="script"} {block name="script"}
<script> <script>
//删除tag //删除tag
$(document).ready(function(){ $(document).ready(function(){
$('.layui-btn-container').on('click','button',function(){ $('.layui-btn-container').on('click','button',function(){
@ -142,20 +141,21 @@
}); });
</script> </script>
<script> <script>
layui.cache.page = 'jie';
layui.cache.user = { layui.cache.page = 'jie';
username: '游客' layui.cache.user = {
,uid: -1 username: '{$user.name??'游客'}'
,avatar: '/static/res/images/avatar/00.jpg' ,uid: "{$user.id ? $user.id : -1}"
,avatar: "{$user.name? $user['user_img']:'/static/res/images/avatar/00.jpg'}"
,experience: 83 ,experience: 83
,sex: '男' ,sex: "{if condition="$user['sex'] eq 0"}男{else /}女{/if}"
}; };
layui.config({ layui.config({
version: "3.0.0" version: "3.0.0"
,base: '/static/res/mods/' ,base: '/static/res/mods/'
}).extend({ }).extend({
fly: 'index' fly: 'index'
}).use(['fly','form','colorpicker'], function(){ }).use(['fly','form','colorpicker'], function(){
var $ = layui.$ var $ = layui.$
,form = layui.form ,form = layui.form
,colorpicker = layui.colorpicker; ,colorpicker = layui.colorpicker;
@ -216,7 +216,7 @@
layer.msg('不能为空'); layer.msg('不能为空');
return false; return false;
} }
//把得到的tags放进数组
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());//添加至数组
@ -246,8 +246,6 @@
return false; return false;
}); });
});
});
</script> </script>
{/block} {/block}

View File

@ -26,7 +26,6 @@
{if ($article.is_hot == 1)} {if ($article.is_hot == 1)}
<span class="layui-badge layui-bg-red">精帖</span> <span class="layui-badge layui-bg-red">精帖</span>
{/if} {/if}
<div class="fly-admin-box" data-id="{$article.id}"> <div class="fly-admin-box" data-id="{$article.id}">
{if ($user.auth == 1)} {if ($user.auth == 1)}
<span class="layui-btn layui-btn-xs jie-admin" type="del">删除</span> <span class="layui-btn layui-btn-xs jie-admin" type="del">删除</span>
@ -41,7 +40,6 @@
<span class="layui-btn layui-btn-xs jie-admin" type="set" field="hot" rank="0" style="background-color:#ccc;">取消加精</span> <span class="layui-btn layui-btn-xs jie-admin" type="set" field="hot" rank="0" style="background-color:#ccc;">取消加精</span>
{/if} {/if}
{/if} {/if}
</div> </div>
<span class="fly-list-nums"> <span class="fly-list-nums">
@ -64,20 +62,13 @@
</a> </a>
<span>{$article.create_time|date='Y-m-d H:d'}</span> <span>{$article.create_time|date='Y-m-d H:d'}</span>
</div> </div>
<div class="detail-hits" id="LAY_jieAdmin" data-id="{$article['id']}"> <div class="detail-hits" id="LAY_jieAdmin" data-id="{$article['id']}">
<!--span style="padding-right: 10px; color: #FF7200">悬赏60飞吻</span--> <!--span style="padding-right: 10px; color: #FF7200">悬赏60飞吻</span-->
{if(session('user_name')==$article.user.name || $user.auth == 1)} {if(session('user_name')==$article.user.name || $user.auth == 1)}
<span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="{:url('article/edit',['id'=>$article.id])}">编辑此贴</a></span> <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="{:url('article/edit',['id'=>$article.id])}">编辑此贴</a></span>
{/if} {/if}
</div> </div>
<!--
{if(session('user_id') != '')}
<span class="layui-btn layui-btn-xs jie-admin" type="collect" data-type="add" user_id="{session('user_id')}">收藏</span>
{/if}
-->
</div> </div>
<div class="detail-body photos">{$article.content|raw}</div> <div class="detail-body photos">{$article.content|raw}</div>
</div> </div>
@ -199,7 +190,7 @@
</div> </div>
<div class="fly-panel-main"> <div class="fly-panel-main">
<a href="" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">TaoLer 1.0 旗舰之作</a> <a href="" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">TaoLer 社区快速轻论坛</a>
</div> </div>
</div> </div>
@ -216,57 +207,23 @@
{/block} {/block}
{block name="script"} {block name="script"}
<script> <script>
$(function() { var collectionFind = "{:url('index/Collection/find')}",
$('#recomment').click(function (){ articleJieset = "{:url('index/Article/jieset')}",
var uid = "{:session('user_id')}"; articleDelete = "{:url('index/Article/delete')}",
if (uid != '') { collection = "{:url('index/Collection/')}",
$.ajax({ commentJiedaZan = "{:url('index/Comment/jiedaZan')}",
type:"post", commentJiedaCai = "{:url('index/Comment/jiedaCai')}",
url:"{:url('article/comment')}", commentGetDa = "{:url('index/Comment/getDa')}",
data:$('form').serialize(), commentUpdateDa = "{:url('index/Comment/updateDa')}",
dataType:"json", commentJiedaDelete = "{:url('index/Comment/jiedaDelete')}";
success:function (data) {
if (data.code == 1) {
layer.msg(data.msg,{
icon:6,
time:2000
},function () {
location.reload(true);
});
}else {
layer.open({
title:'评论失败',
content:data.msg,
icon:5,
anim:6
});
}
}
});
} else {
layer.msg('请先登陆',{
icon:5,
time:2000
},function () {
location.href = "{:url('login/index')}";
});
}
return false;
});
});
</script>
<script>
var collectionFind = "{:url('index/collection/find')}";
layui.cache.page = 'jie'; layui.cache.page = 'jie';
layui.cache.user = { layui.cache.user = {
username: '{$user.name??'游客'}' username: '{$user.name??'游客'}'
,uid: {$user.id ? $user.id : -1} ,uid: "{$user.id ? $user.id : -1}"
,avatar: '{$user.name? $user['user_img']:'/static/res/images/avatar/00.jpg'}' ,avatar: "{$user.name? $user['user_img']:'/static/res/images/avatar/00.jpg'}"
,experience: 83 ,experience: 83
,sex: '{if condition="$user['sex'] eq 0"}男{else/}女{/if}' ,sex: "{if condition="$user['sex'] eq 0"}男{else /}女{/if}"
}; };
layui.config({ layui.config({
version: "3.0.0" version: "3.0.0"
,base: '/static/res/mods/' ,base: '/static/res/mods/'
@ -309,6 +266,43 @@ layui.config({
}); });
} }
}); });
//评论需要登陆
$('#recomment').click(function (){
var uid = "{:session('user_id')}";
if (uid != '') {
$.ajax({
type:"post",
url:"{:url('article/comment')}",
data:$('form').serialize(),
dataType:"json",
success:function (data) {
if (data.code == 0) {
layer.msg(data.msg,{
icon:6,
time:2000
},function () {
location.reload(true);
});
}else {
layer.open({
title:'评论失败',
content:data.msg,
icon:5,
anim:6
});
}
}
});
} else {
layer.msg('请先登陆',{
icon:5,
time:2000
},function () {
location.href = "{:url('login/index')}";
});
}
return false;
});
//如果你是采用模版自带的编辑器,你需要开启以下语句来解析。 //如果你是采用模版自带的编辑器,你需要开启以下语句来解析。
$('.detail-body').each(function(){ $('.detail-body').each(function(){

View File

@ -137,20 +137,41 @@
{/block} {/block}
{block name="script"} {block name="script"}
<script> <script>
layui.cache.page = 'jie';
layui.cache.user = {
username: '{$user.name??'游客'}'
,uid: "{$user.id ? $user.id : -1}"
,avatar: "{$user.name? $user['user_img']:'/static/res/images/avatar/00.jpg'}"
,experience: 83
,sex: "{if condition="$user['sex'] eq 0"}男{else /}女{/if}"
};
layui.config({
version: "3.0.0"
,base: '/static/res/mods/'
}).extend({
fly: 'index'
}).use(['fly','colorpicker','form'], function(){
var $ = layui.$
,colorpicker = layui.colorpicker
,form = layui.form;
//删除tag //预定义颜色项
$(document).ready(function(){ colorpicker.render({
$('.layui-btn-container').on('click','button',function(){ elem: '#color'
$(this).remove(); ,color: '{$article.title_color}'
}); ,predefine: true // 开启预定义颜色
,done: function(color){
//console.log(color);
//譬如你可以在回调中把得到的 color 赋值给表单
$('#L_title_color').val(color);
//改变标题颜色
$('#L_title').css("color", color);
}
}); });
layui.use('form', function(){ //编辑文章
var form = layui.form; form.on('submit(article-edit)', function(data){
form.on('submit(article-edit)', 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(){
@ -163,7 +184,7 @@ layui.use('form', function(){
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}, 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", daType:"json",
success:function (data){ success:function (data){
if (data.code == 1) { if (data.code == 0) {
layer.msg(data.msg,{ layer.msg(data.msg,{
icon:6, icon:6,
time:2000 time:2000
@ -182,11 +203,12 @@ layui.use('form', function(){
} }
}); });
return false; return false;
}); });
//添加tags //添加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;
@ -196,14 +218,13 @@ layui.use('form', function(){
$('.layui-btn-container').children('button').each(function(){ $('.layui-btn-container').children('button').each(function(){
numArr.push($(this).val());//添加至数组 numArr.push($(this).val());//添加至数组
}); });
for(var i=0; i<numArr.length; i++){ for(var i=0; i<numArr.length; i++){
if(tags.indexOf(numArr[i])>=0){ if(tags.indexOf(numArr[i])>=0){
layer.msg('不能重复添加'+numArr[i]); layer.msg('不能重复添加'+numArr[i]);
return false; return false;
} }
} }
//保存tags
$.ajax({ $.ajax({
type:"post", type:"post",
url:"{:url('article/tags')}", url:"{:url('article/tags')}",
@ -225,45 +246,16 @@ layui.use('form', function(){
}; };
} }
}); });
return false; return false;
});
//删除tag
$(document).ready(function(){
$('.layui-btn-container').on('click','button',function(){
$(this).remove();
});
}); });
}); });
</script> </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','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} {/block}

View File

@ -3,5 +3,9 @@
<script> <script>
var messageNums = "{:url('index/Message/nums')}", var messageNums = "{:url('index/Message/nums')}",
messageRead = "{:url('index/Message/read')}", messageRead = "{:url('index/Message/read')}",
userMessage = "{:url('index/User/message')}"; userMessage = "{:url('index/User/message')}",
login = "{:url('Login/index')}",
articleAdd = "{:url('Article/add')}",
websearch = "{:url('index/index/search')}",
textImgUpload = "{:url('index/article/textImgUpload')}";
</script> </script>

View File

@ -116,11 +116,13 @@
{block name="script"} {block name="script"}
<script> <script>
var uploadHeadImg = "{:url('User/uploadHeadImg')}",
userSet = "{:url('User/set')}";
$(function(){ $(function(){
$('#ziliao').click(function(){ $('#ziliao').click(function(){
$.ajax({ $.ajax({
type:'post', type:'post',
url:"{:url('user/set')}", url:"{:url('User/set')}",
data:$('#zl').serialize(), data:$('#zl').serialize(),
dataType:"json", dataType:"json",
success:function(data){ success:function(data){
@ -129,7 +131,7 @@ $(function(){
icon:6, icon:6,
tiye:2000 tiye:2000
},function(){ },function(){
location.href = data.url; location.reload();
}); });
} else { } else {
layer.open({ layer.open({
@ -150,7 +152,7 @@ $(function(){
$('#setpass').click(function(){ $('#setpass').click(function(){
$.ajax({ $.ajax({
type:"post", type:"post",
url:"{:url('index/user/setpass')}", url:"{:url('User/setpass')}",
data:$('#newpass').serialize(), data:$('#newpass').serialize(),
dataType:"json", dataType:"json",
success:function(data){ success:function(data){
@ -178,19 +180,19 @@ $(function(){
</script> </script>
<script> <script>
layui.cache.page = 'user'; layui.cache.page = 'user';
layui.cache.user = { layui.cache.user = {
username: '{$user.name??'游客'}' username: '{$user.name??'游客'}'
,uid: {$user.id ? $user.id : -1} ,uid: "{$user.id ? $user.id : -1}"
,avatar: '{$user.name? $user['user_img']:'/static/res/images/avatar/00.jpg'}' ,avatar: "{$user.name? $user['user_img']:'/static/res/images/avatar/00.jpg'}"
,experience: 83 ,experience: 83
,sex: '{if condition="$user['sex'] eq 0"}男{else/}女{/if}' ,sex: "{if condition="$user['sex'] eq 0"}男{else /}女{/if}"
}; };
layui.config({ layui.config({
version: "3.0.0" version: "3.0.0"
,base: '/static/res/mods/' ,base: '/static/res/mods/'
}).extend({ }).extend({
fly: 'index' fly: 'index'
}).use('fly'); }).use('fly');
</script> </script>
{/block} {/block}