改接口匹配新前端
This commit is contained in:
parent
5691a3f677
commit
2161113eae
@ -32,6 +32,144 @@ use app\index\model\Resources\Resources;
|
||||
|
||||
class ArticlesController extends BaseController
|
||||
{
|
||||
// 获取siteinformation分类
|
||||
public function getSiteInformationCategory()
|
||||
{
|
||||
// 获取名为 '站点资讯' 的分类
|
||||
$siteInfoCategory = ArticlesCategory::where('name', '站点资讯')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->field('id,cid,name,image,sort')
|
||||
->find();
|
||||
|
||||
if (!$siteInfoCategory) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '未找到站点资讯分类'
|
||||
]);
|
||||
}
|
||||
|
||||
// 只返回其子分类,cid等于'站点资讯'的id
|
||||
$children = ArticlesCategory::where('cid', $siteInfoCategory['id'])
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->field('id,cid,name,image,sort')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取站点资讯子分类成功',
|
||||
'data' => $children
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取siteinformation内容,传参
|
||||
public function getSiteInformationLists()
|
||||
{
|
||||
try {
|
||||
// 获取前端传递的分类ID
|
||||
$cateid = input('cateid/d', 0);
|
||||
|
||||
// 验证分类ID
|
||||
if ($cateid <= 0) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '分类ID不能为空'
|
||||
]);
|
||||
}
|
||||
|
||||
// 检查分类是否存在且有效
|
||||
$category = ArticlesCategory::where('id', $cateid)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
|
||||
if (!$category) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '分类不存在或已禁用'
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取分页参数
|
||||
$page = input('page/d', 1);
|
||||
$limit = input('limit/d', 10);
|
||||
|
||||
// 获取该分类下的所有子分类ID(包括自身)
|
||||
$subCategoryIds = [$cateid];
|
||||
|
||||
// 查找所有子分类
|
||||
$subCategories = ArticlesCategory::where('cid', $cateid)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->column('id');
|
||||
|
||||
if (!empty($subCategories)) {
|
||||
$subCategoryIds = array_merge($subCategoryIds, $subCategories);
|
||||
}
|
||||
|
||||
// 构建查询条件
|
||||
$where = [
|
||||
['delete_time', '=', null],
|
||||
['status', '=', 2], // 已发布的文章
|
||||
['cate', 'in', $subCategoryIds]
|
||||
];
|
||||
|
||||
// 查询文章总数
|
||||
$total = Articles::where($where)->count();
|
||||
|
||||
// 查询文章列表
|
||||
$articles = Articles::where($where)
|
||||
->field('id,title,cate,image,desc,author,content,publishdate,views,likes,is_trans,transurl,push,create_time')
|
||||
->order('sort DESC, id DESC')
|
||||
->page($page, $limit)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 处理文章数据
|
||||
foreach ($articles as &$article) {
|
||||
// 如果文章没有封面图,使用分类封面图
|
||||
if (empty($article['image'])) {
|
||||
$article['image'] = $category['image'] ?? '';
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
$article['publishdate'] = date('Y-m-d H:i:s', strtotime($article['publishdate']));
|
||||
$article['create_time'] = date('Y-m-d H:i:s', strtotime($article['create_time']));
|
||||
|
||||
// 获取分类名称
|
||||
$articleCategory = ArticlesCategory::where('id', $article['cate'])->find();
|
||||
$article['category_name'] = $articleCategory ? $articleCategory['name'] : '';
|
||||
}
|
||||
|
||||
// 返回数据
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'category' => [
|
||||
'id' => $category['id'],
|
||||
'name' => $category['name'],
|
||||
'desc' => $category['desc'],
|
||||
'image' => $category['image']
|
||||
],
|
||||
'articles' => $articles,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'total_pages' => ceil($total / $limit)
|
||||
]
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '获取失败:' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//文章中心
|
||||
public function index()
|
||||
{
|
||||
@ -237,7 +375,7 @@ class ArticlesController extends BaseController
|
||||
$articleCount = Articles::where('author', $article['author'])->count();
|
||||
// 统计作者的资源数
|
||||
$resourceCount = Resources::where('uploader', $article['author'])->count();
|
||||
|
||||
|
||||
$authorData = [
|
||||
'avatar' => $authorInfo['avatar'] ?: '/static/images/avatar.png',
|
||||
'name' => $authorInfo['name'],
|
||||
@ -469,7 +607,7 @@ class ArticlesController extends BaseController
|
||||
//获取作者信息
|
||||
public function getAuthorInfo()
|
||||
{
|
||||
if (!Request::isPost()) {
|
||||
if (!Request::isPost()) {
|
||||
return json(['code' => 0, 'msg' => '非法请求']);
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Env;
|
||||
use think\facade\Config;
|
||||
use app\index\model\MenuFront\MenuFront;
|
||||
use app\index\model\Banner;
|
||||
use app\index\model\Resources\ResourcesCategory;
|
||||
use app\index\model\Articles\ArticlesCategory;
|
||||
@ -37,6 +38,50 @@ use app\index\model\Attachments;
|
||||
|
||||
class IndexController extends BaseController
|
||||
{
|
||||
//获取主体菜单
|
||||
/**
|
||||
* 获取主菜单列表
|
||||
* @return \think\Response|\think\response\Json
|
||||
*/
|
||||
public function getmainmenu()
|
||||
{
|
||||
try {
|
||||
// 查询所有未删除且启用的一级菜单,只筛选所需字段
|
||||
$menuList = MenuFront::where('status', 1)
|
||||
->where('view', 1)
|
||||
->where('parent_id', 0)
|
||||
->whereNull('delete_time')
|
||||
->order('sort desc,id asc')
|
||||
->field('id,parent_id,title,path,url,icon,sort')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 递归查询每个一级菜单的子菜单,只筛选所需字段
|
||||
foreach ($menuList as &$menu) {
|
||||
$children = MenuFront::where('status', 1)
|
||||
->where('view', 1)
|
||||
->where('parent_id', $menu['id'])
|
||||
->whereNull('delete_time')
|
||||
->order('sort desc,id asc')
|
||||
->field('id,parent_id,title,path,url,icon,sort')
|
||||
->select()
|
||||
->toArray();
|
||||
$menu['children'] = $children;
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取主菜单成功',
|
||||
'data' => $menuList
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '获取主菜单失败: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*/
|
||||
|
||||
25
app/index/model/AdminSysMenu/AdminSysMenu.php
Normal file
25
app/index/model/AdminSysMenu/AdminSysMenu.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* 商业使用授权协议
|
||||
*
|
||||
* Copyright (c) 2025 [云泽网]. 保留所有权利.
|
||||
*
|
||||
* 本软件仅供评估使用。任何商业用途必须获得书面授权许可。
|
||||
* 未经授权商业使用本软件属于侵权行为,将承担法律责任。
|
||||
*
|
||||
* 授权购买请联系: 357099073@qq.com
|
||||
* 官方网站: https://www.yunzer.cn
|
||||
*
|
||||
* 评估用户须知:
|
||||
* 1. 禁止移除版权声明
|
||||
* 2. 禁止用于生产环境
|
||||
* 3. 禁止转售或分发
|
||||
*/
|
||||
|
||||
namespace app\index\model\AdminSysMenu;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class AdminSysMenu extends Model
|
||||
{
|
||||
}
|
||||
25
app/index/model/MenuFront/MenuFront.php
Normal file
25
app/index/model/MenuFront/MenuFront.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* 商业使用授权协议
|
||||
*
|
||||
* Copyright (c) 2025 [云泽网]. 保留所有权利.
|
||||
*
|
||||
* 本软件仅供评估使用。任何商业用途必须获得书面授权许可。
|
||||
* 未经授权商业使用本软件属于侵权行为,将承担法律责任。
|
||||
*
|
||||
* 授权购买请联系: 357099073@qq.com
|
||||
* 官方网站: https://www.yunzer.cn
|
||||
*
|
||||
* 评估用户须知:
|
||||
* 1. 禁止移除版权声明
|
||||
* 2. 禁止用于生产环境
|
||||
* 3. 禁止转售或分发
|
||||
*/
|
||||
|
||||
namespace app\index\model\MenuFront;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class MenuFront extends Model
|
||||
{
|
||||
}
|
||||
440
app/index/view/user/component/publisharticle.php
Normal file
440
app/index/view/user/component/publisharticle.php
Normal file
@ -0,0 +1,440 @@
|
||||
<div class="publish-section">
|
||||
<h2 class="section-title">发布文章</h2>
|
||||
<p class="section-desc">分享您的技术见解、经验总结或其他有价值的内容</p>
|
||||
|
||||
<form class="layui-form" lay-filter="publishForm">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="layui-font-red">*</span>文章标题</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="title" placeholder="请输入文章标题" class="layui-input" lay-verify="required"
|
||||
lay-reqtext="文章标题不能为空" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><span class="layui-font-red">*</span>文章分类</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="category" lay-verify="required" lay-reqtext="请选择文章分类">
|
||||
<option value="">请选择分类</option>
|
||||
<option value="tech">技术文章</option>
|
||||
<option value="tutorial">教程指南</option>
|
||||
<option value="news">行业资讯</option>
|
||||
<option value="experience">经验分享</option>
|
||||
<option value="other">其他文章</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">文章摘要</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="summary" placeholder="请简要概括文章主要内容" class="layui-textarea" rows="4"
|
||||
lay-reqtext="请填写文章摘要"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label"><span class="layui-font-red">*</span>文章内容</label>
|
||||
<div class="layui-input-block">
|
||||
<div id="editor-wrapper" style="border: 1px solid #e8e8e8; border-radius: 6px;">
|
||||
<div id="toolbar-container" style="border-bottom: 1px solid #e8e8e8;"></div>
|
||||
<div id="editor-container" style="height: 400px;"></div>
|
||||
</div>
|
||||
<textarea name="content" id="contentTextarea" style="display: none;"></textarea>
|
||||
<div class="layui-word-aux">支持富文本编辑,可插入图片、链接、代码块等</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="layui-form-item">
|
||||
<label class="layui-form-label">文章标签</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="tags" placeholder="请输入文章标签,用逗号分隔" class="layui-input" />
|
||||
<span class="layui-word-aux">如:PHP,ThinkPHP,开发经验</span>
|
||||
</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="uploadCoverBtn">上传封面</button>
|
||||
<div class="layui-upload-list" id="coverList"></div>
|
||||
<span class="layui-word-aux">建议尺寸:800x450px,支持 JPG、PNG 格式</span>
|
||||
</div>
|
||||
<input type="hidden" name="cover_image" id="coverInput" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">原文链接</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="url" name="source_url" placeholder="如果这是转载文章,请填写原文链接" class="layui-input" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="layui-form-item">
|
||||
<label class="layui-form-label">发布选项</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="is_draft" value="1" title="保存为草稿" lay-skin="primary">
|
||||
<input type="checkbox" name="allow_comment" value="1" title="允许评论" lay-skin="primary" checked>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button type="submit" class="layui-btn" lay-submit lay-filter="publishSubmit">发布文章</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置表单</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/@wangeditor/editor@5.1.23/dist/index.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@wangeditor/editor@5.1.23/dist/css/style.css">
|
||||
<script>
|
||||
layui.use(['form', 'layer', 'upload'], function () {
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
var upload = layui.upload;
|
||||
var $ = layui.jquery;
|
||||
|
||||
// 等待wangeditor加载完成
|
||||
if (typeof window.wangEditor === 'undefined') {
|
||||
console.error('wangEditor未正确加载');
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始化富文本编辑器
|
||||
const { createEditor, createToolbar } = window.wangEditor;
|
||||
|
||||
const editorConfig = {
|
||||
placeholder: '请输入文章内容...',
|
||||
onChange(editor) {
|
||||
const html = editor.getHtml();
|
||||
// 同步到隐藏的textarea
|
||||
$('#contentTextarea').val(html);
|
||||
},
|
||||
MENU_CONF: {}
|
||||
};
|
||||
|
||||
// 配置图片上传
|
||||
editorConfig.MENU_CONF['uploadImage'] = {
|
||||
server: '/index/user/uploadImage',
|
||||
fieldName: 'file',
|
||||
maxFileSize: 2 * 1024 * 1024, // 2M
|
||||
maxNumberOfFiles: 10,
|
||||
allowedFileTypes: ['image/*'],
|
||||
onBeforeUpload(file) {
|
||||
console.log('准备上传图片', file);
|
||||
return file;
|
||||
},
|
||||
onProgress(progress) {
|
||||
console.log('上传进度', progress);
|
||||
},
|
||||
onSuccess(file, res) {
|
||||
console.log('上传成功', file, res);
|
||||
},
|
||||
onFailed(file, res) {
|
||||
console.log('上传失败', file, res);
|
||||
layer.msg('上传失败:' + (res.message || '未知错误'), { icon: 2 });
|
||||
},
|
||||
onError(file, err, res) {
|
||||
console.error('上传出错', file, err, res);
|
||||
layer.msg('上传出错:' + (err.message || '网络错误'), { icon: 2 });
|
||||
},
|
||||
customInsert(res, insertFn) {
|
||||
console.log('自定义插入', res);
|
||||
if (res.code === 0 && res.data && res.data.url) {
|
||||
insertFn(res.data.url, res.data.alt || '', res.data.href || '');
|
||||
} else {
|
||||
layer.msg(res.msg || '上传失败', { icon: 2 });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 创建编辑器
|
||||
const editor = createEditor({
|
||||
selector: '#editor-container',
|
||||
config: editorConfig,
|
||||
html: '<p><br></p>',
|
||||
mode: 'default'
|
||||
});
|
||||
|
||||
// 创建工具栏
|
||||
const toolbar = createToolbar({
|
||||
editor,
|
||||
selector: '#toolbar-container',
|
||||
config: {},
|
||||
mode: 'default'
|
||||
});
|
||||
|
||||
// 表单提交
|
||||
form.on('submit(publishSubmit)', function (data) {
|
||||
// 获取编辑器内容
|
||||
var content = editor.getHtml();
|
||||
if (!content || content === '<p><br></p>') {
|
||||
layer.msg('请输入文章内容', { icon: 2 });
|
||||
return false;
|
||||
}
|
||||
|
||||
var loadIndex = layer.load(2);
|
||||
data.field.content = content;
|
||||
|
||||
$.ajax({
|
||||
url: '/index/user/publishArticle',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
success: function (res) {
|
||||
layer.close(loadIndex);
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
// 重置表单
|
||||
form.val('publishForm', {
|
||||
title: '',
|
||||
category: '',
|
||||
summary: '',
|
||||
tags: '',
|
||||
source_url: '',
|
||||
is_draft: 0,
|
||||
allow_comment: 1
|
||||
});
|
||||
|
||||
// 清空富文本编辑器
|
||||
editor.setHtml('<p><br></p>');
|
||||
$('#contentTextarea').val('');
|
||||
|
||||
// 清空封面图片
|
||||
$('#coverList').empty().hide();
|
||||
$('#coverInput').val('');
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// 封面图片上传
|
||||
upload.render({
|
||||
elem: '#uploadCoverBtn',
|
||||
url: 'index/upload_img',
|
||||
accept: 'image',
|
||||
acceptMime: 'image/*',
|
||||
exts: 'jpg|png|jpeg',
|
||||
size: 2048, // 2MB
|
||||
before: function (obj) {
|
||||
layer.load(1);
|
||||
},
|
||||
done: function (res) {
|
||||
layer.closeAll('loading');
|
||||
if (res.code === 0) {
|
||||
$('#coverList').html(`
|
||||
<div class="upload-item">
|
||||
<img src="${res.data.url}" alt="封面图" />
|
||||
<div class="upload-actions">
|
||||
<i class="layui-icon layui-icon-delete" onclick="removeCover()"></i>
|
||||
</div>
|
||||
</div>
|
||||
`).show();
|
||||
$('#coverInput').val(res.data.url);
|
||||
layer.msg('上传成功', { icon: 1 });
|
||||
} else {
|
||||
layer.msg(res.msg || '上传失败', { icon: 2 });
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
layer.closeAll('loading');
|
||||
layer.msg('上传失败', { icon: 2 });
|
||||
}
|
||||
});
|
||||
|
||||
// 删除封面图片
|
||||
window.removeCover = function () {
|
||||
$('#coverList').empty().hide();
|
||||
$('#coverInput').val('');
|
||||
};
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.layui-form-label {
|
||||
width: 110px !important;
|
||||
}
|
||||
|
||||
.layui-font-red {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.publish-section {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
color: #666;
|
||||
margin-bottom: 32px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.layui-form-label {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.layui-input-block {
|
||||
margin-left: 150px;
|
||||
}
|
||||
|
||||
.layui-form-item {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.layui-input,
|
||||
.layui-textarea,
|
||||
.layui-select {
|
||||
border-radius: 6px;
|
||||
border: 1px solid #e8e8e8;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.layui-input:focus,
|
||||
.layui-textarea:focus,
|
||||
.layui-select:focus {
|
||||
border-color: #1677ff;
|
||||
box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
|
||||
}
|
||||
|
||||
/* 富文本编辑器样式 */
|
||||
#editor-wrapper {
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#toolbar-container {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
/* 封面图片上传样式 */
|
||||
.cover-upload {
|
||||
border: 2px dashed #d9d9d9;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
transition: all 0.3s;
|
||||
cursor: pointer;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.cover-upload:hover {
|
||||
border-color: #1677ff;
|
||||
background: #f8f9ff;
|
||||
}
|
||||
|
||||
.cover-placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.cover-placeholder .layui-icon {
|
||||
font-size: 48px;
|
||||
color: #ccc;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.cover-placeholder p {
|
||||
margin: 8px 0;
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.cover-placeholder span {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
#coverList {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
#coverList .upload-item {
|
||||
position: relative;
|
||||
width: 200px;
|
||||
height: 120px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #e8e8e8;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
#coverList .upload-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
#coverList .upload-actions {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
#coverList .upload-item:hover .upload-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
#coverList .upload-actions .layui-icon {
|
||||
color: #fff;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.layui-btn {
|
||||
border-radius: 6px;
|
||||
padding: 0 24px;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.layui-btn-primary {
|
||||
border-color: #d9d9d9;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.layui-btn-primary:hover {
|
||||
border-color: #1677ff;
|
||||
color: #1677ff;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.layui-form-label {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
.layui-input-block {
|
||||
margin-left: 120px;
|
||||
}
|
||||
|
||||
#coverList .upload-item {
|
||||
width: 150px;
|
||||
height: 90px;
|
||||
}
|
||||
|
||||
.layui-layedit {
|
||||
height: 300px !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -216,7 +216,7 @@
|
||||
<form action="#" method="post" class="layui-form login-form">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block" style="margin-left: 0;">
|
||||
<input type="text" name="account" required lay-verify="required" placeholder="请输入用户名"
|
||||
<input type="text" name="account" required lay-verify="required" placeholder="请输入您的邮箱"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -56,6 +56,17 @@
|
||||
<i class="layui-icon layui-icon-down collapse-icon"></i>
|
||||
</div>
|
||||
<div class="menu-group-content collapsed">
|
||||
<div class="menu-item" data-target="article-publish">
|
||||
<div class="menu-icon">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</div>
|
||||
<div class="menu-content">
|
||||
<span class="menu-title">发布文章</span>
|
||||
<span class="menu-desc">发布站内文章</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="menu-item" data-target="apps-publish">
|
||||
<div class="menu-icon">
|
||||
<i class="fa-regular fa-paper-plane"></i>
|
||||
@ -95,6 +106,11 @@
|
||||
{include file="user/component/basic" /}
|
||||
</div>
|
||||
|
||||
<!-- 发布文章 -->
|
||||
<div id="article-publish" class="content-section">
|
||||
{include file="user/component/publisharticle" /}
|
||||
</div>
|
||||
|
||||
<!-- 发布资源 -->
|
||||
<div id="apps-publish" class="content-section">
|
||||
{include file="user/component/publishresource" /}
|
||||
@ -157,16 +173,16 @@
|
||||
|
||||
// 获取当前菜单项所在的组
|
||||
var $currentGroup = $(this).closest('.menu-group');
|
||||
|
||||
|
||||
// 确保当前菜单项所在的组是展开的
|
||||
var $currentContent = $currentGroup.find('.menu-group-content');
|
||||
if ($currentContent.hasClass('collapsed')) {
|
||||
$currentContent.removeClass('collapsed');
|
||||
$currentGroup.removeClass('collapsed');
|
||||
}
|
||||
|
||||
|
||||
// 闭合其他所有组
|
||||
$('.menu-group').not($currentGroup).each(function() {
|
||||
$('.menu-group').not($currentGroup).each(function () {
|
||||
var $otherGroup = $(this);
|
||||
var $otherContent = $otherGroup.find('.menu-group-content');
|
||||
if (!$otherContent.hasClass('collapsed')) {
|
||||
|
||||
@ -24,6 +24,6 @@ return [
|
||||
// \think\middleware\LoadLangPack::class,
|
||||
// Session初始化
|
||||
\think\middleware\SessionInit::class,
|
||||
// 允许跨域
|
||||
\think\middleware\AllowCrossDomain::class
|
||||
// 允许跨域 - 使用自定义CORS中间件
|
||||
\app\middleware\Cors::class
|
||||
];
|
||||
|
||||
75
app/middleware/Cors.php
Normal file
75
app/middleware/Cors.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* 商业使用授权协议
|
||||
*
|
||||
* Copyright (c) 2025 [云泽网]. 保留所有权利.
|
||||
*
|
||||
* 本软件仅供评估使用。任何商业用途必须获得书面授权许可。
|
||||
* 未经授权商业使用本软件属于侵权行为,将承担法律责任。
|
||||
*
|
||||
* 授权购买请联系: 357099073@qq.com
|
||||
* 官方网站: https://www.yunzer.cn
|
||||
*
|
||||
* 评估用户须知:
|
||||
* 1. 禁止移除版权声明
|
||||
* 2. 禁止用于生产环境
|
||||
* 3. 禁止转售或分发
|
||||
*/
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
|
||||
/**
|
||||
* CORS跨域中间件
|
||||
*/
|
||||
class Cors
|
||||
{
|
||||
public function handle(Request $request, \Closure $next)
|
||||
{
|
||||
// 处理预检请求
|
||||
if ($request->isOptions()) {
|
||||
return $this->handlePreflight();
|
||||
}
|
||||
|
||||
// 处理实际请求
|
||||
$response = $next($request);
|
||||
|
||||
// 添加CORS头
|
||||
return $this->addCorsHeaders($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理预检请求
|
||||
*/
|
||||
private function handlePreflight()
|
||||
{
|
||||
$response = Response::create('', 'html', 200);
|
||||
|
||||
return $this->addCorsHeaders($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加CORS头
|
||||
*/
|
||||
private function addCorsHeaders(Response $response)
|
||||
{
|
||||
$origin = request()->header('origin', '*');
|
||||
|
||||
// 在生产环境中,应该验证允许的域名
|
||||
// 这里为了开发方便,允许所有域名
|
||||
$allowedOrigin = $origin;
|
||||
|
||||
$response->header([
|
||||
'Access-Control-Allow-Origin' => $allowedOrigin,
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS, PATCH',
|
||||
'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Cache-Control, X-CSRF-Token, X-Token, token, Token',
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Max-Age' => '86400', // 24小时
|
||||
'Access-Control-Expose-Headers' => 'Authorization, Content-Disposition',
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
VITE_APP_ENV=development
|
||||
VITE_APP_DEBUG_MODE=true
|
||||
VITE_APP_TITLE=项目管理系统
|
||||
VITE_APP_API_BASE_URL=https://www.yunzer.cn/api
|
||||
VITE_APP_API_BASE_URL=http://localhost:8000/api
|
||||
2
frontend/components.d.ts
vendored
2
frontend/components.d.ts
vendored
@ -29,6 +29,8 @@ declare module 'vue' {
|
||||
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||
ElOption: typeof import('element-plus/es')['ElOption']
|
||||
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
||||
ElRow: typeof import('element-plus/es')['ElRow']
|
||||
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
||||
ElSelect: typeof import('element-plus/es')['ElSelect']
|
||||
|
||||
110
frontend/src/api/article.ts
Normal file
110
frontend/src/api/article.ts
Normal file
@ -0,0 +1,110 @@
|
||||
import axios from 'axios'
|
||||
import ENV_CONFIG from '@/config/env'
|
||||
|
||||
// 创建axios实例
|
||||
const api = axios.create({
|
||||
baseURL: ENV_CONFIG.API_BASE_URL,
|
||||
timeout: ENV_CONFIG.REQUEST_TIMEOUT,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
// 请求拦截器 - 添加token
|
||||
api.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem(ENV_CONFIG.TOKEN_KEY)
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 响应拦截器 - 处理错误
|
||||
api.interceptors.response.use(
|
||||
(response) => {
|
||||
const data = response.data
|
||||
|
||||
// 检查后端返回的状态码
|
||||
if (data.code === 0) {
|
||||
// 成功,返回data字段的内容
|
||||
return data.data
|
||||
} else {
|
||||
// 失败,抛出错误
|
||||
return Promise.reject(new Error(data.msg || '请求失败'))
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
// token过期,清除本地存储
|
||||
localStorage.removeItem(ENV_CONFIG.TOKEN_KEY)
|
||||
localStorage.removeItem(ENV_CONFIG.USER_INFO_KEY)
|
||||
window.location.href = '/#/login'
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 文章接口
|
||||
export interface Article {
|
||||
id: number
|
||||
title: string
|
||||
cate: string
|
||||
image: string
|
||||
desc: string
|
||||
author: string
|
||||
content: string
|
||||
publishdate: string
|
||||
sort: number | null
|
||||
status: number
|
||||
views: number
|
||||
likes: number
|
||||
is_trans: string
|
||||
transurl: string | null
|
||||
push: string
|
||||
create_time: string
|
||||
update_time: string | null
|
||||
delete_time: string | null
|
||||
}
|
||||
|
||||
// 获取文章列表的响应类型
|
||||
export interface ArticleListResponse {
|
||||
data: Article[]
|
||||
count: number
|
||||
}
|
||||
|
||||
// 获取文章列表
|
||||
export const getArticleList = (params?: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
search?: string
|
||||
category?: string
|
||||
}): Promise<ArticleListResponse> => {
|
||||
return api.get('/admin/articles/articlelist', { params })
|
||||
}
|
||||
|
||||
// 删除文章
|
||||
export const deleteArticle = (id: number) => {
|
||||
return api.delete(`/admin/articles/${id}`)
|
||||
}
|
||||
|
||||
// 发布/取消发布文章
|
||||
export const publishArticle = (id: number, status: number) => {
|
||||
return api.put(`/admin/articles/${id}/status`, { status })
|
||||
}
|
||||
|
||||
// 编辑文章
|
||||
export const updateArticle = (id: number, data: Partial<Article>) => {
|
||||
return api.put(`/admin/articles/${id}`, data)
|
||||
}
|
||||
|
||||
// 创建文章
|
||||
export const createArticle = (data: Partial<Omit<Article, 'id' | 'create_time' | 'update_time' | 'delete_time'>>) => {
|
||||
return api.post('/admin/articles', data)
|
||||
}
|
||||
|
||||
export default api
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const ENV_CONFIG = {
|
||||
// API配置
|
||||
API_BASE_URL: import.meta.env.VITE_APP_API_BASE_URL,
|
||||
API_BASE_URL: import.meta.env.VITE_APP_API_BASE_URL || (import.meta.env.DEV ? 'http://localhost:8000/api' : 'https://www.yunzer.cn/api'),
|
||||
REQUEST_TIMEOUT: 10000,
|
||||
|
||||
// 应用配置
|
||||
|
||||
@ -34,15 +34,43 @@
|
||||
border
|
||||
>
|
||||
<el-table-column prop="id" label="ID" width="80" align="center" />
|
||||
<el-table-column prop="title" label="标题" min-width="200" />
|
||||
<el-table-column prop="title" label="标题" min-width="200">
|
||||
<template #default="scope">
|
||||
<div class="title-cell">
|
||||
<span class="title-text">{{ scope.row.title }}</span>
|
||||
<el-tag v-if="scope.row.is_trans === '是'" size="small" type="warning">转</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="cate" label="分类" width="120" />
|
||||
<el-table-column prop="author" label="作者" width="120" />
|
||||
<el-table-column prop="category" label="分类" width="120" />
|
||||
<el-table-column prop="create_time" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="220">
|
||||
<el-table-column prop="views" label="浏览" width="80" align="center" />
|
||||
<el-table-column prop="likes" label="点赞" width="80" align="center" />
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.status === 2 ? 'success' : 'info'">
|
||||
{{ scope.row.status === 2 ? '已发布' : '草稿' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="publishdate" label="发布时间" width="180" />
|
||||
<el-table-column label="操作" width="250">
|
||||
<template #default="scope">
|
||||
<el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
|
||||
<el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button>
|
||||
<el-button size="small" type="primary" @click="handlePublishSingle(scope.row)">发布</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
:type="scope.row.status === 2 ? 'warning' : 'success'"
|
||||
@click="handlePublishSingle(scope.row)"
|
||||
>
|
||||
{{ scope.row.status === 2 ? '取消发布' : '发布' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@ -58,16 +86,16 @@
|
||||
</div>
|
||||
</el-card>
|
||||
<!-- 发布文章对话框 -->
|
||||
<el-dialog v-model="publishDialogVisible" title="发布文章" width="500px">
|
||||
<el-dialog v-model="publishDialogVisible" title="发布文章" width="600px">
|
||||
<el-form :model="publishForm" label-width="80px">
|
||||
<el-form-item label="标题">
|
||||
<el-input v-model="publishForm.title" />
|
||||
<el-form-item label="标题" required>
|
||||
<el-input v-model="publishForm.title" placeholder="请输入文章标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="作者">
|
||||
<el-input v-model="publishForm.author" />
|
||||
<el-form-item label="作者" required>
|
||||
<el-input v-model="publishForm.author" placeholder="请输入作者姓名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类">
|
||||
<el-select v-model="publishForm.category" placeholder="请选择分类">
|
||||
<el-form-item label="分类" required>
|
||||
<el-select v-model="publishForm.cate" placeholder="请选择分类">
|
||||
<el-option
|
||||
v-for="item in categoryOptions"
|
||||
:key="item"
|
||||
@ -76,91 +104,172 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="内容">
|
||||
<el-form-item label="是否转载">
|
||||
<el-radio-group v-model="publishForm.is_trans">
|
||||
<el-radio label="否">原创</el-radio>
|
||||
<el-radio label="是">转载</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="原文链接" v-if="publishForm.is_trans === '是'">
|
||||
<el-input v-model="publishForm.transurl" placeholder="请输入原文链接" />
|
||||
</el-form-item>
|
||||
<el-form-item label="内容" required>
|
||||
<el-input
|
||||
v-model="publishForm.content"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:rows="6"
|
||||
placeholder="请输入文章内容"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="publishDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitPublish">发布</el-button>
|
||||
<el-button type="primary" @click="submitPublish" :loading="loading">发布</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
// 这里假设有文章API
|
||||
// import { getArticleList } from '@/api/article'
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { getArticleList, deleteArticle, publishArticle, createArticle, Article, ArticleListResponse } from '@/api/article'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
const articles = ref<any[]>([])
|
||||
const articles = ref<Article[]>([])
|
||||
const loading = ref(false)
|
||||
const search = ref('')
|
||||
const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const total = ref(0)
|
||||
const selectedCategory = ref('')
|
||||
const categoryOptions = ref<string[]>([
|
||||
'前端', '后端', '数据库', '架构', '安全', '运维', '测试'
|
||||
])
|
||||
|
||||
// 从文章数据中提取分类选项
|
||||
const categoryOptions = computed(() => {
|
||||
const categories = new Set<string>()
|
||||
articles.value.forEach(article => {
|
||||
categories.add(article.cate)
|
||||
})
|
||||
return Array.from(categories).sort()
|
||||
})
|
||||
|
||||
// 发布文章相关
|
||||
const publishDialogVisible = ref(false)
|
||||
const publishForm = ref({
|
||||
title: '',
|
||||
author: '',
|
||||
category: '',
|
||||
content: ''
|
||||
cate: '',
|
||||
content: '',
|
||||
is_trans: '否',
|
||||
transurl: ''
|
||||
})
|
||||
|
||||
function fetchArticles() {
|
||||
async function fetchArticles() {
|
||||
loading.value = true
|
||||
// 这里用模拟数据,实际请替换为API请求
|
||||
setTimeout(() => {
|
||||
// 假数据
|
||||
const all = [
|
||||
{ id: 1, title: 'Vue3 入门', author: '张三', category: '前端', create_time: '2024-06-01 10:00' },
|
||||
{ id: 2, title: 'TypeScript 实践', author: '李四', category: '前端', create_time: '2024-06-02 11:00' },
|
||||
{ id: 3, title: 'PHP 高级技巧', author: '王五', category: '后端', create_time: '2024-06-03 12:00' },
|
||||
{ id: 4, title: '数据库优化', author: '赵六', category: '数据库', create_time: '2024-06-04 13:00' },
|
||||
{ id: 5, title: '云原生架构', author: '钱七', category: '架构', create_time: '2024-06-05 14:00' },
|
||||
{ id: 6, title: '安全最佳实践', author: '孙八', category: '安全', create_time: '2024-06-06 15:00' },
|
||||
{ id: 7, title: '性能调优', author: '周九', category: '运维', create_time: '2024-06-07 16:00' },
|
||||
{ id: 8, title: '微服务设计', author: '吴十', category: '架构', create_time: '2024-06-08 17:00' },
|
||||
{ id: 9, title: '前端工程化', author: '郑十一', category: '前端', create_time: '2024-06-09 18:00' },
|
||||
{ id: 10, title: '测试驱动开发', author: '冯十二', category: '测试', create_time: '2024-06-10 19:00' },
|
||||
{ id: 11, title: '持续集成', author: '褚十三', category: '运维', create_time: '2024-06-11 20:00' }
|
||||
]
|
||||
let filtered = all
|
||||
if (search.value) {
|
||||
filtered = filtered.filter(a => a.title.includes(search.value))
|
||||
try {
|
||||
const params = {
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
search: search.value || undefined,
|
||||
category: selectedCategory.value || undefined
|
||||
}
|
||||
if (selectedCategory.value) {
|
||||
filtered = filtered.filter(a => a.category === selectedCategory.value)
|
||||
}
|
||||
total.value = filtered.length
|
||||
const start = (page.value - 1) * pageSize.value
|
||||
articles.value = filtered.slice(start, start + pageSize.value)
|
||||
|
||||
const result = await getArticleList(params)
|
||||
articles.value = result.data
|
||||
total.value = result.count
|
||||
} catch (error: any) {
|
||||
console.error('获取文章列表失败:', error)
|
||||
ElMessage.error(error.message || '获取文章列表失败')
|
||||
// 如果API调用失败,使用模拟数据作为后备
|
||||
loadMockData()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
function handleEdit(row: any) {
|
||||
// 后备模拟数据
|
||||
function loadMockData() {
|
||||
const all: Article[] = [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Vue3 入门',
|
||||
cate: '前端',
|
||||
author: '张三',
|
||||
create_time: '2024-06-01 10:00',
|
||||
views: 0,
|
||||
status: 1,
|
||||
image: '',
|
||||
desc: '',
|
||||
content: '',
|
||||
publishdate: '2024-06-01 10:00',
|
||||
sort: null,
|
||||
likes: 0,
|
||||
is_trans: '否',
|
||||
transurl: null,
|
||||
push: '0',
|
||||
update_time: null,
|
||||
delete_time: null
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'TypeScript 实践',
|
||||
cate: '前端',
|
||||
author: '李四',
|
||||
create_time: '2024-06-02 11:00',
|
||||
views: 0,
|
||||
status: 1,
|
||||
image: '',
|
||||
desc: '',
|
||||
content: '',
|
||||
publishdate: '2024-06-02 11:00',
|
||||
sort: null,
|
||||
likes: 0,
|
||||
is_trans: '否',
|
||||
transurl: null,
|
||||
push: '0',
|
||||
update_time: null,
|
||||
delete_time: null
|
||||
}
|
||||
]
|
||||
|
||||
let filtered = all
|
||||
if (search.value) {
|
||||
filtered = filtered.filter(a => a.title.includes(search.value))
|
||||
}
|
||||
if (selectedCategory.value) {
|
||||
filtered = filtered.filter(a => a.cate === selectedCategory.value)
|
||||
}
|
||||
|
||||
total.value = filtered.length
|
||||
const start = (page.value - 1) * pageSize.value
|
||||
articles.value = filtered.slice(start, start + pageSize.value)
|
||||
}
|
||||
|
||||
function handleEdit(row: Article) {
|
||||
// 编辑文章逻辑
|
||||
alert('编辑文章: ' + row.title)
|
||||
ElMessage.info('编辑功能开发中: ' + row.title)
|
||||
// TODO: 跳转到编辑页面或打开编辑对话框
|
||||
}
|
||||
|
||||
function handleDelete(row: any) {
|
||||
// 删除文章逻辑
|
||||
if (confirm('确定要删除文章 "' + row.title + '" 吗?')) {
|
||||
// 实际应调用API
|
||||
articles.value = articles.value.filter(a => a.id !== row.id)
|
||||
total.value--
|
||||
async function handleDelete(row: Article) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要删除文章 "${row.title}" 吗?此操作不可恢复。`,
|
||||
'确认删除',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}
|
||||
)
|
||||
|
||||
await deleteArticle(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
fetchArticles()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除文章失败:', error)
|
||||
ElMessage.error(error.message || '删除失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,42 +278,73 @@ function handlePageChange(val: number) {
|
||||
fetchArticles()
|
||||
}
|
||||
|
||||
// 点击“发布文章”按钮
|
||||
// 点击"发布文章"按钮
|
||||
function handlePublish() {
|
||||
publishForm.value = {
|
||||
title: '',
|
||||
author: '',
|
||||
category: '',
|
||||
content: ''
|
||||
cate: '',
|
||||
content: '',
|
||||
is_trans: '否',
|
||||
transurl: ''
|
||||
}
|
||||
publishDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 单条发布(模拟,实际应调用API)
|
||||
function handlePublishSingle(row: any) {
|
||||
alert('发布文章: ' + row.title)
|
||||
// 单条发布/取消发布
|
||||
async function handlePublishSingle(row: Article) {
|
||||
try {
|
||||
const newStatus = row.status === 1 ? 2 : 1
|
||||
const actionText = newStatus === 2 ? '发布' : '取消发布'
|
||||
|
||||
await publishArticle(row.id, newStatus)
|
||||
ElMessage.success(`${actionText}成功`)
|
||||
fetchArticles()
|
||||
} catch (error: any) {
|
||||
console.error('发布操作失败:', error)
|
||||
ElMessage.error(error.message || '操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 提交发布
|
||||
function submitPublish() {
|
||||
if (!publishForm.value.title || !publishForm.value.author || !publishForm.value.category) {
|
||||
alert('请填写完整信息')
|
||||
async function submitPublish() {
|
||||
if (!publishForm.value.title || !publishForm.value.author || !publishForm.value.cate || !publishForm.value.content) {
|
||||
ElMessage.error('请填写完整信息')
|
||||
return
|
||||
}
|
||||
// 实际应调用API,这里直接添加到表格
|
||||
const newId = Math.max(...articles.value.map(a => a.id), 0) + 1
|
||||
articles.value.unshift({
|
||||
id: newId,
|
||||
title: publishForm.value.title,
|
||||
author: publishForm.value.author,
|
||||
category: publishForm.value.category,
|
||||
create_time: new Date().toISOString().slice(0, 16).replace('T', ' ')
|
||||
})
|
||||
total.value++
|
||||
publishDialogVisible.value = false
|
||||
// 可选:重置分页到第一页
|
||||
page.value = 1
|
||||
fetchArticles()
|
||||
|
||||
if (publishForm.value.is_trans === '是' && !publishForm.value.transurl) {
|
||||
ElMessage.error('转载文章必须填写原文链接')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备提交的数据
|
||||
const submitData = {
|
||||
title: publishForm.value.title,
|
||||
author: publishForm.value.author,
|
||||
cate: publishForm.value.cate,
|
||||
content: publishForm.value.content,
|
||||
desc: publishForm.value.content.substring(0, 200), // 摘要,取前200字符
|
||||
image: '',
|
||||
publishdate: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
sort: null,
|
||||
status: 1,
|
||||
views: 0,
|
||||
likes: 0,
|
||||
is_trans: publishForm.value.is_trans,
|
||||
transurl: publishForm.value.is_trans === '是' ? publishForm.value.transurl : null,
|
||||
push: '0'
|
||||
}
|
||||
|
||||
await createArticle(submitData)
|
||||
ElMessage.success('发布成功')
|
||||
publishDialogVisible.value = false
|
||||
fetchArticles()
|
||||
} catch (error: any) {
|
||||
console.error('发布文章失败:', error)
|
||||
ElMessage.error(error.message || '发布失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@ -231,4 +371,17 @@ onMounted(() => {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.title-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title-text {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
<el-input
|
||||
:prefix-icon="User"
|
||||
v-model="loginForm.account"
|
||||
placeholder="请输入您的邮箱"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
@ -17,6 +18,7 @@
|
||||
type="password"
|
||||
:prefix-icon="Lock"
|
||||
v-model="loginForm.password"
|
||||
placeholder="请输入您的密码"
|
||||
show-password
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
|
||||
@ -52,6 +52,13 @@ export default defineConfig({
|
||||
}
|
||||
},
|
||||
|
||||
// 环境变量配置
|
||||
define: {
|
||||
__API_BASE_URL__: JSON.stringify(process.env.NODE_ENV === 'production'
|
||||
? 'https://www.yunzer.cn/api'
|
||||
: 'http://localhost:8000/api')
|
||||
},
|
||||
|
||||
// 服务器配置
|
||||
server: {
|
||||
port: 5173, // 保持你当前使用的端口
|
||||
|
||||
@ -41,10 +41,10 @@ Route::post('index/wechat/testWechat', 'index/wechat/testWechat');
|
||||
Route::group('api', function () {
|
||||
// 管理员登录
|
||||
Route::post('admin/login', 'api/Admin/login');
|
||||
|
||||
|
||||
// 管理员相关接口
|
||||
Route::get('admin/info', 'api/Admin/info');
|
||||
Route::post('admin/logout', 'api/Admin/logout');
|
||||
Route::post('admin/change-password', 'api/Admin/changePassword');
|
||||
Route::get('admin/menus', 'api/Admin/menus');
|
||||
});
|
||||
})->middleware(\app\middleware\Cors::class);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1754756464;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1750323451;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1751594649;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1750323451;}*/ ?>
|
||||
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1766456641;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1750323451;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1766456641;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1750323451;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user