feat(plugins): Cookie 管理插件(账号/站点 + 刷新记录)
以插件方式新增 Cookie 管理模块,不改动 framework 业务逻辑。
数据层
- CookieUser / CookieSite 两个模型(applications/models/admin_cookie.py)
- 对应 ManageSchema(applications/schemas/admin_cookie.py)
- 模型与 schema 在 applications/{models,schemas}/__init__.py 中注册,便于 Alembic 跟踪
- 新增两个迁移脚本(cookie_site / cookie_user + cookie 站点表)
插件
- plugins/cookieManager/:入口 __init__.py + 三个视图(概览 / 账号 / 站点)
- 后台模板:cookie_user 与 cookie_site 各自的 main/add/edit
- 路由前缀 /system/cookie-user/*、/system/cookie-site/*
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>登录用户</title>
|
||||
{% include 'system/common/header.html' %}
|
||||
</head>
|
||||
<body class="pear-container">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<form class="layui-form" action="" lay-filter="cookie-user-query-form">
|
||||
<div class="layui-form-item" style="margin-bottom: unset;">
|
||||
<label class="layui-form-label">关键词</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="keyword" placeholder="用户名/网站名/链接" class="layui-input">
|
||||
</div>
|
||||
<button class="layui-btn layui-btn-md" lay-submit lay-filter="cookie-user-query">
|
||||
<i class="layui-icon layui-icon-search"></i> 查询
|
||||
</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary layui-btn-md">
|
||||
<i class="layui-icon layui-icon-refresh"></i> 重置
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-md" id="btn-add">
|
||||
<i class="layui-icon layui-icon-add-1"></i> 新增登录用户
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<table id="cookie-user-table" lay-filter="cookie-user-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% include 'system/common/footer.html' %}
|
||||
{% raw %}
|
||||
<script type="text/html" id="col-cookie-user-status">
|
||||
{{# if(d.enable === 1){ }}
|
||||
<span class="layui-badge layui-bg-green">启用</span>
|
||||
{{# } else { }}
|
||||
<span class="layui-badge layui-bg-gray">禁用</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="col-cookie-user-value">
|
||||
{{# var v = d.cookie_value || ''; }}
|
||||
{{# if(v.length > 30){ }}
|
||||
<span title="{{ v }}">{{ v.slice(0, 30) }}...</span>
|
||||
{{# } else { }}
|
||||
<span>{{ v }}</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="col-cookie-user-op">
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
||||
{{# if(d.enable === 1){ }}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="disable">禁用</a>
|
||||
{{# } else { }}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="enable">启用</a>
|
||||
{{# } }}
|
||||
<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="remove">删除</a>
|
||||
</script>
|
||||
{% endraw %}
|
||||
|
||||
<script>
|
||||
layui.use(['table', 'form', 'layer'], function(){
|
||||
var table = layui.table;
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var $ = layui.$;
|
||||
|
||||
var renderTable = function(){
|
||||
var keyword = $('input[name="keyword"]').val() || '';
|
||||
table.render({
|
||||
elem: '#cookie-user-table',
|
||||
url: '/system/cookie-user/data',
|
||||
where: { keyword: keyword },
|
||||
page: true,
|
||||
limit: 20,
|
||||
cols: [[
|
||||
{field: 'id', title: 'ID', width: 60},
|
||||
{field: 'username', title: '用户名', width: 150},
|
||||
{field: 'nickname', title: '昵称', width: 120},
|
||||
{field: 'website_name', title: '网站名称', width: 150},
|
||||
{field: 'website_url', title: '网站链接', minWidth: 200},
|
||||
{field: 'cookie_value', title: 'Cookie值', minWidth: 200, templet: '#col-cookie-user-value'},
|
||||
{field: 'domain', title: '域名', width: 150},
|
||||
{field: 'expiry', title: '过期时间', width: 160},
|
||||
{field: 'enable', title: '状态', width: 80, templet: '#col-cookie-user-status'},
|
||||
{field: 'create_at', title: '创建时间', width: 160},
|
||||
{fixed: 'right', title: '操作', toolbar: '#col-cookie-user-op', width: 200}
|
||||
]],
|
||||
skin: 'line',
|
||||
text: {none: '暂无登录用户'},
|
||||
});
|
||||
};
|
||||
|
||||
renderTable();
|
||||
|
||||
form.on('submit(cookie-user-query)', function(){
|
||||
renderTable();
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#btn-add').on('click', function(){
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '新增登录用户',
|
||||
area: ['700px', '680px'],
|
||||
content: '/system/cookie-user/add'
|
||||
});
|
||||
});
|
||||
|
||||
table.on('tool(cookie-user-table)', function(obj){
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit'){
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '编辑登录用户',
|
||||
area: ['700px', '680px'],
|
||||
content: '/system/cookie-user/edit?cookieUserId=' + data.id
|
||||
});
|
||||
} else if (obj.event === 'remove'){
|
||||
layer.confirm('确定删除该登录用户吗?', function(idx){
|
||||
$.ajax({
|
||||
url: '/system/cookie-user/remove/' + data.id,
|
||||
type: 'DELETE',
|
||||
success: function(res){
|
||||
if (res.code === 0 || res.success) { layer.msg(res.msg); obj.del(); }
|
||||
else layer.msg(res.msg);
|
||||
}
|
||||
});
|
||||
layer.close(idx);
|
||||
});
|
||||
} else if (obj.event === 'enable'){
|
||||
$.ajax({
|
||||
url: '/system/cookie-user/enable',
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({cookieUserId: data.id}),
|
||||
success: function(res){ layer.msg(res.msg); renderTable(); }
|
||||
});
|
||||
} else if (obj.event === 'disable'){
|
||||
$.ajax({
|
||||
url: '/system/cookie-user/disable',
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({cookieUserId: data.id}),
|
||||
success: function(res){ layer.msg(res.msg); renderTable(); }
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user