更新前端首页显示文章

This commit is contained in:
云泽网
2025-05-12 01:52:39 +08:00
parent b1356231d4
commit f55b0068a2
20 changed files with 624 additions and 373 deletions
@@ -1,4 +1,4 @@
<?php /*a:2:{s:53:"E:\Demo\PHP\yunzer\app\admin\view\article\cateadd.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
<?php /*a:2:{s:53:"E:\Demo\PHP\yunzer\app\admin\view\article\cateadd.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -6,7 +6,7 @@
<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/third/layui/css/layui.css" media="all"/>
<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">
@@ -79,7 +79,7 @@
}
.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/third/layui/layui.js"></script>
<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 弹框
@@ -1,4 +1,4 @@
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlelist.php";i:1746800071;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlelist.php";i:1746800071;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -6,7 +6,7 @@
<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/third/layui/css/layui.css" media="all"/>
<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">
@@ -79,7 +79,7 @@
}
.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/third/layui/layui.js"></script>
<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 弹框
@@ -1,4 +1,4 @@
<?php /*a:2:{s:54:"E:\Demo\PHP\yunzer\app\admin\view\article\cateedit.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
<?php /*a:2:{s:54:"E:\Demo\PHP\yunzer\app\admin\view\article\cateedit.php";i:1746890051;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -6,7 +6,7 @@
<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/third/layui/css/layui.css" media="all"/>
<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">
@@ -79,7 +79,7 @@
}
.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/third/layui/layui.js"></script>
<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 弹框
@@ -96,6 +96,26 @@
<div style="padding: 50px;padding-bottom: 0px;">
<form class="layui-form" action="" method="post">
<input type="hidden" name="id" value="<?php echo htmlentities((string) $info['id']); ?>">
<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;" src="<?php echo htmlentities((string) $info['image']); ?>">
<div id="upload-text"></div>
</div>
<div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="filter-demo">
<div class="layui-progress-bar" lay-percent=""></div>
</div>
<input type="hidden" name="image" id="image" value="<?php echo htmlentities((string) $info['image']); ?>">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分类名称</label>
<div class="layui-input-block">
@@ -125,7 +145,8 @@
<div class="layui-form-item">
<label class="layui-form-label">排序</label>
<div class="layui-input-block">
<input type="number" id="sort" name="sort" value="<?php echo htmlentities((string) $info['sort']); ?>" placeholder="请输入排序值" class="layui-input">
<input type="number" id="sort" name="sort" value="<?php echo htmlentities((string) $info['sort']); ?>" placeholder="请输入排序值"
class="layui-input">
</div>
</div>
@@ -138,23 +159,66 @@
</div>
<script>
layui.use(['form', 'layer'], function () {
// 首先定义PHP变量,确保类型正确
var currentCid = parseInt('<?php echo htmlentities((string) (isset($info['cid']) && ($info['cid'] !== '')?$info['cid']:0)); ?>'); // 转换为数字
var currentId = parseInt('<?php echo htmlentities((string) (isset($info['id']) && ($info['id'] !== '')?$info['id']:0)); ?>'); // 转换为数字
layui.use(['form', 'layer', 'upload', 'element'], function () {
var form = layui.form;
var layer = layui.layer;
var $ = layui.jquery;
var upload = layui.upload;
var element = layui.element;
// 获取URL中的id参数
var urlParams = new URLSearchParams(window.location.search);
var id = urlParams.get('id');
var id = parseInt(urlParams.get('id')) || 0; // 转换为数字
// 图片上传
var uploadInst = 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('filter-demo', '0%');
layer.msg('上传中', { icon: 16, time: 0 });
},
done: function (res) {
if (res.code > 0) {
return layer.msg('上传失败');
}
$('#image').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 () {
uploadInst.upload();
});
},
progress: function (n, elem, e) {
element.progress('filter-demo', n + '%');
if (n == 100) {
layer.msg('上传完毕', { icon: 1 });
}
}
});
// 获取分类列表
$.get('<?php echo url("article/getcate"); ?>', function (res) {
if (res.code == 0) {
var html = '<option value="0">顶级分类</option>';
res.data.forEach(function (item) {
// 排除自己及其子分类作为父级选项
if(item.id != id) {
html += '<option value="' + item.id + '"' + (item.id == <?php echo htmlentities((string) $info['cid']); ?> ? ' selected' : '') + '>' + item.name + '</option>';
// 确保item.id是数字类型
var itemId = parseInt(item.id);
if (itemId !== id) { // 使用严格比较
html += '<option value="' + itemId + '"' +
(itemId === currentCid ? ' selected' : '') +
'>' + item.name + '</option>';
}
});
$('#cid').html(html);
@@ -1,4 +1,4 @@
<?php /*a:3:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\index\welcome.php";i:1745855804;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;s:49:"E:\Demo\PHP\yunzer\app\admin\view\public\tail.php";i:1745855804;}*/ ?>
<?php /*a:3:{s:51:"E:\Demo\PHP\yunzer\app\admin\view\index\welcome.php";i:1745855804;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;s:49:"E:\Demo\PHP\yunzer\app\admin\view\public\tail.php";i:1745855804;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -6,7 +6,7 @@
<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/third/layui/css/layui.css" media="all"/>
<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">
@@ -79,7 +79,7 @@
}
.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/third/layui/layui.js"></script>
<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 弹框
@@ -1,4 +1,4 @@
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlecate.php";i:1746796639;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlecate.php";i:1746890051;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -6,7 +6,7 @@
<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/third/layui/css/layui.css" media="all"/>
<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">
@@ -79,7 +79,7 @@
}
.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/third/layui/layui.js"></script>
<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 弹框
@@ -113,6 +113,7 @@
<tr>
<th width="20">ID</th>
<th width="120">分类名称</th>
<th width="120">分类图片</th>
<th>描述</th>
<th width="80">排序</th>
<th width="80">状态</th>
@@ -125,7 +126,8 @@
<tr>
<td><?php echo htmlentities((string) $vo['id']); ?></td>
<td><?php echo htmlentities((string) $vo['name']); ?></td>
<td><?php echo htmlentities((string) $vo['desc']); ?></td>
<td><img src="<?php echo htmlentities((string) $vo['image']); ?>" style="width: 100px;height: auto;"></td>
<td></td><?php echo htmlentities((string) $vo['desc']); ?></td>
<td><?php echo htmlentities((string) $vo['sort']); ?></td>
<td><?php echo $vo['status']==1 ? '开启' : '<span style="color:red;">禁用</span>'; ?></td>
<td><?php echo htmlentities((string) $vo['create_time']); ?></td>
@@ -146,6 +148,7 @@
<tr>
<td><?php echo htmlentities((string) $sub['id']); ?></td>
<td style="padding-left: 30px;">├─ <?php echo htmlentities((string) $sub['name']); ?></td>
<td><img src="<?php echo htmlentities((string) $sub['image']); ?>" style="width: 100px;height: auto;"></td>
<td><?php echo htmlentities((string) $sub['desc']); ?></td>
<td><?php echo htmlentities((string) $sub['sort']); ?></td>
<td><?php echo $sub['status']==1 ? '开启' : '<span style="color:red;">禁用</span>'; ?></td>
@@ -190,7 +193,7 @@
title: '编辑分类',
shadeClose: true,
shade: 0.8,
area: ['500px', '400px'],
area: ['800px', '800px'],
content: '<?php echo url("article/cateedit"); ?>?id=' + id
});
}
@@ -1,4 +1,4 @@
<?php /*a:2:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\article\add.php";i:1746802033;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746796639;}*/ ?>
<?php /*a:2:{s:49:"E:\Demo\PHP\yunzer\app\admin\view\article\add.php";i:1746804004;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
<!DOCTYPE html>
<html>
<head>
@@ -6,7 +6,7 @@
<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/third/layui/css/layui.css" media="all"/>
<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">
@@ -79,7 +79,7 @@
}
.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/third/layui/layui.js"></script>
<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 弹框
@@ -286,36 +286,61 @@
const { createEditor, createToolbar } = window.wangEditor
const editorConfig = {
MENU_CONF: {},
placeholder: '请输入内容...',
onChange(editor) {
const html = editor.getHtml()
// console.log('editor content', html)
// 也可以同步到 <textarea>
},
menus: [
'head', // 标题
'bold', // 粗体
'fontSize', // 字号
'fontName', // 字体
'italic', // 斜体
'underline', // 下划线
'strikeThrough', // 删除线
'foreColor', // 文本颜色
'backColor', // 背景颜色
'link', // 插入链接
'list', // 列表
'justify', // 对齐方式
'quote', // 引用
'emoticon', // 表情
'image', // 插入图片
'video', // 插入视频
'audio', // 插入音频
'table', // 表格
'code', // 插入代码
'undo', // 撤销
'redo', // 重做
],
uploadImgServer: '/index/upload_imgs', // 图片上传接口
}
// 配置图片上传
editorConfig.MENU_CONF['uploadImage'] = {
server: '<?php echo url("index/upload_imgs"); ?>',
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({