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}
diff --git a/public/themes/website/1/zh/demo/components/empty.html b/public/themes/website/1/zh/demo/components/empty.html new file mode 100644 index 0000000..84b80ab --- /dev/null +++ b/public/themes/website/1/zh/demo/components/empty.html @@ -0,0 +1,8 @@ +{php} +if (!isset($empty_text) || $empty_text === '') { + $empty_text = '暂无相关内容'; +} +{/php} +
+

{$empty_text}

+
diff --git a/public/themes/website/1/zh/demo/download.html b/public/themes/website/1/zh/demo/download.html index 77c6e01..ff55e9e 100644 --- a/public/themes/website/1/zh/demo/download.html +++ b/public/themes/website/1/zh/demo/download.html @@ -49,6 +49,7 @@ + @@ -117,8 +118,17 @@ {/hcTaglib:contentPage}
- - {$hc_content|raw} + {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}
diff --git a/public/themes/website/1/zh/demo/faq.html b/public/themes/website/1/zh/demo/faq.html index 0069f42..b0be08a 100644 --- a/public/themes/website/1/zh/demo/faq.html +++ b/public/themes/website/1/zh/demo/faq.html @@ -47,6 +47,7 @@ + @@ -94,7 +95,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}
diff --git a/public/themes/website/1/zh/demo/news.html b/public/themes/website/1/zh/demo/news.html index f42f8e1..d037f2c 100644 --- a/public/themes/website/1/zh/demo/news.html +++ b/public/themes/website/1/zh/demo/news.html @@ -54,6 +54,7 @@ + @@ -202,8 +203,18 @@
+ {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} diff --git a/public/themes/website/1/zh/demo/search.html b/public/themes/website/1/zh/demo/search.html index 859dd34..5655d95 100644 --- a/public/themes/website/1/zh/demo/search.html +++ b/public/themes/website/1/zh/demo/search.html @@ -47,6 +47,7 @@ + @@ -116,10 +117,17 @@ {/volist} - {empty name="list"} -

未找到相关结果,请尝试其他关键词

- {/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}