better-staridc-MNBT
1<template>
2 <div class="home">
3 <!-- Hero 轮播(guanwang1 风格:全屏背景图 + 居中文案 + 双向箭头 + 指示器) -->
4 <section class="hero">
5 <div class="carousel">
6 <div class="carousel-inner">
7 <div
8 v-for="(item, index) in carouselItems"
9 :key="index"
10 class="carousel-item"
11 :class="{ active: index === currentSlide }"
12 >
13 <div class="carousel-bg" :style="{ 'background-image': 'url(' + item.image + ')' }"></div>
14 <div class="carousel-caption">
15 <h2 class="carousel-title">{{ item.title }}</h2>
16 <p class="carousel-subtitle">{{ item.subtitle }}</p>
17 <p class="carousel-description">{{ item.description }}</p>
18 <div class="hero-buttons">
19 <router-link :to="productsUrl" class="btn btn-primary">了解产品</router-link>
20 <router-link :to="aboutUrl" class="btn btn-secondary">关于我们</router-link>
21 </div>
22 </div>
23 </div>
24 </div>
25 <div class="carousel-controls">
26 <button class="carousel-btn prev" @click="prevSlide">‹</button>
27 <button class="carousel-btn next" @click="nextSlide">›</button>
28 </div>
29 <div class="carousel-indicators">
30 <span
31 v-for="(item, index) in carouselItems"
32 :key="index"
33 :class="{ active: index === currentSlide }"
34 @click="goToSlide(index)"
35 ></span>
36 </div>
37 </div>
38 </section>
39
40 <!-- 公告 -->
41 <section v-if="boot.showNotice && boot.notice" class="notice-strip">
42 <div class="container">
43 <div class="hd-notice">
44 <i class="mdi mdi-bullhorn"></i>
45 <div class="txt">{{ boot.notice }}</div>
46 </div>
47 </div>
48 </section>
49
50 <!-- 套餐区(hosting_shop 插件) -->
51 <section v-if="boot.showPlans !== false && boot.hasShop" class="plans-section section">
52 <div class="container">
53 <div class="section-header">
54 <h2 class="section-title">选择适合的套餐</h2>
55 <p class="section-subtitle">按需选择,随时升级。价格透明,开通简单。</p>
56 </div>
57 <div v-if="plans.length === 0" class="hd-empty">
58 <i class="mdi mdi-package-variant"></i>
59 <p>暂无可购买套餐,请联系管理员</p>
60 </div>
61 <div v-else class="hd-plans">
62 <div
63 v-for="(plan, i) in plans.slice(0, 3)"
64 :key="plan.id"
65 class="hd-plan-card"
66 :class="{ pop: i === 1 }"
67 >
68 <div class="hd-plan-top">
69 <span v-if="i === 1" class="hd-plan-chip">推荐</span>
70 <h3>{{ plan.name }}</h3>
71 <div class="hd-plan-desc">{{ plan.desc || '适合中小站点快速上线' }}</div>
72 </div>
73 <div class="hd-plan-body">
74 <div class="hd-plan-price">
75 <div class="num">{{ plan.price }}</div>
76 <div class="sub">含基础资源与自动开通</div>
77 </div>
78 <ul class="hd-plan-feats">
79 <li v-for="feat in plan.feats" :key="feat"><span class="ok">✓</span>{{ feat }}</li>
80 <li v-if="!plan.feats || plan.feats.length === 0"><span class="ok">✓</span>高性能节点资源</li>
81 <li v-if="!plan.feats || plan.feats.length === 0"><span class="ok">✓</span>一键开通部署</li>
82 </ul>
83 <t-button block theme="primary" size="large" @click="goBuy('shop')">立即购买</t-button>
84 </div>
85 </div>
86 </div>
87 </div>
88 </section>
89
90 <!-- Docker 售卖区(docker_shop 插件) -->
91 <section v-if="boot.hasDocker" class="plans-section section">
92 <div class="container">
93 <div class="section-header">
94 <h2 class="section-title">Docker 容器套餐</h2>
95 <p class="section-subtitle">轻量级容器服务,秒级部署,按需扩展</p>
96 <router-link to="/docker-shop" class="more-news">查看全部 Docker 套餐 ›</router-link>
97 </div>
98 <div v-if="dockerPlans.length === 0" class="hd-empty">
99 <i class="mdi mdi-docker"></i>
100 <p>暂无可购买的 Docker 套餐,请联系管理员</p>
101 </div>
102 <div v-else class="hd-plans">
103 <div
104 v-for="(plan, i) in dockerPlans.slice(0, 3)"
105 :key="plan.id"
106 class="hd-plan-card"
107 :class="{ pop: i === 1 }"
108 >
109 <div class="hd-plan-top">
110 <span v-if="i === 1" class="hd-plan-chip">推荐</span>
111 <h3>{{ plan.name }}</h3>
112 <div class="hd-plan-desc">{{ plan.description || 'Docker 容器服务,即买即用' }}</div>
113 </div>
114 <div class="hd-plan-body">
115 <div class="hd-plan-price">
116 <div class="num">{{ dockerPriceText(plan) }}</div>
117 <div class="sub">{{ plan.node?.name ? '开通节点:' + plan.node.name : '自动分配节点' }}</div>
118 </div>
119 <ul class="hd-plan-feats">
120 <li><span class="ok">✓</span>CPU {{ dockerSpecText(plan.base_plan, 'cpu') }}</li>
121 <li><span class="ok">✓</span>内存 {{ dockerSpecText(plan.base_plan, 'mem') }}</li>
122 <li><span class="ok">✓</span>磁盘 {{ dockerSpecText(plan.base_plan, 'disk') }}</li>
123 <li><span class="ok">✓</span>代理 {{ dockerSpecText(plan.base_plan, 'proxy') }}</li>
124 </ul>
125 <t-button block theme="primary" size="large" @click="goBuy('docker-shop')">立即购买</t-button>
126 </div>
127 </div>
128 </div>
129 </div>
130 </section>
131
132 <!-- 云服务器区(zjmfmanager_reserve 插件) -->
133 <section v-if="boot.hasZjmf" class="plans-section section">
134 <div class="container">
135 <div class="section-header">
136 <h2 class="section-title">云服务器</h2>
137 <p class="section-subtitle">魔方财务代理分销,即买即用,支付完成自动开通</p>
138 <a :href="accountUrl('zjmf-shop')" class="more-news">查看全部云服务器 ›</a>
139 </div>
140 <div v-if="zjmfProducts.length === 0" class="hd-empty">
141 <i class="mdi mdi-cloud-outline"></i>
142 <p>暂无可购买的云服务器,请联系管理员</p>
143 </div>
144 <div v-else class="hd-plans">
145 <div
146 v-for="(p, i) in zjmfProducts.slice(0, 3)"
147 :key="p.id"
148 class="hd-plan-card"
149 :class="{ pop: i === 1 }"
150 >
151 <div class="hd-plan-top">
152 <span v-if="i === 1" class="hd-plan-chip">推荐</span>
153 <h3>{{ p.name }}</h3>
154 <div class="hd-plan-desc" v-if="p.description" v-html="p.description"></div>
155 <div class="hd-plan-desc" v-else>云服务器服务,即买即用</div>
156 </div>
157 <div class="hd-plan-body">
158 <div class="hd-plan-price">
159 <div class="num">{{ zjmfPriceText(p) }}</div>
160 <div class="sub">即买即用</div>
161 </div>
162 <t-button block theme="primary" size="large" @click="goZjmfBuy">立即购买</t-button>
163 </div>
164 </div>
165 </div>
166 </div>
167 </section>
168
169 <!-- 核心优势 -->
170 <section class="features section">
171 <div class="container">
172 <div class="section-header">
173 <h2 class="section-title">核心优势</h2>
174 <p class="section-subtitle">我们专注于为客户提供稳定可靠的虚拟主机与云计算服务</p>
175 </div>
176 <div class="features-grid">
177 <div v-for="f in features" :key="f.title" class="feature-card">
178 <div class="feature-icon"><i :class="'mdi ' + f.icon"></i></div>
179 <h3>{{ f.title }}</h3>
180 <p>{{ f.desc }}</p>
181 </div>
182 </div>
183 </div>
184 </section>
185
186 <!-- 新闻预览(official_site 插件) -->
187 <section v-if="boot.hasSite" class="news-preview section">
188 <div class="container">
189 <div class="section-header">
190 <h2 class="section-title">新闻资讯</h2>
191 <p class="section-subtitle">了解平台最新动态与发展历程</p>
192 <router-link to="/site/news" class="more-news">查看更多新闻 ›</router-link>
193 </div>
194 <div v-if="newsList.length === 0" class="hd-empty">
195 <i class="mdi mdi-newspaper-variant-outline"></i>
196 <p>暂无资讯</p>
197 </div>
198 <div v-else class="news-grid">
199 <div v-for="n in newsList" :key="n.id" class="news-card" @click="$router.push('/site/news/' + n.id)">
200 <div class="news-date">{{ formatDate(n.created_at) }}</div>
201 <h3 class="news-title">{{ n.title }}</h3>
202 <p class="news-excerpt">{{ excerpt(n.content) }}</p>
203 <span class="read-more">阅读更多</span>
204 </div>
205 </div>
206 </div>
207 </section>
208
209 <!-- 客户评价 -->
210 <section class="testimonials section">
211 <div class="container">
212 <div class="section-header">
213 <h2 class="section-title">客户评价</h2>
214 <p class="section-subtitle">听听我们的客户怎么说</p>
215 </div>
216 <div class="testimonials-grid">
217 <div v-for="t in testimonials" :key="t.name" class="testimonial-card">
218 <div class="testimonial-header">
219 <div class="client-avatar">
220 <div class="avatar-placeholder">{{ t.name.slice(0, 1) }}</div>
221 </div>
222 <div class="client-details">
223 <div class="client-name">{{ t.name }}</div>
224 <div class="client-title">{{ t.role }}</div>
225 </div>
226 </div>
227 <p class="testimonial-text">"{{ t.text }}"</p>
228 <i class="mdi mdi-format-quote-close quote-icon"></i>
229 </div>
230 </div>
231 </div>
232 </section>
233
234 <!-- 底部 CTA -->
235 <section v-if="!authState.loggedIn && boot.hasUser" class="section">
236 <div class="container">
237 <div class="hd-cta">
238 <h3>准备好开始了吗?</h3>
239 <p>注册账户,立即体验高性能虚拟主机。</p>
240 <router-link to="/register" class="btn btn-light">免费注册</router-link>
241 </div>
242 </div>
243 </section>
244
245 <!-- 扩展区块 -->
246 <section v-for="block in boot.blocks" :key="block.id" class="section">
247 <div class="container">
248 <div v-if="block.title" class="section-header">
249 <h2 class="section-title">{{ block.title }}</h2>
250 </div>
251 <div v-html="block.html"></div>
252 </div>
253 </section>
254 </div>
255</template>
256
257<script setup>
258import { ref, computed, onMounted, onUnmounted } from 'vue'
259import authState from '@/home/store/auth'
260import { getSiteNews } from '@/home/api/site'
261import { getDockerPlans } from '@/home/api/docker'
262import { getZjmfProducts } from '@/home/api/zjmf'
263import { formatDate } from '@/home/utils/format'
264import { accountUrl } from '@/home/utils/account'
265import bg1 from '@/shared/assets/bg1.jpg'
266import bg2 from '@/shared/assets/bg2.jpg'
267import bg3 from '@/shared/assets/bg3.jpg'
268
269const boot = window.__TD_BOOT__ || {}
270
271const plans = computed(() => boot.plans || [])
272
273// Docker 售卖套餐(客户端加载,docker_shop 插件)
274const dockerPlans = ref([])
275function dockerPriceText(plan) {
276 if (!plan.prices) return '免费'
277 let min = 0
278 for (const cents of Object.values(plan.prices)) {
279 if (cents > 0 && (min === 0 || cents < min)) min = cents
280 }
281 return min > 0 ? '¥' + (min / 100).toFixed(2) + ' 起' : '免费'
282}
283function dockerSpecText(base, key) {
284 if (!base) return '—'
285 if (key === 'cpu') {
286 const v = Number(base.cpu_max)
287 return v > 0 ? v + ' 核' : '—'
288 }
289 if (key === 'mem' || key === 'disk') {
290 const mb = Number(key === 'mem' ? base.mem_max : base.disk_max)
291 if (!mb) return '—'
292 return mb >= 1024 ? mb / 1024 + ' GB' : mb + ' MB'
293 }
294 if (key === 'proxy') {
295 const v = Number(base.proxy_max)
296 return v > 0 ? v + ' 个' : '不限'
297 }
298 return '—'
299}
300
301// 云服务器(zjmfmanager_reserve 插件)
302const zjmfProducts = ref([])
303/** 最低价展示:有价显示 ¥x.xx 起,无价显示 咨询价格 */
304function zjmfPriceText(p) {
305 const cents = Number(p.min_price_cents || 0)
306 return cents > 0 ? '¥' + (cents / 100).toFixed(2) + ' 起' : '咨询价格'
307}
308/** 立即购买:与主机/Docker 一致,跳转 account SPA 商城 */
309function goZjmfBuy() {
310 if (!authState.loggedIn) {
311 window.location.href = accountUrl()
312 return
313 }
314 window.location.href = accountUrl('zjmf-shop')
315}
316
317// hero 按钮路由:优先官网产品页,无官网插件则回退套餐/登录
318const productsUrl = computed(() =>
319 boot.hasSite ? '/site/products' : (boot.hasShop ? '/shop' : '/')
320)
321// 已登录用户点“关于我们”时直接进入用户中心(account SPA)
322const aboutUrl = computed(() =>
323 boot.hasSite ? '/about'
324 : (boot.hasUser ? (authState.loggedIn ? accountUrl('profile') : '/login') : '/')
325)
326
327// 购买统一跳转 account SPA 商城(hosting_shop → shop,docker_shop → docker-shop)
328function goBuy(module) {
329 if (!authState.loggedIn) {
330 window.location.href = accountUrl()
331 return
332 }
333 window.location.href = accountUrl(module)
334}
335
336// 三张轮播文案:优先使用后台「主页内容」配置,未配置时回退内置默认
337const defaultBannerTexts = [
338 {
339 title: '高性能虚拟主机',
340 subtitle: '即买即用 · 自动开通 · 秒级部署',
341 description: '全 SSD 存储与 BGP 多线接入,支付完成后自动开通,分钟级上线,为企业和开发者打造稳定高效的主机平台。',
342 },
343 {
344 title: '专业团队支持',
345 subtitle: '7×24 小时全天候技术支持',
346 description: '经验丰富的运维与开发团队随时待命,从建站到运维全程护航,让您专注于业务本身。',
347 },
348 {
349 title: '企业级安全防护',
350 subtitle: 'DDoS 清洗 · WAF 规则 · 每日备份',
351 description: '内置安全防护体系与自动备份能力,SSL 一键签发,全面保障您的数据与业务安全。',
352 },
353]
354const bannerTexts =
355 boot.bannerTexts && boot.bannerTexts.length >= 3
356 ? boot.bannerTexts
357 : defaultBannerTexts
358
359const carouselItems = [
360 { ...bannerTexts[0], image: bg1 },
361 { ...bannerTexts[1], image: bg2 },
362 { ...bannerTexts[2], image: bg3 },
363]
364
365const currentSlide = ref(0)
366let timer = null
367
368function nextSlide() {
369 currentSlide.value = (currentSlide.value + 1) % carouselItems.length
370}
371function prevSlide() {
372 currentSlide.value = (currentSlide.value - 1 + carouselItems.length) % carouselItems.length
373}
374function goToSlide(index) {
375 currentSlide.value = index
376}
377function startAutoPlay() {
378 stopAutoPlay()
379 timer = setInterval(nextSlide, 5000)
380}
381function stopAutoPlay() {
382 if (timer) {
383 clearInterval(timer)
384 timer = null
385 }
386}
387
388const features = [
389 { icon: 'mdi-shield-check', title: '稳定可靠', desc: '企业级硬件架构与 BGP 多线接入,SLA 99.9% 保障,网站始终在线。' },
390 { icon: 'mdi-rocket', title: '极速开通', desc: '支付成功自动开通主机,分钟级上线,无需等待人工处理。' },
391 { icon: 'mdi-headset', title: '专业服务', desc: '7×24 小时技术支持,从建站到运维全程护航,问题快速响应。' },
392]
393
394const newsList = ref([])
395
396function excerpt(html, len = 72) {
397 if (!html) return ''
398 const text = String(html).replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim()
399 return text.length > len ? text.slice(0, len) + '…' : text
400}
401
402const testimonials = [
403 { name: '张先生', role: '个人站长', text: '从下单到开通不到一分钟,面板操作也很顺手,续费两年了一直很稳定。' },
404 { name: '李女士', role: '电商创业者', text: '网站迁移过来后访问速度明显提升,客服响应很快,问题当天就解决了。' },
405 { name: '陈先生', role: '企业运维', text: '自动备份和 SSL 功能非常省心,售后工单处理专业,值得信赖。' },
406]
407
408onMounted(async () => {
409 startAutoPlay()
410 if (boot.hasSite) {
411 const res = await getSiteNews({ page: 1, perPage: 3 })
412 if (res.ok && res.data?.news) {
413 newsList.value = res.data.news
414 }
415 }
416 if (boot.hasDocker) {
417 const res = await getDockerPlans()
418 if (res.ok && res.data?.plans) {
419 dockerPlans.value = res.data.plans
420 }
421 }
422 if (boot.hasZjmf) {
423 const res = await getZjmfProducts()
424 if (res.ok && res.data?.list) {
425 zjmfProducts.value = res.data.list
426 }
427 }
428})
429onUnmounted(stopAutoPlay)
430</script>