This commit is contained in:
Default
2025-04-17 17:29:51 +08:00
parent efad19295d
commit 1f8c738381
16 changed files with 466 additions and 215 deletions

View File

@@ -0,0 +1,78 @@
<?php
namespace template\taglib;
use think\template\TagLib;
class Novel extends TagLib
{
protected $tags = [
'list' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'],
];
private function customBuildVar($mixedArgs)
{
if (substr($mixedArgs, 0, 1) == '$') {
return $this->autoBuildVar($mixedArgs);
} else {
return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'";
}
}
/**
* novel 自定义标签
*/
public function tagList($tag, $content)
{
$page = $tag['page'] ?? '0';
$limit = $tag['limit'] ?? '10';
$n_category = $tag['n_category'] ?? "all";
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "all";
$n_sex = $tag['n_sex'] ?? "all";
$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';
$page = $this->customBuildVar($page);
$limit = $this->customBuildVar($limit);
$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);
$parse = <<<EOT
<?php
\$novelData = app(\\app\\services\\NovelService::class)->getNovelData([
'page' => {$page},
'limit' => {$limit},
'n_category' => {$n_category},
'sort_type' => {$sort_type},
'n_status' => {$n_status},
'n_sex' => {$n_sex},
'key' => {$key},
'diff_key' => {$diff_key},
'cache_life' => {$cache_life}
]);
if (isset(\$novelData['data']) && is_array(\$novelData['data'])):
\${$p_val} = \$novelData['p_data'] ?? [];
?>
EOT;
$parse .= <<<EOT
<?php foreach (\$novelData['data'] as \${$d_key} => \${$d_val}): ?>
EOT;
$parse .= $content;
$parse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $parse;
}
}

View File

@@ -78,7 +78,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getNovelInfoUrl("{$intNId}","{$strNPy}");
\$strUrl = app(\\app\\services\\NovelService::class)->getNovelInfoUrl("{$intNId}","{$strNPy}");
echo \$strUrl;
?>
EOD;
@@ -99,7 +99,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getForgeNovelInfoUrl("{$intNId}","{$strNPy}","{$intNForgeId}");
\$strUrl = app(\\app\\services\\NovelService::class)->getForgeNovelInfoUrl("{$intNId}","{$strNPy}","{$intNForgeId}");
echo \$strUrl;
?>
EOD;
@@ -121,7 +121,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getNovelChapterUrl("{$intNId}","{$strNPy}","{$intChapterSort}","{$intChapterPage}");
\$strUrl = app(\\app\\services\\NovelService::class)->getNovelChapterUrl("{$intNId}","{$strNPy}","{$intChapterSort}","{$intChapterPage}");
echo \$strUrl;
?>
EOD;
@@ -141,7 +141,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getNovelLasterChapterUrl("{$intNId}","{$strNPy}");
\$strUrl = app(\\app\\services\\NovelService::class)->getNovelLasterChapterUrl("{$intNId}","{$strNPy}");
echo \$strUrl;
?>
EOD;
@@ -163,7 +163,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getNovelCatalogUrl("{$intNId}","{$strNPy}","{$strOrder}","{$intPage}");
\$strUrl = app(\\app\\services\\NovelService::class)->getNovelCatalogUrl("{$intNId}","{$strNPy}","{$strOrder}","{$intPage}");
echo \$strUrl;
?>
EOD;
@@ -185,7 +185,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getNovelCategoryUrl("{$strGender}","{$strCategory}","{$strStatus}","{$intPage}");
\$strUrl = app(\\app\\services\\NovelService::class)->getNovelCategoryUrl("{$strGender}","{$strCategory}","{$strStatus}","{$intPage}");
echo \$strUrl;
?>
EOD;
@@ -205,7 +205,7 @@ EOD;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\NovelModel::getNovelSearchUrl("{$strKey}","{$intPage}");
\$strUrl = app(\\app\\services\\NovelService::class)->getNovelSearchUrl("{$strKey}","{$intPage}");
echo \$strUrl;
?>
EOD;