This commit is contained in:
2017-12-05 11:59:58 +08:00
parent 5c708a3efd
commit 92d3f7a49e
50 changed files with 2396 additions and 1717 deletions

View File

@@ -4,35 +4,56 @@
*/
layui.define(['laypage', 'fly', 'form'], function(exports){
layui.define('fly', function(exports){
var $ = layui.jquery;
var layer = layui.layer;
var util = layui.util;
var laytpl = layui.laytpl;
var form = layui.form();
var form = layui.form;
var fly = layui.fly;
var laypage = layui.laypage;
var gather = {}, dom = {
jieda: $('#jieda')
,content: $('#L_content')
,jiedaCount: $('#jiedaCount')
};
//监听专栏选择
form.on('select(column)', function(obj){
var value = obj.value
,elemQuiz = $('#LAY_quiz')
,tips = {
tips: 1
,maxWidth: 250
,time: 10000
};
elemQuiz.addClass('layui-hide');
if(value === '0'){
layer.tips('下面的信息将便于您获得更好的答案', obj.othis, tips);
elemQuiz.removeClass('layui-hide');
} else if(value === '99'){
layer.tips('系统会对【分享】类型的帖子予以飞吻奖励,但我们需要审核,通过后方可展示', obj.othis, tips);
}
});
//提交回答
fly.form['/jie/reply/'] = function(data, required){
var tpl = '<li>\
<div class="detail-about detail-about-reply">\
<a class="jie-user" href="/user/">\
<a class="fly-avatar" href="/u/{{ layui.cache.mine.userId }}" target="_blank">\
<img src="{{= d.user.avatar}}" alt="{{= d.user.username}}">\
<cite>{{d.user.username}}</cite>\
</a>\
<div class="fly-detail-user">\
<a href="/u/{{ layui.cache.user.uid }}" target="_blank" class="fly-link">\
<cite>{{d.user.username}}</cite>\
</a>\
</div>\
<div class="detail-hits">\
<span>刚刚</span>\
</div>\
</div>\
<div class="detail-body jieda-body">\
<div class="detail-body jieda-body photos">\
{{ d.content}}\
</div>\
</li>'
@@ -84,41 +105,35 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
//收藏
,collect: function(div){
var othis = $(this), type = othis.data('type');
$.post('/os/content/collect', {
contentId: div.data('id')
,ok: type === 'add'? 1:-1
fly.json('/os/content/collect', {
contentId: div.data('id')
,ok: type === 'add'? 1:-1
}, function(res){
res = JSON.parse(res);
console.log(res);
if(res.retcode == 0){
if(type === 'add'){
othis.data('type', 'remove').html('取消收藏').addClass('layui-btn-danger');
layer.msg("收藏成功");
othis.data('type', 'remove').html('取消收藏').addClass('layui-btn-danger');
layer.msg("收藏成功");
} else if(type === 'remove'){
othis.data('type', 'add').html('收藏').removeClass('layui-btn-danger');
layer.msg("已取消收藏");
othis.data('type', 'add').html('收藏').removeClass('layui-btn-danger');
layer.msg("已取消收藏");
}
}else {
layer.msg(res.retinfo);
}
});
}
};
$('body').on('click', '.jie-admin', function(){
var othis = $(this), type = othis.attr('type');
gather.jieAdmin[type].call(this, othis.parent());
gather.jieAdmin[type] && gather.jieAdmin[type].call(this, othis.parent());
});
//异步渲染
var asyncRender = function(){
var div = $('.fly-detail-hint'), jieAdmin = $('#LAY_jieAdmin');
var div = $('.fly-admin-box'), jieAdmin = $('#LAY_jieAdmin');
//查询帖子是否收藏
if(jieAdmin[0] && layui.cache.user.uid != -1){
fly.json('/collection/find/', {
cid: div.data('id')
}, function(res){
jieAdmin.append('<span class="layui-btn layui-btn-mini jie-admin '+ (res.data.collection ? 'layui-btn-danger' : '') +'" type="collect" data-type="'+ (res.data.collection ? 'remove' : 'add') +'">'+ (res.data.collection ? '取消收藏' : '收藏') +'</span>');
jieAdmin.append('<span class="layui-btn layui-btn-xs jie-admin '+ (res.data.collection ? 'layui-btn-danger' : '') +'" type="collect" data-type="'+ (res.data.collection ? 'remove' : 'add') +'">'+ (res.data.collection ? '取消收藏' : '收藏') +'</span>');
});
}
}();
@@ -127,24 +142,18 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
gather.jiedaActive = {
zan: function(li){ //赞
var othis = $(this), ok = othis.hasClass('zanok');
$.post('/os/comment/support', {
ok: ok?-1:1
,commentId: li.data('id')
fly.json('/os/comment/support', {
commentId: li.data('id')
,ok: ok?-1:1
}, function(res){
res = JSON.parse(res);
console.log(res);
if(res.retcode === 0){
var zans = othis.find('em').html()|0;
othis[ok ? 'removeClass' : 'addClass']('zanok');
othis.find('em').html(ok ? (--zans) : (++zans));
} else {
layer.msg(res.retinfo);
}
});
}
,reply: function(li){ //回复
var val = dom.content.val();
var aite = '@'+ li.find('.jie-user cite i').text().replace(/\s/g, '');
var aite = '@'+ li.find('.fly-detail-user cite').text().replace(/\s/g, '');
dom.content.focus()
if(val.indexOf(aite) !== -1) return;
dom.content.val(aite +' ' + val);
@@ -173,9 +182,16 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
}, function(res){
var data = res.rows;
layer.prompt({
formType: 2
,value: data.content
,maxlength: 100000
formType: 2
,value: data.content
,maxlength: 100000
,title: '编辑回帖'
,area: ['728px', '300px']
,success: function(layero){
fly.layEditor({
elem: layero.find('textarea')
});
}
}, function(value, index){
fly.json('/jie/updateDa/', {
id: li.data('id')
@@ -208,11 +224,13 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
});
}
};
$('.jieda-reply span').on('click', function(){
var othis = $(this), type = othis.attr('type');
gather.jiedaActive[type].call(this, othis.parents('li'));
});
form.on('submit(jie-add)', function(data){
var bean = {};
["contentId","title", "content", "cate"].forEach(function (value) {
@@ -220,17 +238,11 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
});
console.log(bean);
$.post("/os/content/save",{
fly.json("/os/content/save",{
bean:JSON.stringify(bean)
},function (res) {
res = JSON.parse(res);
if(res.retcode != 0){
layer.msg(res.retinfo);
return false;
}
layer.msg("发布成功",{time:2000},function () {
location.href = "/";
location.href = "/";
});
});
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
@@ -242,18 +254,12 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
});
console.log(bean);
$.post("/os/comment/save",{
fly.json("/os/comment/save",{
bean:JSON.stringify(bean)
},function (res) {
res = JSON.parse(res);
if(res.retcode != 0){
layer.msg(res.retinfo);
return false;
}
layer.msg("回复成功",{time:2000},function () {
//location.href = "/";
location.reload();
//location.href = "/";
location.reload();
});
});
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
@@ -272,7 +278,7 @@ layui.define(['laypage', 'fly', 'form'], function(exports){
location.href=layui.cache.url+"?curr="+curr;
}
});
}
}
exports('jie', null);
exports('jie', null);
});