From bc41c2430d94c369c19d2a857f7fb3fb119d3df7 Mon Sep 17 00:00:00 2001 From: yumo Date: Thu, 7 Dec 2023 15:19:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=BB=E9=A2=98=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=92=8C=E6=94=AF=E6=8C=81page=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/common.php | 4 ++-- app/admin/controller/Page.php | 19 ++++++++----------- app/admin/view/page/add.html | 4 ++-- app/admin/view/page/edit.html | 6 +++--- app/index/controller/Index.php | 9 +++++++-- app/index/route/app.php | 4 +++- public/install/ape_blog.sql | 4 ++-- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/admin/common.php b/app/admin/common.php index ad0193b..146c35a 100644 --- a/app/admin/common.php +++ b/app/admin/common.php @@ -152,8 +152,8 @@ if (!function_exists('get_tree_list')) { } -if (!function_exists('get_theme_list')) { - function get_theme_list($type = ''): array +if (!function_exists('get_template_list')) { + function get_template_list($type = ''): array { $themeList = []; $themeDir = public_path('template') . system_config('web_template') . '/pc/' . $type; diff --git a/app/admin/controller/Page.php b/app/admin/controller/Page.php index 0a40195..ca0a230 100644 --- a/app/admin/controller/Page.php +++ b/app/admin/controller/Page.php @@ -87,7 +87,7 @@ class Page extends AuthController ['is_recommend', 0], ['is_top', 0], ['is_hot', 0], - ['theme', ''], + ['template', ''], ['link_str', ''], ['cover_path', ''], ['display', 1], @@ -98,7 +98,7 @@ class Page extends AuthController ['uid', $this->adminId], ]); if ($data['title'] == "") return app("json")->fail("文章名称不能为空"); - if ($data['theme'] == "") return app("json")->fail("文章模板不能为空"); + if ($data['template'] == "") return app("json")->fail("文章模板不能为空"); if ($data['cover_path'] == "") return app("json")->fail("主图不能为空"); $model = new Document(); $res = $model->updateInfo($data, Data::DOCUMENT_TYPE_PAGE); @@ -130,21 +130,18 @@ class Page extends AuthController * @author 木子的忧伤 * @date 2021-03-10 14:46 */ - public function add() + public function add(): string { // 获取页面模板列表 - $this->getThemeList(); - $themeList = get_theme_list(Data::DOCUMENT_TYPE_PAGE); - $this->assign("theme_list", $themeList); + $templateList = get_template_list(Data::DOCUMENT_TYPE_PAGE); + $this->assign("template_list", $templateList); return $this->fetch(); } /** * 编辑页 * @return string|void - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException + * @throws \Exception */ public function edit() { @@ -159,8 +156,8 @@ class Page extends AuthController $this->error('数据不存在'); } // 获取页面模板列表 - $themeList = get_theme_list(Data::DOCUMENT_TYPE_PAGE); - $this->assign("theme_list", $themeList); + $templateList = get_template_list(Data::DOCUMENT_TYPE_PAGE); + $this->assign("template_list", $templateList); $this->assign("info", $info); return $this->fetch(); } diff --git a/app/admin/view/page/add.html b/app/admin/view/page/add.html index 0bfd979..474a55e 100644 --- a/app/admin/view/page/add.html +++ b/app/admin/view/page/add.html @@ -31,9 +31,9 @@
- - {volist name="theme_list" id="vo"} + {volist name="template_list" id="vo"} {/volist} diff --git a/app/admin/view/page/edit.html b/app/admin/view/page/edit.html index f0db494..17cd6f1 100644 --- a/app/admin/view/page/edit.html +++ b/app/admin/view/page/edit.html @@ -32,10 +32,10 @@
- - {volist name="theme_list" id="vo"} - + {volist name="template_list" id="vo"} + {/volist}
diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index f938890..7c2bf18 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -153,10 +153,15 @@ class Index extends Base $article['position'] = '首页>'; //更新浏览次数 $documentModel->where('id', $article['id'])->inc('view')->update(); - $template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['theme'] ?: 'detail.html'); + $template = Data::DOCUMENT_TYPE_PAGE . '/' . ($article['template'] ?: 'index.html'); $templateFile = config('view.view_path') . $template; if (!is_file($templateFile)) { - $this->error('模板文件不存在!'); + //配置的模版文件不存在则走默认模版 + $template = Data::DOCUMENT_TYPE_PAGE . '/' . 'index.html'; + $templateFile = config('view.view_path') . $template; + if (!is_file($templateFile)){ + $this->error('模板文件不存在!'); + } } $article['category_title'] = "单页"; //判断SEO 为空则取系统 diff --git a/app/index/route/app.php b/app/index/route/app.php index 04a589d..5954c68 100644 --- a/app/index/route/app.php +++ b/app/index/route/app.php @@ -15,4 +15,6 @@ Route::get('think', function () { }); Route::get('hello/:name', 'index/hello'); -Route::rule('/sitemap.xml', 'index/sitemap'); \ No newline at end of file +Route::rule('/sitemap.xml', 'index/sitemap'); +//单页面访问 +Route::get('page/:id', 'page/index'); \ No newline at end of file diff --git a/public/install/ape_blog.sql b/public/install/ape_blog.sql index 8650d49..ad66d2e 100644 --- a/public/install/ape_blog.sql +++ b/public/install/ape_blog.sql @@ -334,7 +334,7 @@ CREATE TABLE `ape_document` ( `category_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所属分类', `cover_path` varchar(255) NOT NULL DEFAULT '' COMMENT '封面', `type` varchar(50) NOT NULL DEFAULT 'article' COMMENT '内容类型', - `theme` varchar(40) NOT NULL DEFAULT '' COMMENT '主题模板', + `template` varchar(40) NOT NULL DEFAULT '' COMMENT '主题模板', `is_recommend` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否推荐', `is_top` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否置顶', `is_hot` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否热门', @@ -362,7 +362,7 @@ CREATE TABLE `ape_document` ( -- Records of ape_document -- ---------------------------- BEGIN; -INSERT INTO `ape_document` (`id`, `alias`, `uid`, `author`, `title`, `category_id`, `cover_path`, `type`, `theme`, `is_recommend`, `is_top`, `is_hot`, `link_str`, `is_jump`, `display`, `view`, `tags`, `abstract`, `keywords`, `description`, `sort`, `create_date`, `create_time`, `update_time`, `status`, `password`) VALUES (1, 'about', 1, '超级管理员', '关于博客', 0, '/storage/image/20220710/a5059baa808c46f83674cb5dbcae8dc5.png', 'page', 'article.html', 0, 0, 0, '', 0, 1, 570, '源码云', '关于源码云博客', '关于小站,源码云,源码云博客,关于源码云博客', '关于源码云博客', 99, '2022-07-10', 1657464428, 1657464428, 1, ''); +INSERT INTO `ape_document` (`id`, `alias`, `uid`, `author`, `title`, `category_id`, `cover_path`, `type`, `template`, `is_recommend`, `is_top`, `is_hot`, `link_str`, `is_jump`, `display`, `view`, `tags`, `abstract`, `keywords`, `description`, `sort`, `create_date`, `create_time`, `update_time`, `status`, `password`) VALUES (1, 'about', 1, '超级管理员', '关于博客', 0, '/storage/image/20220710/a5059baa808c46f83674cb5dbcae8dc5.png', 'page', 'article.html', 0, 0, 0, '', 0, 1, 570, '源码云', '关于源码云博客', '关于小站,源码云,源码云博客,关于源码云博客', '关于源码云博客', 99, '2022-07-10', 1657464428, 1657464428, 1, ''); COMMIT; -- ----------------------------