TaoLer/public/static/admin/modules/forum.js

192 lines
5.9 KiB
JavaScript
Raw Normal View History

2022-08-02 20:48:54 +08:00

2022-09-23 10:59:41 +08:00
layui.define(['table'], function(exports){
2020-01-01 13:17:19 +08:00
var $ = layui.$
2022-09-23 10:59:41 +08:00
,table = layui.table;
2020-01-01 13:17:19 +08:00
//帖子管理
2022-08-02 20:48:54 +08:00
var forms = table.render({
2020-01-01 13:17:19 +08:00
elem: '#LAY-app-forum-list'
2020-04-28 18:44:40 +08:00
,url: forumList //帖子数据接口
2020-01-01 13:17:19 +08:00
,cols: [[
{type: 'checkbox'}
,{field: 'id', width: 60, title: 'ID', sort: true}
2022-08-02 20:48:54 +08:00
,{field: 'poster', title: '账号',width: 80}
,{field: 'avatar', title: '头像', width: 60, templet: '#avatarTpl'}
2022-09-23 10:59:41 +08:00
,{field: 'title', title: '标题', minWidth: 180,templet: '<div><a href="{{- d.url }}" target="_blank">{{- d.title }}</a></div>'}
,{field: 'content', title: '内容', templet: '<div>{{= d.content }}</div>', minWidth: 200}
,{field: 'posttime', title: '时间',width: 120, sort: true}
,{field: 'top', title: '置顶', templet: '#buttonTpl', width: 80, align: 'center'}
2021-12-15 15:46:04 +08:00
,{field: 'hot', title: '加精', templet: '#buttonHot', width: 80, align: 'center'}
,{field: 'reply', title: '禁评', templet: '#buttonReply', width: 80, align: 'center'}
2022-08-02 20:48:54 +08:00
,{field: 'check', title: '审帖', templet: '#buttonCheck', width: 95, align: 'center'}
2022-08-16 15:19:21 +08:00
,{title: '操作', width: 110, align: 'center', toolbar: '#table-forum-list'}
2020-01-01 13:17:19 +08:00
]]
,page: true
,limit: 15
,limits: [10, 15, 20, 25, 30]
,text: '对不起,加载出现异常!'
});
//监听工具条
table.on('tool(LAY-app-forum-list)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('确定删除此条帖子?', function(index){
2020-01-14 15:47:11 +08:00
//obj.del();
2022-08-02 20:48:54 +08:00
$.ajax({
type:'post',
url:forumListdel,
data:{id:data.id},
dataType:'json',
success:function(data){
if(data.code == 0){
layer.msg(data.msg,{
icon:6,
time:2000
},function(){
forms.reload();
});
} else {
layer.open({
title:'删除失败',
content:data.msg,
icon:5,
adim:6
})
}
}
});
2020-01-01 13:17:19 +08:00
layer.close(index);
});
} else if(obj.event === 'edit'){
var tr = $(obj.tr);
layer.open({
type: 2
,title: '编辑帖子'
2022-08-16 15:19:21 +08:00
,content: forumEdit + '?id='+ data.id
,area: ['100%', '100%']
2020-01-01 13:17:19 +08:00
,btn: ['确定', '取消']
,resize: false
,yes: function(index, layero){
var iframeWindow = window['layui-layer-iframe'+ index]
2022-08-16 15:19:21 +08:00
,submitID = 'article-edit'
,submit = layero.find('iframe').contents().find('#'+ submitID)
2020-01-01 13:17:19 +08:00
//监听提交
iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
var field = data.field; //获取提交的字段
2022-08-16 15:21:08 +08:00
//tag
var numArr = new Array();
layero.find('iframe').contents().find(".layui-btn-container").children("button").each(function () {
numArr.push($(this).val()); //添加至数组
});
field.tags = numArr.lenth ? "" : numArr.join(",");
2022-08-16 15:19:21 +08:00
2021-12-15 15:46:04 +08:00
$.ajax({
type:"post",
2022-08-16 15:19:21 +08:00
url: forumEdit,
data: field,
2021-12-15 15:46:04 +08:00
daType:"json",
success:function (data){
if (data.code == 0) {
2022-08-16 15:19:21 +08:00
layer.msg(data.msg,{icon:6,time:2000});
2021-12-15 15:46:04 +08:00
} else {
2022-08-16 15:19:21 +08:00
layer.open({title:'编辑失败',content:data.msg,icon:5,anim:6});
};
2021-12-15 15:46:04 +08:00
}
});
2020-01-01 13:17:19 +08:00
table.reload('LAY-app-forum-list'); //数据刷新
layer.close(index); //关闭弹层
});
submit.trigger('click');
}
});
}
});
2020-01-14 15:47:11 +08:00
//评论管理
2020-01-01 13:17:19 +08:00
table.render({
elem: '#LAY-app-forumreply-list'
2020-04-28 18:44:40 +08:00
,url: forumReplys
2020-01-01 13:17:19 +08:00
,cols: [[
{type: 'checkbox'}
,{field: 'id', width: 80, title: 'ID', sort: true}
2022-08-02 21:13:36 +08:00
,{field: 'title', title: '标题',minWidth: 150, templet: '<div><a href="{{d.url}}" target="_blank">{{d.title}}</a></div>'}
,{field: 'replyer', title: '账号', width: 80}
,{field: 'avatar', title: '头像', width: 60, templet: '#imgTpl'}
,{field: 'content', title: '评论', minWidth: 200}
,{field: 'replytime', title: '回复时间', width: 120, sort: true}
2022-08-02 20:48:54 +08:00
,{field: 'check', title: '审核', templet: '#buttonCheck', width: 100}
2021-12-15 15:46:04 +08:00
,{title: '操作', width: 60, align: 'center', toolbar: '#table-forum-replys'}
2020-01-01 13:17:19 +08:00
]]
,page: true
2020-01-14 15:47:11 +08:00
,limit: 15
2020-01-01 13:17:19 +08:00
,limits: [10, 15, 20, 25, 30]
,text: '对不起,加载出现异常!'
});
//监听工具条
table.on('tool(LAY-app-forumreply-list)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('确定删除此条评论?', function(index){
2020-01-14 15:47:11 +08:00
//obj.del();
$.ajax({
type:'post',
2020-04-28 18:44:40 +08:00
url:forumRedel,
2020-01-14 15:47:11 +08:00
data:{id:data.id},
dataType:'json',
success:function(data){
if(data.code == 0){
layer.msg(data.msg,{
icon:6,
time:2000
},function(){
location.reload();
});
} else {
layer.open({
title:'删除失败',
content:data.msg,
icon:5,
adim:6
})
}
}
});
2020-01-01 13:17:19 +08:00
layer.close(index);
});
} else if(obj.event === 'edit'){
var tr = $(obj.tr);
layer.open({
type: 2
,title: '编辑评论'
2020-01-14 15:47:11 +08:00
,content: '/admin/Forum/replysform.html'
2020-01-01 13:17:19 +08:00
,area: ['550px', '350px']
,btn: ['确定', '取消']
,resize: false
,yes: function(index, layero){
//获取iframe元素的值
var othis = layero.find('iframe').contents().find("#layuiadmin-form-replys");
var content = othis.find('textarea[name="content"]').val();
//数据更新
obj.update({
content: content
});
layer.close(index);
}
,success: function(layero, index){
}
});
}
});
exports('forum', {})
});