From ed4a97bc1933386b629ca8ca886eb16b954eb43a Mon Sep 17 00:00:00 2001 From: make Date: Fri, 18 Apr 2025 22:20:35 +0800 Subject: [PATCH] debug --- code/app/home/BaseController.php | 1 - code/app/home/config/router.php | 183 +++++++++++++++--- code/app/home/view/default/Index/index.html | 45 ++--- .../home/view/default/Novel/getLibrary.html | 67 +++---- .../view/default/Novel/getNovelCatalog.html | 6 +- .../view/default/Novel/getNovelChapter.html | 6 +- .../home/view/default/Novel/getNovelInfo.html | 103 ++++------ .../view/default/Novel/getSearchNovel.html | 6 +- code/app/home/view/default/Pc/getLibrary.html | 80 ++++---- .../home/view/default/Pc/getNovelCatalog.html | 6 +- .../home/view/default/Pc/getNovelChapter.html | 6 +- .../home/view/default/Pc/getNovelInfo.html | 99 ++++------ .../home/view/default/Pc/getSearchNovel.html | 6 +- code/app/home/view/default/Pc/index.html | 46 ++--- code/app/home/view/default/baseH5.html | 9 +- code/app/home/view/default/basePc.html | 18 +- code/app/services/NovelService.php | 40 +++- code/app/services/SiteContext.php | 41 +++- code/extend/template/taglib/Novel.php | 9 +- code/extend/template/taglib/Site.php | 43 +++- doc/TemplateTag.md | 8 +- 21 files changed, 487 insertions(+), 341 deletions(-) diff --git a/code/app/home/BaseController.php b/code/app/home/BaseController.php index 1ad634e..1b45103 100644 --- a/code/app/home/BaseController.php +++ b/code/app/home/BaseController.php @@ -104,7 +104,6 @@ abstract class BaseController View::assign("DomainModel", $this->request->DomainModel); View::assign("TemplatesModel", $this->request->TemplatesModel); - View::assign("strPcPath", $strPcUrlTemp); View::assign("strNanUrlTemp", $strNanUrlTemp); View::assign("strNvUrlTemp", $strNvUrlTemp); diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index 8cfa882..caa2313 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -9,9 +9,9 @@ use app\services\SiteContext; use think\facade\Route; -Route::get('/article/fenlei/:category', function (\think\Request $Request, SiteContext $SiteContext) { - return view($SiteContext->getHomeView()); -}); +// Route::get('/article/fenlei/:category', function (\think\Request $Request, SiteContext $SiteContext) { +// return view($SiteContext->getHomeView()); +// }); @@ -161,53 +161,70 @@ foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { case 'latest': //最新章节 Route::get($strRoute, [Novel::class, 'getNovelLatestChapter']) - ->append(['boolIsMobile' => $boolIsMobile]) + ->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]); break; case 'chapter': //章节 Route::get($strRoute, [Novel::class, 'getNovelChapter']) - ->append(['boolIsMobile' => $boolIsMobile]) + ->pattern(['intNovelId' => '\d+', 'name' => '[\w-]+', 'intChapterSort' => '\d+', 'intChapterPage' => '\d+']); break; case 'kan-novel': //伪造小说详情 Route::get($strRoute, [Novel::class, 'getKanNovelInfo']) - ->append(['boolIsMobile' => $boolIsMobile]) + ->pattern(['n_id' => '\d+', 'n_forge_id' => '\d+', 'name' => '[\w-]+',]); break; case 'novel': //小说详情 - Route::get($strRoute, [Novel::class, 'getNovelInfo']) - ->append(['boolIsMobile' => $boolIsMobile]) - ->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]); + $strView = 'pc/getNovelInfo.html'; + if ($platform == 'h5') { + $strView = 'novel/getNovelInfo.html'; + } + Route::get($strRoute, function () use ($strView) { + return view($strView); + }) + ->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]); + break; case 'catalog': //目录 - Route::get($strRoute, [Novel::class, 'getNovelCatalog']) - ->append(['boolIsMobile' => $boolIsMobile]) - ->pattern(['intNovelId' => '\d+', 'name' => '[\w-]+', 'strOrder' => 'zheng|dao', 'intPage' => '\d+']); + $strView = 'pc/getNovelCatalog.html'; + if ($platform == 'h5') { + $strView = 'novel/getNovelCatalog.html'; + } + Route::get($strRoute, function () use ($strView) { + return view($strView); + }) + ->pattern(['intNovelId' => '\d+', 'name' => '[\w-]+', 'strOrder' => 'zheng|dao', 'intPage' => '\d+']); + break; case 'library': - //书库/分类 /shuku/all/xuanhuan-xiuzhen/all/all/page1 - Route::get($strRoute, [Novel::class, 'getLibrary']) - ->append(['boolIsMobile' => $boolIsMobile]) - ->pattern([ - //'strGender' => 'all|nansheng-xiaoshuo|boys-novel|nansheng-shu|man-read|nansheng-book|male-novels|nvsheng-xiaoshuo|girls-novel|nvsheng-shu|woman-read|nvsheng-book|female-novels', - 'strGender' => '[a-z\-]+', - 'strCategory' => '[a-z\-]+', - 'strStatus' => 'all|lianzai|wanjie', - // 'strOrder' => '[a-z\-]+', - 'intPage' => '\d+' - ]); + $strView = 'pc/getLibrary.html'; + if ($platform == 'h5') { + $strView = 'novel/getLibrary.html'; + } + //书库/分类 + Route::get($strRoute, function () use ($strView) { + return view($strView); + }) + ->pattern([ + // 'strGender' => '[a-z\-]+', + 'strCategory' => '[a-z\-]+', + 'strStatus' => 'all|lianzai|wanjie', + // 'strOrder' => '[a-z\-]+', + 'intPage' => '\d+' + ]); break; + case 'library-index': //书库/分类首页 - Route::get($strRoute, [Novel::class, 'getLibrary'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, [Novel::class, 'getLibrary']); break; case 'rank': //排行榜 - Route::get($strRoute, [Novel::class, 'getNovelRank'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, [Novel::class, 'getNovelRank']); break; case 'boys': //男生 @@ -219,26 +236,30 @@ foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { break; case 'search': //搜素 - Route::get($strRoute, [Novel::class, 'getSearchNovel'])->ext('html')->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, [Novel::class, 'getSearchNovel'])->ext('html'); break; case 'user': //用户中心 - Route::get($strRoute, [User::class, 'Index'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, [User::class, 'Index']); break; case 'bookshelf': //书架 - Route::get($strRoute, [User::class, 'getBookShelf'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, [User::class, 'getBookShelf']); break; case 'history': //历史记录 - Route::get($strRoute, [User::class, 'getHistory'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, [User::class, 'getHistory']); break; case 'index': // 首页 if ($platform == 'h5') { - Route::get($strRoute, [Index::class, 'index'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, function (\think\Request $Request, SiteContext $SiteContext ) { + return view($SiteContext->getHomeView('h5')); + }); } else { - Route::get($strRoute, [Index::class, 'getPcIndex'])->append(['boolIsMobile' => $boolIsMobile]); + Route::get($strRoute, function (\think\Request $Request, SiteContext $SiteContext ) { + return view($SiteContext->getHomeView('pc')); + }); } break; } @@ -246,3 +267,103 @@ foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { } } } + +/** + * 遍历路由配置,动态注册 H5 和 PC 路由 + */ +// foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { +// $prefixes = is_array($prefixes) ? $prefixes : [$prefixes]; +// $boolIsMobile = $platform === 'h5'; +// foreach ($prefixes as $strPath) { +// foreach ($arrRoutes['paths'] as $key => $arrUrl) { +// foreach ($arrUrl as $strUrl) { +// $strRoute = $strPath . $strUrl; +// switch ($key) { +// case 'latest': +// //最新章节 +// Route::get($strRoute, [Novel::class, 'getNovelLatestChapter']) +// ->append(['boolIsMobile' => $boolIsMobile]) +// ->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]); +// break; +// case 'chapter': +// //章节 +// Route::get($strRoute, [Novel::class, 'getNovelChapter']) +// ->append(['boolIsMobile' => $boolIsMobile]) +// ->pattern(['intNovelId' => '\d+', 'name' => '[\w-]+', 'intChapterSort' => '\d+', 'intChapterPage' => '\d+']); +// break; +// case 'kan-novel': +// //伪造小说详情 +// Route::get($strRoute, [Novel::class, 'getKanNovelInfo']) +// ->append(['boolIsMobile' => $boolIsMobile]) +// ->pattern(['n_id' => '\d+', 'n_forge_id' => '\d+', 'name' => '[\w-]+',]); +// break; +// case 'novel': +// //小说详情 +// Route::get($strRoute, [Novel::class, 'getNovelInfo']) +// ->append(['boolIsMobile' => $boolIsMobile]) +// ->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]); +// break; +// case 'catalog': +// //目录 +// Route::get($strRoute, [Novel::class, 'getNovelCatalog']) +// ->append(['boolIsMobile' => $boolIsMobile]) +// ->pattern(['intNovelId' => '\d+', 'name' => '[\w-]+', 'strOrder' => 'zheng|dao', 'intPage' => '\d+']); +// break; +// case 'library': +// //书库/分类 /shuku/all/xuanhuan-xiuzhen/all/all/page1 +// Route::get($strRoute, [Novel::class, 'getLibrary']) +// ->append(['boolIsMobile' => $boolIsMobile]) +// ->pattern([ +// //'strGender' => 'all|nansheng-xiaoshuo|boys-novel|nansheng-shu|man-read|nansheng-book|male-novels|nvsheng-xiaoshuo|girls-novel|nvsheng-shu|woman-read|nvsheng-book|female-novels', +// 'strGender' => '[a-z\-]+', +// 'strCategory' => '[a-z\-]+', +// 'strStatus' => 'all|lianzai|wanjie', +// // 'strOrder' => '[a-z\-]+', +// 'intPage' => '\d+' +// ]); +// break; +// case 'library-index': +// //书库/分类首页 +// Route::get($strRoute, [Novel::class, 'getLibrary'])->append(['boolIsMobile' => $boolIsMobile]); +// break; +// case 'rank': +// //排行榜 +// Route::get($strRoute, [Novel::class, 'getNovelRank'])->append(['boolIsMobile' => $boolIsMobile]); +// break; +// case 'boys': +// //男生 +// Route::get($strRoute, [Novel::class, 'getNovelChannel'])->append(['boolIsMobile' => $boolIsMobile, 'strChannel' => 'boys']); +// break; +// case 'girls': +// //女生 +// Route::get($strRoute, [Novel::class, 'getNovelChannel'])->append(['boolIsMobile' => $boolIsMobile, 'strChannel' => 'girls']); +// break; +// case 'search': +// //搜素 +// Route::get($strRoute, [Novel::class, 'getSearchNovel'])->ext('html')->append(['boolIsMobile' => $boolIsMobile]); +// break; +// case 'user': +// //用户中心 +// Route::get($strRoute, [User::class, 'Index'])->append(['boolIsMobile' => $boolIsMobile]); +// break; +// case 'bookshelf': +// //书架 +// Route::get($strRoute, [User::class, 'getBookShelf'])->append(['boolIsMobile' => $boolIsMobile]); +// break; +// case 'history': +// //历史记录 +// Route::get($strRoute, [User::class, 'getHistory'])->append(['boolIsMobile' => $boolIsMobile]); +// break; +// case 'index': +// // 首页 +// if ($platform == 'h5') { +// Route::get($strRoute, [Index::class, 'index'])->append(['boolIsMobile' => $boolIsMobile]); +// } else { +// Route::get($strRoute, [Index::class, 'getPcIndex'])->append(['boolIsMobile' => $boolIsMobile]); +// } +// break; +// } +// } +// } +// } +// } diff --git a/code/app/home/view/default/Index/index.html b/code/app/home/view/default/Index/index.html index 07ba1d9..65411d6 100644 --- a/code/app/home/view/default/Index/index.html +++ b/code/app/home/view/default/Index/index.html @@ -1,7 +1,7 @@ {extend name="baseH5" /} -{block name="title"}{$strTitle??''}{/block} -{block name="keywords"}{$strKeywords??''}{/block} -{block name="description"}{$strDescription??''}{/block} +{block name="title"}{site:replace code="INDEX@INDEX@TITLE"}{/block} +{block name="keywords"}{site:replace code="INDEX@INDEX@KEYWORDS"}{/block} +{block name="description"}{site:replace code="INDEX@INDEX@DESCRIPTION"}{/block} {block name="head"} @@ -44,7 +44,7 @@

封面推荐

- {foreach $arrRecommendNovel as $key=>$Novel } + {novel:list count="8" sort_type="tuijian" d_key="d_key" d_val="Novel" p_val="page_data" cache_life="86400"}
@@ -58,45 +58,42 @@

{$Novel.n_description}

- {/foreach} + {/novel:list}
-{foreach $arrAllCategoryNovel as $category} - +{novel:category d_key="strCategoryPinyin" d_val="strCategoryName"}

- {$category.xsfl_name} - 更多.. + {$strCategoryName} + 更多..

- {foreach $arrNovels[$category.xsfl_source_id] as $key2 => $vo} - {if $key2 == 0} -
{$vo.xsxq_ming_zi}
+ {novel:list count="1" n_category="$strCategoryPinyin" sort_type="news" d_key="d_key" d_val="Novel" p_val="page_data" cache_life="86400"} +
{$Novel.n_name ?? ''} - {$Novel.n_category ?? ''}最新章节在线免费阅读
-

{$vo.xsxq_ming_zi}

-

作者:{$vo.xsxq_zuozhe}

-

{$vo.xsxq_jie_shao}

+

{$Novel.n_name}

+

作者:{$Novel.n_author}

+

{$Novel.n_description}

- {/if} - {/foreach} + {/novel:list}
    - {foreach $arrNovels[$category.xsfl_source_id] as $key2 => $vo} - {if $key2 >= 1} -
  • {$vo.xsxq_ming_zi}{$vo.xsxq_zuozhe}
  • - {/if} - {/foreach} + {novel:list count="9" n_category="$strCategoryPinyin" sort_type="news" d_key="d_key" d_val="Novel" p_val="page_data" cache_life="86400"} +
  • {$Novel.n_name}{$Novel.n_author}
  • + {/novel:list}
-{/foreach} +{/novel:category} {/block} diff --git a/code/app/home/view/default/Novel/getLibrary.html b/code/app/home/view/default/Novel/getLibrary.html index c6aa2b6..d06b132 100644 --- a/code/app/home/view/default/Novel/getLibrary.html +++ b/code/app/home/view/default/Novel/getLibrary.html @@ -1,8 +1,8 @@ {extend name="baseH5" /} -{block name="title"}{$strTitle??''}{/block} -{block name="keywords"}{$strKeywords??''}{/block} -{block name="description"}{$strDescription??''}{/block} +{block name="title"}{site:replace code="NOVEL@GETLIBRARY@TITLE"}{/block} +{block name="keywords"}{site:replace code="NOVEL@GETLIBRARY@KEYWORDS"}{/block} +{block name="description"}{site:replace code="NOVEL@GETLIBRARY@DESCRIPTION"}{/block} {block name="head-js"}{/block} {block name='nav-active-class'}home{/block} @@ -10,7 +10,8 @@ {block name="logo-html"}

- {$DomainModel->d_name}-{$strSearchCategory}{$strOrder}{$strSearchStatus}免费阅读 + {$DomainModel->d_name}-{$Request.route.strCategory}{$Request.route.strOrder}{$Request.route.strStatus}免费阅读

{/block} @@ -19,48 +20,42 @@ {block name="main"}

{$strDescription??''}

- -

更新列表

- {volist name="arrPaginator" id="vo" key="k"} + {volist name="page_data" id="vo" key="k"} {switch $vo.label} {case value="上一页"} - {if $intPage == 1} + {if $Request.route.intPage == 1} « {else} « {/if} {/case} {case value="下一页"} - {if $intPage >= $intTotalPage} + {if $Request.route.intPage >= $n_num} » {else} » @@ -107,7 +102,7 @@ 封面推荐
- {foreach $arrTopNovel as $key=>$Novel } + {novel:list count="8" sort_type="tuijian" d_key="d_key" d_val="Novel" p_val="page_data" cache_life="86400"}
@@ -126,7 +121,7 @@

{$Novel.n_description}

- {/foreach} + {/novel:list}
diff --git a/code/app/home/view/default/Novel/getNovelCatalog.html b/code/app/home/view/default/Novel/getNovelCatalog.html index a167759..732369f 100644 --- a/code/app/home/view/default/Novel/getNovelCatalog.html +++ b/code/app/home/view/default/Novel/getNovelCatalog.html @@ -1,7 +1,7 @@ {extend name="baseH5" /} -{block name="title"}{$strTitle??''}{/block} -{block name="keywords"}{$strKeywords??''}{/block} -{block name="description"}{$strDescription??''}{/block} +{block name="title"}{site:replace code="NOVEL@GETNOVELCATALOG@TITLE"}{/block} +{block name="keywords"}{site:replace code="NOVEL@GETNOVELCATALOG@KEYWORDS"}{/block} +{block name="description"}{site:replace code="NOVEL@GETNOVELCATALOG@DESCRIPTION"}{/block} {block name="head"} diff --git a/code/app/home/view/default/Novel/getNovelChapter.html b/code/app/home/view/default/Novel/getNovelChapter.html index f89dc48..29314a8 100644 --- a/code/app/home/view/default/Novel/getNovelChapter.html +++ b/code/app/home/view/default/Novel/getNovelChapter.html @@ -1,7 +1,7 @@ {extend name="baseH5" /} -{block name="title"}{$strTitle??''}{/block} -{block name="keywords"}{$strKeywords??''}{/block} -{block name="description"}{$strDescription??''}{/block} +{block name="title"}{site:replace code="NOVEL@GETNOVELCHAPTER@TITLE"}{/block} +{block name="keywords"}{site:replace code="NOVEL@GETNOVELCHAPTER@KEYWORDS"}{/block} +{block name="description"}{site:replace code="NOVEL@GETNOVELCHAPTER@DESCRIPTION"}{/block} {block name="head"} diff --git a/code/app/home/view/default/Novel/getNovelInfo.html b/code/app/home/view/default/Novel/getNovelInfo.html index cdf210e..bd0d816 100644 --- a/code/app/home/view/default/Novel/getNovelInfo.html +++ b/code/app/home/view/default/Novel/getNovelInfo.html @@ -1,13 +1,15 @@ -{extend name="baseH5" /} -{block name="title"}{$strTitle??''}{/block} -{block name="keywords"}{$strKeywords??''}{/block} -{block name="description"}{$strDescription??''}{/block} +$Novel.n_id{extend name="baseH5" /} +{block name="title"}{site:replace code="NOVEL@GETNOVELINFO@TITLE"}{/block} +{block name="keywords"}{site:replace code="NOVEL@GETNOVELINFO@KEYWORDS"}{/block} +{block name="description"}{site:replace code="NOVEL@GETNOVELINFO@DESCRIPTION"}{/block} {block name="head"} +{novel:info n_id="$Request.route.n_id" n_key="arrNovel" n_forge_id="0" /} +{site:grm page_code="pc_novel_info" diff="$arrNovel.n_id" num="100" g_key="arrGrm" /} - + + content='https://{$DomainModel->d_domain}{site:nurl n_id="$arrNovel.n_id" n_py="$arrNovel.n_name_pinyin" /}' /> @@ -15,16 +17,16 @@ + content='https://{$DomainModel->d_domain}{site:cpurl n_id="$arrNovel.n_id" n_py="$arrNovel.n_name_pinyin" c_sort="$arrNovel.intFirstChapterSort"/}'> - + + content='https://{$DomainModel->d_domain}{site:lcpurl n_id="$arrNovel.n_id" n_py="$arrNovel.n_name_pinyin" /}'> - +