mirror of
https://github.com/xingsu1021/pthelper.git
synced 2026-06-18 09:47:01 +08:00
新增网站配置导出导入
This commit is contained in:
@@ -425,11 +425,12 @@ def hares(site_name, site_name_cn, site_url, site_cookie):
|
||||
headers = {
|
||||
'user-agent': user_agent,
|
||||
'referer': site_url,
|
||||
'cookie': site_cookie
|
||||
'cookie': site_cookie,
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
|
||||
#获取网站url,不带/结尾
|
||||
sign_url = getSiteUrl(site_url) + '/attendance.php'
|
||||
sign_url = getSiteUrl(site_url) + '/attendance.php?action=sign'
|
||||
|
||||
logger.info('--------------%s开始签到----------------' % site_name)
|
||||
|
||||
@@ -437,32 +438,27 @@ def hares(site_name, site_name_cn, site_url, site_cookie):
|
||||
response = requests.get(sign_url, headers=headers, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
|
||||
html = response.text
|
||||
|
||||
soup = BeautifulSoup(html, "lxml")
|
||||
#script = soup.findAll('script')
|
||||
#sign_data = script[-1]
|
||||
#print(sign_data)
|
||||
pattern = re.compile(r"layer.confirm\('(.*)',")
|
||||
script = soup.find("script", text=pattern)
|
||||
|
||||
if script != None:
|
||||
try:
|
||||
|
||||
data = re.search(r"layer.confirm\('(.*),",str(script)).group()
|
||||
sign_data = data.replace("layer.confirm('",'').replace("。',",'')
|
||||
|
||||
if '签到获得' in sign_data:
|
||||
#替换掉p标签,tg不支持
|
||||
msg = "%s(%s) %s" % (site_name,site_name_cn,sign_data)
|
||||
|
||||
#正确请求,得到json字符串
|
||||
response_msg = json.loads(response.text)
|
||||
if response_msg['code'] == '0':
|
||||
sign_data = response_msg['datas']
|
||||
uid = sign_data['uid']
|
||||
#签到魔力
|
||||
points = sign_data['points']
|
||||
#连续签到天数
|
||||
days = sign_data['days']
|
||||
|
||||
msg = "%s(%s) 签到成功,连续签到%s,今日签到得%s积分" % (site_name,site_name_cn,str(days),str(points))
|
||||
else:
|
||||
msg = "%s(%s) 您今天已经签到过了,请勿重复签到" % (site_name,site_name_cn)
|
||||
else:
|
||||
msg = "%s(%s) cookie失效" % (site_name,site_name_cn)
|
||||
return False, msg
|
||||
msg = "%s(%s) 提示:%s" % (site_name,site_name_cn,response_msg['msg'])
|
||||
|
||||
return True, msg
|
||||
return True, msg
|
||||
except:
|
||||
#失败,返回html
|
||||
msg = "%s(%s) cookie失效" % (site_name,site_name_cn)
|
||||
return False, msg
|
||||
else:
|
||||
msg = "%s(%s) 请求签到地址失败" % (site_name,site_name_cn)
|
||||
logger.error('--------------%s----------------' % site_name)
|
||||
|
||||
@@ -7,13 +7,22 @@
|
||||
<div class="layui-form-item">
|
||||
|
||||
<div class="layui-inline searchInput">
|
||||
<input id="siteconfigSearchValue" class="layui-input" type="text" placeholder="输入关键字"/>
|
||||
<input id="siteconfigSearchValue" class="layui-input" type="text" placeholder="输入关键字" />
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button id="siteconfigBtnSearch" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索
|
||||
</button>
|
||||
<button id="siteconfigBtnAdd" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
<button id="siteconfigBtnDel" class="layui-btn layui-btn-danger icon-btn"><i class="layui-icon"></i>删除</button>
|
||||
<button id="siteconfigBtnAdd" class="layui-btn icon-btn"><i
|
||||
class="layui-icon"></i>添加</button>
|
||||
<button id="siteconfigBtnDel" class="layui-btn layui-btn-danger icon-btn"><i
|
||||
class="layui-icon"></i>删除</button>
|
||||
<button id="siteconfigExportBtn" class="layui-btn icon-btn" type="button">
|
||||
<i class="layui-icon"></i>导出
|
||||
</button>
|
||||
<button id="siteconfigImportBtn" class="layui-btn icon-btn" type="button">
|
||||
<!--i class="layui-icon layui-icon-upload">导入</i-->
|
||||
<i class="layui-icon"></i>导入
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -33,7 +42,7 @@
|
||||
|
||||
|
||||
<script>
|
||||
layui.use(['layer', 'form', 'table', 'tableX', 'util', 'admin', 'xmSelect', 'formX', 'dropdown'], function () {
|
||||
layui.use(['layer', 'form', 'table', 'tableX', 'util', 'admin', 'xmSelect', 'formX', 'dropdown'], function () {
|
||||
var $ = layui.jquery;
|
||||
var layer = layui.layer;
|
||||
var form = layui.form;
|
||||
@@ -52,16 +61,16 @@
|
||||
url: setter.base_server + 'sites/siteconfig/list',
|
||||
method: 'GET',
|
||||
page: true,
|
||||
limit:15,
|
||||
limits:[15,50,100],
|
||||
limit: 15,
|
||||
limits: [15, 50, 100],
|
||||
cols: [[
|
||||
{type: 'checkbox'},
|
||||
{field: 'id', title: 'ID',hide:true},
|
||||
{field: 'name', sort: true, title: '简称EN'},
|
||||
{field: 'name_cn', sort: true, title: '简称CN'},
|
||||
{field: 'index_url', sort: true, title: '网站地址'},
|
||||
{field: 'sign_type', sort: true, title: '签到类型'},
|
||||
{align: 'center', toolbar: '#siteconfigTableBar', title: '操作'}
|
||||
{ type: 'checkbox' },
|
||||
{ field: 'id', title: 'ID', hide: true },
|
||||
{ field: 'name', sort: true, title: '简称EN' },
|
||||
{ field: 'name_cn', sort: true, title: '简称CN' },
|
||||
{ field: 'index_url', sort: true, title: '网站地址' },
|
||||
{ field: 'sign_type', sort: true, title: '签到类型' },
|
||||
{ align: 'center', toolbar: '#siteconfigTableBar', title: '操作' }
|
||||
]]
|
||||
});
|
||||
|
||||
@@ -77,33 +86,33 @@
|
||||
|
||||
if (layEvent === 'edit') { // 修改
|
||||
showEditModel(data);
|
||||
} else if(layEvent === 'del'){
|
||||
} else if (layEvent === 'del') {
|
||||
|
||||
//var csrftoken = getCookie('csrftoken');
|
||||
layer.confirm('确定删除此记录 ' + data.name + '?',{icon: 3, title: '警告', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
$.ajax({
|
||||
url : "sites/siteconfig/del",
|
||||
type: 'POST',
|
||||
dataType : "json",
|
||||
data: {'ids':[data.id], csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
layer.confirm('确定删除此记录 ' + data.name + '?', { icon: 3, title: '警告', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
$.ajax({
|
||||
url: "sites/siteconfig/del",
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
data: { 'ids': [data.id], csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
// beforeSend: function(request) {
|
||||
// //django需要csrf验证,Forbidden (CSRF cookie not set.):
|
||||
// request.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
// },
|
||||
success : function(d) {
|
||||
success: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteconfigTable', {});
|
||||
layer.msg(d.msg, {icon: 1});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, {icon: 2});
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,70 +128,70 @@
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
var showEditModel = function (data) {
|
||||
var title = '编辑';
|
||||
admin.open({
|
||||
title: title,
|
||||
//area: ['600px', '500px'],
|
||||
url: 'sites/siteconfig/edit?id='+data.id,
|
||||
url: 'sites/siteconfig/edit?id=' + data.id,
|
||||
success: function (layero, index) {
|
||||
$(layero).children('.layui-layer-content').css('overflow', 'visible'); // 禁止出现滚动条
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 批量删除按钮点击事件
|
||||
$('#siteconfigBtnDel').click(function () {
|
||||
// 批量删除按钮点击事件
|
||||
$('#siteconfigBtnDel').click(function () {
|
||||
//选中事件
|
||||
var checkStatus = table.checkStatus('siteconfigTable')
|
||||
//得到选择长度
|
||||
dataLength = checkStatus.data.length
|
||||
data = checkStatus.data;
|
||||
var ids = [];
|
||||
if (dataLength==0){
|
||||
if (dataLength == 0) {
|
||||
//未选中
|
||||
layer.msg("请选择需要删除的记录", {icon: 2});
|
||||
}else{
|
||||
layer.confirm('确定删除选中的'+dataLength+'个记录?',{icon: 3, title: '警告', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
$.ajax({
|
||||
url : "sites/siteconfig/del",
|
||||
type: 'POST',
|
||||
dataType : "json",
|
||||
data: {'ids':ids, csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
success : function(d) {
|
||||
layer.msg("请选择需要删除的记录", { icon: 2 });
|
||||
} else {
|
||||
layer.confirm('确定删除选中的' + dataLength + '个记录?', { icon: 3, title: '警告', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
$.ajax({
|
||||
url: "sites/siteconfig/del",
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
data: { 'ids': ids, csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
success: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteconfigTable', {});
|
||||
layer.msg(d.msg, {icon: 1});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, {icon: 2});
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 监听enter键,光标在搜索框
|
||||
$('#siteconfigSearchValue').keydown(function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
var key = 'search';
|
||||
var value = $('#siteconfigSearchValue').val();
|
||||
if (event.keyCode === 13) {
|
||||
var key = 'search';
|
||||
var value = $('#siteconfigSearchValue').val();
|
||||
|
||||
table.reload('siteconfigTable', {where: {searchKey: key, searchValue: value}});
|
||||
} else if (event.keyCode === 8 && !$psw.val()) {
|
||||
$("#siteconfigSearchValue").val('');
|
||||
ptable();
|
||||
if (event.preventDefault) event.preventDefault();
|
||||
if (event.returnValue) event.returnValue = false;
|
||||
}
|
||||
table.reload('siteconfigTable', { where: { searchKey: key, searchValue: value } });
|
||||
} else if (event.keyCode === 8 && !$psw.val()) {
|
||||
$("#siteconfigSearchValue").val('');
|
||||
ptable();
|
||||
if (event.preventDefault) event.preventDefault();
|
||||
if (event.returnValue) event.returnValue = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 搜索按钮点击事件
|
||||
@@ -190,7 +199,78 @@
|
||||
var key = 'search';
|
||||
var value = $('#siteconfigSearchValue').val();
|
||||
|
||||
table.reload('siteconfigTable', {where: {searchKey: key, searchValue: value}});
|
||||
table.reload('siteconfigTable', { where: { searchKey: key, searchValue: value } });
|
||||
});
|
||||
|
||||
|
||||
/* 导出json */
|
||||
$('#siteconfigExportBtn').click(function () {
|
||||
|
||||
var checkStatus = table.checkStatus('siteconfigTable');
|
||||
//得到选择长度
|
||||
dataLength = checkStatus.data.length
|
||||
data = checkStatus.data;
|
||||
var ids = [];
|
||||
if (dataLength == 0) {
|
||||
//未选中
|
||||
layer.confirm('确定导出所有记录?', { icon: 1, title: '提示', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
tableX.exportDataBack('sites/siteconfig/export', {}, 'post');
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
layer.confirm('确定导出选中的' + dataLength + '个记录?', { icon: 1, title: '提示', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
|
||||
fetch("sites/siteconfig/export", {
|
||||
body: JSON.stringify({ 'ids': ids, csrfmiddlewaretoken: '{{ csrf_token }}' }),
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
},
|
||||
})
|
||||
.then(response => response.blob())
|
||||
.then(response => {
|
||||
const blob = new Blob([response], { type: 'application/json' });
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = downloadUrl;
|
||||
a.download = "pthelper站点配置信息";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* 导入json */
|
||||
var uploadInst = upload.render({
|
||||
elem: '#siteconfigImportBtn',
|
||||
url: 'sites/siteconfig/import', //上传接口
|
||||
accept: 'file', //可选值有:images(图片)、file(所有文件)、video(视频)、audio(音频)
|
||||
exts: 'json', //exts: 'zip|rar|7z' 即代表只允许上传压缩格式的文件
|
||||
multiple: false, //多文件上传
|
||||
done: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteconfigTable', {});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
//请求异常回调
|
||||
layer.msg("请求错误", { icon: 2 });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
<div class="layui-form-item">
|
||||
|
||||
<div class="layui-inline searchInput">
|
||||
<input id="siteinfoSearchValue" class="layui-input" type="text" placeholder="输入关键字"/>
|
||||
<input id="siteinfoSearchValue" class="layui-input" type="text" placeholder="输入关键字" />
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button id="siteinfoBtnSearch" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索
|
||||
</button>
|
||||
<button id="siteinfoBtnAdd" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
|
||||
<button id="siteinfoBtnDel" class="layui-btn layui-btn-danger icon-btn"><i class="layui-icon"></i>删除</button>
|
||||
<button id="siteinfoBtnAdd" class="layui-btn icon-btn"><i
|
||||
class="layui-icon"></i>添加</button>
|
||||
<button id="siteinfoBtnDel" class="layui-btn layui-btn-danger icon-btn"><i
|
||||
class="layui-icon"></i>删除</button>
|
||||
<button id="siteinfoExportBtn" class="layui-btn icon-btn" type="button">
|
||||
<i class="layui-icon"></i>导出
|
||||
</button>
|
||||
@@ -41,7 +43,7 @@
|
||||
|
||||
|
||||
<script>
|
||||
layui.use(['layer', 'form', 'table', 'tableX', 'util', 'admin', 'xmSelect', 'formX', 'dropdown','upload'], function () {
|
||||
layui.use(['layer', 'form', 'table', 'tableX', 'util', 'admin', 'xmSelect', 'formX', 'dropdown', 'upload'], function () {
|
||||
var $ = layui.jquery;
|
||||
var layer = layui.layer;
|
||||
var form = layui.form;
|
||||
@@ -61,16 +63,16 @@
|
||||
url: setter.base_server + 'sites/siteinfo/list',
|
||||
method: 'GET',
|
||||
page: true,
|
||||
limit:15,
|
||||
limits:[15,50,100],
|
||||
limit: 15,
|
||||
limits: [15, 50, 100],
|
||||
cols: [[
|
||||
{type: 'checkbox'},
|
||||
{field: 'id', title: 'ID',hide:true},
|
||||
{field: 'siteconfig_name', sort: true, title: '站点'},
|
||||
{field: 'siteconfig_name_cn', sort: true, title: '中文'},
|
||||
{field: 'cookie', title: 'Cookie'},
|
||||
{field: 'passkey', title: 'Passkey'},
|
||||
{align: 'center', toolbar: '#siteinfoTableBar', title: '操作'}
|
||||
{ type: 'checkbox' },
|
||||
{ field: 'id', title: 'ID', hide: true },
|
||||
{ field: 'siteconfig_name', sort: true, title: '站点' },
|
||||
{ field: 'siteconfig_name_cn', sort: true, title: '中文' },
|
||||
{ field: 'cookie', title: 'Cookie' },
|
||||
{ field: 'passkey', title: 'Passkey' },
|
||||
{ align: 'center', toolbar: '#siteinfoTableBar', title: '操作' }
|
||||
]]
|
||||
});
|
||||
|
||||
@@ -86,61 +88,61 @@
|
||||
|
||||
if (layEvent === 'edit') { // 修改
|
||||
showEditModel(data);
|
||||
} else if(layEvent === 'del'){
|
||||
} else if (layEvent === 'del') {
|
||||
|
||||
//var csrftoken = getCookie('csrftoken');
|
||||
layer.confirm('确定删除此记录 ' + data.siteconfig_name + '?',{icon: 3, title: '警告', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
$.ajax({
|
||||
url : "sites/siteinfo/del",
|
||||
type: 'POST',
|
||||
dataType : "json",
|
||||
data: {'ids':[data.id], csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
layer.confirm('确定删除此记录 ' + data.siteconfig_name + '?', { icon: 3, title: '警告', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
$.ajax({
|
||||
url: "sites/siteinfo/del",
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
data: { 'ids': [data.id], csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
// beforeSend: function(request) {
|
||||
// //django需要csrf验证,Forbidden (CSRF cookie not set.):
|
||||
// request.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
// },
|
||||
success : function(d) {
|
||||
success: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteinfoTable', {});
|
||||
layer.msg(d.msg, {icon: 1});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, {icon: 2});
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}else if(layEvent === 'checkSign'){
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (layEvent === 'checkSign') {
|
||||
|
||||
//var csrftoken = getCookie('csrftoken');
|
||||
layer.confirm('确定校验此配置 ' + data.siteconfig_name + '?',{icon: 0, title: '提示', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
$.ajax({
|
||||
url : "common/signcheck",
|
||||
type: 'POST',
|
||||
dataType : "json",
|
||||
data: {'id':data.id, 'action':'check',csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
layer.confirm('确定校验此配置 ' + data.siteconfig_name + '?', { icon: 0, title: '提示', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
$.ajax({
|
||||
url: "common/signcheck",
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
data: { 'id': data.id, 'action': 'check', csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
// beforeSend: function(request) {
|
||||
// //django需要csrf验证,Forbidden (CSRF cookie not set.):
|
||||
// request.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
// },
|
||||
success : function(d) {
|
||||
success: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteinfoTable', {});
|
||||
layer.msg(d.msg, {icon: 1});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, {icon: 2});
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -157,70 +159,70 @@
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
var showEditModel = function (data) {
|
||||
var title = '编辑';
|
||||
admin.open({
|
||||
title: title,
|
||||
area: ['650px', '300px'],
|
||||
url: 'sites/siteinfo/edit?id='+data.id,
|
||||
url: 'sites/siteinfo/edit?id=' + data.id,
|
||||
success: function (layero, index) {
|
||||
$(layero).children('.layui-layer-content').css('overflow', 'visible'); // 禁止出现滚动条
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 批量删除按钮点击事件
|
||||
$('#siteinfoBtnDel').click(function () {
|
||||
// 批量删除按钮点击事件
|
||||
$('#siteinfoBtnDel').click(function () {
|
||||
//选中事件
|
||||
var checkStatus = table.checkStatus('siteinfoTable')
|
||||
//得到选择长度
|
||||
dataLength = checkStatus.data.length
|
||||
data = checkStatus.data;
|
||||
var ids = [];
|
||||
if (dataLength==0){
|
||||
if (dataLength == 0) {
|
||||
//未选中
|
||||
layer.msg("请选择需要删除的记录", {icon: 2});
|
||||
}else{
|
||||
layer.confirm('确定删除选中的'+dataLength+'个记录?',{icon: 3, title: '警告', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
$.ajax({
|
||||
url : "sites/siteinfo/del",
|
||||
type: 'POST',
|
||||
dataType : "json",
|
||||
data: {'ids':ids, csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
success : function(d) {
|
||||
layer.msg("请选择需要删除的记录", { icon: 2 });
|
||||
} else {
|
||||
layer.confirm('确定删除选中的' + dataLength + '个记录?', { icon: 3, title: '警告', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
layer.load(2);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
$.ajax({
|
||||
url: "sites/siteinfo/del",
|
||||
type: 'POST',
|
||||
dataType: "json",
|
||||
data: { 'ids': ids, csrfmiddlewaretoken: '{{ csrf_token }}' },
|
||||
success: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteinfoTable', {});
|
||||
layer.msg(d.msg, {icon: 1});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, {icon: 2});
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 监听enter键,光标在搜索框
|
||||
$('#siteinfoSearchValue').keydown(function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
var key = 'search';
|
||||
var value = $('#siteinfoSearchValue').val();
|
||||
if (event.keyCode === 13) {
|
||||
var key = 'search';
|
||||
var value = $('#siteinfoSearchValue').val();
|
||||
|
||||
table.reload('siteinfoTable', {where: {searchKey: key, searchValue: value}});
|
||||
} else if (event.keyCode === 8 && !$psw.val()) {
|
||||
$("#siteinfoSearchValue").val('');
|
||||
ptable();
|
||||
if (event.preventDefault) event.preventDefault();
|
||||
if (event.returnValue) event.returnValue = false;
|
||||
}
|
||||
table.reload('siteinfoTable', { where: { searchKey: key, searchValue: value } });
|
||||
} else if (event.keyCode === 8 && !$psw.val()) {
|
||||
$("#siteinfoSearchValue").val('');
|
||||
ptable();
|
||||
if (event.preventDefault) event.preventDefault();
|
||||
if (event.returnValue) event.returnValue = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 搜索按钮点击事件
|
||||
@@ -228,7 +230,7 @@
|
||||
var key = 'search';
|
||||
var value = $('#siteinfoSearchValue').val();
|
||||
|
||||
table.reload('siteinfoTable', {where: {searchKey: key, searchValue: value}});
|
||||
table.reload('siteinfoTable', { where: { searchKey: key, searchValue: value } });
|
||||
});
|
||||
|
||||
/* 导出json */
|
||||
@@ -239,43 +241,43 @@
|
||||
dataLength = checkStatus.data.length
|
||||
data = checkStatus.data;
|
||||
var ids = [];
|
||||
if (dataLength==0){
|
||||
if (dataLength == 0) {
|
||||
//未选中
|
||||
layer.confirm('确定导出所有记录?',{icon: 1, title: '提示', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
tableX.exportDataBack('sites/siteinfo/export', {}, 'post');
|
||||
});
|
||||
|
||||
layer.confirm('确定导出所有记录?', { icon: 1, title: '提示', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
tableX.exportDataBack('sites/siteinfo/export', {}, 'post');
|
||||
});
|
||||
|
||||
}else{
|
||||
layer.confirm('确定导出选中的'+dataLength+'个记录?',{icon: 1, title: '提示', shadeClose: true},
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
|
||||
fetch("sites/siteinfo/export", {
|
||||
body: JSON.stringify({'ids':ids, csrfmiddlewaretoken: '{{ csrf_token }}' }),
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
},
|
||||
})
|
||||
.then(response => response.blob())
|
||||
.then(response => {
|
||||
const blob = new Blob([response], {type: 'application/json'});
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = downloadUrl;
|
||||
a.download = "pthelper站点配置信息";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
})
|
||||
} else {
|
||||
layer.confirm('确定导出选中的' + dataLength + '个记录?', { icon: 1, title: '提示', shadeClose: true },
|
||||
function (i) {
|
||||
layer.close(i);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].id);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
fetch("sites/siteinfo/export", {
|
||||
body: JSON.stringify({ 'ids': ids, csrfmiddlewaretoken: '{{ csrf_token }}' }),
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
},
|
||||
})
|
||||
.then(response => response.blob())
|
||||
.then(response => {
|
||||
const blob = new Blob([response], { type: 'application/json' });
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = downloadUrl;
|
||||
a.download = "pthelper站点配置信息";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -286,18 +288,18 @@
|
||||
accept: 'file', //可选值有:images(图片)、file(所有文件)、video(视频)、audio(音频)
|
||||
exts: 'json', //exts: 'zip|rar|7z' 即代表只允许上传压缩格式的文件
|
||||
multiple: false, //多文件上传
|
||||
done: function(d){
|
||||
done: function (d) {
|
||||
layer.closeAll('loading');
|
||||
if (d.code == 1) {
|
||||
table.reload('siteinfoTable', {});
|
||||
layer.msg(d.msg, {icon: 1});
|
||||
layer.msg(d.msg, { icon: 1 });
|
||||
} else {
|
||||
layer.msg(d.msg, {icon: 2});
|
||||
layer.msg(d.msg, { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
error: function () {
|
||||
//请求异常回调
|
||||
layer.msg("请求错误", {icon: 2});
|
||||
layer.msg("请求错误", { icon: 2 });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ urlpatterns = [
|
||||
path('siteconfig/list', views_request.siteconfig),
|
||||
path('siteconfigname/list', views_request.siteconfigname),
|
||||
path('siteconfigname2siteinfo/list', views_request.siteconfigname2siteinfo),
|
||||
path('siteconfig/export', views_request.siteconfigExport),
|
||||
path('siteconfig/import', views_request.siteconfigImport),
|
||||
#站点升级配置
|
||||
path('siterankconfig', views.SiteRankConfigListView.as_view()),
|
||||
path('siterankconfig/add', views.SiteRankConfigAddView.as_view()),
|
||||
@@ -27,8 +29,8 @@ urlpatterns = [
|
||||
path('siteinfo/edit', views.SiteInfoEditView.as_view()),
|
||||
path('siteinfo/del', views.SiteInfoDelView.as_view()),
|
||||
path('siteinfo/list', views_request.siteinfo),
|
||||
path('siteinfo/export', views_request.export),
|
||||
path('siteinfo/import', views_request.importJson),
|
||||
path('siteinfo/export', views_request.siteinfoExport),
|
||||
path('siteinfo/import', views_request.siteinfoImport),
|
||||
|
||||
]
|
||||
|
||||
|
||||
@@ -209,7 +209,104 @@ def get_stream(data):
|
||||
|
||||
#==================
|
||||
@login_required
|
||||
def export(request):
|
||||
def siteconfigExport(request):
|
||||
"""
|
||||
文件导出
|
||||
"""
|
||||
|
||||
ids = []
|
||||
#fetch方法
|
||||
if request.method == "PUT":
|
||||
body = request.body
|
||||
json_body = json.loads(body)
|
||||
|
||||
ids = json_body['ids']
|
||||
|
||||
data = []
|
||||
|
||||
if len(ids) == 0:
|
||||
ormdata = SiteConfig.objects.all()
|
||||
else:
|
||||
ormdata = SiteConfig.objects.filter(id__in=ids)
|
||||
|
||||
for i in ormdata:
|
||||
|
||||
data.append({"name":i.name,
|
||||
"name_cn":i.name_cn,
|
||||
"index_url":i.index_url,
|
||||
"torrent_url":i.torrent_url,
|
||||
"bonus_url":i.bonus_url,
|
||||
"sign_type":i.sign_type,
|
||||
})
|
||||
#print(data)
|
||||
json_stream=get_stream(data)
|
||||
response = HttpResponse(content_type='application/json')
|
||||
|
||||
response['Content-Disposition'] = 'attachment;filename=' + parse.quote('pthelper站点配置') + '.json'
|
||||
response.write(json_stream)
|
||||
|
||||
return response
|
||||
|
||||
#==================
|
||||
@login_required
|
||||
def siteconfigImport(request):
|
||||
"""
|
||||
文件上传
|
||||
"""
|
||||
data = {}
|
||||
data['code'] = 0
|
||||
data['msg'] = ""
|
||||
data['data'] = []
|
||||
|
||||
if request.method == 'POST':
|
||||
file_obj = request.FILES.get('file')
|
||||
#data = get_stream(file_obj)
|
||||
|
||||
file_temp = tempfile.NamedTemporaryFile()
|
||||
file_temp.write(file_obj.read())
|
||||
#res=file_temp.getvalue()
|
||||
file_temp.seek(0)
|
||||
data = file_temp.read()
|
||||
file_temp.close()
|
||||
|
||||
#print(data)
|
||||
try:
|
||||
json_data = json.loads(data)
|
||||
for i in json_data:
|
||||
name = i['name']
|
||||
name_cn = i['name_cn']
|
||||
index_url = i['index_url']
|
||||
torrent_url = i['torrent_url']
|
||||
bonus_url = i['bonus_url']
|
||||
sign_type = i['sign_type']
|
||||
|
||||
get_site = SiteConfig.objects.filter(name=name).count()
|
||||
if get_site == 0:
|
||||
SiteConfig.objects.create(name = name,
|
||||
name_cn = name_cn,
|
||||
index_url = index_url,
|
||||
torrent_url = torrent_url,
|
||||
bonus_url = bonus_url,
|
||||
sign_type = sign_type
|
||||
)
|
||||
else:
|
||||
#更新站点配置
|
||||
SiteConfig.objects.filter(name=name).update(name_cn = name_cn,
|
||||
index_url = index_url,
|
||||
torrent_url = torrent_url,
|
||||
bonus_url = bonus_url,
|
||||
sign_type = sign_type
|
||||
)
|
||||
response_data={"code":1,"msg":"更新成功"}
|
||||
|
||||
except:
|
||||
response_data={"code":0,"msg":"非法文件"}
|
||||
|
||||
return JsonResponse(response_data)
|
||||
|
||||
#==================
|
||||
@login_required
|
||||
def siteinfoExport(request):
|
||||
"""
|
||||
文件导出
|
||||
"""
|
||||
@@ -242,14 +339,14 @@ def export(request):
|
||||
json_stream=get_stream(data)
|
||||
response = HttpResponse(content_type='application/json')
|
||||
|
||||
response['Content-Disposition'] = 'attachment;filename=' + parse.quote('pthelper站点配置信息') + '.json'
|
||||
response['Content-Disposition'] = 'attachment;filename=' + parse.quote('pthelper站点信息') + '.json'
|
||||
response.write(json_stream)
|
||||
|
||||
return response
|
||||
|
||||
#==================
|
||||
@login_required
|
||||
def importJson(request):
|
||||
def siteinfoImport(request):
|
||||
"""
|
||||
文件上传
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user