pycharm下格式化模板文件,统一风格

This commit is contained in:
zhengxinonly
2021-06-13 12:45:11 +08:00
parent d9a5bcb0de
commit 5faf88283f
39 changed files with 2829 additions and 2712 deletions
+226 -226
View File
@@ -37,234 +37,234 @@
</script>
{% include 'admin/common/footer.html' %}
<script>
layui.use(['table', 'form', 'jquery'], function () {
let table = layui.table;
let form = layui.form;
let $ = layui.jquery;
let cols = [
[
{
type: 'checkbox'
},
{
field: 'id',
title: 'ID',
sort: true,
align: 'center',
unresize: true,
width: 80
},
{
field: 'name',
title: '文件名称',
unresize: true,
align: 'center'
},
{
field: 'href',
title: '图片',
unresize: true,
align: 'center',
templet: function (d) {
return '<img class="photo" style="max-width: 100%;\n' +
' height: 100%;\n' +
' cursor: pointer;" lay-event="photo" src=" ' + d.href + '"></i>';
}
layui.use(['table', 'form', 'jquery'], function () {
let table = layui.table
let form = layui.form
let $ = layui.jquery
let cols = [
[
{
type: 'checkbox'
},
{
field: 'id',
title: 'ID',
sort: true,
align: 'center',
unresize: true,
width: 80
},
{
field: 'name',
title: '文件名称',
unresize: true,
align: 'center'
},
{
field: 'href',
title: '图片',
unresize: true,
align: 'center',
templet: function (d) {
return '<img class="photo" style="max-width: 100%;\n' +
' height: 100%;\n' +
' cursor: pointer;" lay-event="photo" src=" ' + d.href + '"></i>'
}
},
{
field: 'mime',
title: 'mime类型',
unresize: true,
align: 'center'
},
{
field: 'size',
title: '文件大小',
unresize: true,
align: 'center'
},
{
field: 'create_time',
title: '创建时间',
templet: '#file-uploadTime',
unresize: true,
align: 'center'
},
{
title: '操作',
toolbar: '#user-bar',
align: 'center',
unresize: true,
width: 200
}
]
];
table.render({
elem: '#dataTable',
url: 'table',
page: true,
cols: cols,
skin: 'line',
toolbar: '#toolbar',
defaultToolbar: [{
layEvent: 'refresh',
icon: 'layui-icon-refresh',
}, 'filter', 'print', 'exports']
});
table.on('tool(dataTable)', function (obj) {
if (obj.event === 'remove') {
window.remove(obj);
} else if (obj.event === 'photo') {
window.photo(obj);
}
});
table.on('toolbar(dataTable)', function (obj) {
if (obj.event === 'add') {
window.add();
} else if (obj.event === 'refresh') {
window.refresh();
} else if (obj.event === 'batchRemove') {
window.batchRemove(obj);
}
});
//弹出窗设置 自己设置弹出百分比
function screen() {
if (typeof width !== 'number' || width === 0) {
width = $(window).width() * 0.8;
}
if (typeof height !== 'number' || height === 0) {
height = $(window).height() - 20;
}
return [width + 'px', height + 'px'];
},
{
field: 'mime',
title: 'mime类型',
unresize: true,
align: 'center'
},
{
field: 'size',
title: '文件大小',
unresize: true,
align: 'center'
},
{
field: 'create_time',
title: '创建时间',
templet: '#file-uploadTime',
unresize: true,
align: 'center'
},
{
title: '操作',
toolbar: '#user-bar',
align: 'center',
unresize: true,
width: 200
}
]
]
window.add = function () {
layer.open({
type: 2,
maxmin: true,
title: '新增图片',
shade: 0.1,
area: screen(),
content: 'upload'
});
};
window.remove = function (obj) {
layer.confirm('确定要删除该图片', {
icon: 3,
title: '提示'
}, function (index) {
layer.close(index);
let loading = layer.load();
$.ajax({
url: 'delete',
data: {id: obj.data['id']},
dataType: 'json',
type: 'POST',
success: function (res) {
layer.close(loading);
if (res.success) {
layer.msg(res.msg, {
icon: 1,
time: 1000
}, function () {
obj.del();
});
} else {
layer.msg(res.msg, {
icon: 2,
time: 1000
});
}
}
})
});
};
window.batchRemove = function (obj) {
let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) {
layer.msg("未选中数据", {
icon: 3,
time: 1000
});
return false;
}
var ids = [];
var hasCheck = table.checkStatus('dataTable');
var hasCheckData = hasCheck.data;
if (hasCheckData.length > 0) {
$.each(hasCheckData, function (index, element) {
ids.push(element.id)
})
}
layer.confirm('确定要删除这些图片', {
icon: 3,
title: '提示'
}, function (index) {
layer.close(index);
let loading = layer.load();
$.ajax({
url: "{{ url_for('adminFile.batch_remove') }}",
data: {ids: ids},
dataType: 'json',
type: 'POST',
success: function (res) {
layer.close(loading);
if (res.success) {
layer.msg(res.msg, {
icon: 1,
time: 1000
}, function () {
table.reload('dataTable');
});
} else {
layer.msg(res.msg, {
icon: 2,
time: 1000
});
}
}
})
});
};
window.refresh = function () {
table.reload('dataTable');
};
// 查看大图
window.photo = function (obj) {
if (!obj.data.href || obj.data.href === "") {
layer.msg("图片地址错误!");
return;
}
var auto_img = {};
var img = new Image();
img.src = obj.data.href;
img.onload = function () {
var max_height = $(window).height() - 100;
var max_width = $(window).width();
var rate1 = max_height / img.height;
var rate2 = max_width / img.width;
var rate3 = 1;
var rate = Math.min(rate1, rate2, rate3);
auto_img.height = img.height * rate;
auto_img.width = img.width * rate;
layer.open({
type: 1,
title: false,
area: ['auto'],
skin: 'layui-layer-nobg', //没有背景色
shadeClose: true,
content: "<img src='" + obj.data['href'] + "' width='" + auto_img.width + "px' height='" + auto_img.height + "px'>"
});
}
};
table.render({
elem: '#dataTable',
url: 'table',
page: true,
cols: cols,
skin: 'line',
toolbar: '#toolbar',
defaultToolbar: [{
layEvent: 'refresh',
icon: 'layui-icon-refresh',
}, 'filter', 'print', 'exports']
})
table.on('tool(dataTable)', function (obj) {
if (obj.event === 'remove') {
window.remove(obj)
} else if (obj.event === 'photo') {
window.photo(obj)
}
})
table.on('toolbar(dataTable)', function (obj) {
if (obj.event === 'add') {
window.add()
} else if (obj.event === 'refresh') {
window.refresh()
} else if (obj.event === 'batchRemove') {
window.batchRemove(obj)
}
})
//弹出窗设置 自己设置弹出百分比
function screen () {
if (typeof width !== 'number' || width === 0) {
width = $(window).width() * 0.8
}
if (typeof height !== 'number' || height === 0) {
height = $(window).height() - 20
}
return [width + 'px', height + 'px']
}
window.add = function () {
layer.open({
type: 2,
maxmin: true,
title: '新增图片',
shade: 0.1,
area: screen(),
content: 'upload'
})
}
window.remove = function (obj) {
layer.confirm('确定要删除该图片', {
icon: 3,
title: '提示'
}, function (index) {
layer.close(index)
let loading = layer.load()
$.ajax({
url: 'delete',
data: { id: obj.data['id'] },
dataType: 'json',
type: 'POST',
success: function (res) {
layer.close(loading)
if (res.success) {
layer.msg(res.msg, {
icon: 1,
time: 1000
}, function () {
obj.del()
})
} else {
layer.msg(res.msg, {
icon: 2,
time: 1000
})
}
}
})
})
}
window.batchRemove = function (obj) {
let data = table.checkStatus(obj.config.id).data
if (data.length === 0) {
layer.msg('未选中数据', {
icon: 3,
time: 1000
})
return false
}
var ids = []
var hasCheck = table.checkStatus('dataTable')
var hasCheckData = hasCheck.data
if (hasCheckData.length > 0) {
$.each(hasCheckData, function (index, element) {
ids.push(element.id)
})
}
layer.confirm('确定要删除这些图片', {
icon: 3,
title: '提示'
}, function (index) {
layer.close(index)
let loading = layer.load()
$.ajax({
url: "{{ url_for('adminFile.batch_remove') }}",
data: { ids: ids },
dataType: 'json',
type: 'POST',
success: function (res) {
layer.close(loading)
if (res.success) {
layer.msg(res.msg, {
icon: 1,
time: 1000
}, function () {
table.reload('dataTable')
})
} else {
layer.msg(res.msg, {
icon: 2,
time: 1000
})
}
}
})
})
}
window.refresh = function () {
table.reload('dataTable')
}
// 查看大图
window.photo = function (obj) {
if (!obj.data.href || obj.data.href === '') {
layer.msg('图片地址错误!')
return
}
var auto_img = {}
var img = new Image()
img.src = obj.data.href
img.onload = function () {
var max_height = $(window).height() - 100
var max_width = $(window).width()
var rate1 = max_height / img.height
var rate2 = max_width / img.width
var rate3 = 1
var rate = Math.min(rate1, rate2, rate3)
auto_img.height = img.height * rate
auto_img.width = img.width * rate
layer.open({
type: 1,
title: false,
area: ['auto'],
skin: 'layui-layer-nobg', //没有背景色
shadeClose: true,
content: '<img src=\'' + obj.data['href'] + '\' width=\'' + auto_img.width + 'px\' height=\'' + auto_img.height + 'px\'>'
})
}
}
})
</script>