TaoLer/public/static/admin/modules/contlist.js
2020-03-13 22:59:38 +08:00

246 lines
7.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
@NamelayuiAdmin 内容系统
@Authorstar1029
@Sitehttp://www.layui.com/admin/
@LicenseLPPL
*/
layui.define(['table', 'form'], function(exports){
var $ = layui.$
,table = layui.table
,form = layui.form;
//文章管理
table.render({
elem: '#LAY-app-content-list'
,url: layui.setter.base + 'json/content/list.js' //模拟接口
,cols: [[
{type: 'checkbox', fixed: 'left'}
,{field: 'id', width: 100, title: '文章ID', sort: true}
,{field: 'label', title: '文章标签', minWidth: 100}
,{field: 'title', title: '文章标题'}
,{field: 'author', title: '作者'}
,{field: 'uploadtime', title: '上传时间', sort: true}
,{field: 'status', title: '发布状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
]]
,page: true
,limit: 10
,limits: [10, 15, 20, 25, 30]
,text: '对不起,加载出现异常!'
});
//监听工具条
table.on('tool(LAY-app-content-list)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('确定删除此文章?', function(index){
obj.del();
layer.close(index);
});
} else if(obj.event === 'edit'){
layer.open({
type: 2
,title: '编辑文章'
,content: '../../../views/app/content/listform.html?id='+ data.id
,maxmin: true
,area: ['550px', '550px']
,btn: ['确定', '取消']
,yes: function(index, layero){
var iframeWindow = window['layui-layer-iframe'+ index]
,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");
//监听提交
iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
var field = data.field; //获取提交的字段
//提交 Ajax 成功后,静态更新表格中的数据
//$.ajax({});
obj.update({
label: field.label
,title: field.title
,author: field.author
,status: field.status
}); //数据更新
form.render();
layer.close(index); //关闭弹层
});
submit.trigger('click');
}
});
}
});
//分类管理
table.render({
elem: '#LAY-app-content-tags'
,url: '/admin/Forum/tags' //模拟接口
,cols: [[
{type: 'numbers', fixed: 'left'}
,{field: 'sort', title: '排序', width: 80, sort: true}
,{field: 'id', title: 'ID',Width: 50}
,{field: 'tags', title: '分类名', minWidth: 100}
,{field: 'ename', title: 'EN别名', minWidth: 100}
,{field: 'desc', title: '描述', minWidth: 100}
,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar'}
]]
,text: '对不起,加载出现异常!'
});
//监听工具条
table.on('tool(LAY-app-content-tags)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('确定删除此分类?', function(index){
$.ajax({
type:'post',
url:"/admin/Forum/tagsdelete",
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
})
}
}
});
//obj.del();
layer.close(index);
});
} else if(obj.event === 'edit'){
var tr = $(obj.tr);
layer.open({
type: 2
,title: '编辑分类'
,content: '/admin/Forum/tagsform?id='+ data.id
,area: ['450px', '300px']
,btn: ['确定', '取消']
,yes: function(index, layero){
//获取iframe元素的值
var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
,sort = othis.find('input[name="sort"]').val()
,tags = othis.find('input[name="tags"]').val()
,ename = othis.find('input[name="ename"]').val()
,desc = othis.find('input[name="desc"]').val();
if(!tags.replace(/\s/g, '')) return;
$.ajax({
type:"post",
url:"/admin/Forum/tagsform",
data:{"id":data.id,"sort":sort,"catename":tags,"ename":ename,"desc":desc},
daType:"json",
success:function (data){
if (data.code == 0) {
layer.msg(data.msg,{
icon:6,
time:2000
}, function(){
location.reload();
});
} else {
layer.open({
tiele:'修改失败',
content:data.msg,
icon:5,
anim:6
});
}
}
});
/*
obj.update({
tags: tags
,ename: ename
,sort: sort
});
*/
layer.close(index);
}
,success: function(layero, index){
//给iframe元素赋值
var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags").click();
othis.find('input[name="sort"]').val(data.sort)
,othis.find('input[name="tags"]').val(data.tags)
,othis.find('input[name="ename"]').val(data.ename)
,othis.find('input[name="desc"]').val(data.desc);
}
});
}
});
//评论管理
table.render({
elem: '#LAY-app-content-comm'
,url: layui.setter.base + 'json/content/comment.js' //模拟接口
,cols: [[
{type: 'checkbox', fixed: 'left'}
,{field: 'id', width: 100, title: 'ID', sort: true}
,{field: 'reviewers', title: '评论者', minWidth: 100}
,{field: 'content', title: '评论内容', minWidth: 100}
,{field: 'commtime', title: '评论时间', minWidth: 100, sort: true}
,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-content-com'}
]]
,page: true
,limit: 10
,limits: [10, 15, 20, 25, 30]
,text: '对不起,加载出现异常!'
});
//监听工具条
table.on('tool(LAY-app-content-comm)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('确定删除此条评论?', function(index){
obj.del();
layer.close(index);
});
} else if(obj.event === 'edit') {
layer.open({
type: 2
,title: '编辑评论'
,content: '../../../views/app/content/contform.html'
,area: ['450px', '300px']
,btn: ['确定', '取消']
,yes: function(index, layero){
var iframeWindow = window['layui-layer-iframe'+ index]
,submitID = 'layuiadmin-app-comm-submit'
,submit = layero.find('iframe').contents().find('#'+ submitID);
//监听提交
iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
var field = data.field; //获取提交的字段
//提交 Ajax 成功后,静态更新表格中的数据
//$.ajax({});
table.reload('LAY-app-content-comm'); //数据刷新
layer.close(index); //关闭弹层
});
submit.trigger('click');
}
,success: function(layero, index){
}
});
}
});
exports('contlist', {})
});