更新前端首页显示文章
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user