🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` ,{field: 'status', title: '状态',templet : function (d) { var state = ""; if (d.status == "0") { state = "<input type='checkbox' value='" + d.id + "' id='status' lay-filter='stat' checked='checked' name='status' lay-skin='switch' lay-text='正常|禁用' >"; }else { state = "<input type='checkbox' value='" + d.id + "' id='status' lay-filter='stat' name='status' lay-skin='switch' lay-text='正常|禁用' >"; } return state; } } ``` ``` //监听开关事件 form.on('switch(stat)', function (data) { var contexts; var sta; var x = data.elem.checked;//判断开关状态 if (x==true) { contexts = "启用"; sta=0; } else { contexts = "禁用"; sta=1; } //自定义弹窗 layer.open({ title:contexts + '用户', content: "确定要"+contexts+"?" , btn: ['确定', '取消'] , yes: function (index, layero) { data.elem.checked = x; $.ajax({ type: "post", url: "{:url('admin/user/changeStatus')}", data: { "id": data.value, "status":sta }, success: function (data) { if (data.code == 1) { layer.msg(contexts+'成功', {icon: 1, time: 1000,}); }else{ layer.msg('修改失败', {icon: 2, time: 1000,}); } } }); form.render(); layer.close(index); } , btn2: function (index, layero) { //按钮【按钮二】的回调 data.elem.checked = !x; form.render(); layer.close(index); //return false 开启该代码可禁止点击该按钮关闭 } , cancel: function () { //右上角关闭回调 data.elem.checked = !x; form.render(); // return false; //开启该代码可禁止点击该按钮关闭 } }); return false; }); ```