功能:新增微信小程序界面

This commit is contained in:
xiaowang
2026-04-01 15:18:35 +08:00
parent bb2d8c4410
commit 7fa67d0511
92 changed files with 7463 additions and 0 deletions
+223
View File
@@ -0,0 +1,223 @@
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const { buildProductCards } = require('../../utils/product')
const { resolveImageList } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
const productApi = require('../../api/product')
const shopApi = require('../../api/shop')
const userApi = require('../../api/user')
Page({
data: {
initialized: false,
loading: false,
isLoggedIn: false,
userInfo: null,
greeting: '欢迎来到 Yumi Nail',
displayName: '先看看门店和作品',
searchKeyword: '',
bannerImages: [],
featuredItems: [],
popularSource: [],
popularItems: [],
popularPage: 1,
pageSize: 6,
hasMore: false
},
onLoad() {
this.loadHomeData()
},
onShow() {
this.syncUserState()
if (this.data.initialized && this.data.isLoggedIn) {
this.loadUserProfile()
}
},
async onPullDownRefresh() {
await this.loadHomeData()
wx.stopPullDownRefresh()
},
onReachBottom() {
if (!this.data.hasMore) {
return
}
const nextPage = this.data.popularPage + 1
const nextItems = this.data.popularSource.slice(0, nextPage * this.data.pageSize)
this.setData({
popularPage: nextPage,
popularItems: nextItems,
hasMore: nextItems.length < this.data.popularSource.length
})
},
syncUserState() {
const app = getApp()
const userInfo = auth.getStoredUserInfo()
const isLoggedIn = auth.isLoggedIn()
if (app) {
app.globalData.userInfo = userInfo
app.globalData.isLoggedIn = isLoggedIn
}
this.setData({
isLoggedIn,
userInfo,
greeting: isLoggedIn ? '欢迎回来' : '游客模式',
displayName: isLoggedIn
? ((userInfo && userInfo.nickname) || 'Yumi 用户')
: '先逛逛喜欢的款式和门店'
})
},
async loadUserProfile() {
if (!auth.isLoggedIn()) {
this.syncUserState()
return
}
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
this.syncUserState()
} catch (error) {}
},
async loadHomeData() {
this.setData({ loading: true })
this.syncUserState()
try {
await Promise.all([
this.loadUserProfile(),
this.loadBannerImages(),
this.loadFeaturedProducts(),
this.loadPopularProducts()
])
this.setData({
initialized: true
})
} catch (error) {
wx.showToast({
title: error.message || '首页加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
async loadBannerImages() {
const shops = await shopApi.getPublicShops()
const list = Array.isArray(shops) ? shops : []
const banners = []
for (let index = 0; index < list.length; index += 1) {
const shop = list[index]
const imageIds = shop.coverImageFileId || shop.imageFileIds
const urls = await resolveImageList(imageIds, DEFAULT_SHOP_IMAGE)
if (urls[0]) {
banners.push({
id: `${shop.id}-${index}`,
shopId: shop.id,
shopName: shop.shopName,
businessHours: shop.businessHours || '欢迎到店体验',
imageUrl: urls[0]
})
}
}
this.setData({
bannerImages: banners.slice(0, 6)
})
},
async loadFeaturedProducts() {
let products = await productApi.getProductsByTag('精选')
if (!Array.isArray(products) || !products.length) {
products = await productApi.getAllProducts()
}
const cards = await buildProductCards((products || []).slice(0, 6))
this.setData({
featuredItems: cards
})
},
async loadPopularProducts() {
let products = await productApi.getProductsByTag('热门')
if (!Array.isArray(products) || !products.length) {
products = await productApi.getAllProducts()
}
const cards = await buildProductCards(products || [])
const initialItems = cards.slice(0, this.data.pageSize)
this.setData({
popularSource: cards,
popularItems: initialItems,
popularPage: 1,
hasMore: initialItems.length < cards.length
})
},
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
})
},
handleSearchConfirm() {
navigation.openProducts({
keyword: this.data.searchKeyword.trim()
})
},
handleBannerTap(event) {
const shopId = event.currentTarget.dataset.shopId
if (!shopId) {
return
}
navigation.navigate('/pages/shop-detail/index', {
id: shopId,
returnTo: navigation.getCurrentPageUrl()
})
},
handleProfileTap() {
if (this.data.isLoggedIn) {
navigation.switchTab('/pages/profile/index')
return
}
navigation.openAuth()
},
handleProductSelect(event) {
const product = event.detail || {}
if (!product.id) {
return
}
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
handleSeeAllFeatured() {
navigation.openProducts({
tag: '精选'
})
},
handleSeeAllPopular() {
navigation.openProducts({
tag: '热门'
})
}
})
+7
View File
@@ -0,0 +1,7 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"product-card": "/components/product-card/product-card"
},
"enablePullDownRefresh": true
}
+137
View File
@@ -0,0 +1,137 @@
<view class="home-page-root">
<navigation-bar title="Yumi Nail" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
<scroll-view class="home-scroll" scroll-y enable-flex enhanced show-scrollbar="false">
<view class="page-shell home-page">
<view class="page-content">
<view class="page-hero home-hero">
<text class="hero-kicker">{{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}}</text>
<text class="hero-title">{{displayName}}</text>
<text class="hero-desc">先看门店氛围,再挑喜欢的作品,最后一站式完成收藏、加购和预约。</text>
<view class="hero-action-row">
<view class="hero-action primary" bindtap="handleProfileTap">{{isLoggedIn ? '进入个人中心' : '立即登录'}}</view>
<view class="hero-action secondary" bindtap="handleSeeAllPopular">看看热门作品</view>
</view>
<view class="search-box">
<input
class="search-input"
placeholder="搜索作品、风格或门店"
placeholder-class="field-placeholder"
value="{{searchKeyword}}"
bindinput="handleSearchInput"
bindconfirm="handleSearchConfirm"
confirm-type="search"
/>
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
</view>
<view class="summary-strip">
<view class="summary-metric">
<text class="summary-label">门店橱窗</text>
<text class="summary-value">{{bannerImages.length ? bannerImages.length : 0}} 家</text>
<text class="summary-note">先看环境,再决定去哪家</text>
</view>
<view class="summary-metric">
<text class="summary-label">精选作品</text>
<text class="summary-value">{{featuredItems.length ? featuredItems.length : 0}} 款</text>
<text class="summary-note">适合快速找到灵感</text>
</view>
<view class="summary-metric">
<text class="summary-label">热门推荐</text>
<text class="summary-value">{{popularItems.length ? popularItems.length : 0}} 条</text>
<text class="summary-note">当前最受欢迎的预约款式</text>
</view>
</view>
<view wx:if="{{!isLoggedIn}}" class="guest-tip">
登录后可同步收藏、购物车和预约记录,切换设备也不会丢。
</view>
</view>
<view class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">门店氛围</text>
<text class="section-title">先看看线下环境</text>
<text class="section-subtitle">轮播展示门店图片和营业时间,帮助你快速判断想去的店。</text>
</view>
</view>
<view wx:if="{{bannerImages.length}}" class="banner-box page-card">
<swiper class="banner-swiper" indicator-dots autoplay circular interval="3200">
<swiper-item wx:for="{{bannerImages}}" wx:key="id">
<view class="banner-item" data-shop-id="{{item.shopId}}" bindtap="handleBannerTap">
<image class="banner-image" src="{{item.imageUrl}}" mode="aspectFill"></image>
<view class="banner-mask">
<view class="banner-badge">门店实拍</view>
<view class="banner-title">{{item.shopName}}</view>
<view class="banner-desc">{{item.businessHours}}</view>
</view>
</view>
</swiper-item>
</swiper>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">门店内容正在补充中</text>
<text class="empty-desc">可以先浏览精选作品,稍后再回来查看门店环境展示。</text>
</view>
</view>
<view class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">快速入门</text>
<text class="section-title">精选作品</text>
<text class="section-subtitle">适合先快速逛一圈的热门款式,向右滑动查看更多。</text>
</view>
<view class="section-link" bindtap="handleSeeAllFeatured">查看全部</view>
</view>
<view wx:if="{{featuredItems.length}}" class="featured-panel">
<scroll-view class="featured-scroll" scroll-x enable-flex>
<view class="featured-list">
<view wx:for="{{featuredItems}}" wx:key="id" class="featured-card">
<product-card item="{{item}}" bindselect="handleProductSelect"></product-card>
</view>
</view>
</scroll-view>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">精选作品正在整理中</text>
<text class="empty-desc">等门店补齐款式后,这里会优先展示最值得先看的内容。</text>
</view>
</view>
<view class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">热门预约</text>
<text class="section-title">最近大家都在看</text>
<text class="section-subtitle">结合点赞和收藏热度展示当前最受欢迎的款式。</text>
</view>
<view class="section-link" bindtap="handleSeeAllPopular">查看全部</view>
</view>
<view wx:if="{{popularItems.length}}" class="popular-grid">
<view wx:for="{{popularItems}}" wx:key="id" class="popular-card">
<product-card item="{{item}}" show-stats="{{true}}" bindselect="handleProductSelect"></product-card>
</view>
</view>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载首页内容</text>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">还没有热门作品</text>
<text class="empty-desc">当前门店还在补充作品数据,稍后再回来看看。</text>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
+150
View File
@@ -0,0 +1,150 @@
.home-page-root {
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
.home-scroll {
flex: 1;
min-height: 0;
}
.home-page {
min-height: 100%;
background:
radial-gradient(circle at top right, rgba(255, 196, 214, 0.4), transparent 36%),
linear-gradient(180deg, #fff7f8 0%, #fffdfb 100%);
}
.home-hero {
background:
radial-gradient(circle at top right, rgba(255, 186, 207, 0.5), transparent 36%),
linear-gradient(145deg, #fffdfd 0%, #fff2f6 52%, #ffe8ef 100%);
}
.search-box {
display: flex;
align-items: center;
gap: 16rpx;
margin-top: 30rpx;
padding: 10rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.92);
}
.search-input {
flex: 1;
height: 72rpx;
padding: 0 24rpx;
font-size: 28rpx;
color: #2d2430;
}
.search-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 150rpx;
height: 72rpx;
border-radius: 999rpx;
background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%);
color: #ffffff;
font-size: 26rpx;
font-weight: 700;
}
.guest-tip {
margin-top: 24rpx;
padding: 20rpx 24rpx;
border-radius: 22rpx;
background: rgba(255, 255, 255, 0.85);
color: #8d7a84;
font-size: 24rpx;
line-height: 1.7;
}
.banner-box {
overflow: hidden;
border-radius: 34rpx;
}
.banner-swiper,
.banner-item {
width: 100%;
height: 396rpx;
}
.banner-item {
position: relative;
}
.banner-image {
width: 100%;
height: 100%;
}
.banner-mask {
position: absolute;
left: 24rpx;
right: 24rpx;
bottom: 24rpx;
padding: 22rpx 24rpx;
border-radius: 24rpx;
background: rgba(255, 255, 255, 0.9);
}
.banner-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 8rpx 18rpx;
border-radius: 999rpx;
background: #fce8ef;
color: #c6597d;
font-size: 22rpx;
font-weight: 700;
}
.banner-title {
margin-top: 14rpx;
font-size: 34rpx;
font-weight: 700;
color: #2d2430;
}
.banner-desc {
margin-top: 8rpx;
font-size: 24rpx;
color: #8d7a84;
}
.featured-panel {
padding: 2rpx 0 4rpx;
}
.featured-scroll {
width: 100%;
white-space: nowrap;
}
.featured-list {
display: inline-flex;
gap: 18rpx;
padding: 4rpx 2rpx 12rpx;
}
.featured-card {
width: 332rpx;
}
.popular-grid {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
padding-top: 2rpx;
}
.popular-card {
width: calc(50% - 9rpx);
}