diff --git a/app/common.php b/app/common.php index a8350f1..62e7bb3 100644 --- a/app/common.php +++ b/app/common.php @@ -1613,4 +1613,27 @@ if (!function_exists('getCategoryChildrenCount')) { $categoryModel = new \app\model\Category(); return $categoryModel->where('parent_id', $id)->count(); } -} \ No newline at end of file +} +if (!function_exists('isHcListEmpty')) { + /** + * 判断内容列表/分页结果是否为空(兼容数组与 ThinkPHP Paginator) + * @param mixed $list + * @return bool + */ + function isHcListEmpty($list): bool + { + if ($list === null || $list === '' || $list === []) { + return true; + } + if (is_object($list) && method_exists($list, 'isEmpty')) { + return (bool)$list->isEmpty(); + } + if (is_object($list) && method_exists($list, 'total')) { + return (int)$list->total() === 0; + } + if (is_countable($list)) { + return count($list) === 0; + } + return false; + } +} diff --git a/public/themes/dist_static/static/css/empty.css b/public/themes/dist_static/static/css/empty.css new file mode 100644 index 0000000..fc0bb85 --- /dev/null +++ b/public/themes/dist_static/static/css/empty.css @@ -0,0 +1,30 @@ +.s-empty { + display: flex; + align-items: center; + justify-content: center; + min-height: 16rem; + padding: 2.5rem 1.5rem; + border-radius: 1.25rem; + background: rgba(175, 181, 185, 0.08); + box-sizing: border-box; +} +.s-empty__text { + margin: 0; + color: var(--color-text-muted); + font-family: "MiSans VF", "PingFang SC", sans-serif; + font-size: var(--font-18); + line-height: var(--font-26); + text-align: center; +} + +@media (max-width: 576px) { + .s-empty { + min-height: 12rem; + padding: 32Px 16Px; + border-radius: 16Px; + } + .s-empty__text { + font-size: 16Px; + line-height: 24Px; + } +} diff --git a/public/themes/dist_static/static/css/search.css b/public/themes/dist_static/static/css/search.css index 45ca8c2..8a028cd 100644 --- a/public/themes/dist_static/static/css/search.css +++ b/public/themes/dist_static/static/css/search.css @@ -228,18 +228,6 @@ color: var(--color-primary); } -.sr-empty { - margin: 4rem 0 0; - color: var(--color-text-muted); - font-family: "MiSans VF", "PingFang SC", sans-serif; - font-size: var(--font-16); - line-height: var(--font-24); - text-align: center; -} -.sr-empty[hidden] { - display: none; -} - @media (max-width: 992px) { .sr-page { padding-top: calc(var(--header-h) + 32Px); diff --git a/public/themes/website/1/zh/demo/announce.html b/public/themes/website/1/zh/demo/announce.html index 0c8cd24..ceda4f2 100644 --- a/public/themes/website/1/zh/demo/announce.html +++ b/public/themes/website/1/zh/demo/announce.html @@ -47,6 +47,7 @@ + @@ -99,7 +100,17 @@ {/hcTaglib:contentPage} + {php} + $list_empty = isHcListEmpty($hc_content ?? null); + if ($list_empty) { + $empty_text = '暂无相关公告'; + } + {/php} + {if $list_empty} + {include file="components/empty"} + {else /} {$hc_content|raw} + {/if}
{$empty_text}
+未找到相关结果,请尝试其他关键词
- {/empty} + {php} + $list_empty = isHcListEmpty($list ?? null); + if ($list_empty) { + $empty_text = '未找到相关结果,请尝试其他关键词'; + } + {/php} + {if $list_empty} + {include file="components/empty"} + {else /} {$list_page|raw} + {/if} diff --git a/public/themes/website/1/zh/demo/video.html b/public/themes/website/1/zh/demo/video.html index 2388f7f..e7d8fb6 100644 --- a/public/themes/website/1/zh/demo/video.html +++ b/public/themes/website/1/zh/demo/video.html @@ -47,6 +47,7 @@ + @@ -100,7 +101,17 @@ {/hcTaglib:contentPage} + {php} + $list_empty = isHcListEmpty($hc_content ?? null); + if ($list_empty) { + $empty_text = '暂无相关视频'; + } + {/php} + {if $list_empty} + {include file="components/empty"} + {else /} {$hc_content|raw} + {/if}