diff --git a/code/app/common.php b/code/app/common.php index 9ab0186..35f5a03 100644 --- a/code/app/common.php +++ b/code/app/common.php @@ -808,4 +808,22 @@ namespace { } } } + + /** + * generate string + * + * @param integer $length + * @return string + */ + function randomString(int $length): string { + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $max = 51; // 字符集长度减1 (0-51) + $result = ''; + + for ($i = 0; $i < $length; $i++) { + $result .= $chars[random_int(0, $max)]; + } + + return $result; + } } diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index 4d33c81..a38a2e5 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('test/test01/index.html'); +}); diff --git a/code/app/home/view/default/test/test01/index.html b/code/app/home/view/default/test/test01/index.html index 9c7e4d6..77c3344 100644 --- a/code/app/home/view/default/test/test01/index.html +++ b/code/app/home/view/default/test/test01/index.html @@ -1,3 +1,24 @@ +{novel:pagerexp page="1" limit="10" n_category="$Request.route.category" d_key="d_key" d_val="novel" p_val="page_data" +cache_life="1000" func="generateSearchPager" export_name="fadfads" /} + +{php}var_dump($fadfads['p_data']);{/php} + + + + + + + + @@ -49,9 +70,9 @@ {/novel:sort} --> - + @@ -66,17 +87,3 @@ {/novel:list} --> - \ No newline at end of file diff --git a/code/app/services/ChapterService.php b/code/app/services/ChapterService.php index 957bdc8..b8c1d50 100644 --- a/code/app/services/ChapterService.php +++ b/code/app/services/ChapterService.php @@ -168,7 +168,7 @@ class ChapterService $strCacheKey = ''; $intLifeTime = 0; - + if (empty($arrFilter['$and'])) { $arrFilter = []; } @@ -188,7 +188,7 @@ class ChapterService $intLifeTime = $intLifeTime; } - $arrNovel = $this->ChapterModel->findPaginatedWithCache( + $arrChapter = $this->ChapterModel->findPaginatedWithCache( $arrFilter, $intPage, $intLimit, @@ -197,10 +197,14 @@ class ChapterService $intLifeTime, ); - $arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel); + $arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrChapter); + + $arrPager = $arrChapter; + unset($arrPager['data']); + $arrPager['pager'] = call_user_func([$this, $Func], $arrParams, $arrSort, $arrChapter); $arrResult = [ - 'data' => $arrNovel['data'], + 'data' => $arrChapter['data'], 'p_data' => $arrPager, ]; @@ -218,7 +222,7 @@ class ChapterService { // 小说详情 $arrNovel = $this->NovelModel->getNovelByNId($intNId); - + // 章节 $ChapterModel = ChapterModel::getInstance(); $arrFilter = ['n_id' => $intNId, 'c_sort_num' => $intCSortNum, 'c_page' => $intCPage]; diff --git a/code/app/services/NovelService.php b/code/app/services/NovelService.php index bb22b05..db3400e 100644 --- a/code/app/services/NovelService.php +++ b/code/app/services/NovelService.php @@ -416,8 +416,8 @@ class NovelService } } - # n_category_sex_zh filter - if (!empty($strNSex)) { + # key filter + if (!empty($strKey)) { $strKey = mb_substr($strKey, 0, 30); $arrFilter['$and'][] = [ @@ -468,7 +468,11 @@ class NovelService $intLifeTime = $intLifeTime; } - + + if (empty($arrFilter['$and'])) { + $arrFilter = []; + } + $arrNovel = $this->NovelModel->findPaginatedWithCache( $arrFilter, $intPage, @@ -478,11 +482,12 @@ class NovelService $intLifeTime, ); - $arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel); - + $arrPager = $arrNovel; + unset($arrPager['data']); + $arrPager['pager'] = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel); + $arrResult = [ - 'data' => $arrNovel['data'] ?? [], - 'pages' => $arrNovel['pages'] ?? 0, + 'data' => $arrNovel['data'], 'p_data' => $arrPager, ]; diff --git a/code/extend/template/taglib/Chapter.php b/code/extend/template/taglib/Chapter.php index f18cb85..358420b 100644 --- a/code/extend/template/taglib/Chapter.php +++ b/code/extend/template/taglib/Chapter.php @@ -8,7 +8,8 @@ class Chapter extends TagLib { protected $tags = [ 'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val'], - 'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'], + 'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,export_name'], + 'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0], 'info' => ['attr' => 'n_id,n_key', 'close' => 0], ]; @@ -22,6 +23,19 @@ class Chapter extends TagLib } + /** + * pagerexp tag code + * + * @param array $tag + * @param string $content + * @return string + */ + public function tagPagerExp($tag, $content) + { + return $this->tagPager($tag, $content); + } + + /** * chapter pager * @@ -42,6 +56,7 @@ class Chapter extends TagLib $d_val = $tag['d_val'] ?? 'd_val'; $p_val = $tag['p_val'] ?? 'p_val'; $func = $tag['func']; + $export_name = $tag['export_name'] ?? ''; $n_id = $this->customBuildVar($n_id); $sort_type = $this->customBuildVar($sort_type); @@ -53,9 +68,11 @@ class Chapter extends TagLib $cache_life = $this->customBuildVar($cache_life); $func = $this->customBuildVar($func); + $arrDataName = randomString(5); + $strParse = <<getNovelPager([ +\${$arrDataName} = app(\\app\\services\\ChapterService::class)->getNovelPager([ 'page' => {$page}, 'limit' => {$limit}, 'button_num' => {$button_num}, @@ -65,19 +82,27 @@ class Chapter extends TagLib 'cache_life' => {$cache_life}, 'func' => {$func}, ]); +EOT; -if (isset(\$arrChapter['data']) && is_array(\$arrChapter['data'])): - \${$p_val} = \$arrChapter['p_data'] ?? []; + if (empty($export_name)) { + $strParse .= << EOT; - $strParse .= << \${$d_val}): ?> + $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; + } else { + $strParse .= <<customBuildVar($count); $n_id = $this->customBuildVar($n_id); $sort_type = $this->customBuildVar($sort_type); $diff_key = $this->customBuildVar($diff_key); $cache_life = $this->customBuildVar($cache_life); - + $arrDataName = randomString(5); $strParse = <<getChapterList([ +\${$arrDataName} = app(\\app\\services\\ChapterService::class)->getChapterList([ 'n_id' => {$n_id}, 'count' => {$count}, 'sort_type' => {$sort_type}, @@ -115,12 +140,12 @@ EOT; 'cache_life' => {$cache_life}, ]); -if (!empty(\$arrChapter) && is_array(\$arrChapter)): +if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})): ?> EOT; $strParse .= << \${$d_val}): ?> + \${$d_val}): ?> EOT; $strParse .= $content; $strParse .= <<customBuildVar($n_id); $c_sort_num = $this->customBuildVar($c_sort_num); $c_page = $this->customBuildVar($c_page); - + $strParse = <<getChapterInfo( diff --git a/code/extend/template/taglib/Novel.php b/code/extend/template/taglib/Novel.php index d0612fa..581ea1a 100644 --- a/code/extend/template/taglib/Novel.php +++ b/code/extend/template/taglib/Novel.php @@ -6,62 +6,75 @@ use think\template\TagLib; class Novel extends TagLib { - protected $tags = [ - 'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val'], - 'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'], - 'info' => ['attr' => 'n_id,n_key', 'close' => 0], - 'sort' => ['attr' => 'd_key,d_val'], - 'status' => ['attr' => 'd_key,d_val'], - 'sex' => ['attr' => 'd_key,d_val'], - 'category' => ['attr' => 'd_key,d_val'], - ]; + protected $tags = [ + 'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val', 'close' => 1], + 'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 1], + 'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0], + 'info' => ['attr' => 'n_id,n_key', 'close' => 0], + 'sort' => ['attr' => 'd_key,d_val'], + 'status' => ['attr' => 'd_key,d_val'], + 'sex' => ['attr' => 'd_key,d_val'], + 'category' => ['attr' => 'd_key,d_val'], + ]; - private function customBuildVar($mixedArgs) - { - if (substr($mixedArgs, 0, 1) == '$') { - return $this->autoBuildVar($mixedArgs); - } else { - return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'"; + private function customBuildVar($mixedArgs) + { + if (substr($mixedArgs, 0, 1) == '$') { + return $this->autoBuildVar($mixedArgs); + } else { + return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'"; + } } - } - /** - * novel 自定义标签 - */ - public function tagPager($tag, $content) - { - $page = $tag['page'] ?? '0'; - $limit = $tag['limit'] ?? '10'; - $button_num = $tag['button_num'] ?? '10'; - $n_category = $tag['n_category'] ?? "all"; - $sort_type = $tag['sort_type'] ?? ""; - $n_status = $tag['n_status'] ?? ""; - $n_sex = $tag['n_sex'] ?? ""; - $key = $tag['key'] ?? ""; - $diff_key = $tag['diff_key'] ?? ""; - $cache_life = $tag['cache_life'] ?? '0'; - $d_key = $tag['d_key'] ?? 'd_key'; - $d_val = $tag['d_val'] ?? 'd_val'; - $p_val = $tag['p_val'] ?? 'p_val'; - $n_num = $tag['n_num'] ?? 'n_num'; - $func = $tag['func']; + /** + * novel 自定义标签 + */ + public function tagPagerExp($tag, $content) + { + return $this->tagPager($tag, $content); + } - $page = $this->customBuildVar($page); - $limit = $this->customBuildVar($limit); - $button_num = $this->customBuildVar($button_num); - $n_category = $this->customBuildVar($n_category); - $sort_type = $this->customBuildVar($sort_type); - $n_status = $this->customBuildVar($n_status); - $n_sex = $this->customBuildVar($n_sex); - $key = $this->customBuildVar($key); - $diff_key = $this->customBuildVar($diff_key); - $cache_life = $this->customBuildVar($cache_life); - $func = $this->customBuildVar($func); + /** + * novel 自定义标签 + */ + public function tagPager($tag, $content) + { + $page = $tag['page'] ?? '0'; + $limit = $tag['limit'] ?? '10'; + $button_num = $tag['button_num'] ?? '10'; + $n_category = $tag['n_category'] ?? "all"; + $sort_type = $tag['sort_type'] ?? ""; + $n_status = $tag['n_status'] ?? ""; + $n_sex = $tag['n_sex'] ?? ""; + $key = $tag['key'] ?? ""; + $diff_key = $tag['diff_key'] ?? ""; + $cache_life = $tag['cache_life'] ?? '0'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; + $p_val = $tag['p_val'] ?? 'p_val'; - $strParse = <<customBuildVar($page); + $limit = $this->customBuildVar($limit); + $button_num = $this->customBuildVar($button_num); + $n_category = $this->customBuildVar($n_category); + $sort_type = $this->customBuildVar($sort_type); + $n_status = $this->customBuildVar($n_status); + $n_sex = $this->customBuildVar($n_sex); + $key = $this->customBuildVar($key); + $diff_key = $this->customBuildVar($diff_key); + $cache_life = $this->customBuildVar($cache_life); + $func = $this->customBuildVar($func); + + $arrDataName = randomString(5); + + $strParse = <<getNovelPager([ +\${$arrDataName} = app(\\app\\services\\NovelService::class)->getNovelPager([ 'page' => {$page}, 'limit' => {$limit}, 'button_num' => {$button_num}, @@ -74,49 +87,61 @@ class Novel extends TagLib 'cache_life' => {$cache_life}, 'func' => {$func}, ]); +EOT; -if (isset(\$novelData['data']) && is_array(\$novelData['data'])): - \${$p_val} = \$novelData['p_data'] ?? []; - \${$n_num} = \$novelData['pages'] ?? []; + + if (empty($export_name)) { + $strParse .= << EOT; - $strParse .= << \${$d_val}): ?> + $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; - return $strParse; - } + } else { + $strParse .= << +EOT; + } - /** - * novel 自定义标签 - */ - public function tagList($tag, $content) - { - $count = $tag['count'] ?? '10'; - $n_category = $tag['n_category'] ?? "all"; - $sort_type = $tag['sort_type'] ?? ""; - $n_status = $tag['n_status'] ?? "all"; - $n_sex = $tag['n_sex'] ?? "all"; - $diff_key = $tag['diff_key'] ?? ""; - $cache_life = $tag['cache_life'] ?? '0'; - $d_key = $tag['d_key'] ?? 'd_key'; - $d_val = $tag['d_val'] ?? 'd_val'; + return $strParse; + } + + /** + * novel 自定义标签 + */ + public function tagList($tag, $content) + { + $count = $tag['count'] ?? '10'; + $n_category = $tag['n_category'] ?? "all"; + $sort_type = $tag['sort_type'] ?? ""; + $n_status = $tag['n_status'] ?? "all"; + $n_sex = $tag['n_sex'] ?? "all"; + $diff_key = $tag['diff_key'] ?? ""; + $cache_life = $tag['cache_life'] ?? '0'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; - $n_category = $this->customBuildVar($n_category); - $sort_type = $this->customBuildVar($sort_type); - $n_status = $this->customBuildVar($n_status); - $n_sex = $this->customBuildVar($n_sex); - $diff_key = $this->customBuildVar($diff_key); - $cache_life = $this->customBuildVar($cache_life); + $n_category = $this->customBuildVar($n_category); + $sort_type = $this->customBuildVar($sort_type); + $n_status = $this->customBuildVar($n_status); + $n_sex = $this->customBuildVar($n_sex); + $diff_key = $this->customBuildVar($diff_key); + $cache_life = $this->customBuildVar($cache_life); - $strParse = <<getNovelList([ +\${$arrDataName} = app(\\app\\services\\NovelService::class)->getNovelList([ 'count' => {$count}, 'n_category' => {$n_category}, 'sort_type' => {$sort_type}, @@ -126,42 +151,42 @@ EOT; 'cache_life' => {$cache_life} ]); -if (!empty(\$novelData) && is_array(\$novelData)): +if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})): ?> EOT; - $strParse .= << \${$d_val}): ?> + $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; - return $strParse; - } + return $strParse; + } - /** - * 获取小说详情 - * - * @param array $tag - * @param string $content - * @return void - */ - public function tagInfo($tag) - { - $n_id = $tag['n_id'] ?? '0'; - $n_forge_id = $tag['n_forge_id'] ?? 0; + /** + * 获取小说详情 + * + * @param array $tag + * @param string $content + * @return void + */ + public function tagInfo($tag) + { + $n_id = $tag['n_id'] ?? '0'; + $n_forge_id = $tag['n_forge_id'] ?? 0; - $n_key = $tag['n_key'] ?? 'arrNovel'; + $n_key = $tag['n_key'] ?? 'arrNovel'; - $n_id = $this->customBuildVar($n_id); + $n_id = $this->customBuildVar($n_id); - $strParse = <<getNovelByNId( {$n_id}, @@ -172,23 +197,23 @@ EOT; ?> EOT; - return $strParse; - } + return $strParse; + } - /** - * 获取排序筛选参数 - * - * @param array $tag - * @param string $content - * @return string - */ - public function tagSort($tag, $content) - { + /** + * 获取排序筛选参数 + * + * @param array $tag + * @param string $content + * @return string + */ + public function tagSort($tag, $content) + { - $d_key = $tag['d_key'] ?? 'd_key'; - $d_val = $tag['d_val'] ?? 'd_val'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; - $strParse = <<arrSortType; @@ -196,31 +221,31 @@ if (!empty(\$arrSort) && is_array(\$arrSort)): ?> EOT; - $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; - return $strParse; - } + return $strParse; + } - /** - * 获取状态筛选参数 - * - * @param array $tag - * @param string $content - * @return string - */ - public function tagStatus($tag, $content) - { + /** + * 获取状态筛选参数 + * + * @param array $tag + * @param string $content + * @return string + */ + public function tagStatus($tag, $content) + { - $d_key = $tag['d_key'] ?? 'd_key'; - $d_val = $tag['d_val'] ?? 'd_val'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; - $strParse = <<arrStatus; @@ -228,32 +253,32 @@ if (!empty(\$arrStatus) && is_array(\$arrStatus)): ?> EOT; - $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; - return $strParse; - } + return $strParse; + } - /** - * 获取状态筛选参数 - * - * @param array $tag - * @param string $content - * @return string - */ - public function tagSex($tag, $content) - { + /** + * 获取状态筛选参数 + * + * @param array $tag + * @param string $content + * @return string + */ + public function tagSex($tag, $content) + { - $d_key = $tag['d_key'] ?? 'd_key'; - $d_val = $tag['d_val'] ?? 'd_val'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; - $strParse = <<arrSex; @@ -261,31 +286,31 @@ if (!empty(\$arrSex) && is_array(\$arrSex)): ?> EOT; - $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; - return $strParse; - } + return $strParse; + } - /** - * 获取状态筛选参数 - * - * @param array $tag - * @param string $content - * @return string - */ - public function tagCategory($tag, $content) - { + /** + * 获取状态筛选参数 + * + * @param array $tag + * @param string $content + * @return string + */ + public function tagCategory($tag, $content) + { - $d_key = $tag['d_key'] ?? 'd_key'; - $d_val = $tag['d_val'] ?? 'd_val'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; - $strParse = <<getCategoryFilter(); @@ -293,14 +318,14 @@ if (!empty(\$arrCategory) && is_array(\$arrCategory)): ?> EOT; - $strParse .= << \${$d_val}): ?> EOT; - $strParse .= $content; - $strParse .= << EOT; - return $strParse; - } + return $strParse; + } }