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

View File

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

View File

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

View File

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

View File

@ -133,7 +133,6 @@
{block name="script"}
<script>
//删除tag
$(document).ready(function(){
$('.layui-btn-container').on('click','button',function(){
@ -142,112 +141,111 @@
});
</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;
//预定义颜色项
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());//添加至数组
});
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','form','colorpicker'], function(){
var $ = layui.$
,form = layui.form
,colorpicker = layui.colorpicker;
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;
});
});
//预定义颜色项
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;
}
//把得到的tags放进数组
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

@ -26,7 +26,6 @@
{if ($article.is_hot == 1)}
<span class="layui-badge layui-bg-red">精帖</span>
{/if}
<div class="fly-admin-box" data-id="{$article.id}">
{if ($user.auth == 1)}
<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>
{/if}
{/if}
</div>
<span class="fly-list-nums">
@ -64,20 +62,13 @@
</a>
<span>{$article.create_time|date='Y-m-d H:d'}</span>
</div>
<div class="detail-hits" id="LAY_jieAdmin" data-id="{$article['id']}">
<!--span style="padding-right: 10px; color: #FF7200">悬赏60飞吻</span-->
{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>
{/if}
</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 class="detail-body photos">{$article.content|raw}</div>
</div>
@ -140,7 +131,7 @@
</li>
{/volist}
</ul>
<div style="text-align: center">
{$comments|raw}
</div>
@ -199,7 +190,7 @@
</div>
<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>
@ -216,57 +207,23 @@
{/block}
{block name="script"}
<script>
$(function() {
$('#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 == 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')}";
var collectionFind = "{:url('index/Collection/find')}",
articleJieset = "{:url('index/Article/jieset')}",
articleDelete = "{:url('index/Article/delete')}",
collection = "{:url('index/Collection/')}",
commentJiedaZan = "{:url('index/Comment/jiedaZan')}",
commentJiedaCai = "{:url('index/Comment/jiedaCai')}",
commentGetDa = "{:url('index/Comment/getDa')}",
commentUpdateDa = "{:url('index/Comment/updateDa')}",
commentJiedaDelete = "{:url('index/Comment/jiedaDelete')}";
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}'
};
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/'
@ -309,7 +266,44 @@ 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(){
var othis = $(this), html = othis.html();

View File

@ -137,118 +137,24 @@
{/block}
{block name="script"}
<script>
//删除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:{"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) {
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;
}
}
$.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>
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;
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;
//预定义颜色项
colorpicker.render({
@ -263,7 +169,93 @@ layui.use('form', function(){
$('#L_title').css("color", color);
}
});
});
//编辑文章
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:{"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 == 0) {
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;
}
}
//保存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("");
} else {
layer.open({
tiele:'添加失败',
content:data.msg,
icon:5,
anim:6
});
};
}
});
return false;
});
//删除tag
$(document).ready(function(){
$('.layui-btn-container').on('click','button',function(){
$(this).remove();
});
});
});
</script>
{/block}

View File

@ -3,5 +3,9 @@
<script>
var messageNums = "{:url('index/Message/nums')}",
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>

View File

@ -116,11 +116,13 @@
{block name="script"}
<script>
var uploadHeadImg = "{:url('User/uploadHeadImg')}",
userSet = "{:url('User/set')}";
$(function(){
$('#ziliao').click(function(){
$.ajax({
type:'post',
url:"{:url('user/set')}",
url:"{:url('User/set')}",
data:$('#zl').serialize(),
dataType:"json",
success:function(data){
@ -129,7 +131,7 @@ $(function(){
icon:6,
tiye:2000
},function(){
location.href = data.url;
location.reload();
});
} else {
layer.open({
@ -146,51 +148,51 @@ $(function(){
});
</script>
<script>
$(function(){
$('#setpass').click(function(){
$.ajax({
type:"post",
url:"{:url('index/user/setpass')}",
data:$('#newpass').serialize(),
dataType:"json",
success:function(data){
if(data.code == 1){
layer.msg(data.msg,{
icon:6,
tiye:2000
},function(){
location.href = data.url;
});
} else{
layer.open({
title:"密码设置失败",
content:data.msg,
icon:5,
anim:6
});
}
}
});
return false;
});
$(function(){
$('#setpass').click(function(){
$.ajax({
type:"post",
url:"{:url('User/setpass')}",
data:$('#newpass').serialize(),
dataType:"json",
success:function(data){
if(data.code == 1){
layer.msg(data.msg,{
icon:6,
tiye:2000
},function(){
location.href = data.url;
});
} else{
layer.open({
title:"密码设置失败",
content:data.msg,
icon:5,
anim:6
});
}
}
});
return false;
});
});
</script>
<script>
layui.cache.page = 'user';
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');
layui.cache.page = 'user';
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');
</script>
{/block}