Ai_Admin/templates/wechat_users.html
2024-06-05 05:10:50 +08:00

72 lines
2.5 KiB
HTML
Raw Permalink 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.

<body>
<table class="layui-hide" id="friendRequestTable" lay-filter="friendRequestTableFilter"></table>
<script>
layui.use(['table', 'layer'], function(){
var table = layui.table;
var layer = layui.layer;
// 初始化表格
table.render({
elem: '#friendRequestTable',
url: '/admin/wechat_users/', // 修改为你的接口地址
method: 'post',
where: {action: 'fetch'}, // 传递给后端的参数例如action: 'fetch'用于获取数据
contentType: 'application/json', // 设置发送请求的内容类型为JSON
page: true,
cols: [[
{field: 'fromusername', title: '微信ID', sort: true},
{field: 'alias', title: '微信号'},
{field: 'fromnickname', title: '昵称'},
{field: 'country', title: '国家'},
{field: 'province', title: '省份'},
{field: 'city', title: '城市'},
{field: 'sex', title: '性别', sort: true},
{field: 'scene', title: '来源'},
{field: 'time', title: '申请时间', sort: true},
{field: 'towxid', title: '目标微信ID'},
{title: '操作', toolbar: '#barDemo'} // 操作列,使用模板引擎渲染
]]
});
// 工具条事件
table.on('tool(friendRequestTableFilter)', function(obj){
var data = obj.data; // 获取当前行数据
if(obj.event === 'edit'){
// 编辑操作
console.log('编辑', data);
// 实现编辑操作...
} else if(obj.event === 'delete'){
// 删除操作
console.log('删除', data.id);
layer.confirm('确定删除该好友请求吗?', function(index){
// 发起POST请求到后端进行删除
layui.$.post('/admin/wechat_users/', {
action: 'delete',
id: data.id
}, function(res){
if(res.status === 'success'){
layer.msg('删除成功');
obj.del(); // 删除表格行
} else {
layer.msg('删除失败');
}
});
layer.close(index);
});
}
});
});
</script>
<!-- 表格操作栏模板 -->
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
</body>