<script type="text/javascript">
layui.use(['form', 'table', 'laydate', 'upload'], function () {
var <!--声明--> form = layui.form;
var table = layui.table;
var upload = layui.upload;
$("#search").click(function () {
GetData();<!--获取数据的-->
return false;
});
GetData();
function GetData() {
$.post("Training/checkSession", function (res) {
if (res.code == 0) {
var para = "zxbt=" + $("#zxbt").val().trim() + "&zxfl=" + $("#zxfl").val() + "&zxzt=" + $("#zxzt").val()+ "&fbpt=" + $("#fbpt").val();
table.render({
elem/*元素*/: '#test'
, id: 'test'
, url: 'Training/zxggSearch?' + para
, height: 'full-150'////设置标头浮动
, limits: [20, 50, 100, 200, 500]//每页条数的选择项。如果 layout 参数开启了 limit,则会出现每页条数的select选择框
, limit: 50
, page: true
, even: true
, cols: [
[
{type: 'checkbox', fixed: 'left'},
{field: 'zxbt', align: 'left', title: '资讯标题', width: 300, fixed: 'left'},
{
field: 'zxfl', align: 'center', title: '资讯分类', width: 120,
templet: function (res) {
if (res.zxfl == "0") {
return "新闻资讯";
} else if (res.zxfl == "1") {
return "政策文件";
} else if (res.zxfl == "2") {
return "大师工匠";
} else {
return "";
}
}
},
{
field: 'zxzt', align: 'center', title: '资讯状态', width: 120,
templet: function (res) {
if (res.zxzt == "0") {
return "未发布";
} else if (res.zxzt == "1") {
return "已发布";
} else {
return "";
}
}
},
{
field: 'fbpt', align: 'center', title: '发布平台', width: 200,
templet: function (res) {
if (res.fbpt == "0") {
return "本溪职业培训在线";
} else if (res.fbpt == "1") {
return "本钢职业培训在线";
} else {
return "";
}
}
},
{
field: '', align: 'center', title: '封面图片', width: 200,
templet: function (res) {
if (res.zxtplj == null || res.zxtplj == "") {
return "<a class='layui-btn layui-btn-normal' onclick=\"upload('" + res.zxbh + "','ZXTP')\">上传</a>" +
"<div class='layui-inline' style='width: 90px;'></div>";
} else {
return "<a class='layui-btn layui-btn-normal' onclick=\"upload('" + res.zxbh + "','ZXTP')\">上传</a>" +
"<a class='layui-btn layui-btn-normal' onclick=\"preview('" + res.zxbh + "','" + res.zxbt + "')\">预览</a>";
}
}
},
{field: 'tjry', align: 'left', title: '添加人员', width: 150},
{field: 'tjsj', align: 'center', title: '添加时间', width: 200}
]
]
});
} else if (res.code == 1) {
showMsg(res.msg);
} else if (res.code == 2) {
window.parent.showLogin();
}
});
}
$("#add").click(function () {
$.post("Training/zxggDoAdd", function (res) {
if (res.code == 0) {
$("#search").click();
layer.open({
type: 2,
title: '添加资讯公告',
content: 'zxggEdit?zxbh=' + res.data.zxbh,
resize: false,
area: ['100%', '100%'],
success: function (layer, index) {
}
})
} else if (res.code == 1) {
showMsg(res.msg);
} else if (res.code == 2) {
window.parent.showLogin();
}
});
return false;
});
$("#edit").click(function () {
var checkStatus = table.checkStatus('test');
if (checkStatus.data.length == 1) {
layer.open({
type: 2,
title: '修改资讯公告',
content: 'zxggEdit?zxbh=' + checkStatus.data[0].zxbh,
resize: false,
area: ['100%', '100%'],
success: function (layer, index) {
}
})
} else {
showMsg("请选择一条数据,进行修改。");
}
return false;
});
$("#delete").click(function () {
var checkStatus = table.checkStatus('test');
if (checkStatus.data.length > 0) {
var index = layer.confirm('<span style="font-size: 16px;">确定删除【' + checkStatus.data.length + '】条数据?</span>', {
btn: ['确定', '取消']
}, function () {
layer.close(index);
$.ajax({
url: "Training/zxggDelete",
type: 'POST',
dataType: 'json',
contentType: "application/json",
data: JSON.stringify(checkStatus.data),
success: function (res) {
if (res.code == 0) {
showConfirmMsg(res.msg);
setTimeout(function () {
GetData();
}, 1000);
} else if (res.code == 1) {
showMsg(res.msg);
} else if (res.code == 2) {
window.parent.showLogin();
}
}
});
});
} else {
showMsg("请选择要删除的数据。");
}
return false;
});
$("#upload").click(function () {
return false;
});
var m_zxbh = '';
var m_type = '';
window.upload = function (zxbh, type) {
m_zxbh = zxbh;
m_type = type;
$("#upload").click();
};
upload.render({
elem: '#upload'
, url: 'Training/fileUpload'
, accept: 'file'
, size: 0
, acceptMime: 'image/jpeg, image/png'
, exts: 'jpg|png'
, data: {bh: m_zxbh, type: m_type}
, before: function (obj) {
this.data.bh = m_zxbh;
this.data.type = m_type;
showWaiting('数据上传中...');
}
, done: function (res) {
layer.closeAll();
if (res.code == 0) {
showMsg(res.msg);
setTimeout(function () {
GetData();
}, 1000);
} else if (res.code == 1) {
showMsg(res.msg);
} else if (res.code == 2) {
window.parent.showLogin();
}
}
});
window.preview = function (zxbh, zxbt) {
layer.open({
type: 2,
title: zxbt,
content: "zxggPreview?zxbh=" + zxbh,
shadeClose: true,
maxmin: true,
area: ['1000px', '800px']
});
return false;
};
});
</script>
这段js是什么意思?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- AllPromise 2021-03-03 16:33关注
基于layui框架的一个页面功能,包含表格数据的获取,表单新增,表单修改,删除数据,上传文件的功能
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 求高通平台Softsim调试经验
- ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
- ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
- ¥15 栅极驱动低侧烧毁MOSFET
- ¥30 写segy数据时出错3
- ¥100 linux下qt运行QCefView demo报错
- ¥50 F1C100S下的红外解码IR_RX驱动问题
- ¥20 基于matlab的航迹融合 航迹关联 航迹插补
- ¥15 用Matlab实现图中的光线追迹
- ¥15 联想笔记本开机出现系统更新界面