完善资源模块
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php /*a:1:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\login\index.php";i:1745855804;}*/ ?>
|
||||
<?php /*a:1:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\login\index.php";i:1747321871;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="account"></label>
|
||||
<input type="text" id="account" name="account" placeholder="邮箱" class="layui-input"
|
||||
value="357099073@qq.com">
|
||||
value="">
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
|
||||
<input type="password" name="password" class="layui-input" placeholder="密码" class="layui-input"
|
||||
<input type="password" name="password" lay-affix="eye" class="layui-input" placeholder="密码" class="layui-input"
|
||||
value="">
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
<?php /*a:2:{s:52:"E:\Demo\PHP\yunzer\app\admin\view\resources\edit.php";i:1747409592;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo htmlentities((string) $config['admin_name']); ?></title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
.header span{background:#009688;margin-left:30px;padding:10px;color:#ffffff;}
|
||||
.header div{border-bottom:solid 2px #009688;margin-top: 8px;}
|
||||
.header button{float:right;margin-top:-5px;}
|
||||
.pagination {
|
||||
display: inline-block;
|
||||
padding-left: 0;
|
||||
margin: 20px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.pagination > li {
|
||||
display: inline;
|
||||
}
|
||||
.pagination > li > a,
|
||||
.pagination > li > span {
|
||||
position: relative;
|
||||
float: left;
|
||||
padding: 6px 12px;
|
||||
margin-left: -1px;
|
||||
line-height: 1.42857143;
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.pagination > li:first-child > a,
|
||||
.pagination > li:first-child > span {
|
||||
margin-left: 0;
|
||||
border-top-left-radius: 4px;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
.pagination > li:last-child > a,
|
||||
.pagination > li:last-child > span {
|
||||
border-top-right-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
.pagination > li > a:hover,
|
||||
.pagination > li > span:hover,
|
||||
.pagination > li > a:focus,
|
||||
.pagination > li > span:focus {
|
||||
z-index: 2;
|
||||
color: #23527c;
|
||||
background-color: #eee;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.pagination > .active > a,
|
||||
.pagination > .active > span,
|
||||
.pagination > .active > a:hover,
|
||||
.pagination > .active > span:hover,
|
||||
.pagination > .active > a:focus,
|
||||
.pagination > .active > span:focus {
|
||||
z-index: 3;
|
||||
color: #fff;
|
||||
cursor: default;
|
||||
background-color: #337ab7;
|
||||
border-color: #337ab7;
|
||||
}
|
||||
.pagination > .disabled > span,
|
||||
.pagination > .disabled > span:hover,
|
||||
.pagination > .disabled > span:focus,
|
||||
.pagination > .disabled > a,
|
||||
.pagination > .disabled > a:hover,
|
||||
.pagination > .disabled > a:focus {
|
||||
color: #777;
|
||||
cursor: not-allowed;
|
||||
background-color: #fff;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
form = layui.form; // layui form表单
|
||||
table = layui.table; // layui 表格
|
||||
laydate = layui.laydate; // layui 时间框
|
||||
element = layui.element; // layui element
|
||||
upload = layui.upload; // layui 上传
|
||||
$ = layui.jquery; // layui jquery
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body style="padding:10px; box-sizing: border-box;">
|
||||
<div class="config-container">
|
||||
<div class="config-header" style="display:flex;justify-content: space-between;">
|
||||
<div>
|
||||
<span>编辑资源</span>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="goBack()">
|
||||
<i class="layui-icon layui-icon-return"></i>返回
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form class="layui-form" action="" method="post">
|
||||
<input type="hidden" name="id" value="<?php echo htmlentities((string) (isset($resource['id']) && ($resource['id'] !== '')?$resource['id']:'')); ?>">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="title" required lay-verify="required" placeholder="请输入资源名称" autocomplete="off"
|
||||
class="layui-input" value="<?php echo htmlentities((string) (isset($resource['title']) && ($resource['title'] !== '')?$resource['title']:'')); ?>" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="cate" lay-verify="required">
|
||||
<option value="">请选择分类</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">描述</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="desc" placeholder="请输入资源描述" class="layui-textarea" lay-affix="clear"><?php echo htmlentities((string) (isset($resource['desc']) && ($resource['desc'] !== '')?$resource['desc']:'')); ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">上传者</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="uploader" required lay-verify="required" placeholder="请输入上传者"
|
||||
autocomplete="off" class="layui-input" value="<?php echo htmlentities((string) (isset($resource['uploader']) && ($resource['uploader'] !== '')?$resource['uploader']:'')); ?>" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源图标</label>
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn" id="upload-btn">
|
||||
<i class="layui-icon layui-icon-upload"></i> 图标上传
|
||||
</button>
|
||||
<div style="width: 120px;">
|
||||
<div class="layui-upload-list">
|
||||
<img class="layui-upload-img" id="upload-img"
|
||||
style="width: 118px; height: 118px;object-fit: cover;">
|
||||
<div id="upload-text"></div>
|
||||
</div>
|
||||
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="icon-progress">
|
||||
<div class="layui-progress-bar" lay-percent=""></div>
|
||||
</div>
|
||||
<input type="hidden" name="icon" id="icon" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">建议尺寸:128px * 128px</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源文件</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="fileurl" required placeholder="本地资源地址" autocomplete="off"
|
||||
class="layui-input" value="<?php echo htmlentities((string) (isset($resource['fileurl']) && ($resource['fileurl'] !== '')?$resource['fileurl']:'')); ?>" style="margin-bottom: 10px;" lay-affix="clear">
|
||||
<div class="layui-upload-drag" style="display: block;" id="ID-upload-demo-drag">
|
||||
<i class="layui-icon layui-icon-upload"></i>
|
||||
<div>点击上传,或将文件拖拽到此处</div>
|
||||
<div class="layui-hide" id="ID-upload-demo-preview">
|
||||
<hr>
|
||||
<div class="file-info">
|
||||
<i class="layui-icon layui-icon-file"></i>
|
||||
<span class="file-name"></span>
|
||||
<span class="file-size"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="file-progress" style="margin-top: 10px;">
|
||||
<div class="layui-progress-bar" lay-percent=""></div>
|
||||
</div>
|
||||
<input type="hidden" name="file" id="file" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源链接</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="url" required placeholder="百度网盘、115网盘、蓝奏云等" autocomplete="off"
|
||||
class="layui-input" value="<?php echo htmlentities((string) (isset($resource['url']) && ($resource['url'] !== '')?$resource['url']:'')); ?>" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分享码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="code" required placeholder="请输入分享码" autocomplete="off"
|
||||
class="layui-input" value="<?php echo htmlentities((string) (isset($resource['code']) && ($resource['code'] !== '')?$resource['code']:'')); ?>" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="sort" value="<?php echo htmlentities((string) (isset($resource['sort']) && ($resource['sort'] !== '')?$resource['sort']:'0')); ?>" class="layui-input" placeholder="数字越大越靠前" lay-affix="clear">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var $ = layui.$;
|
||||
var upload = layui.upload;
|
||||
var element = layui.element;
|
||||
|
||||
// 获取资源详情
|
||||
var resourceId = $('input[name="id"]').val();
|
||||
var resourceData = null;
|
||||
|
||||
if (resourceId) {
|
||||
$.get('<?php echo url("resources/get"); ?>', {id: resourceId}, function(res) {
|
||||
if (res.code == 0) {
|
||||
resourceData = res.data;
|
||||
console.log('Resource data:', resourceData); // 调试输出
|
||||
|
||||
// 设置表单值
|
||||
$('input[name="title"]').val(resourceData.title || '');
|
||||
$('select[name="cate"]').val(resourceData.cate || '');
|
||||
form.render('select'); // 重新渲染select以显示选中值
|
||||
$('textarea[name="desc"]').val(resourceData.desc || '');
|
||||
$('input[name="uploader"]').val(resourceData.uploader || '');
|
||||
$('input[name="url"]').val(resourceData.url || '');
|
||||
$('input[name="code"]').val(resourceData.code || '');
|
||||
$('input[name="sort"]').val(resourceData.sort || '0');
|
||||
$('input[name="icon"]').val(resourceData.icon || '');
|
||||
$('input[name="file"]').val(resourceData.file || '');
|
||||
|
||||
// 设置图标预览
|
||||
if (resourceData.icon) {
|
||||
$('#upload-img').attr('src', resourceData.icon);
|
||||
}
|
||||
|
||||
// 设置文件预览
|
||||
if (resourceData.file) {
|
||||
$('#ID-upload-demo-preview').show();
|
||||
$('.file-name').text(resourceData.file_name || '已上传文件');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 图标上传
|
||||
var iconUpload = upload.render({
|
||||
elem: '#upload-btn',
|
||||
url: '<?php echo url("index/upload_img"); ?>',
|
||||
before: function (obj) {
|
||||
obj.preview(function (index, file, result) {
|
||||
$('#upload-img').attr('src', result);
|
||||
});
|
||||
element.progress('icon-progress', '0%');
|
||||
layer.msg('图标上传中', { icon: 16, time: 0 });
|
||||
},
|
||||
done: function (res) {
|
||||
if (res.code > 0) {
|
||||
return layer.msg('图标上传失败');
|
||||
}
|
||||
$('#icon').val(res.data);
|
||||
$('#upload-text').html('');
|
||||
layer.msg('图标上传成功', { icon: 1 });
|
||||
},
|
||||
uploadError: function () {
|
||||
var demoText = $('#upload-text');
|
||||
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
|
||||
demoText.find('.demo-reload').on('click', function () {
|
||||
iconUpload.upload();
|
||||
});
|
||||
},
|
||||
progress: function (n, elem, e) {
|
||||
element.progress('icon-progress', n + '%');
|
||||
if (n == 100) {
|
||||
layer.msg('图标上传完毕', { icon: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 文件上传
|
||||
var fileUpload = upload.render({
|
||||
elem: '#ID-upload-demo-drag',
|
||||
url: '<?php echo url("index/upload_file"); ?>',
|
||||
accept: 'file',
|
||||
exts: 'doc|docx|xls|xlsx|ppt|pptx|pdf|txt|zip|rar|7z',
|
||||
before: function (obj) {
|
||||
obj.preview(function (index, file, result) {
|
||||
$('#ID-upload-demo-preview').show();
|
||||
$('.file-name').text(file.name);
|
||||
$('.file-size').text(formatFileSize(file.size));
|
||||
});
|
||||
element.progress('file-progress', '0%');
|
||||
layer.msg('文件上传中', { icon: 16, time: 0 });
|
||||
},
|
||||
done: function (res) {
|
||||
if (res.code > 0) {
|
||||
return layer.msg('文件上传失败');
|
||||
}
|
||||
$('#file').val(res.data.src);
|
||||
$('input[name="fileurl"]').val(res.data.src);
|
||||
layer.msg('文件上传成功', { icon: 1 });
|
||||
},
|
||||
uploadError: function () {
|
||||
layer.msg('文件上传失败', { icon: 2 });
|
||||
},
|
||||
progress: function (n, elem, e) {
|
||||
element.progress('file-progress', n + '%');
|
||||
if (n == 100) {
|
||||
layer.msg('文件上传完毕', { icon: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 格式化文件大小
|
||||
function formatFileSize(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
// 获取分类列表
|
||||
$.get('<?php echo url("resources/getcate"); ?>', function (res) {
|
||||
if (res.code == 0) {
|
||||
var html = '<option value="">请选择分类</option>';
|
||||
res.data.forEach(function (item) {
|
||||
html += '<option value="' + item.id + '">' + item.name + '</option>';
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(function (child) {
|
||||
html += '<option value="' + child.id + '">├─ ' + child.name + '</option>';
|
||||
});
|
||||
}
|
||||
});
|
||||
$('select[name="cate"]').html(html);
|
||||
|
||||
// 如果有资源数据,设置分类值
|
||||
if (resourceData && resourceData.cate) {
|
||||
console.log('Setting cate value:', resourceData.cate); // 调试输出
|
||||
setTimeout(function() {
|
||||
$('select[name="cate"]').val(resourceData.cate);
|
||||
form.render('select');
|
||||
}, 100);
|
||||
}
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
|
||||
// 表单提交
|
||||
form.on('submit(formSubmit)', function (data) {
|
||||
var loadIndex = layer.load(2);
|
||||
$.ajax({
|
||||
url: '<?php echo url("resources/edit"); ?>',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function (res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
window.location.href = '<?php echo url("resources/lists"); ?>';
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// 重置按钮点击事件
|
||||
$('button[type="reset"]').on('click', function() {
|
||||
// 重新加载分类列表
|
||||
$.get('<?php echo url("resources/getcate"); ?>', function (res) {
|
||||
if (res.code == 0) {
|
||||
var html = '<option value="">请选择分类</option>';
|
||||
res.data.forEach(function (item) {
|
||||
html += '<option value="' + item.id + '">' + item.name + '</option>';
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(function (child) {
|
||||
html += '<option value="' + child.id + '">├─ ' + child.name + '</option>';
|
||||
});
|
||||
}
|
||||
});
|
||||
$('select[name="cate"]').html(html);
|
||||
|
||||
// 如果有资源数据,设置分类值
|
||||
if (resourceData && resourceData.cate) {
|
||||
setTimeout(function() {
|
||||
$('select[name="cate"]').val(resourceData.cate);
|
||||
form.render('select');
|
||||
}, 100);
|
||||
} else {
|
||||
form.render('select');
|
||||
}
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
//返回资源列表
|
||||
function goBack() {
|
||||
window.location.href = '<?php echo url("resources/lists"); ?>';
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,348 @@
|
||||
<?php /*a:2:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\resources\add.php";i:1747406940;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo htmlentities((string) $config['admin_name']); ?></title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
.header span{background:#009688;margin-left:30px;padding:10px;color:#ffffff;}
|
||||
.header div{border-bottom:solid 2px #009688;margin-top: 8px;}
|
||||
.header button{float:right;margin-top:-5px;}
|
||||
.pagination {
|
||||
display: inline-block;
|
||||
padding-left: 0;
|
||||
margin: 20px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.pagination > li {
|
||||
display: inline;
|
||||
}
|
||||
.pagination > li > a,
|
||||
.pagination > li > span {
|
||||
position: relative;
|
||||
float: left;
|
||||
padding: 6px 12px;
|
||||
margin-left: -1px;
|
||||
line-height: 1.42857143;
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.pagination > li:first-child > a,
|
||||
.pagination > li:first-child > span {
|
||||
margin-left: 0;
|
||||
border-top-left-radius: 4px;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
.pagination > li:last-child > a,
|
||||
.pagination > li:last-child > span {
|
||||
border-top-right-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
.pagination > li > a:hover,
|
||||
.pagination > li > span:hover,
|
||||
.pagination > li > a:focus,
|
||||
.pagination > li > span:focus {
|
||||
z-index: 2;
|
||||
color: #23527c;
|
||||
background-color: #eee;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.pagination > .active > a,
|
||||
.pagination > .active > span,
|
||||
.pagination > .active > a:hover,
|
||||
.pagination > .active > span:hover,
|
||||
.pagination > .active > a:focus,
|
||||
.pagination > .active > span:focus {
|
||||
z-index: 3;
|
||||
color: #fff;
|
||||
cursor: default;
|
||||
background-color: #337ab7;
|
||||
border-color: #337ab7;
|
||||
}
|
||||
.pagination > .disabled > span,
|
||||
.pagination > .disabled > span:hover,
|
||||
.pagination > .disabled > span:focus,
|
||||
.pagination > .disabled > a,
|
||||
.pagination > .disabled > a:hover,
|
||||
.pagination > .disabled > a:focus {
|
||||
color: #777;
|
||||
cursor: not-allowed;
|
||||
background-color: #fff;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
form = layui.form; // layui form表单
|
||||
table = layui.table; // layui 表格
|
||||
laydate = layui.laydate; // layui 时间框
|
||||
element = layui.element; // layui element
|
||||
upload = layui.upload; // layui 上传
|
||||
$ = layui.jquery; // layui jquery
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body style="padding:10px; box-sizing: border-box;">
|
||||
<div class="config-container">
|
||||
<div class="config-header" style="display:flex;justify-content: space-between;">
|
||||
<div>
|
||||
<span>添加资源</span>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="goBack()">
|
||||
<i class="layui-icon layui-icon-return"></i>返回
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form class="layui-form" action="" method="post">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="name" required lay-verify="required" placeholder="请输入资源名称" autocomplete="off"
|
||||
class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="cate" lay-verify="required">
|
||||
<option value="">请选择分类</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">描述</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="desc" placeholder="请输入资源描述" class="layui-textarea"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">上传者</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="uploader" required lay-verify="required" placeholder="请输入上传者"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源图标</label>
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn" id="upload-btn">
|
||||
<i class="layui-icon layui-icon-upload"></i> 图标上传
|
||||
</button>
|
||||
<div style="width: 120px;">
|
||||
<div class="layui-upload-list">
|
||||
<img class="layui-upload-img" id="upload-img"
|
||||
style="width: 118px; height: 118px;object-fit: cover;">
|
||||
<div id="upload-text"></div>
|
||||
</div>
|
||||
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="icon-progress">
|
||||
<div class="layui-progress-bar" lay-percent=""></div>
|
||||
</div>
|
||||
<input type="hidden" name="icon" id="icon" value="">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">建议尺寸:128px * 128px</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源文件</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-upload-drag" style="display: block;" id="ID-upload-demo-drag">
|
||||
<i class="layui-icon layui-icon-upload"></i>
|
||||
<div>点击上传,或将文件拖拽到此处</div>
|
||||
<div class="layui-hide" id="ID-upload-demo-preview">
|
||||
<hr>
|
||||
<div class="file-info">
|
||||
<i class="layui-icon layui-icon-file"></i>
|
||||
<span class="file-name"></span>
|
||||
<span class="file-size"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="file-progress" style="margin-top: 10px;">
|
||||
<div class="layui-progress-bar" lay-percent=""></div>
|
||||
</div>
|
||||
<input type="hidden" name="file" id="file" value="">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源链接</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="url" required placeholder="百度网盘、115网盘、蓝奏云等" autocomplete="off"
|
||||
class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分享码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="code" required placeholder="请输入分享码" autocomplete="off"
|
||||
class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="sort" value="0" class="layui-input" placeholder="数字越大越靠前">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
layui.use(['form', 'layer'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var $ = layui.$;
|
||||
var upload = layui.upload;
|
||||
var element = layui.element;
|
||||
|
||||
// 图标上传
|
||||
var iconUpload = upload.render({
|
||||
elem: '#upload-btn',
|
||||
url: '<?php echo url("index/upload_img"); ?>',
|
||||
before: function (obj) {
|
||||
obj.preview(function (index, file, result) {
|
||||
$('#upload-img').attr('src', result);
|
||||
});
|
||||
element.progress('icon-progress', '0%');
|
||||
layer.msg('图标上传中', { icon: 16, time: 0 });
|
||||
},
|
||||
done: function (res) {
|
||||
if (res.code > 0) {
|
||||
return layer.msg('图标上传失败');
|
||||
}
|
||||
$('#icon').val(res.data);
|
||||
$('#upload-text').html('');
|
||||
layer.msg('图标上传成功', { icon: 1 });
|
||||
},
|
||||
uploadError: function () {
|
||||
var demoText = $('#upload-text');
|
||||
demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
|
||||
demoText.find('.demo-reload').on('click', function () {
|
||||
iconUpload.upload();
|
||||
});
|
||||
},
|
||||
progress: function (n, elem, e) {
|
||||
element.progress('icon-progress', n + '%');
|
||||
if (n == 100) {
|
||||
layer.msg('图标上传完毕', { icon: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 文件上传
|
||||
var fileUpload = upload.render({
|
||||
elem: '#ID-upload-demo-drag',
|
||||
url: '<?php echo url("index/upload_file"); ?>',
|
||||
accept: 'file',
|
||||
exts: 'doc|docx|xls|xlsx|ppt|pptx|pdf|txt|zip|rar|7z',
|
||||
before: function (obj) {
|
||||
obj.preview(function (index, file, result) {
|
||||
$('#ID-upload-demo-preview').show();
|
||||
$('.file-name').text(file.name);
|
||||
$('.file-size').text(formatFileSize(file.size));
|
||||
});
|
||||
element.progress('file-progress', '0%');
|
||||
layer.msg('文件上传中', { icon: 16, time: 0 });
|
||||
},
|
||||
done: function (res) {
|
||||
if (res.code > 0) {
|
||||
return layer.msg('文件上传失败');
|
||||
}
|
||||
$('#file').val(res.data.src);
|
||||
layer.msg('文件上传成功', { icon: 1 });
|
||||
},
|
||||
uploadError: function () {
|
||||
layer.msg('文件上传失败', { icon: 2 });
|
||||
},
|
||||
progress: function (n, elem, e) {
|
||||
element.progress('file-progress', n + '%');
|
||||
if (n == 100) {
|
||||
layer.msg('文件上传完毕', { icon: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 格式化文件大小
|
||||
function formatFileSize(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
// 获取分类列表
|
||||
$.get('<?php echo url("resources/getcate"); ?>', function (res) {
|
||||
if (res.code == 0) {
|
||||
var html = '<option value="">请选择分类</option>';
|
||||
res.data.forEach(function (item) {
|
||||
var disabled = item.cid == 0 ? 'disabled' : '';
|
||||
html += '<option value="' + item.id + '" ' + disabled + '>' + item.name + '</option>';
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(function (child) {
|
||||
html += '<option value="' + child.id + '">├─ ' + child.name + '</option>';
|
||||
});
|
||||
}
|
||||
});
|
||||
$('select[name="cate"]').html(html);
|
||||
form.render('select');
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
|
||||
// 表单提交
|
||||
form.on('submit(formSubmit)', function (data) {
|
||||
var loadIndex = layer.load(2);
|
||||
$.ajax({
|
||||
url: '<?php echo url("resources/add"); ?>',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function (res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
window.location.href = '<?php echo url("resources/lists"); ?>';
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
//返回资源列表
|
||||
function goBack() {
|
||||
window.location.href = '<?php echo url("resources/lists"); ?>';
|
||||
}
|
||||
</script>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php /*a:1:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\index\index.php";i:1746796639;}*/ ?>
|
||||
<?php /*a:1:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\index\index.php";i:1747402501;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@@ -18,6 +18,43 @@
|
||||
width: 60px;
|
||||
background-image: url("/static/images/logob32.jpg");
|
||||
}
|
||||
.main-content {
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
}
|
||||
#mainWorkspace {
|
||||
height: 100%;
|
||||
}
|
||||
#mainTabs.layui-tab {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
.layui-tab-content {
|
||||
padding: 0;
|
||||
height: calc(100% - 41px);
|
||||
}
|
||||
.layui-tab-item {
|
||||
height: 100%;
|
||||
}
|
||||
.main-iframe {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
/* background-color: #f2f2f2; */
|
||||
}
|
||||
.layui-tab-title {
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 2px 0 rgba(0,0,0,.1);
|
||||
}
|
||||
.layui-tab-title .layui-this:after {
|
||||
border-bottom-color: #009688;
|
||||
}
|
||||
#LAY_app_body {
|
||||
overflow: hidden;
|
||||
}
|
||||
.layui-tab-content .layui-tab-item {
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -69,9 +106,20 @@
|
||||
</div>
|
||||
<ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu"
|
||||
lay-filter="layadmin-system-side-menu">
|
||||
<!-- 固定的工作台菜单项 -->
|
||||
<li class="layui-nav-item" data-name="index/welcome">
|
||||
<a href="javascript:;" lay-tips="工作台" lay-direction="2"
|
||||
onclick="menuFire('index/welcome',1)">
|
||||
<i class="layui-icon layui-icon-home" style="margin-top: -30px;"></i>
|
||||
<cite>工作台</cite>
|
||||
</a>
|
||||
</li>
|
||||
<!-- 下面是原有的菜单循环 -->
|
||||
<?php if(is_array($menu) || $menu instanceof \think\Collection || $menu instanceof \think\Paginator): $i = 0; $__LIST__ = $menu;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
|
||||
<li data-name="" data-jump="" class="layui-nav-item">
|
||||
<a href="javascript:;" lay-tips="<?php echo htmlentities((string) $vo['label']); ?>" lay-direction="2">
|
||||
<li data-name="<?php echo htmlentities((string) $vo['src']); ?>" data-jump="" class="layui-nav-item">
|
||||
<!-- 修改一级菜单的点击事件,只有当有src时才跳转 -->
|
||||
<a href="javascript:;" lay-tips="<?php echo htmlentities((string) $vo['label']); ?>" lay-direction="2" <?php if(isset($vo['src']) &&
|
||||
$vo['src']): ?>onclick="menuFire('<?php echo htmlentities((string) $vo['src']); ?>',1)" <?php endif; ?>>
|
||||
<i class="layui-icon layui-icons <?php echo htmlentities((string) $vo['icon_class']); ?>"></i>
|
||||
<cite><?php echo htmlentities((string) $vo['label']); ?></cite>
|
||||
</a>
|
||||
@@ -102,12 +150,15 @@
|
||||
</div>
|
||||
<!-- 主体内容 -->
|
||||
<div class="layui-body" id="LAY_app_body">
|
||||
<div class="layadmin-tabsbody-item layui-show">
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
<iframe src="<?php echo htmlentities((string) $config['admin_route']); ?>index/welcome" onload="resetMainHeight(this)"
|
||||
style="width:100%;height:100%;" frameborder="0" scrolling="0"></iframe>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
<!-- 默认工作台界面 -->
|
||||
<div id="mainWorkspace">
|
||||
<iframe src="<?php echo htmlentities((string) $config['admin_route']); ?>index/welcome" class="main-iframe" frameborder="0" scrolling="0"></iframe>
|
||||
</div>
|
||||
<!-- 动态标签页 -->
|
||||
<div id="mainTabs" class="layui-tab" lay-allowClose="true" lay-filter="mainTabs" style="margin-top: 10px;">
|
||||
<ul class="layui-tab-title"></ul>
|
||||
<div class="layui-tab-content"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -125,38 +176,228 @@
|
||||
$ = layui.jquery;
|
||||
layer = layui.layer;
|
||||
setter = layui.setter;
|
||||
$('#clearcache').on('click', function () {
|
||||
$.ajax({
|
||||
url: "<?php echo htmlentities((string) $config['admin_route']); ?>index/clear",
|
||||
success: function (res) {
|
||||
if (res.code > 0) {
|
||||
layer.msg(res.msg, { 'icon': 2 });
|
||||
} else {
|
||||
layer.msg(res.msg, { 'icon': 1 });
|
||||
setTimeout(function () { parent.window.location.reload(); }, 1000);
|
||||
|
||||
// 保存标签状态
|
||||
function saveTabState(layid, title, url) {
|
||||
var tabState = {
|
||||
layid: layid,
|
||||
title: title,
|
||||
url: url
|
||||
};
|
||||
sessionStorage.setItem('currentTab', JSON.stringify(tabState));
|
||||
}
|
||||
|
||||
// 恢复标签状态
|
||||
function restoreTabState() {
|
||||
var tabState = sessionStorage.getItem('currentTab');
|
||||
if (tabState) {
|
||||
try {
|
||||
var tab = JSON.parse(tabState);
|
||||
if (tab.url && tab.title) {
|
||||
addTab(tab.title, tab.url, tab.layid);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to restore tab state:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 在页面加载完成后执行
|
||||
$(document).ready(function () {
|
||||
// 获取URL参数
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var page = urlParams.get('page');
|
||||
|
||||
if (page) {
|
||||
// 如果有page参数,加载对应页面到iframe
|
||||
$('iframe').attr('src', "<?php echo htmlentities((string) $config['admin_route']); ?>" + page);
|
||||
} else {
|
||||
// 否则加载默认页面
|
||||
$('iframe').attr('src', "<?php echo htmlentities((string) $config['admin_route']); ?>index/welcome");
|
||||
}
|
||||
|
||||
// 恢复标签状态
|
||||
restoreTabState();
|
||||
});
|
||||
|
||||
// 添加或切换到标签页
|
||||
window.addTab = function(title, url, id) {
|
||||
var element = layui.element;
|
||||
var $ = layui.jquery;
|
||||
var layid = id || url.replace(/\//g, '_');
|
||||
|
||||
// 如果是首页/工作台,直接显示主工作区
|
||||
if(url.indexOf('index/welcome') > -1 || url.indexOf('welcome') > -1) {
|
||||
$('#mainTabs').hide();
|
||||
$('#mainWorkspace').show();
|
||||
$('#mainWorkspace iframe').attr('src', url);
|
||||
sessionStorage.removeItem('currentTab');
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示标签区域
|
||||
$('#mainWorkspace').hide();
|
||||
$('#mainTabs').show();
|
||||
|
||||
// 如果标签已存在,直接切换
|
||||
if($('.layui-tab-title li[lay-id="'+ layid +'"]').length > 0) {
|
||||
element.tabChange('mainTabs', layid);
|
||||
saveTabState(layid, title, url);
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加新标签
|
||||
element.tabAdd('mainTabs', {
|
||||
title: title,
|
||||
content: '<iframe src="' + url + '" class="main-iframe" frameborder="0"></iframe>',
|
||||
id: layid
|
||||
});
|
||||
|
||||
// 切换到新标签页
|
||||
element.tabChange('mainTabs', layid);
|
||||
|
||||
// 保存当前标签状态
|
||||
saveTabState(layid, title, url);
|
||||
};
|
||||
|
||||
// 监听标签切换事件
|
||||
element.on('tab(mainTabs)', function(data){
|
||||
var layid = $(this).attr('lay-id');
|
||||
// 确保当前标签页内容可见
|
||||
$('.layui-tab-content .layui-tab-item').eq(data.index).addClass('layui-show')
|
||||
.siblings().removeClass('layui-show');
|
||||
|
||||
// 更新保存的标签状态
|
||||
var title = $(this).text();
|
||||
var url = $('.layui-tab-content .layui-tab-item').eq(data.index).find('iframe').attr('src');
|
||||
saveTabState(layid, title, url);
|
||||
});
|
||||
|
||||
// 监听标签删除事件
|
||||
element.on('tabDelete(mainTabs)', function(data){
|
||||
// 如果没有标签了,显示工作台
|
||||
if($('.layui-tab-title li').length === 0) {
|
||||
$('#mainTabs').hide();
|
||||
$('#mainWorkspace').show();
|
||||
sessionStorage.removeItem('currentTab');
|
||||
}
|
||||
});
|
||||
|
||||
// 左侧菜单点击事件
|
||||
$('.left-nav #nav li').click(function (event) {
|
||||
if ($(this).children('.sub-menu').length) {
|
||||
if ($(this).hasClass('open')) {
|
||||
$(this).removeClass('open');
|
||||
$(this).find('.nav_right').html('');
|
||||
$(this).children('.sub-menu').stop().slideUp();
|
||||
$(this).siblings().children('.sub-menu').slideUp();
|
||||
} else {
|
||||
$(this).addClass('open');
|
||||
$(this).children('a').find('.nav_right').html('');
|
||||
$(this).children('.sub-menu').stop().slideDown();
|
||||
$(this).siblings().children('.sub-menu').stop().slideUp();
|
||||
$(this).siblings().find('.nav_right').html('');
|
||||
$(this).siblings().removeClass('open');
|
||||
}
|
||||
} else {
|
||||
var url = $(this).children('a').attr('_href');
|
||||
var title = $(this).children('a').html();
|
||||
title = title.replace(/<[^>]+>/g, "").trim(); // 移除HTML标签
|
||||
|
||||
if (url) {
|
||||
window.addTab(title, url);
|
||||
}
|
||||
}
|
||||
event.stopPropagation();
|
||||
})
|
||||
|
||||
// 修改resetMainHeight函数
|
||||
function resetMainHeight(iframe) {
|
||||
if (!iframe) return;
|
||||
try {
|
||||
// 获取视口高度
|
||||
var clientHeight = document.documentElement.clientHeight;
|
||||
// 计算iframe应该的高度(减去头部和tab标签的高度)
|
||||
var iframeHeight = clientHeight - 60 - 40; // 60px是头部高度,40px是tab标签高度
|
||||
$(iframe).css({
|
||||
'height': iframeHeight + 'px',
|
||||
'width': '100%',
|
||||
'display': 'block'
|
||||
});
|
||||
} catch(e) {
|
||||
console.error('Reset iframe height failed:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 在窗口大小改变时重置所有iframe高度
|
||||
$(window).on('resize', function() {
|
||||
$('.main-iframe').each(function() {
|
||||
resetMainHeight(this);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
// 重新设置主操作页面高度
|
||||
function resetMainHeight(obj) {
|
||||
// parent 上级
|
||||
// clientHeight 元素的像素高度,包含元素的高度+内边距,不包含水平滚动条,边框和外边距
|
||||
var height = parent.document.documentElement.clientHeight - 80;
|
||||
$(obj).parent('div').height(height);
|
||||
}
|
||||
|
||||
// 菜单点击
|
||||
function menuFire(obj, num) {
|
||||
if (num == 1) {
|
||||
$('iframe').attr('src', "<?php echo htmlentities((string) $config['admin_route']); ?>" + obj);
|
||||
var title = '';
|
||||
// 获取菜单标题
|
||||
$('.layui-nav-item a').each(function() {
|
||||
if($(this).attr('onclick') && $(this).attr('onclick').indexOf(obj) > -1) {
|
||||
title = $(this).text().trim();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// 如果没找到标题,使用子菜单查找
|
||||
if(!title) {
|
||||
$('.layui-nav-child a').each(function() {
|
||||
if($(this).attr('onclick') && $(this).attr('onclick').indexOf(obj) > -1) {
|
||||
title = $(this).text().trim();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 添加或切换到标签页
|
||||
window.addTab(title || '新页面', "<?php echo htmlentities((string) $config['admin_route']); ?>" + obj, obj.replace(/\//g, '_'));
|
||||
|
||||
// 更新浏览器URL,但保持在index页面
|
||||
window.history.pushState({}, '', "<?php echo htmlentities((string) $config['admin_route']); ?>index/index?page=" + obj);
|
||||
|
||||
// 如果是子菜单,确保父菜单展开
|
||||
if (obj.indexOf('/') > -1) {
|
||||
var parentMenu = obj.split('/')[0];
|
||||
$('.layui-nav-item').each(function () {
|
||||
var menuSrc = $(this).find('a').attr('onclick');
|
||||
if (menuSrc && menuSrc.indexOf(parentMenu) > -1) {
|
||||
$(this).addClass('layui-nav-itemed');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
var width = screen();
|
||||
if (width < 2) {
|
||||
shrink();
|
||||
}
|
||||
}
|
||||
|
||||
// 监听浏览器前进后退按钮
|
||||
window.addEventListener('popstate', function (event) {
|
||||
// 获取URL参数
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var page = urlParams.get('page');
|
||||
|
||||
if (page) {
|
||||
// 如果有page参数,通过标签系统加载页面
|
||||
var title = '新页面';
|
||||
window.addTab(title, "<?php echo htmlentities((string) $config['admin_route']); ?>" + page, page.replace(/\//g, '_'));
|
||||
} else {
|
||||
// 否则加载默认页面
|
||||
element.tabChange('mainTabs', 'welcome');
|
||||
}
|
||||
});
|
||||
|
||||
// 退出
|
||||
function logout() {
|
||||
layer.confirm('确定要退出吗?', {
|
||||
@@ -175,7 +416,7 @@
|
||||
}
|
||||
|
||||
//跳转前端站点
|
||||
function gotoFront(){
|
||||
function gotoFront() {
|
||||
window.open("//<?php echo htmlentities((string) $config['admin_domain']); ?>", "_blank");
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php /*a:2:{s:53:"E:\Demo\PHP\yunzer\app\admin\view\resources\lists.php";i:1747407920;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo htmlentities((string) $config['admin_name']); ?></title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
.header span{background:#009688;margin-left:30px;padding:10px;color:#ffffff;}
|
||||
.header div{border-bottom:solid 2px #009688;margin-top: 8px;}
|
||||
.header button{float:right;margin-top:-5px;}
|
||||
.pagination {
|
||||
display: inline-block;
|
||||
padding-left: 0;
|
||||
margin: 20px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.pagination > li {
|
||||
display: inline;
|
||||
}
|
||||
.pagination > li > a,
|
||||
.pagination > li > span {
|
||||
position: relative;
|
||||
float: left;
|
||||
padding: 6px 12px;
|
||||
margin-left: -1px;
|
||||
line-height: 1.42857143;
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.pagination > li:first-child > a,
|
||||
.pagination > li:first-child > span {
|
||||
margin-left: 0;
|
||||
border-top-left-radius: 4px;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
.pagination > li:last-child > a,
|
||||
.pagination > li:last-child > span {
|
||||
border-top-right-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
.pagination > li > a:hover,
|
||||
.pagination > li > span:hover,
|
||||
.pagination > li > a:focus,
|
||||
.pagination > li > span:focus {
|
||||
z-index: 2;
|
||||
color: #23527c;
|
||||
background-color: #eee;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.pagination > .active > a,
|
||||
.pagination > .active > span,
|
||||
.pagination > .active > a:hover,
|
||||
.pagination > .active > span:hover,
|
||||
.pagination > .active > a:focus,
|
||||
.pagination > .active > span:focus {
|
||||
z-index: 3;
|
||||
color: #fff;
|
||||
cursor: default;
|
||||
background-color: #337ab7;
|
||||
border-color: #337ab7;
|
||||
}
|
||||
.pagination > .disabled > span,
|
||||
.pagination > .disabled > span:hover,
|
||||
.pagination > .disabled > span:focus,
|
||||
.pagination > .disabled > a,
|
||||
.pagination > .disabled > a:hover,
|
||||
.pagination > .disabled > a:focus {
|
||||
color: #777;
|
||||
cursor: not-allowed;
|
||||
background-color: #fff;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
form = layui.form; // layui form表单
|
||||
table = layui.table; // layui 表格
|
||||
laydate = layui.laydate; // layui 时间框
|
||||
element = layui.element; // layui element
|
||||
upload = layui.upload; // layui 上传
|
||||
$ = layui.jquery; // layui jquery
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body style="padding:10px; box-sizing: border-box;">
|
||||
<div class="config-container">
|
||||
<!-- 页面头部样式 -->
|
||||
<div class="config-header" style="display: flex;flex-direction: column;flex-wrap: wrap;align-items: flex-start;">
|
||||
<div class="maintitle">
|
||||
<i class="layui-icon layui-icon-file"></i>
|
||||
<span>资源列表</span>
|
||||
</div>
|
||||
<div style="display: flex;align-items: flex-start;flex-direction: column;gap: 15px;margin-bottom: 10px;">
|
||||
<div class="shaixuan">
|
||||
<label>筛选:</label>
|
||||
<div class="layui-form" style="display: flex; gap: 10px;">
|
||||
<div class="layui-input-inline">
|
||||
<select id="categoryFilter" lay-filter="categoryFilter" lay-verify="">
|
||||
<option value="">全部分类</option>
|
||||
<?php if(is_array($categories) || $categories instanceof \think\Collection || $categories instanceof \think\Paginator): $i = 0; $__LIST__ = $categories;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$category): $mod = ($i % 2 );++$i;?>
|
||||
<optgroup label="<?php echo htmlentities((string) $category['name']); ?>">
|
||||
<?php if(is_array($category['children']) || $category['children'] instanceof \think\Collection || $category['children'] instanceof \think\Paginator): $i = 0; $__LIST__ = $category['children'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$subCategory): $mod = ($i % 2 );++$i;?>
|
||||
<option value="<?php echo htmlentities((string) $subCategory['id']); ?>"><?php echo htmlentities((string) $subCategory['name']); ?></option>
|
||||
<?php endforeach; endif; else: echo "" ;endif; ?>
|
||||
</optgroup>
|
||||
<?php endforeach; endif; else: echo "" ;endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="nameSearch" placeholder="搜索资源名称" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" id="uploaderSearch" placeholder="搜索上传者" class="layui-input">
|
||||
</div>
|
||||
<button type="button" class="layui-btn layui-btn-normal" onclick="doSearch()">
|
||||
<i class="layui-icon layui-icon-search"></i>搜索
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="doRefresh()">
|
||||
<i class="layui-icon layui-icon-refresh"></i>重置
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="layui-btn layui-btn-normal" onclick="add()">
|
||||
<i class="layui-icon layui-icon-add-1"></i>添加资源
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="refresh()">
|
||||
<i class="layui-icon layui-icon-refresh"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="resourceTable" lay-filter="resourceTable"></table>
|
||||
</div>
|
||||
|
||||
<script type="text/html" id="iconTemplate">
|
||||
{{# if(d.icon){ }}
|
||||
<img src="{{ d.icon }}" style="max-width: 50px; max-height: 50px;">
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="statusTemplate">
|
||||
{{# if(d.status === 0){ }}
|
||||
<span style="color:red;">未审核</span>
|
||||
{{# } else if(d.status === 1){ }}
|
||||
<span style="color:orange;">待审核</span>
|
||||
{{# } else if(d.status === 2){ }}
|
||||
<span style="color:green;">已发布</span>
|
||||
{{# } else if(d.status === 3){ }}
|
||||
<span style="color:gray;">已下架</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="operationBar">
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
|
||||
<i class="layui-icon layui-icon-edit"></i>编辑
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="del">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer', 'form', 'table'], function () {
|
||||
var layer = layui.layer;
|
||||
var $ = layui.jquery;
|
||||
var form = layui.form;
|
||||
var table = layui.table;
|
||||
|
||||
// 初始化表格
|
||||
table.render({
|
||||
elem: '#resourceTable',
|
||||
url: '/admin/resources/lists',
|
||||
method: 'post',
|
||||
cols: [[
|
||||
{ field: 'id', title: 'ID', align: 'center', width: 80 },
|
||||
{ field: 'title', title: '资源名称' },
|
||||
{ field: 'cate', title: '分类', align: 'center', width: 120 },
|
||||
{ field: 'icon', title: '图标', templet: '#iconTemplate', align: 'center', width: 100 },
|
||||
{ field: 'uploader', title: '上传者', align: 'center', width: 100 },
|
||||
{ field: 'desc', title: '描述', width: 200 },
|
||||
{ field: 'status', title: '状态', templet: '#statusTemplate', align: 'center', width: 80 },
|
||||
{ title: '操作', toolbar: '#operationBar', align: 'center', width: 150, fixed: 'right' }
|
||||
]],
|
||||
page: true,
|
||||
limit: 10,
|
||||
limits: [10, 50, 100],
|
||||
//height: 'full-220'
|
||||
});
|
||||
|
||||
// 监听工具条事件
|
||||
table.on('tool(resourceTable)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit') {
|
||||
edit(data.id);
|
||||
} else if (obj.event === 'del') {
|
||||
del(data.id);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听分类筛选变化
|
||||
form.on('select(categoryFilter)', function (data) {
|
||||
filterByCategory(data.value);
|
||||
});
|
||||
});
|
||||
|
||||
function filterByCategory(categoryId) {
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
function doSearch() {
|
||||
var nameKeyword = $('#nameSearch').val().trim();
|
||||
var uploaderKeyword = $('#uploaderSearch').val().trim();
|
||||
|
||||
if (!nameKeyword && !uploaderKeyword && !$('#categoryFilter').val()) {
|
||||
layer.msg('请输入搜索条件', { icon: 0 });
|
||||
return;
|
||||
}
|
||||
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
function doRefresh() {
|
||||
// 清空搜索条件
|
||||
$('#nameSearch').val('');
|
||||
$('#uploaderSearch').val('');
|
||||
$('#categoryFilter').val('');
|
||||
layui.form.render('select'); // 重新渲染select
|
||||
|
||||
// 重新加载表格,不带任何筛选条件
|
||||
layui.table.reload('resourceTable', {
|
||||
where: {},
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
|
||||
layer.msg('已重置', { icon: 1 });
|
||||
}
|
||||
|
||||
function reloadTable() {
|
||||
var categoryId = $('#categoryFilter').val();
|
||||
var categoryName = categoryId ? $('#categoryFilter option[value="' + categoryId + '"]').text() : '';
|
||||
var nameKeyword = $('#nameSearch').val().trim();
|
||||
var uploaderKeyword = $('#uploaderSearch').val().trim();
|
||||
|
||||
layui.table.reload('resourceTable', {
|
||||
where: {
|
||||
category: categoryName,
|
||||
name: nameKeyword,
|
||||
uploader: uploaderKeyword
|
||||
},
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function add() {
|
||||
window.location.href = '/admin/resources/add';
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
window.location.href = '/admin/resources/edit?id=' + id;
|
||||
}
|
||||
|
||||
function del(id) {
|
||||
layer.confirm('确定要删除该资源吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.post('/admin/resources/delete', { id: id }, function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
layui.table.reload('resourceTable');
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
layui.table.reload('resourceTable');
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,619 @@
|
||||
<?php /*a:2:{s:52:"E:\Demo\PHP\yunzer\app\admin\view\resources\cate.php";i:1747402501;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo htmlentities((string) $config['admin_name']); ?></title>
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/moban.css" media="all"/>
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/wangeditor.css" media="all"/>
|
||||
<style type="text/css">
|
||||
.header span{background:#009688;margin-left:30px;padding:10px;color:#ffffff;}
|
||||
.header div{border-bottom:solid 2px #009688;margin-top: 8px;}
|
||||
.header button{float:right;margin-top:-5px;}
|
||||
.pagination {
|
||||
display: inline-block;
|
||||
padding-left: 0;
|
||||
margin: 20px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.pagination > li {
|
||||
display: inline;
|
||||
}
|
||||
.pagination > li > a,
|
||||
.pagination > li > span {
|
||||
position: relative;
|
||||
float: left;
|
||||
padding: 6px 12px;
|
||||
margin-left: -1px;
|
||||
line-height: 1.42857143;
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.pagination > li:first-child > a,
|
||||
.pagination > li:first-child > span {
|
||||
margin-left: 0;
|
||||
border-top-left-radius: 4px;
|
||||
border-bottom-left-radius: 4px;
|
||||
}
|
||||
.pagination > li:last-child > a,
|
||||
.pagination > li:last-child > span {
|
||||
border-top-right-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
.pagination > li > a:hover,
|
||||
.pagination > li > span:hover,
|
||||
.pagination > li > a:focus,
|
||||
.pagination > li > span:focus {
|
||||
z-index: 2;
|
||||
color: #23527c;
|
||||
background-color: #eee;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.pagination > .active > a,
|
||||
.pagination > .active > span,
|
||||
.pagination > .active > a:hover,
|
||||
.pagination > .active > span:hover,
|
||||
.pagination > .active > a:focus,
|
||||
.pagination > .active > span:focus {
|
||||
z-index: 3;
|
||||
color: #fff;
|
||||
cursor: default;
|
||||
background-color: #337ab7;
|
||||
border-color: #337ab7;
|
||||
}
|
||||
.pagination > .disabled > span,
|
||||
.pagination > .disabled > span:hover,
|
||||
.pagination > .disabled > span:focus,
|
||||
.pagination > .disabled > a,
|
||||
.pagination > .disabled > a:hover,
|
||||
.pagination > .disabled > a:focus {
|
||||
color: #777;
|
||||
cursor: not-allowed;
|
||||
background-color: #fff;
|
||||
border-color: #ddd;
|
||||
}
|
||||
.close-img { background: url(/static/images/close_img.png); background-size: 20px 20px; width:20px; height: 20px; position: absolute; right: 5px; top: 5px; z-index: 2;}
|
||||
</style>
|
||||
<script type="text/javascript" src="/static/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer','form','table','laydate','element','upload'],function(){
|
||||
layer = layui.layer; // layui 弹框
|
||||
form = layui.form; // layui form表单
|
||||
table = layui.table; // layui 表格
|
||||
laydate = layui.laydate; // layui 时间框
|
||||
element = layui.element; // layui element
|
||||
upload = layui.upload; // layui 上传
|
||||
$ = layui.jquery; // layui jquery
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body style="padding:10px; box-sizing: border-box;">
|
||||
<div class="config-container">
|
||||
<!-- 页面头部样式 -->
|
||||
<div class="config-header" style="display: flex;flex-direction: column;flex-wrap: wrap;align-items: flex-start;">
|
||||
<div class="maintitle">
|
||||
<i class="layui-icon layui-icon-app"></i>
|
||||
<span>资源分类管理</span>
|
||||
</div>
|
||||
<div style="display: flex;align-items: flex-start;flex-direction: column;gap: 15px;margin-bottom: 10px;">
|
||||
<div>
|
||||
<button type="button" class="layui-btn layui-btn-normal" onclick="add()">
|
||||
<i class="layui-icon layui-icon-add-1"></i>添加分类
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="refresh()">
|
||||
<i class="layui-icon layui-icon-refresh"></i>刷新
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 主要内容区 -->
|
||||
<div class="main-content">
|
||||
<div class="layui-row layui-col-space20">
|
||||
<!-- 左侧分类列表 -->
|
||||
<div class="layui-col-md7">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">
|
||||
<span>分类列表</span>
|
||||
<small class="text-muted">支持两级分类结构</small>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
<div id="categoryList" class="category-tree"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧分类信息 -->
|
||||
<div class="layui-col-md5">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">
|
||||
<span>分类信息</span>
|
||||
</div>
|
||||
<div class="layui-card-body">
|
||||
<!-- 默认提示 -->
|
||||
<div id="defaultTip" class="empty-tip">
|
||||
<i class="layui-icon layui-icon-face-surprised"></i>
|
||||
<p>请选择左侧分类或点击新增按钮</p>
|
||||
</div>
|
||||
|
||||
<!-- 分类表单 -->
|
||||
<form class="layui-form category-form" lay-filter="categoryForm" style="display: none;">
|
||||
<input type="hidden" name="id" id="categoryId">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="name" required lay-verify="required" placeholder="请输入分类名称"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">父级分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="cid" lay-verify="required">
|
||||
<option value="0">顶级分类</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">分类图标</label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-upload-drag" id="uploadImage">
|
||||
<i class="layui-icon layui-icon-upload"></i>
|
||||
<p>点击上传或拖拽图片至此处</p>
|
||||
<div class="layui-hide" id="uploadPreview">
|
||||
<hr>
|
||||
<img src="" alt="分类图标" style="max-width: 100%">
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="icon" id="imageInput">
|
||||
<div class="layui-form-mid layui-word-aux">建议尺寸:128px * 128px</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="sort" value="0" class="layui-input"
|
||||
placeholder="数字越大越靠前">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">状态</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="status" value="1" title="正常" checked>
|
||||
<input type="radio" name="status" value="0" title="禁用">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item form-actions">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="saveCategory">保存</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger" id="deleteBtn"
|
||||
style="display: none;">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* 页面整体样式 */
|
||||
.config-container {
|
||||
padding: 15px;
|
||||
/* background: #f2f2f2; */
|
||||
}
|
||||
|
||||
.layui-col-md7 .layui-btn-primary {
|
||||
border-color: #d2d2d2;
|
||||
background: 0 0;
|
||||
color: #5f5f5f
|
||||
}
|
||||
|
||||
.layui-col-md7 .layui-btn-primary:hover {
|
||||
background-color: #1e9fff;
|
||||
color: #efefef
|
||||
}
|
||||
|
||||
/* 页面头部样式 */
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding: 10px 15px;
|
||||
background: #fff;
|
||||
border-radius: 2px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.header-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.header-title .layui-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.header-actions .layui-btn {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
/* 主要内容区样式 */
|
||||
.main-content {
|
||||
min-height: calc(100vh - 170px);
|
||||
}
|
||||
|
||||
.layui-card {
|
||||
margin-bottom: 0;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.layui-card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: auto;
|
||||
padding: 12px 15px;
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.text-muted {
|
||||
margin-left: 10px;
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 分类树样式 */
|
||||
.category-tree {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.category-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 15px;
|
||||
background-color: #f8f8f8;
|
||||
border-radius: 2px;
|
||||
transition: all 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.category-header:hover {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.category-header.active {
|
||||
background-color: #e6f7ff;
|
||||
border-right: 3px solid #1890ff;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.category-actions {
|
||||
/* opacity: 0; */
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.category-header:hover .category-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.category-children {
|
||||
margin-left: 20px;
|
||||
padding-left: 15px;
|
||||
border-left: 1px dashed #e6e6e6;
|
||||
}
|
||||
|
||||
.add-child {
|
||||
padding: 3px 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.add-child .layui-icon {
|
||||
font-size: 12px;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
/* 空状态提示 */
|
||||
.empty-tip {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 0;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-tip .layui-icon {
|
||||
font-size: 32px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
/* 表单样式优化 */
|
||||
.category-form {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.layui-form-label {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.layui-input-block {
|
||||
margin-left: 130px;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.layui-upload-drag {
|
||||
padding: 20px;
|
||||
border: 1px dashed #e2e2e2;
|
||||
background-color: #fff;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.layui-upload-drag:hover {
|
||||
border-color: #009688;
|
||||
}
|
||||
|
||||
.layui-upload-drag img {
|
||||
max-width: 100%;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.layui-btn-xs {
|
||||
height: 30px;
|
||||
line-height: 25px;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// 定义全局变量和函数
|
||||
var categoryManager = {
|
||||
init: function () {
|
||||
this.initLayui();
|
||||
},
|
||||
|
||||
initLayui: function () {
|
||||
var that = this;
|
||||
layui.use(['layer', 'form', 'upload'], function () {
|
||||
var layer = layui.layer;
|
||||
var form = layui.form;
|
||||
var upload = layui.upload;
|
||||
var $ = layui.jquery;
|
||||
|
||||
// 初始化分类列表
|
||||
that.initCategoryList = function () {
|
||||
$.ajax({
|
||||
url: '/admin/resources/cate',
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
var html = '';
|
||||
res.data.forEach(function (item) {
|
||||
html += that.renderCategory(item);
|
||||
});
|
||||
$('#categoryList').html(html);
|
||||
that.bindEvents();
|
||||
} else {
|
||||
layer.msg('获取分类数据失败', { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 渲染分类项
|
||||
that.renderCategory = function (category, level = 0) {
|
||||
var html = '<div class="category-item" data-id="' + category.id + '">';
|
||||
html += '<div class="category-header">';
|
||||
html += '<div class="category-name">' + category.title + '</div>';
|
||||
if (level === 0) {
|
||||
html += '<div class="category-actions">';
|
||||
html += '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs add-child">';
|
||||
html += '<i class="layui-icon layui-icon-add-1"></i>添加子分类</button>';
|
||||
html += '</div>';
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
if (category.children && category.children.length > 0) {
|
||||
html += '<div class="category-children">';
|
||||
category.children.forEach(function (child) {
|
||||
html += that.renderCategory(child, level + 1);
|
||||
});
|
||||
html += '</div>';
|
||||
}
|
||||
html += '</div>';
|
||||
return html;
|
||||
};
|
||||
|
||||
// 绑定事件
|
||||
that.bindEvents = function () {
|
||||
// 点击分类项加载编辑信息
|
||||
$('.category-header').off('click').on('click', function (e) {
|
||||
if (!$(e.target).closest('.add-child').length) {
|
||||
var id = $(this).closest('.category-item').data('id');
|
||||
that.loadCategoryInfo(id);
|
||||
|
||||
// 添加选中效果
|
||||
$('.category-header').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
}
|
||||
});
|
||||
|
||||
// 添加子分类
|
||||
$('.add-child').off('click').on('click', function (e) {
|
||||
e.stopPropagation();
|
||||
var parentId = $(this).closest('.category-item').data('id');
|
||||
that.showCategoryForm(parentId);
|
||||
});
|
||||
};
|
||||
|
||||
// 加载分类信息
|
||||
that.loadCategoryInfo = function (id) {
|
||||
$.get('/admin/resources/cateedit?id=' + id, function (res) {
|
||||
if (res.code === 0) {
|
||||
that.showCategoryForm(0, res.data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 显示分类表单
|
||||
that.showCategoryForm = function (parentId = 0, data = null) {
|
||||
$('#defaultTip').hide();
|
||||
$('.category-form').show();
|
||||
|
||||
// 重置表单
|
||||
form.val('categoryForm', {
|
||||
id: data ? data.info.id : '',
|
||||
name: data ? data.info.name : '',
|
||||
cid: data ? data.info.cid : parentId,
|
||||
sort: data ? data.info.sort : 0,
|
||||
status: data ? data.info.status : 1
|
||||
});
|
||||
|
||||
// 更新父级分类选项
|
||||
var $select = $('select[name="cid"]');
|
||||
$select.empty().append('<option value="0">顶级分类</option>');
|
||||
// 获取所有分类作为父级选项
|
||||
$.ajax({
|
||||
url: '/admin/resources/cate',
|
||||
type: 'POST',
|
||||
async: false,
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
// 当前编辑的分类ID
|
||||
var currentId = data ? data.info.id : 0;
|
||||
// 递归构建分类选项
|
||||
function buildOptions(categories, level) {
|
||||
categories.forEach(function (category) {
|
||||
// 不能选择自己或自己的子分类作为父级
|
||||
if (category.id != currentId) {
|
||||
var prefix = new Array(level + 1).join('├─ ');
|
||||
$select.append('<option value="' + category.id + '">' + prefix + category.title + '</option>'); if (category.children && category.children.length > 0) { buildOptions(category.children, level + 1); }
|
||||
}
|
||||
});
|
||||
} buildOptions(res.data, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 设置选中的父级分类
|
||||
if (data && data.info.cid) {
|
||||
$select.val(data.info.cid);
|
||||
}
|
||||
|
||||
// 更新图标预览
|
||||
if (data && data.info.icon) {
|
||||
$('#uploadPreview').removeClass('layui-hide').find('img').attr('src', data.info.icon);
|
||||
$('#imageInput').val(data.info.icon);
|
||||
} else {
|
||||
$('#uploadPreview').addClass('layui-hide').find('img').attr('src', '');
|
||||
$('#imageInput').val('');
|
||||
}
|
||||
|
||||
// 显示/隐藏删除按钮
|
||||
$('#deleteBtn')[data ? 'show' : 'hide']();
|
||||
|
||||
form.render();
|
||||
};
|
||||
|
||||
// 初始化上传组件
|
||||
upload.render({
|
||||
elem: '#uploadImage',
|
||||
url: '/admin/upload/image',
|
||||
accept: 'images',
|
||||
acceptMime: 'image/*',
|
||||
done: function (res) {
|
||||
if (res.code === 0) {
|
||||
$('#uploadPreview').removeClass('layui-hide').find('img').attr('src', res.data.url);
|
||||
$('#imageInput').val(res.data.url);
|
||||
layer.msg('上传成功');
|
||||
} else {
|
||||
layer.msg('上传失败');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 监听表单提交
|
||||
form.on('submit(saveCategory)', function (data) {
|
||||
var url = data.field.id ? '/admin/resources/cateedit' : '/admin/resources/cateadd';
|
||||
$.post(url, data.field, function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
that.initCategoryList();
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// 监听删除按钮
|
||||
$('#deleteBtn').on('click', function () {
|
||||
var id = $('#categoryId').val();
|
||||
if (!id) return;
|
||||
|
||||
layer.confirm('确定要删除该分类吗?', function (index) {
|
||||
$.post('/admin/resources/catedel', { id: id }, function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
that.initCategoryList();
|
||||
$('#defaultTip').show();
|
||||
$('.category-form').hide();
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
});
|
||||
|
||||
// 初始化页面
|
||||
that.initCategoryList();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化
|
||||
categoryManager.init();
|
||||
|
||||
// 新增分类
|
||||
function add() {
|
||||
categoryManager.showCategoryForm();
|
||||
}
|
||||
|
||||
// 刷新列表
|
||||
function refresh() {
|
||||
categoryManager.initCategoryList();
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user