更新主题读取和支持page单独访问

This commit is contained in:
yumo 2023-12-07 15:19:36 +08:00
parent 8e185ca1a9
commit bc41c2430d
7 changed files with 27 additions and 23 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -31,9 +31,9 @@
<div class="col-xs-4">
<label>展示模板</label>
<div class="form-group form-controls">
<select name="theme" id="theme" class="form-control">
<select name="template" id="template" class="form-control">
<option value="0">请选择</option>
{volist name="theme_list" id="vo"}
{volist name="template_list" id="vo"}
<option value="{$vo}">{$vo}</option>
{/volist}
</select>

View File

@ -32,10 +32,10 @@
<div class="col-xs-4">
<label>展示模板</label>
<div class="form-group form-controls">
<select name="theme" id="theme" class="form-control">
<select name="template" id="template" class="form-control">
<option value="0">请选择</option>
{volist name="theme_list" id="vo"}
<option value="{$vo}" {if $vo == $info.theme}selected{/if}>{$vo}</option>
{volist name="template_list" id="vo"}
<option value="{$vo}" {if $vo == $info.template}selected{/if}>{$vo}</option>
{/volist}
</select>
</div>

View File

@ -153,10 +153,15 @@ class Index extends Base
$article['position'] = '<a href="/">首页</a><span>&gt;</span>';
//更新浏览次数
$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 为空则取系统

View File

@ -16,3 +16,5 @@ Route::get('think', function () {
Route::get('hello/:name', 'index/hello');
Route::rule('/sitemap.xml', 'index/sitemap');
//单页面访问
Route::get('page/:id', 'page/index');

View File

@ -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;
-- ----------------------------