更新资源编辑

This commit is contained in:
2025-06-09 15:33:30 +08:00
parent 876e1092cc
commit 234fc206d5
18 changed files with 1720 additions and 179 deletions
@@ -1,4 +1,4 @@
<?php /*a:3:{s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\index\welcome.php";i:1747701414;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\tail.php";i:1746709977;}*/ ?>
<?php /*a:3:{s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\index\welcome.php";i:1749433730;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\tail.php";i:1746709977;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -545,7 +545,7 @@ function initVisitTrend() {
},
xAxis: {
type: 'category',
data: <?php echo htmlentities((string) json_encode($chartData['visitTrend']['dates'])); ?>,
data: <?php echo json_encode($chartData['visitTrend']['dates']); ?>,
axisLine: {
lineStyle: {
color: '#e2e8f0'
@@ -567,7 +567,7 @@ function initVisitTrend() {
},
series: [{
name: '访问量',
data: <?php echo htmlentities((string) json_encode($chartData['visitTrend']['visits'])); ?>,
data: <?php echo json_encode($chartData['visitTrend']['visits']); ?>,
type: 'line',
smooth: true,
areaStyle: {
@@ -581,7 +581,7 @@ function initVisitTrend() {
}
}, {
name: '独立访客',
data: <?php echo htmlentities((string) json_encode($chartData['visitTrend']['uvs'])); ?>,
data: <?php echo json_encode($chartData['visitTrend']['uvs']); ?>,
type: 'line',
smooth: true,
itemStyle: {
@@ -620,7 +620,7 @@ function initUserGrowth() {
xAxis: {
type: 'category',
boundaryGap: false,
data: <?php echo htmlentities((string) json_encode($chartData['userGrowth']['dates'])); ?>
data: <?php echo json_encode($chartData['userGrowth']['dates']); ?>
},
yAxis: {
type: 'value'
@@ -629,7 +629,7 @@ function initUserGrowth() {
{
name: '新增用户',
type: 'bar',
data: <?php echo htmlentities((string) json_encode($chartData['userGrowth']['newUsers'])); ?>,
data: <?php echo json_encode($chartData['userGrowth']['newUsers']); ?>,
itemStyle: {
color: '#3881fd'
}
@@ -638,7 +638,7 @@ function initUserGrowth() {
name: '总用户数',
type: 'line',
smooth: true,
data: <?php echo htmlentities((string) json_encode($chartData['userGrowth']['totalUsers'])); ?>,
data: <?php echo json_encode($chartData['userGrowth']['totalUsers']); ?>,
itemStyle: {
color: '#10b981'
},
@@ -676,7 +676,7 @@ function initResourceStats() {
xAxis: {
type: 'category',
boundaryGap: false,
data: <?php echo htmlentities((string) json_encode($chartData['resourceStats']['dates'])); ?>
data: <?php echo json_encode($chartData['resourceStats']['dates']); ?>
},
yAxis: {
type: 'value'
@@ -685,7 +685,7 @@ function initResourceStats() {
{
name: '新增资源',
type: 'bar',
data: <?php echo htmlentities((string) json_encode($chartData['resourceStats']['newResources'])); ?>,
data: <?php echo json_encode($chartData['resourceStats']['newResources']); ?>,
itemStyle: {
color: '#3881fd'
}
@@ -694,7 +694,7 @@ function initResourceStats() {
name: '总资源数',
type: 'line',
smooth: true,
data: <?php echo htmlentities((string) json_encode($chartData['resourceStats']['totalResources'])); ?>,
data: <?php echo json_encode($chartData['resourceStats']['totalResources']); ?>,
itemStyle: {
color: '#10b981'
},
@@ -706,7 +706,7 @@ function initResourceStats() {
name: '下载量',
type: 'line',
smooth: true,
data: <?php echo htmlentities((string) json_encode($chartData['resourceStats']['downloads'])); ?>,
data: <?php echo json_encode($chartData['resourceStats']['downloads']); ?>,
itemStyle: {
color: '#f59e0b'
},
@@ -744,7 +744,7 @@ function initArticleStats() {
xAxis: {
type: 'category',
boundaryGap: false,
data: <?php echo htmlentities((string) json_encode($chartData['articleStats']['dates'])); ?>
data: <?php echo json_encode($chartData['articleStats']['dates']); ?>
},
yAxis: {
type: 'value'
@@ -753,7 +753,7 @@ function initArticleStats() {
{
name: '新增文章',
type: 'bar',
data: <?php echo htmlentities((string) json_encode($chartData['articleStats']['newArticles'])); ?>,
data: <?php echo json_encode($chartData['articleStats']['newArticles']); ?>,
itemStyle: {
color: '#3881fd'
}
@@ -762,7 +762,7 @@ function initArticleStats() {
name: '总文章数',
type: 'line',
smooth: true,
data: <?php echo htmlentities((string) json_encode($chartData['articleStats']['totalArticles'])); ?>,
data: <?php echo json_encode($chartData['articleStats']['totalArticles']); ?>,
itemStyle: {
color: '#10b981'
},
@@ -774,7 +774,7 @@ function initArticleStats() {
name: '浏览量',
type: 'line',
smooth: true,
data: <?php echo htmlentities((string) json_encode($chartData['articleStats']['views'])); ?>,
data: <?php echo json_encode($chartData['articleStats']['views']); ?>,
itemStyle: {
color: '#f59e0b'
},
@@ -1,4 +1,4 @@
<?php /*a:2:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\resources\lists.php";i:1747702165;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<?php /*a:2:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\resources\lists.php";i:1747817496;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -154,7 +154,7 @@
{{# if(d.status == '0'){ }}
<span style="color:red;">未审核</span>
{{# } else if(d.status == '1'){ }}
<span style="color:orange;">已审核</span>
<span style="color:green;">已审核</span>
{{# } }}
</script>
@@ -181,6 +181,7 @@
method: 'post',
cols: [[
{ field: 'id', title: 'ID', align: 'center', width: 80 },
{ field: 'number', title: '资源编号', width: 100 },
{ field: 'title', title: '资源名称' },
{ field: 'cate', title: '分类', align: 'center', width: 120 },
{ field: 'icon', title: '图标', templet: '#iconTemplate', align: 'center', width: 100 },
@@ -1,4 +1,4 @@
<?php /*a:2:{s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\resources\edit.php";i:1747445574;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<?php /*a:2:{s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\resources\edit.php";i:1749454320;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -117,16 +117,25 @@
<div class="layui-form-item">
<label class="layui-form-label">分类</label>
<div class="layui-input-block">
<select name="cate" lay-verify="required">
<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>
<textarea name="desc" placeholder="请输入资源描述" class="layui-textarea"
lay-affix="clear"><?php echo htmlentities((string) (isset($resource['desc']) && ($resource['desc'] !== '')?$resource['desc']:'')); ?></textarea>
</div>
</div>
@@ -162,8 +171,8 @@
<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">
<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>
@@ -176,7 +185,8 @@
</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 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="">
@@ -191,18 +201,65 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">图片上传</label>
<div class="layui-input-block">
<div class="layui-upload">
<button type="button" class="layui-btn" id="imageUpload">多图片上传</button>
<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
预览图:
<div class="layui-upload-list" id="imagePreview" style="display: flex; flex-direction: column;">
<?php if($resource['images']): if(is_array($images) || $images instanceof \think\Collection || $images instanceof \think\Paginator): if( count($images)==0 ) : echo "" ;else: foreach($images as $key=>$image): ?>
<div class="layui-upload-img-item" data-src="<?php echo htmlentities((string) $image); ?>">
<img src="<?php echo htmlentities((string) $image); ?>" alt="已上传图片" style="width: 100px; height: 100px; object-fit: cover;">
<p><?php echo htmlentities((string) basename($image)); ?></p>
<button type="button"
class="layui-btn layui-btn-xs layui-btn-danger delete-image">删除</button>
</div>
<?php endforeach; endif; else: echo "" ;endif; ?>
<?php endif; ?>
</div>
</blockquote>
</div>
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="image-progress"
style="margin-top: 10px;">
<div class="layui-progress-bar" lay-percent=""></div>
</div>
<input type="hidden" name="images" id="images" value="<?php echo htmlentities((string) (isset($resource['images']) && ($resource['images'] !== '')?$resource['images']:'')); ?>">
</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">
<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">
<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>
@@ -215,6 +272,7 @@
</form>
</div>
<script src="/static/js/wangeditor.js"></script>
<script>
layui.use(['form', 'layer'], function () {
var form = layui.form;
@@ -226,13 +284,13 @@
// 获取资源详情
var resourceId = $('input[name="id"]').val();
var resourceData = null;
if (resourceId) {
$.get('<?php echo url("resources/get"); ?>', {id: resourceId}, function(res) {
$.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 || '');
@@ -244,12 +302,12 @@
$('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();
@@ -278,7 +336,7 @@
$('#upload-text').html('');
layer.msg('图标上传成功', { icon: 1 });
},
uploadError: function () {
error: 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 () {
@@ -293,6 +351,58 @@
}
});
// 多图片上传
var uploadInst = upload.render({
elem: '#imageUpload',
url: '<?php echo url("index/upload_img"); ?>',
multiple: true,
accept: 'images',
before: function (obj) {
obj.preview(function (index, file, result) {
$('#imagePreview').append('<div class="layui-upload-img-item" data-src="' + result + '"><img src="' + result + '" alt="' + file.name + '" style="width: 100px; height: 100px; object-fit: cover;"><p>' + file.name + '</p><button type="button" class="layui-btn layui-btn-xs layui-btn-danger delete-image">删除</button></div>');
});
element.progress('image-progress', '0%');
layer.msg('图片上传中', { icon: 16, time: 0 });
},
done: function (res) {
if (res.code > 0) {
return layer.msg('图片上传失败');
}
var images = $('#images').val().split(',');
if (res.data) {
images.push(res.data);
}
$('#images').val(images.filter(Boolean).join(','));
layer.msg('图片上传成功', { icon: 1 });
},
error: function () {
var demoText = $('#imagePreview');
demoText.append('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
demoText.find('.demo-reload').on('click', function () {
uploadInst.upload();
});
},
progress: function (n, elem, e) {
element.progress('image-progress', n + '%');
if (n == 100) {
layer.msg('图片上传完毕', { icon: 1 });
}
}
});
// 删除图片功能
$('#imagePreview').on('click', '.delete-image', function () {
var $item = $(this).closest('.layui-upload-img-item');
var imageSrc = $item.data('src');
var images = $('#images').val().split(',');
var index = images.indexOf(imageSrc);
if (index > -1) {
images.splice(index, 1);
}
$('#images').val(images.join(','));
$item.remove();
});
// 文件上传
var fileUpload = upload.render({
elem: '#ID-upload-demo-drag',
@@ -339,6 +449,9 @@
// 获取分类列表
$.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>';
@@ -349,11 +462,11 @@
}
});
$('select[name="cate"]').html(html);
// 如果有资源数据,设置分类值
if (resourceData && resourceData.cate) {
console.log('Setting cate value:', resourceData.cate); // 调试输出
setTimeout(function() {
setTimeout(function () {
$('select[name="cate"]').val(resourceData.cate);
form.render('select');
}, 100);
@@ -363,9 +476,50 @@
}
});
// 监听分类选择变化
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',
@@ -386,7 +540,7 @@
});
// 重置按钮点击事件
$('button[type="reset"]').on('click', function() {
$('button[type="reset"]').on('click', function () {
// 重新加载分类列表
$.get('<?php echo url("resources/getcate"); ?>', function (res) {
if (res.code == 0) {
@@ -400,10 +554,10 @@
}
});
$('select[name="cate"]').html(html);
// 如果有资源数据,设置分类值
if (resourceData && resourceData.cate) {
setTimeout(function() {
setTimeout(function () {
$('select[name="cate"]').val(resourceData.cate);
form.render('select');
}, 100);
@@ -418,6 +572,86 @@
});
</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: 50 * 1024 * 1024, // 50M
maxNumberOfFiles: 10,
allowedFileTypes: ['image/*'],
meta: {
token: 'xxx'
},
metaWithUrl: true,
headers: {
Accept: 'text/x-json'
},
timeout: 30 * 1000, // 30s
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) {
// 只使用返回的url字段,并确保使用完整的URL
if (res.code === 0 && res.url) {
// 如果URL不是以http开头,添加https://
let imageUrl = res.url;
if (!imageUrl.startsWith('http')) {
imageUrl = 'https://' + imageUrl;
}
// 移除可能存在的重复域名和路径
imageUrl = imageUrl.replace(/^https?:\/\/[^\/]+\/admin\/resources\//, 'https://www.yunzer.cn/');
insertFn(imageUrl);
} else {
layer.msg('图片上传失败:' + (res.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() {