| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- <template>
- <view>
- <!-- 未登录态 — 发现页/引流内容,直接内嵌,不跳转 -->
- <view v-if="!currentRole" class="discover-container">
- <!-- 品牌头部 -->
- <view class="brand-header">
- <image class="brand-logo" src="/static/logo.png" mode="aspectFit" />
- <view class="brand-text-wrap">
- <text class="brand-title">浠艾福</text>
- <text class="brand-subtitle">家庭健康成长俱乐部</text>
- </view>
- </view>
- <!-- 五行沙盘预览 -->
- <wuxing-sandbox mode="preview" badgeText="登录查看完整报告" @point-click="handleLogin" />
- <!-- 活动/商品推荐 -->
- <view class="recommend-section">
- <view class="section-header">
- <text class="section-title">🔥 热门推荐</text>
- <text class="section-more" @click="goShop">查看更多 ›</text>
- </view>
- <scroll-view scroll-x enable-flex show-scrollbar="false" class="type-filter-scroll">
- <view
- v-for="item in typeList"
- :key="item.value"
- :class="['filter-chip', currentType === item.value ? 'active' : '']"
- @click="onTypeChange(item.value)"
- >
- {{ item.label }}
- </view>
- </scroll-view>
- <view v-if="loading" class="loading-state">
- <text class="loading-text">加载中...</text>
- </view>
- <view v-else-if="products.length === 0" class="empty-state">
- <text class="empty-text">暂无商品,去商城看看吧</text>
- </view>
- <view v-else class="product-grid">
- <view
- v-for="item in products"
- :key="item.id"
- class="product-card"
- @click="goDetail(item.id)"
- >
- <image class="product-cover" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
- <view class="product-info">
- <text class="product-name">{{ item.name }}</text>
- <view class="product-price-row">
- <text class="product-price">¥{{ item.price }}</text>
- <text v-if="item.memberPrice" class="product-member">会员¥{{ item.memberPrice }}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 为何选择浠艾福 -->
- <view class="why-section">
- <view class="section-header">
- <text class="section-title">💡 为什么选择浠艾福</text>
- </view>
- <view class="feature-grid">
- <view class="feature-item">
- <text class="feature-icon">🎯</text>
- <text class="feature-title">科学评估</text>
- <text class="feature-desc">DAN少儿核心素养评估体系</text>
- </view>
- <view class="feature-item">
- <text class="feature-icon">🏆</text>
- <text class="feature-title">积分激励</text>
- <text class="feature-desc">完成任务得积分,兑换心愿</text>
- </view>
- <view class="feature-item">
- <text class="feature-icon">👨👩👧👦</text>
- <text class="feature-title">家庭参与</text>
- <text class="feature-desc">全家一起见证成长每一步</text>
- </view>
- <view class="feature-item">
- <text class="feature-icon">🌟</text>
- <text class="feature-title">专业规划</text>
- <text class="feature-desc">成长规划师一对一指导</text>
- </view>
- </view>
- </view>
- <!-- 底部登录按钮 -->
- <view class="login-footer">
- <button class="login-btn" @click="handleLogin">登录 / 注册</button>
- <text class="login-footer-text">登录即表示同意《用户协议》和《隐私政策》</text>
- </view>
- <!-- 底部占位 -->
- <view style="height: 120rpx;"></view>
- <!-- 未登录态自定义底栏(仅 首页/行动) -->
- <bottom-nav v-if="!currentRole" current="index" />
- </view>
- <!-- 登录态 — 按角色渲染 -->
- <template v-else>
- <parent-index v-if="currentRole === 'parent'" />
- <child-index v-else-if="currentRole === 'child'" />
- <teacher-index v-else-if="currentRole === 'teacher'" />
- <view v-else class="loading-container">
- <text>加载中...</text>
- </view>
- </template>
- </view>
- </template>
- <script>
- import ParentIndex from './parent-index.vue'
- import ChildIndex from './child-index.vue'
- import TeacherIndex from '../teacher/index.vue'
- import WuxingSandbox from '../../components/wuxing-sandbox.vue'
- import BottomNav from '../../components/bottom-nav.vue'
- import { acceptParentInvite, productList } from '../../utils/api.js'
- export default {
- components: {
- ParentIndex,
- ChildIndex,
- TeacherIndex,
- WuxingSandbox,
- BottomNav
- },
- data() {
- return {
- currentRole: '',
- typeList: [
- { label: '全部', value: '' },
- { label: '活动', value: 'activity' },
- { label: '课程', value: 'course' },
- { label: '实物', value: 'physical' },
- { label: '数字', value: 'digital' },
- { label: '服务', value: 'service' }
- ],
- currentType: '',
- products: [],
- loading: false
- }
- },
- onLoad(options) {
- if (!this.isLoggedIn()) {
- this.currentRole = ''
- setTimeout(() => { uni.hideTabBar() }, 100)
- return
- }
- this.syncRoleAndTabBar()
- // 检查是否有邀请码参数
- if (options.inviteCode && options.type === 'parent_invite') {
- this.handleParentInvite(options.inviteCode)
- } else {
- // 检查是否有存储的邀请码(登录后返回)
- const storedCode = uni.getStorageSync('inviteCode')
- const storedType = uni.getStorageSync('inviteType')
- if (storedCode && storedType === 'parent_invite') {
- this.handleParentInvite(storedCode)
- // 清除存储
- uni.removeStorageSync('inviteCode')
- uni.removeStorageSync('inviteType')
- }
- }
- },
- onShow() {
- if (!this.isLoggedIn()) {
- this.currentRole = ''
- setTimeout(() => { uni.hideTabBar() }, 100)
- return
- }
- this.syncRoleAndTabBar()
- setTimeout(() => { uni.showTabBar() }, 100)
- },
- methods: {
- isLoggedIn() {
- return !!uni.getStorageSync('token')
- },
- normalizeCurrentRole() {
- const role = uni.getStorageSync('role') || 'parent'
- const currentRole = uni.getStorageSync('currentRole')
- if (!currentRole) {
- return role
- }
- // 非规划师账号不允许落到规划师首页
- if (currentRole === 'teacher' && role !== 'teacher') {
- return role
- }
- // 只有家长账号允许切换到孩子视角
- if (currentRole === 'child' && role !== 'parent') {
- return role
- }
- return currentRole
- },
- syncTabBarText(role) {
- const secondText = role === 'teacher' ? '家庭管理' : '任务'
- const thirdText = role === 'teacher' ? '消息' : '心愿单'
- uni.setTabBarItem({ index: 1, text: secondText })
- uni.setTabBarItem({ index: 2, text: thirdText })
- },
- syncRoleAndTabBar() {
- this.currentRole = this.normalizeCurrentRole()
- uni.setStorageSync('currentRole', this.currentRole)
- this.syncTabBarText(this.currentRole)
- },
- // ===== 发现页 / 未登录态方法 =====
- loadProducts() {
- this.loading = true
- const params = { page: 1, size: 10 }
- if (this.currentType) {
- params.productType = this.currentType
- }
- productList(params).then(res => {
- this.loading = false
- if (res.code === 200 && res.data) {
- this.products = res.data.records || []
- }
- }).catch(() => {
- this.loading = false
- })
- },
- onTypeChange(value) {
- this.currentType = value
- this.loadProducts()
- },
- goShop() {
- uni.navigateTo({ url: '/pages/shop/index' })
- },
- goDetail(id) {
- uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
- },
- handleLogin() {
- uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/index/index') })
- },
- async handleParentInvite(code) {
- // 延迟显示,等待登录完成
- setTimeout(async () => {
- const hasToken = uni.getStorageSync('token')
- if (!hasToken) {
- // 未登录,先去登录
- uni.reLaunch({
- url: '/pages/login/login?inviteCode=' + code
- })
- return
- }
- // 已登录,显示确认框
- uni.showModal({
- title: '加入家庭',
- content: '您已被邀请加入家庭,是否接受?',
- success: async (res) => {
- if (res.confirm) {
- try {
- uni.showLoading({ title: '加入中...' })
- const result = await acceptParentInvite(code)
- uni.hideLoading()
- if (result.code === 200) {
- const { familyId, role, token } = result.data
- uni.setStorageSync('familyId', familyId)
- uni.setStorageSync('role', role)
- uni.setStorageSync('token', token)
- uni.showToast({ title: '加入成功', icon: 'success' })
- // 刷新页面
- setTimeout(() => {
- uni.reLaunch({ url: '/pages/index/index' })
- }, 1500)
- }
- } catch (e) {
- uni.hideLoading()
- uni.showToast({ title: e.message || '加入失败', icon: 'none' })
- }
- }
- }
- })
- }, 500)
- }
- }
- }
- </script>
- <style>
- .discover-container {
- min-height: 100vh;
- background: #f5f7fa;
- padding-bottom: 100rpx;
- }
- /* ===== 品牌头部 ===== */
- .brand-header {
- display: flex;
- flex-direction: row;
- align-items: center;
- padding: 20rpx 30rpx 12rpx;
- background: linear-gradient(180deg, #EBF2FA 0%, #f5f9fc 100%);
- }
- .brand-logo {
- width: 64rpx;
- height: 64rpx;
- border-radius: 14rpx;
- flex-shrink: 0;
- }
- .brand-text-wrap {
- display: flex;
- flex-direction: column;
- margin-left: 14rpx;
- }
- .brand-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #2C5282;
- letter-spacing: 4rpx;
- line-height: 1.2;
- }
- .brand-subtitle {
- font-size: 20rpx;
- color: #5B9BD5;
- margin-top: 2rpx;
- line-height: 1.2;
- }
- /* ===== 推荐 ===== */
- .recommend-section {
- margin: 20rpx 30rpx;
- }
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- .section-more {
- font-size: 24rpx;
- color: #5B9BD5;
- }
- .type-filter-scroll {
- white-space: nowrap;
- margin-bottom: 20rpx;
- }
- .filter-chip {
- display: inline-block;
- padding: 8rpx 24rpx;
- font-size: 24rpx;
- color: #666;
- background: #f0f0f0;
- border-radius: 30rpx;
- margin-right: 16rpx;
- }
- .filter-chip.active {
- background: #5B9BD5;
- color: #fff;
- }
- .loading-state,
- .empty-state {
- display: flex;
- justify-content: center;
- padding: 60rpx 0;
- }
- .loading-text,
- .empty-text {
- font-size: 26rpx;
- color: #999;
- }
- .product-grid {
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- }
- .product-card {
- width: 48%;
- background: #fff;
- border-radius: 16rpx;
- overflow: hidden;
- margin-bottom: 20rpx;
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
- }
- .product-cover {
- width: 100%;
- height: 200rpx;
- background: #f0f0f0;
- }
- .product-info {
- padding: 14rpx;
- }
- .product-name {
- display: block;
- font-size: 26rpx;
- color: #333;
- margin-bottom: 10rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .product-price-row {
- display: flex;
- align-items: baseline;
- }
- .product-price {
- font-size: 28rpx;
- color: #5B9BD5;
- font-weight: bold;
- margin-right: 10rpx;
- }
- .product-member {
- font-size: 20rpx;
- color: #999;
- }
- /* ===== 为何选择 ===== */
- .why-section {
- margin: 30rpx;
- }
- .feature-grid {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- justify-content: space-between;
- }
- .feature-item {
- width: calc(50% - 10rpx);
- box-sizing: border-box;
- background: #fff;
- border-radius: 20rpx;
- padding: 24rpx;
- margin-bottom: 20rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- text-align: center;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .feature-icon {
- font-size: 48rpx;
- margin-bottom: 10rpx;
- }
- .feature-title {
- font-size: 24rpx;
- font-weight: bold;
- color: #333;
- margin-bottom: 6rpx;
- }
- .feature-desc {
- font-size: 20rpx;
- color: #999;
- }
- /* ===== 底部登录 ===== */
- .login-footer {
- margin: 40rpx 30rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .login-btn {
- width: 100%;
- height: 88rpx;
- line-height: 88rpx;
- background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
- color: #fff;
- font-size: 32rpx;
- font-weight: bold;
- border-radius: 44rpx;
- text-align: center;
- border: none;
- }
- .login-btn::after {
- border: none;
- }
- .login-footer-text {
- font-size: 20rpx;
- color: #bbb;
- margin-top: 16rpx;
- }
- /* ===== 加载占位 ===== */
- .loading-container {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- }
- </style>
|