Layui代码记录

Layui代码记录

七月 18, 2019

页面之间参数传递

1
2
3
4
5
6
7
8
<script type="text/html" template lay-done="layui.data.sendParams(d.params)">
</script>
<script>
//定义一个 lay-done 对应的全局方法,以供动态模板执行
layui.data.sendParams = function(params) {
var adid = params.adId; //得到传递过来的 id 参数(或其他参数)值
}
</script>

table控件使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<table id="LAY-shop-ad-list" lay-filter="LAY-shop-ad-list"></table>

table.render({
elem: '#LAY-shop-ad-list'
, request: {
pageName: 'pagenum' //页码的参数名称,默认:page
, limitName: 'nums' //每页数据量的参数名,默认:limit
}
, where: {shopid: shopid}
, method: "get"
, url: urlhost.geturl(urlhost.ad) //模拟接口
, parseData: function (res) { //res 即为原始返回的数据
console.log(res.data)
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.data.count,//对象数据
"data": res.data.data //解析数据列表
}
}
, cols: [[
{field: 'id', title: 'ID'}
, {field: 'adTitle', title: '标题'}
, {field: 'adUrl', title: '广告图片', templet: '#imgTpl'}
, {field: 'adType', title: '商品种类'}
, {field: 'adRemark', title: '商品来源'}
]]
, page: true
, limit: 10
, height: 'full-250'
, text: '对不起,加载出现异常!'
});

select控件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<select id="LAY-ad-shoplist" name="shoplist" lay-filter="LAY-ad-shoplist">
<option value="">请选择门店</option>
</select>

//动态加载数据
$('#LAY-ad-shoplist').empty();
for (var i = 0; i < res.data.length; i++) {
$('#LAY-ad-shoplist').append($("<option>").val(res.data[i].platformId).text(res.data[i].shopName + " " + res.data[i].adminName));
}
form.render('select');

//select按键监听
form.on('select(LAY-ad-shoplist)', function (data) {
if (data.value!=0){
getShopList(data.value);
}
})

ajax请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
admin.req({
type: "post",
url: urlhost.geturl(urlhost.agencygoods),
data: JSON.stringify(field),
contentType: "application/json",
success:function (res) {
console.log(res);
layui.table.reload('LAY-agencygood-manage'); //重载表格
layer.close(index); //执行关闭
},
error:function (res) {
console.log(res);
}
})

[popup弹框]

1
2
3
4
5
6
7
8
9
10
admin.popup({
title: '添加总店商品'
,area: ['500px', '600px']
,id: 'LAY-popup-good-add'
,success: function(layero, index){
view(this.id).render('beila/good/goodaddform').done(function(){

});
}
});