| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- <template>
- <view>
- <!-- Tabbar 切换过渡页 -->
- <tab-transition v-if="showTabTransition" dimCode="action" />
- <!-- 未登录态 — 发现页/引流内容,直接内嵌,不跳转 -->
- <view v-if="!currentRole" class="discover-container">
- <!-- 品牌头部 -->
- <PageBanner theme="home"
- tagline="家庭健康成长俱乐部"
- quote="给全家的一站式幸福提案" />
- <!-- 五行沙盘预览 -->
- <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="handleLogin()"
- >
- <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-login">登录查看</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 五维全景幸福矩阵 -->
- <view class="why-section">
- <view class="section-header">
- <text class="section-title">🌏 五维全景幸福矩阵 — 给全家的一站式幸福提案</text>
- </view>
- <view class="dim-matrix">
- <view
- v-for="dim in dimList" :key="dim.code"
- class="dim-card"
- :style="'border-left:6rpx solid ' + dim.color"
- @click="handleLogin"
- >
- <view class="dim-icon-circle" :style="'background:' + dim.bgColor">
- <text class="dim-icon">{{ dim.icon }}</text>
- </view>
- <view class="dim-tag" :style="'color:' + dim.color + ';background:' + dim.bgColor">{{ dim.name }} · {{ dim.title }}</view>
- <text class="dim-desc">{{ dim.desc }}</text>
- </view>
- </view>
- <!-- 五维能量环装饰 -->
- <view class="dim-energy-row">
- <view
- v-for="c in energyDotColors" :key="c"
- class="energy-dot"
- :style="'background:' + c"
- ></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>
- </view>
- <!-- 登录态 — 按角色渲染(带淡入淡出过渡)-->
- <view v-else class="role-switch-wrapper">
- <transition name="fade" mode="out-in">
- <parent-index v-if="currentRole === 'parent'" key="parent" />
- <child-index v-else-if="currentRole === 'child'" key="child" />
- <!-- teacher-index 已废弃,教师功能折入 parent-index -->
- <view v-else class="loading-container" key="loading">
- <text>加载中...</text>
- </view>
- </transition>
- </view>
- </view>
- </template>
- <script>
- import ParentIndex from './parent-index.vue'
- import ChildIndex from './child-index.vue'
- // TeacherIndex 已废弃,教师功能折入 parent-index
- import PageBanner from '../../components/PageBanner.vue'
- import WuxingSandbox from '../../components/wuxing-sandbox.vue'
- import TabTransition from '../../components/tab-transition.vue'
- import { acceptParentInvite, productList } from '../../utils/api.js'
- var DIMENSIONS = [
- { code: 'body', name: '身', icon: '🌏', color: '#8D6E63', bgColor: 'rgba(141,110,99,0.15)', title: '主动健康', desc: '用最适合的方法,从根源调理家人体质,畅享高质量长寿生活' },
- { code: 'mind', name: '心', icon: '🔥', color: '#FF6B35', bgColor: 'rgba(255,107,53,0.15)', title: '大爱传承', desc: '将长辈陪护升华为家族纽带,让家风温暖代代相传' },
- { code: 'wisdom', name: '智', icon: '⚡', color: '#FFD700', bgColor: 'rgba(255,215,0,0.15)', title: '赋能未来', desc: '专业测评与素质培养,开启孩子面向未来的大智慧' },
- { code: 'action', name: '行', icon: '🌿', color: '#4CAF50', bgColor: 'rgba(76,175,80,0.15)', title: '知行合一', desc: '在亲子户外与沙龙中,让健康生活方式真正知行合一' },
- { code: 'wealth', name: '富', icon: '💧', color: '#42A5F5', bgColor: 'rgba(66,165,245,0.15)', title: '利他创富', desc: '依托创客生态,在利他分享中实现家庭第二收入曲线' }
- ]
- export default {
- components: {
- ParentIndex,
- ChildIndex,
- PageBanner,
- WuxingSandbox,
- TabTransition
- },
- data() {
- // 从 storage 预取登录态/角色,确保首次渲染即正确(WeChat 渲染层/逻辑层分离架构下 onLoad 执行前已渲染)
- var _token = uni.getStorageSync('token')
- var _currentRole = ''
- if (_token) {
- _currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || ''
- }
- return {
- currentRole: _currentRole,
- showTabTransition: false,
- typeList: [
- { label: '全部', value: '' },
- { label: '活动', value: 'activity' },
- { label: '课程', value: 'course' },
- { label: '实物', value: 'physical' },
- { label: '数字', value: 'digital' },
- { label: '服务', value: 'service' }
- ],
- currentType: '',
- products: [],
- loading: false
- }
- },
- onLoad(options) {
- this._doInit(options)
- },
- onShow() {
- // Tabbar 切换过渡动画(最少停留 1 秒)
- this.showTabTransition = true
- var self = this
- setTimeout(function() {
- self.showTabTransition = false
- }, 1100)
- // 始终执行初始化,确保登录态变更后及时切换视图
- this._doInit()
- },
- methods: {
- _doInit(options) {
- options = options || {}
- if (!this.isLoggedIn()) {
- this.currentRole = ''
- this.loadProducts()
- return
- }
- this.syncRoleAndTabBar()
- if (options.inviteCode && options.type === 'parent_invite') {
- this.handleParentInvite(options.inviteCode)
- } else {
- var storedCode = uni.getStorageSync('inviteCode')
- var storedType = uni.getStorageSync('inviteType')
- if (storedCode && storedType === 'parent_invite') {
- this.handleParentInvite(storedCode)
- uni.removeStorageSync('inviteCode')
- uni.removeStorageSync('inviteType')
- }
- }
- },
- 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
- },
- syncRoleAndTabBar() {
- this.currentRole = this.normalizeCurrentRole()
- uni.setStorageSync('currentRole', this.currentRole)
- },
- // ===== 发现页 / 未登录态方法 =====
- loadProducts() {
- this.loading = true
- var params = { page: 1, size: 10 }
- if (this.currentType) {
- params.productType = this.currentType
- }
- productList(params).then(function(res) {
- this.loading = false
- if (res.code === 200 && res.data) {
- this.products = res.data.records || []
- }
- }.bind(this)).catch(function() {
- this.loading = false
- }.bind(this))
- },
- onTypeChange(value) {
- this.currentType = value
- this.loadProducts()
- },
- goShop() {
- uni.navigateTo({ url: '/pages/action/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)
- },
- },
- computed: {
- dimList: function() {
- return DIMENSIONS
- },
- energyDotColors: function() {
- return ['#8D6E63', '#FF6B35', '#FFD700', '#4CAF50', '#42A5F5']
- }
- }
- }
- </script>
- <style>
- .discover-container {
- min-height: 100vh;
- background: #f5f7fa;
- padding-bottom: 100rpx;
- }
- /* ===== 推荐 ===== */
- .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-price-login {
- font-size: 24rpx;
- color: #999;
- }
- .product-member {
- font-size: 20rpx;
- color: #999;
- }
- /* ===== 五维全景幸福矩阵 ===== */
- .why-section {
- margin: 30rpx;
- }
- .dim-matrix {
- display: flex;
- flex-wrap: wrap;
- gap: 20rpx;
- justify-content: center;
- }
- .dim-card {
- width: calc(33.33% - 14rpx);
- box-sizing: border-box;
- background: #fff;
- border-radius: 20rpx;
- padding: 28rpx 16rpx 24rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- text-align: center;
- box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
- transition: transform 0.2s ease, box-shadow 0.2s ease;
- position: relative;
- overflow: hidden;
- }
- .dim-card:active {
- transform: scale(0.96);
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);
- }
- .dim-icon-circle {
- width: 72rpx;
- height: 72rpx;
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-bottom: 14rpx;
- flex-shrink: 0;
- }
- .dim-icon {
- font-size: 36rpx;
- line-height: 1;
- }
- .dim-tag {
- font-size: 22rpx;
- font-weight: 600;
- padding: 4rpx 14rpx;
- border-radius: 20rpx;
- margin-bottom: 10rpx;
- max-width: 100%;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .dim-desc {
- font-size: 20rpx;
- color: #888;
- line-height: 1.5;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- overflow: hidden;
- }
- /* 五维能量环 */
- .dim-energy-row {
- display: flex;
- justify-content: center;
- gap: 12rpx;
- margin-top: 24rpx;
- opacity: 0.5;
- }
- .energy-dot {
- width: 10rpx;
- height: 10rpx;
- border-radius: 50%;
- }
- /* ===== 底部登录 ===== */
- .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;
- }
- /* ===== 角色切换淡入淡出 ===== */
- .role-switch-wrapper {
- width: 100%;
- min-height: 100vh;
- }
- .fade-enter-active,
- .fade-leave-active {
- transition: opacity 0.3s ease;
- }
- .fade-enter,
- .fade-leave-to {
- opacity: 0;
- }
- </style>
|