更新模板功能

This commit is contained in:
2026-03-12 17:53:36 +08:00
parent 1f8d876cef
commit bf21006d4e
168 changed files with 82346 additions and 229 deletions
+254 -165
View File
@@ -19,91 +19,126 @@ $host = $_SERVER['HTTP_HOST'] ?? '';
// 查询域名对应的租户ID
$tenantDomain = TenantDomain::where('full_domain', $host)
->where('status', 1)
->whereNull('delete_time')
->find();
->where('status', 1)
->whereNull('delete_time')
->find();
$tid = $tenantDomain ? (int)$tenantDomain['tid'] : 0;
$tid = $tenantDomain ? (int) $tenantDomain['tid'] : 0;
// 获取 Banner 数据
$banners = [];
if ($tid > 0) {
$banners = Banner::where('tid', $tid)
->whereNull('delete_time')
->order('sort', 'asc')
->order('id', 'desc')
->select()
->toArray();
$banners = Banner::where('tid', $tid)
->whereNull('delete_time')
->order('sort', 'asc')
->order('id', 'desc')
->select()
->toArray();
// 处理图片路径
foreach ($banners as &$banner) {
if (!empty($banner['image'])) {
if (!preg_match('/^https?:\/\//', $banner['image'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$banner['image'] = $scheme . '://' . $host .
(strpos($banner['image'], '/') === 0 ? '' : '/') . $banner['image'];
}
}
// 处理图片路径
foreach ($banners as &$banner) {
if (!empty($banner['image'])) {
if (!preg_match('/^https?:\/\//', $banner['image'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$banner['image'] = $scheme . '://' . $host .
(strpos($banner['image'], '/') === 0 ? '' : '/') . $banner['image'];
}
}
}
}
// 获取新闻数据
$articles = [];
if ($tid > 0) {
$articles = Articles::where('tid', $tid)
->where('delete_time', null)
->where('status', 2)
->order('publish_date', 'desc')
->limit(8)
->select()
->toArray();
$articles = Articles::where('tid', $tid)
->where('delete_time', null)
->where('status', 2)
->order('publish_date', 'desc')
->limit(8)
->select()
->toArray();
// 处理图片:如果文章image为空,则取分类的image
foreach ($articles as &$article) {
if (empty($article['image']) && !empty($article['cate'])) {
$category = ArticlesCategory::where('id', $article['cate'])
->where('delete_time', null)
->find();
if ($category && !empty($category['image'])) {
$article['image'] = $category['image'];
}
}
// 处理图片路径
if (!empty($article['image']) && !preg_match('/^https?:\/\//', $article['image'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$article['image'] = $scheme . '://' . $host .
(strpos($article['image'], '/') === 0 ? '' : '/') . $article['image'];
}
if (!empty($article['thumb']) && !preg_match('/^https?:\/\//', $article['thumb'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$article['thumb'] = $scheme . '://' . $host .
(strpos($article['thumb'], '/') === 0 ? '' : '/') . $article['thumb'];
}
// 处理图片:如果文章image为空,则取分类的image
foreach ($articles as &$article) {
if (empty($article['image']) && !empty($article['cate'])) {
$category = ArticlesCategory::where('id', $article['cate'])
->where('delete_time', null)
->find();
if ($category && !empty($category['image'])) {
$article['image'] = $category['image'];
}
}
// 处理图片路径
if (!empty($article['image']) && !preg_match('/^https?:\/\//', $article['image'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$article['image'] = $scheme . '://' . $host .
(strpos($article['image'], '/') === 0 ? '' : '/') . $article['image'];
}
if (!empty($article['thumb']) && !preg_match('/^https?:\/\//', $article['thumb'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$article['thumb'] = $scheme . '://' . $host .
(strpos($article['thumb'], '/') === 0 ? '' : '/') . $article['thumb'];
}
}
}
// 获取企业联系信息
// 获取企业联系信息和站点设置
$companyInfo = [];
if ($tid > 0) {
$companyInfo = Tenant::where('id', $tid)
->where('delete_time', null)
->field('contact_phone, contact_email, address, worktime')
->find();
}else{
// 获取租户信息
$tenant = Tenant::where('id', $tid)
->where('delete_time', null)
->field('contact_phone, contact_email, address, worktime')
->find();
// 获取站点设置
$siteSetting = \app\model\System\SystemSiteSetting::where('tid', $tid)
->where('delete_time', null)
->find();
$companyInfo = array_merge(
$tenant ? $tenant->toArray() : [],
$siteSetting ? $siteSetting->toArray() : []
);
} else {
$companyInfo = [
'contact_phone' => '-',
'contact_email' => '-',
'address' => '-',
'worktime' => '-'
'sitename' => '',
'logo' => '',
'logow' => '',
'ico' => '',
'description' => '',
'contact_phone' => '-',
'contact_email' => '-',
'address' => '-',
'worktime' => '-'
];
}
// 处理图片路径
if (!empty($companyInfo['logo']) && !preg_match('/^https?:\/\//', $companyInfo['logo'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$companyInfo['logo'] = $scheme . '://' . $host .
(strpos($companyInfo['logo'], '/') === 0 ? '' : '/') . $companyInfo['logo'];
}
if (!empty($companyInfo['logow']) && !preg_match('/^https?:\/\//', $companyInfo['logow'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$companyInfo['logow'] = $scheme . '://' . $host .
(strpos($companyInfo['logow'], '/') === 0 ? '' : '/') . $companyInfo['logow'];
}
if (!empty($companyInfo['ico']) && !preg_match('/^https?:\/\//', $companyInfo['ico'])) {
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$companyInfo['ico'] = $scheme . '://' . $host .
(strpos($companyInfo['ico'], '/') === 0 ? '' : '/') . $companyInfo['ico'];
}
// 辅助函数:去除 HTML 标签
function stripHtml($html) {
if (empty($html)) return '';
$text = preg_replace('/<[^>]+>/', ' ', $html);
$text = preg_replace('/\s+/', ' ', $text);
return trim($text);
function stripHtml($html)
{
if (empty($html))
return '';
$text = preg_replace('/<[^>]+>/', ' ', $html);
$text = preg_replace('/\s+/', ' ', $text);
return trim($text);
}
?>
<!DOCTYPE html>
@@ -112,8 +147,11 @@ function stripHtml($html) {
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Nova - Bootstrap 5 Template</title>
<meta name="description" content="" />
<title><?php echo !empty($companyInfo['sitename']) ? $companyInfo['sitename'] : '实例 - 云泽网模板'; ?></title>
<?php if (!empty($companyInfo['ico'])): ?>
<link rel="icon" href="<?php echo $companyInfo['ico']; ?>" type="image/x-icon" />
<?php endif; ?>
<meta name="description" content="<?php echo !empty($companyInfo['description']) ? $companyInfo['description'] : ''; ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="assets/css/bootstrap-5.0.0-beta1.min.css" />
<link rel="stylesheet" href="assets/css/LineIcons.2.0.css" />
@@ -157,10 +195,12 @@ function stripHtml($html) {
<div class="row align-items-center">
<div class="col-lg-12">
<nav class="navbar navbar-expand-lg">
<a class="navbar-brand" href="index.html">
<img src="assets/img/logo/logo.svg" alt="Logo" />
<a class="navbar-brand" href="index.php">
<img src="<?php echo !empty($companyInfo['logo']) ? $companyInfo['logo'] : 'assets/img/logo/logo.svg'; ?>" alt="Logo" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent6" aria-controls="navbarSupportedContent6" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent6" aria-controls="navbarSupportedContent6"
aria-expanded="false" aria-label="Toggle navigation">
<span class="toggler-icon"></span>
<span class="toggler-icon"></span>
<span class="toggler-icon"></span>
@@ -172,17 +212,17 @@ function stripHtml($html) {
<a class="page-scroll active" href="#home">主页</a>
</li>
<li class="nav-item">
<a class="page-scroll" href="#feature">新闻中心</a>
<a class="page-scroll" href="#newsCenter">新闻中心</a>
</li>
<li class="nav-item">
<a class="page-scroll" href="#about">关于我们</a>
<a class="page-scroll" href="#aboutUs">关于我们</a>
</li>
<li class="nav-item">
<a class="page-scroll" href="#pricing">Pricing</a>
<a class="page-scroll" href="#services">特色业务</a>
</li>
<li class="nav-item">
<a class="page-scroll" href="#contact">联系我们</a>
<a class="page-scroll" href="#contactUs">联系我们</a>
</li>
</ul>
</div>
@@ -202,12 +242,15 @@ function stripHtml($html) {
<div class="swiper-button-prev"></div>
</div>
</section>
<section id="feature" class="feature-section feature-style-5">
<section id="newsCenter" class="feature-section feature-style-5">
<div class="container">
<div class="row justify-content-center">
<div class="col-xxl-5 col-xl-5 col-lg-7 col-md-8">
<div class="section-title text-center mb-60">
<div class="section-title text-center mb-60" style="display: flex;align-items: center;justify-content: center;">
<h3 class="mb-15 wow fadeInUp" data-wow-delay=".2s">新闻中心</h3>
<a href="/news/index.php" target="_blank">
<span style="font-size: 14px;margin-left: 50px;">Read More</span>
</a>
</div>
</div>
</div>
@@ -218,30 +261,18 @@ function stripHtml($html) {
</div>
</section>
<section id="about" class="about-section about-style-4">
<section id="aboutUs" class="about-section about-style-4">
<div class="container">
<div class="row align-items-center">
<div class="col-xl-5 col-lg-6">
<div class="about-content-wrapper">
<div class="section-title mb-30">
<h3 class="mb-25 wow fadeInUp" data-wow-delay=".2s">The future of designing starts here</h3>
<p class="wow fadeInUp" data-wow-delay=".3s">Stop wasting time and money designing and managing a website that doesnt get results. Happiness guaranteed,</p>
<h3 class="mb-25 wow fadeInUp" data-wow-delay=".2s">关于我们</h3>
<p class="wow fadeInUp" data-wow-delay=".3s">
<?php echo !empty($companyInfo['companyintroduction']) ? $companyInfo['companyintroduction'] : ''; ?>
</p>
</div>
<ul>
<li class="wow fadeInUp" data-wow-delay=".35s">
<i class="lni lni-checkmark-circle"></i>
Stop wasting time and money designing and managing a website that doesnt get results.
</li>
<li class="wow fadeInUp" data-wow-delay=".4s">
<i class="lni lni-checkmark-circle"></i>
Stop wasting time and money designing and managing.
</li>
<li class="wow fadeInUp" data-wow-delay=".45s">
<i class="lni lni-checkmark-circle"></i>
Stop wasting time and money designing and managing a website that doesnt get results.
</li>
</ul>
<a href="#0" class="button button-lg radius-10 wow fadeInUp" data-wow-delay=".5s">Learn More</a>
<!-- <a href="#0" class="button button-lg radius-10 wow fadeInUp" data-wow-delay=".5s">Learn More</a> -->
</div>
</div>
<div class="col-xl-7 col-lg-6">
@@ -252,13 +283,14 @@ function stripHtml($html) {
</div>
</div>
</section>
<section id="pricing" class="pricing-section pricing-style-4 bg-light">
<section id="services" class="pricing-section pricing-style-4 bg-light">
<div class="container">
<div class="row align-items-center">
<div class="col-xl-5 col-lg-6">
<div class="section-title mb-60">
<h3 class="mb-15 wow fadeInUp" data-wow-delay=".2s">特色业务</h3>
<p class="wow fadeInUp" data-wow-delay=".4s">我们始终以专业、高效、创新为核心,深耕行业多年,形成了独具优势的特色业务体系。凭借成熟的服务流程、过硬的技术实力与丰富的实战经验,为客户提供一站式、定制化解决方案。</p>
<p class="wow fadeInUp" data-wow-delay=".4s">
我们始终以专业、高效、创新为核心,深耕行业多年,形成了独具优势的特色业务体系。凭借成熟的服务流程、过硬的技术实力与丰富的实战经验,为客户提供一站式、定制化解决方案。</p>
</div>
</div>
<div class="col-xl-7 col-lg-6">
@@ -313,7 +345,7 @@ function stripHtml($html) {
</div>
</div>
</section>
<section id="contact" class="contact-section contact-style-3">
<section id="contactUs" class="contact-section contact-style-3">
<div class="container">
<div class="row justify-content-center">
<div class="col-xxl-5 col-xl-5 col-lg-7 col-md-10">
@@ -360,7 +392,8 @@ function stripHtml($html) {
</div>
<div class="col-md-12">
<div class="form-button">
<button type="submit" class="button" id="submitBtn"> <i class="lni lni-telegram-original"></i> 提交</button>
<button type="submit" class="button" id="submitBtn"> <i class="lni lni-telegram-original"></i>
提交</button>
</div>
</div>
</div>
@@ -384,29 +417,29 @@ function stripHtml($html) {
};
fetch('/index/requirement', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(result => {
if (result.code === 200) {
alert('提交成功!我们会尽快与您联系。');
document.getElementById('requirementForm').reset();
} else {
alert(result.msg || '提交失败,请稍后重试');
}
})
.catch(err => {
console.error('提交失败:', err);
alert('提交失败,请稍后重试');
})
.finally(() => {
submitBtn.disabled = false;
submitBtn.innerHTML = '<i class="lni lni-telegram-original"></i> 提交';
});
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(result => {
if (result.code === 200) {
alert('提交成功!我们会尽快与您联系。');
document.getElementById('requirementForm').reset();
} else {
alert(result.msg || '提交失败,请稍后重试');
}
})
.catch(err => {
console.error('提交失败:', err);
alert('提交失败,请稍后重试');
})
.finally(() => {
submitBtn.disabled = false;
submitBtn.innerHTML = '<i class="lni lni-telegram-original"></i> 提交';
});
});
</script>
@@ -416,52 +449,52 @@ function stripHtml($html) {
<div class="left-wrapper">
<div class="row">
<?php if (!empty($companyInfo['contact_phone'])): ?>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-phone"></i>
</div>
<div class="text">
<p>+86 <?php echo htmlspecialchars($companyInfo['contact_phone']); ?></p>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-phone"></i>
</div>
<div class="text">
<p>+86 <?php echo htmlspecialchars($companyInfo['contact_phone']); ?></p>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if (!empty($companyInfo['contact_email'])): ?>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-envelope"></i>
</div>
<div class="text">
<p><?php echo htmlspecialchars($companyInfo['contact_email']); ?></p>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-envelope"></i>
</div>
<div class="text">
<p><?php echo htmlspecialchars($companyInfo['contact_email']); ?></p>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if (!empty($companyInfo['address'])): ?>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-map-marker"></i>
</div>
<div class="text">
<p><?php echo htmlspecialchars($companyInfo['address']); ?></p>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-map-marker"></i>
</div>
<div class="text">
<p><?php echo htmlspecialchars($companyInfo['address']); ?></p>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if (!empty($companyInfo['worktime'])): ?>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-timer"></i>
</div>
<div class="text">
<p><?php echo htmlspecialchars($companyInfo['worktime']); ?></p>
<div class="col-lg-12 col-md-6">
<div class="single-item">
<div class="icon">
<i class="lni lni-timer"></i>
</div>
<div class="text">
<p><?php echo htmlspecialchars($companyInfo['worktime']); ?></p>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
@@ -492,9 +525,11 @@ function stripHtml($html) {
<div class="col-xl-3 col-lg-4 col-md-6">
<div class="footer-widget wow fadeInUp" data-wow-delay=".2s">
<div class="logo">
<a href="#0"> <img src="assets/img/logo/logo.svg" alt=""> </a>
<a href="#0"> <img src="<?php echo !empty($companyInfo['logow']) ? $companyInfo['logow'] : 'assets/img/logo/logo.svg'; ?>" alt=""> </a>
</div>
<p class="desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Facilisis nulla placerat amet amet congue.</p>
<p class="desc">
<?php echo !empty($companyInfo['description']) ? $companyInfo['description'] : ''; ?>
</p>
<ul class="socials">
<li> <a href="#0"> <i class="fa-brands fa-qq"></i> </a> </li>
<li> <a href="#0"> <i class="fa-brands fa-weixin"></i> </a> </li>
@@ -506,11 +541,11 @@ function stripHtml($html) {
<div class="footer-widget wow fadeInUp" data-wow-delay=".3s">
<h6>快捷链接</h6>
<ul class="links">
<li> <a href="#0">主页</a> </li>
<li> <a href="#0">关于我们</a> </li>
<li> <a href="#0">服务</a> </li>
<li> <a href="#0">客户评价</a> </li>
<li> <a href="#0">联系</a> </li>
<li> <a href="#home">主页</a> </li>
<li> <a href="#newsCenter">新闻中心</a> </li>
<li> <a href="#aboutUs">关于我们</a> </li>
<li> <a href="#services">特色业务</a> </li>
<li> <a href="#contactUs">联系我们</a> </li>
</ul>
</div>
</div>
@@ -564,6 +599,16 @@ function stripHtml($html) {
<script>
// API 接口地址配置
const API_BASE_URL = 'https://api.yunzer.cn';
// 主题 URL 前缀:优先从当前脚本路径推断;若脚本被路由到 /news 等,则回退到 /themes/default
const THEME_BASE_PATH = <?php
$scriptName = str_replace('\\', '/', $_SERVER['SCRIPT_NAME'] ?? '');
if ($scriptName && strpos($scriptName, '/themes/') !== false) {
$basePath = rtrim(dirname($scriptName), '/');
} else {
$basePath = '/themes/default';
}
echo json_encode($basePath);
?>;
// 加载 Banner 轮播图
function loadBanners() {
@@ -660,21 +705,39 @@ function stripHtml($html) {
return API_BASE_URL + (imagePath.startsWith('/') ? imagePath : '/' + imagePath);
}
// 加载友情链接
function loadFriendlinks() {
// 加载首页数据
function loadHomeData() {
const container = document.getElementById('friendlink-container');
if (!container) return;
fetch(API_BASE_URL + '/friendlinks')
fetch(API_BASE_URL + '/homeData')
.then(res => res.json())
.then(result => {
if (result.code !== 200 || !result.data || result.data.length === 0) {
if (result.code !== 200 || !result.data || !result.data.links || result.data.links.length === 0) {
container.innerHTML = '<div class="col-12 text-center"><p>暂无友情链接</p></div>';
return;
}
// 更新站点信息
if (result.data.normal) {
const n = result.data.normal;
if (n.sitename) document.title = n.sitename;
if (n.ico) {
const favicon = document.querySelector('link[rel="icon"]');
if (favicon) {
favicon.href = API_BASE_URL + (n.ico.startsWith('/') ? n.ico : '/' + n.ico);
} else {
const newFavicon = document.createElement('link');
newFavicon.rel = 'icon';
newFavicon.href = API_BASE_URL + (n.ico.startsWith('/') ? n.ico : '/' + n.ico);
newFavicon.type = 'image/x-icon';
document.head.appendChild(newFavicon);
}
}
}
let html = '';
result.data.forEach((item) => {
result.data.links.forEach((item) => {
const logoUrl = item.link_logo ? (item.link_logo.startsWith('http') ? item.link_logo : API_BASE_URL + item.link_logo) : '';
const linkName = item.link_name || '';
const linkUrl = item.link_url || '#';
@@ -697,13 +760,15 @@ function stripHtml($html) {
});
}
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
// 加载 Banner 轮播图
loadBanners();
// 加载友情链接
loadFriendlinks();
// 加载首页数据
loadHomeData();
// 加载新闻数据
const container = document.getElementById('news-container');
@@ -718,9 +783,16 @@ function stripHtml($html) {
return;
}
const newsList = result.list;
const showCount = 8; // 初始显示数量
const hasMore = newsList.length > showCount;
let html = '';
result.list.forEach((item, i) => {
// 只显示前 showCount 个新闻
const displayNews = hasMore ? newsList.slice(0, showCount) : newsList;
displayNews.forEach((item, i) => {
const title = item.title || '无标题';
let desc = item.summary || item.description || '';
// 去除 HTML 标签后截取
@@ -736,6 +808,7 @@ function stripHtml($html) {
'<div class="news-thumb-placeholder">暂无图片</div>';
html += '<div class="col-lg-3 col-md-6 mb-4">' +
'<a href="/news/article_detail.php?id=' + item.id + '" target="_blank" class="news-item-link">' +
'<div class="news-card wow fadeInUp" data-wow-delay=".2s">' +
'<div class="news-thumb-wrap">' +
thumbHtml +
@@ -745,9 +818,17 @@ function stripHtml($html) {
'<p class="news-desc">' + desc + '</p>' +
'</div>' +
'</div>' +
'</a>' +
'</div>';
});
// 如果有更多新闻,添加查看更多按钮
if (hasMore) {
html += '<div class="col-12 text-center mt-4">' +
'<a href="/news" class="btn btn-primary">查看更多</a>' +
'</div>';
}
container.innerHTML = html;
})
.catch(err => {
@@ -759,6 +840,14 @@ function stripHtml($html) {
<!-- Banner 轮播图样式 -->
<style>
.desc {
color: #fff;
}
.logo img {
width: 300px;
}
.banner-swiper {
width: 100%;
}