TaoLer/public/static/res/mods/jie.js

276 lines
7.9 KiB
JavaScript
Raw Normal View History

2020-01-01 13:17:19 +08:00
/**
@Name: 求解板块
*/
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 fly = layui.fly;
2023-05-05 11:58:42 +08:00
var uid = layui.cache.user.uid;
2020-01-01 13:17:19 +08:00
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="fly-avatar" href="/u/{{ layui.cache.user.uid }}" target="_blank">\
<img src="{{= d.user.avatar}}" alt="{{= d.user.username}}">\
</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 photos">\
{{ d.content}}\
</div>\
</li>'
data.content = fly.content(data.content);
laytpl(tpl).render($.extend(data, {
user: layui.cache.user
}), function(html){
required[0].value = '';
dom.jieda.find('.fly-none').remove();
dom.jieda.append(html);
var count = dom.jiedaCount.text()|0;
dom.jiedaCount.html(++count);
});
};
2020-04-24 15:07:26 +08:00
//帖子管理
2020-01-01 13:17:19 +08:00
gather.jieAdmin = {
2020-04-24 15:07:26 +08:00
//删帖子
2020-01-01 13:17:19 +08:00
del: function(div){
layer.confirm('确认删除该贴么?', function(index){
2022-08-02 21:13:36 +08:00
layer.close(index);
$.ajax({
type:'get',
url:articleDelete,
data:{id: div.data('id')},
dataType:'json',
success:function(data){
2023-05-05 11:58:42 +08:00
if(data.code === 0){
2022-08-02 21:13:36 +08:00
layer.msg(data.msg,{
icon:6,
time:2000
},function(){
location.href = '/';
});
} else {
layer.open({
title:'删除失败',
content:data.msg,
icon:5,
adim:6
})
}
}
});
2020-01-01 13:17:19 +08:00
});
}
2022-08-02 21:13:36 +08:00
// 设置置顶、加精、禁评、状态
2020-01-01 13:17:19 +08:00
,set: function(div){
var othis = $(this);
2020-04-24 15:07:26 +08:00
fly.json(articleJieset, {
2020-01-01 13:17:19 +08:00
id: div.data('id')
,rank: othis.attr('rank')
,field: othis.attr('field')
}, function(res){
if(res.status === 0){
2022-08-02 21:13:36 +08:00
layer.msg(res.msg);
location.reload();
}
2020-01-01 13:17:19 +08:00
});
}
2022-08-02 21:13:36 +08:00
// 收藏
2020-01-01 13:17:19 +08:00
,collect: function(div){
var othis = $(this), type = othis.data('type');
2020-04-24 15:07:26 +08:00
fly.json(collection+ type +'/', {
2020-01-01 13:17:19 +08:00
cid: div.data('id')
}, function(res){
if(type === 'add'){
othis.data('type', 'remove').html(langCancelCollection).addClass('layui-btn-danger');
2020-01-01 13:17:19 +08:00
} else if(type === 'remove'){
othis.data('type', 'add').html(langCollection).removeClass('layui-btn-danger');
2020-01-01 13:17:19 +08:00
}
});
}
};
$('body').on('click', '.jie-admin', function(){
var othis = $(this), type = othis.attr('type');
gather.jieAdmin[type] && gather.jieAdmin[type].call(this, othis.parent());
});
//异步渲染
var asyncRender = function(){
var div = $('.fly-admin-box'), jieAdmin = $('#LAY_jieAdmin');
//查询帖子是否收藏
if(jieAdmin[0] && layui.cache.user.uid != -1){
2020-04-22 18:37:53 +08:00
fly.json(collectionFind, {
2020-01-01 13:17:19 +08:00
cid: div.data('id')
}, function(res){
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 ? langCancelCollection : langCollection) +'</span>');
2020-01-01 13:17:19 +08:00
});
}
}();
//解答操作
gather.jiedaActive = {
zan: function(li){ //赞
var othis = $(this), ok = othis.hasClass('zanok');
2020-04-24 15:07:26 +08:00
fly.json(commentJiedaZan, {
2020-01-01 13:17:19 +08:00
ok: ok
,id: li.data('id')
}, function(res){
if(res.status === 0){
var zans = othis.find('em').html()|0;
othis[ok ? 'removeClass' : 'addClass']('zanok');
othis.find('em').html(ok ? (--zans) : (++zans));
} else {
2023-05-05 11:58:42 +08:00
layer.msg(res.msg, {icon: 6});
2020-01-01 13:17:19 +08:00
}
});
}
,reply: function(li){ //回复
2023-05-05 11:58:42 +08:00
//判断登陆
if(uid == -1){
layer.msg('请登录再回复', {icon: 6})
return false;
}
2020-01-01 13:17:19 +08:00
var val = dom.content.val();
var aite = '@'+ li.find('.fly-detail-user cite').text().replace(/\s/g, '');
dom.content.focus()
if(val.indexOf(aite) !== -1) return;
2023-05-05 11:58:42 +08:00
// 切换编辑器 回复@赋值
if(taonystatus == 0) {
dom.content.val(aite +' ' + val);
} else { //编辑器插件赋值
tinymce.activeEditor.setContent(aite + ' .' + val);
}
2020-01-01 13:17:19 +08:00
}
,accept: function(li){ //采纳
var othis = $(this);
layer.confirm('是否采纳该回答为最佳答案?', function(index){
layer.close(index);
2020-04-24 15:07:26 +08:00
fly.json(commentJiedaCai, {
2020-01-01 13:17:19 +08:00
id: li.data('id')
}, function(res){
if(res.status === 0){
$('.jieda-accept').remove();
li.addClass('jieda-daan');
li.find('.detail-about').append('<i class="iconfont icon-caina" title="最佳答案"></i>');
2022-09-07 15:26:01 +08:00
location.reload();
2020-01-01 13:17:19 +08:00
} else {
layer.msg(res.msg);
}
});
});
}
2020-04-24 15:07:26 +08:00
,edit: function(li){ //编辑评论
2023-05-05 12:03:45 +08:00
if(taonystatus == 0) {
2023-05-05 11:58:42 +08:00
2023-05-05 12:03:45 +08:00
fly.json(commentGetDa, {
id: li.data('id')
}, function (res) {
var data = res.rows;
layer.prompt({
formType: 2
, value: data.content
, maxlength: 100000
, title: '编辑回帖'
, area: ['738px', '310px']
, success: function (layero) {
fly.layEditor({
elem: layero.find('textarea')
});
2023-05-05 11:58:42 +08:00
}
2023-05-05 12:03:45 +08:00
}, function (value, index) {
fly.json(commentUpdateDa, {
id: li.data('id')
, content: value
}, function (res) {
layer.close(index);
layer.msg(res.msg);
li.find('.detail-body').html(fly.content(value));
});
2020-01-01 13:17:19 +08:00
});
});
2023-05-05 12:03:45 +08:00
}
2020-01-01 13:17:19 +08:00
}
2023-07-03 12:54:48 +08:00
,del: function(span){ //删除评论
if(taonystatus == 0) {
layer.confirm('确认删除该回答么?', function(index){
layer.close(index);
fly.json(commentJiedaDelete, {
id: li.data('id')
}, function(res){
if(res.status === 0){
var count = dom.jiedaCount.text()|0;
dom.jiedaCount.html(--count);
li.remove();
//如果删除了最佳答案
if(li.hasClass('jieda-daan')){
$('.jie-status').removeClass('jie-status-ok').text('求解中');
}
} else {
layer.msg(res.msg);
2020-01-01 13:17:19 +08:00
}
2023-07-03 12:54:48 +08:00
});
2020-01-01 13:17:19 +08:00
});
2023-07-03 12:54:48 +08:00
}
2020-01-01 13:17:19 +08:00
}
};
$('.jieda-reply span').on('click', function(){
var othis = $(this), type = othis.attr('type');
gather.jiedaActive[type].call(this, othis.parents('li'));
});
//定位分页
if(/\/page\//.test(location.href) && !location.hash){
var replyTop = $('#flyReply').offset().top - 80;
$('html,body').scrollTop(replyTop);
}
exports('jie', null);
});