576 lines
		
	
	
		
			24 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			576 lines
		
	
	
		
			24 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php /*a:2:{s:52:"E:\Demo\PHP\yunzer\app\admin\view\resources\edit.php";i:1747755572;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" lay-filter="cate">
 | 
						||
                    <option value="">请选择分类</option>
 | 
						||
                </select>
 | 
						||
            </div>
 | 
						||
        </div>
 | 
						||
        
 | 
						||
        <div class="layui-form-item">
 | 
						||
            <label class="layui-form-label">资源编号</label>
 | 
						||
            <div class="layui-input-block">
 | 
						||
                <input type="text" name="number" required lay-verify="required" placeholder="请输入分类编号" autocomplete="off"
 | 
						||
                    class="layui-input" value="<?php echo htmlentities((string) (isset($resource['number']) && ($resource['number'] !== '')?$resource['number']:'')); ?>" lay-affix="clear" disabled>
 | 
						||
            </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="text" name="zipcode" required placeholder="请输入解压密码" autocomplete="off"
 | 
						||
                    class="layui-input" value="<?php echo htmlentities((string) (isset($resource['zipcode']) && ($resource['zipcode'] !== '')?$resource['zipcode']:'')); ?>" 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 layui-form-text">
 | 
						||
            <label class="layui-form-label">内容</label>
 | 
						||
            <div class="layui-input-block">
 | 
						||
                <div id="editor—wrapper" id="content" name="content" style="border: 1px solid #ccc;">
 | 
						||
                    <div id="toolbar-container" style="border-bottom: 1px solid #ccc;"><!-- 工具栏 --></div>
 | 
						||
                    <div id="editor-container" style="height: 800px;"><!-- 编辑器 --></div>
 | 
						||
                </div>
 | 
						||
            </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 src="/static/js/wangeditor.js"></script>
 | 
						||
<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) {
 | 
						||
                // 存储分类数据供后续使用
 | 
						||
                window.categoryData = res.data;
 | 
						||
                
 | 
						||
                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('select(cate)', function(data) {
 | 
						||
            var selectedId = data.value;
 | 
						||
            if (!selectedId) {
 | 
						||
                $('input[name="number"]').val('');
 | 
						||
                return;
 | 
						||
            }
 | 
						||
 | 
						||
            // 查找选中的分类信息
 | 
						||
            var parentCategory = null;
 | 
						||
            var childCategory = null;
 | 
						||
 | 
						||
            window.categoryData.forEach(function(parent) {
 | 
						||
                if (parent.children) {
 | 
						||
                    parent.children.forEach(function(child) {
 | 
						||
                        if (child.id == selectedId) {
 | 
						||
                            parentCategory = parent;
 | 
						||
                            childCategory = child;
 | 
						||
                        }
 | 
						||
                    });
 | 
						||
                }
 | 
						||
            });
 | 
						||
 | 
						||
            if (parentCategory && childCategory) {
 | 
						||
                // 生成资源编号
 | 
						||
                var total = childCategory.total || 0;
 | 
						||
                // 判断是否是初始化时的分类
 | 
						||
                var isInitialCategory = resourceData && resourceData.cate == selectedId;
 | 
						||
                var nextNumber = isInitialCategory ? total : total + 1;
 | 
						||
                var numberStr = nextNumber.toString().padStart(5, '0');
 | 
						||
                var resourceNumber = parentCategory.number + childCategory.number + numberStr;
 | 
						||
                
 | 
						||
                // 设置资源编号
 | 
						||
                $('input[name="number"]').val(resourceNumber);
 | 
						||
            }
 | 
						||
        });
 | 
						||
 | 
						||
        // 表单提交
 | 
						||
        form.on('submit(formSubmit)', function (data) {
 | 
						||
            // 获取编辑器内容
 | 
						||
            var content = editor.getHtml();
 | 
						||
            var loadIndex = layer.load(2);
 | 
						||
            data.field.content = content;
 | 
						||
            
 | 
						||
            $.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>
 | 
						||
 | 
						||
<!-- wangeditor编辑器脚本 -->
 | 
						||
<script>
 | 
						||
    const { createEditor, createToolbar } = window.wangEditor
 | 
						||
 | 
						||
    const editorConfig = { 
 | 
						||
        MENU_CONF: {},
 | 
						||
        placeholder: '请输入内容...',
 | 
						||
        onChange(editor) {
 | 
						||
            const html = editor.getHtml()
 | 
						||
        },
 | 
						||
    }
 | 
						||
 | 
						||
    // 配置图片上传
 | 
						||
    editorConfig.MENU_CONF['uploadImage'] = {
 | 
						||
        server: '<?php echo url("index/upload_img"); ?>',
 | 
						||
        fieldName: 'file',
 | 
						||
        maxFileSize: 10 * 1024 * 1024, // 10M
 | 
						||
        maxNumberOfFiles: 10,
 | 
						||
        allowedFileTypes: ['image/*'],
 | 
						||
        meta: {
 | 
						||
            token: 'xxx'
 | 
						||
        },
 | 
						||
        metaWithUrl: true,
 | 
						||
        headers: {
 | 
						||
            Accept: 'text/x-json'
 | 
						||
        },
 | 
						||
        timeout: 5 * 1000, // 5s
 | 
						||
 | 
						||
        onBeforeUpload(file) {
 | 
						||
            console.log('准备上传图片', file)
 | 
						||
            return file
 | 
						||
        },
 | 
						||
        onProgress(progress) {
 | 
						||
            console.log('上传进度', progress)
 | 
						||
        },
 | 
						||
        onSuccess(file, res) {
 | 
						||
            console.log('上传成功', file, res)
 | 
						||
        },
 | 
						||
        onFailed(file, res) {
 | 
						||
            layer.msg('上传失败:' + res.msg, { icon: 2 })
 | 
						||
            console.log('上传失败', file, res)
 | 
						||
        },
 | 
						||
        onError(file, err, res) {
 | 
						||
            layer.msg('上传出错:' + err.message, { icon: 2 })
 | 
						||
            console.error('上传出错', file, err, res)
 | 
						||
        },
 | 
						||
        customInsert(res, insertFn) {
 | 
						||
            // res 即服务端的返回结果
 | 
						||
            if (res.code === 0 && res.data) {
 | 
						||
                // 从res.data中获取src字段
 | 
						||
                const url = String(res.data.src || '');
 | 
						||
                if (url) {
 | 
						||
                    insertFn(url);
 | 
						||
                } else {
 | 
						||
                    layer.msg('图片地址无效', { icon: 2 });
 | 
						||
                }
 | 
						||
            } else {
 | 
						||
                layer.msg('图片上传失败', { icon: 2 });
 | 
						||
            }
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
    const editor = createEditor({
 | 
						||
        selector: '#editor-container',
 | 
						||
        html: `<?php echo (isset($resource['content']) && ($resource['content'] !== '')?$resource['content']:''); ?>`,
 | 
						||
        config: editorConfig,
 | 
						||
        mode: 'default', // or 'simple'
 | 
						||
    })
 | 
						||
 | 
						||
    const toolbarConfig = {}
 | 
						||
 | 
						||
    const toolbar = createToolbar({
 | 
						||
        editor,
 | 
						||
        selector: '#toolbar-container',
 | 
						||
        config: toolbarConfig,
 | 
						||
        mode: 'default', // or 'simple'
 | 
						||
    })
 | 
						||
</script>
 | 
						||
 | 
						||
<script>
 | 
						||
    //返回资源列表
 | 
						||
    function goBack() {
 | 
						||
        window.location.href = '<?php echo url("resources/lists"); ?>';
 | 
						||
    }
 | 
						||
</script>
 |