index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <template>
  2. <view>
  3. <!-- 品牌启动页(冷启动时覆盖全屏) -->
  4. <view class="splash-overlay" v-if="showSplash">
  5. <view class="splash-content">
  6. <view class="splash-logo-mark">
  7. <text class="splash-logo-char">浠</text>
  8. </view>
  9. <text class="splash-brand-name">浠艾福</text>
  10. <!-- 五维图标行 -->
  11. <view class="splash-dims-row">
  12. <view
  13. v-for="(item, index) in splashDimList"
  14. :key="item.code"
  15. class="splash-dim-item"
  16. :style="'animation-delay:' + (0.8 + index * 0.25) + 's'"
  17. >
  18. <view class="splash-dim-circle" :style="'background:' + hexToRgba(item.color, 0.25)">
  19. <text class="splash-dim-icon">{{ item.icon }}</text>
  20. </view>
  21. <text class="splash-dim-label">{{ item.name }}</text>
  22. </view>
  23. </view>
  24. <text class="splash-tagline">给全家的一站式幸福提案</text>
  25. <view class="splash-loading">
  26. <view class="splash-dot splash-dot--1"></view>
  27. <view class="splash-dot splash-dot--2"></view>
  28. <view class="splash-dot splash-dot--3"></view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 未登录态 — 发现页/引流内容,直接内嵌,不跳转 -->
  33. <view v-if="!currentRole" class="discover-container">
  34. <!-- 品牌头部 -->
  35. <PageBanner theme="home"
  36. tagline="家庭健康成长俱乐部"
  37. quote="给全家的一站式幸福提案" />
  38. <!-- 五行沙盘预览 -->
  39. <wuxing-sandbox mode="preview" badgeText="登录查看完整报告" @point-click="handleLogin" />
  40. <!-- 活动/商品推荐 -->
  41. <view class="recommend-section">
  42. <view class="section-header">
  43. <text class="section-title">🔥 热门推荐</text>
  44. <text class="section-more" @click="goShop">查看更多 ›</text>
  45. </view>
  46. <scroll-view scroll-x enable-flex show-scrollbar="false" class="type-filter-scroll">
  47. <view
  48. v-for="item in typeList"
  49. :key="item.value"
  50. :class="['filter-chip', currentType === item.value ? 'active' : '']"
  51. @click="onTypeChange(item.value)"
  52. >
  53. {{ item.label }}
  54. </view>
  55. </scroll-view>
  56. <view v-if="loading" class="loading-state">
  57. <text class="loading-text">加载中...</text>
  58. </view>
  59. <view v-else-if="products.length === 0" class="empty-state">
  60. <text class="empty-text">暂无商品,去商城看看吧</text>
  61. </view>
  62. <view v-else class="product-grid">
  63. <view
  64. v-for="item in products"
  65. :key="item.id"
  66. class="product-card"
  67. @click="handleLogin()"
  68. >
  69. <image class="product-cover" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
  70. <view class="product-info">
  71. <text class="product-name">{{ item.name }}</text>
  72. <view class="product-price-row">
  73. <!-- 游客不显示价格 -->
  74. <text class="product-price-login">登录查看</text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- 五维全景幸福矩阵 -->
  81. <view class="why-section">
  82. <view class="section-header">
  83. <text class="section-title">🌏 五维全景幸福矩阵 — 给全家的一站式幸福提案</text>
  84. </view>
  85. <view class="dim-matrix">
  86. <view
  87. v-for="dim in dimList" :key="dim.code"
  88. class="dim-card"
  89. :style="'border-left:6rpx solid ' + dim.color"
  90. @click="handleLogin"
  91. >
  92. <view class="dim-icon-circle" :style="'background:' + dim.bgColor">
  93. <text class="dim-icon">{{ dim.icon }}</text>
  94. </view>
  95. <view class="dim-tag" :style="'color:' + dim.color + ';background:' + dim.bgColor">{{ dim.name }} · {{ dim.title }}</view>
  96. <text class="dim-desc">{{ dim.desc }}</text>
  97. </view>
  98. </view>
  99. <!-- 五维能量环装饰 -->
  100. <view class="dim-energy-row">
  101. <view
  102. v-for="c in energyDotColors" :key="c"
  103. class="energy-dot"
  104. :style="'background:' + c"
  105. ></view>
  106. </view>
  107. </view>
  108. <!-- 底部登录按钮 -->
  109. <view class="login-footer">
  110. <button class="login-btn" @click="handleLogin">登录 / 注册</button>
  111. <text class="login-footer-text">登录即表示同意《用户协议》和《隐私政策》</text>
  112. </view>
  113. <!-- 底部占位 -->
  114. <view style="height: 120rpx;"></view>
  115. </view>
  116. <!-- 登录态 — 按角色渲染(带淡入淡出过渡)-->
  117. <view v-else class="role-switch-wrapper">
  118. <transition name="fade" mode="out-in">
  119. <parent-index v-if="currentRole === 'parent'" key="parent" />
  120. <child-index v-else-if="currentRole === 'child'" key="child" />
  121. <!-- teacher-index 已废弃,教师功能折入 parent-index -->
  122. <view v-else class="loading-container" key="loading">
  123. <text>加载中...</text>
  124. </view>
  125. </transition>
  126. </view>
  127. </view>
  128. </template>
  129. <script>
  130. import ParentIndex from './parent-index.vue'
  131. import ChildIndex from './child-index.vue'
  132. // TeacherIndex 已废弃,教师功能折入 parent-index
  133. import PageBanner from '../../components/PageBanner.vue'
  134. import WuxingSandbox from '../../components/wuxing-sandbox.vue'
  135. import { acceptParentInvite, productList } from '../../utils/api.js'
  136. var DIMENSIONS = [
  137. { code: 'body', name: '身', icon: '🌏', color: '#8D6E63', bgColor: 'rgba(141,110,99,0.15)', title: '主动健康', desc: '用最适合的方法,从根源调理家人体质,畅享高质量长寿生活' },
  138. { code: 'mind', name: '心', icon: '🔥', color: '#FF6B35', bgColor: 'rgba(255,107,53,0.15)', title: '大爱传承', desc: '将长辈陪护升华为家族纽带,让家风温暖代代相传' },
  139. { code: 'wisdom', name: '智', icon: '⚡', color: '#FFD700', bgColor: 'rgba(255,215,0,0.15)', title: '赋能未来', desc: '专业测评与素质培养,开启孩子面向未来的大智慧' },
  140. { code: 'action', name: '行', icon: '🌿', color: '#4CAF50', bgColor: 'rgba(76,175,80,0.15)', title: '知行合一', desc: '在亲子户外与沙龙中,让健康生活方式真正知行合一' },
  141. { code: 'wealth', name: '富', icon: '💧', color: '#42A5F5', bgColor: 'rgba(66,165,245,0.15)', title: '利他创富', desc: '依托创客生态,在利他分享中实现家庭第二收入曲线' }
  142. ]
  143. export default {
  144. components: {
  145. ParentIndex,
  146. ChildIndex,
  147. PageBanner,
  148. WuxingSandbox
  149. },
  150. data() {
  151. return {
  152. currentRole: '',
  153. showSplash: false,
  154. typeList: [
  155. { label: '全部', value: '' },
  156. { label: '活动', value: 'activity' },
  157. { label: '课程', value: 'course' },
  158. { label: '实物', value: 'physical' },
  159. { label: '数字', value: 'digital' },
  160. { label: '服务', value: 'service' }
  161. ],
  162. currentType: '',
  163. products: [],
  164. loading: false
  165. }
  166. },
  167. onLoad(options) {
  168. // 冷启动检查:是否已展示品牌启动页
  169. if (!uni.getStorageSync('_splashReady') && !this.showSplash) {
  170. this.showSplash = true
  171. var self = this
  172. setTimeout(function() {
  173. self.showSplash = false
  174. uni.setStorageSync('_splashReady', true)
  175. // splash 结束后执行初始化
  176. self._doInit()
  177. }, 2500)
  178. return
  179. }
  180. this._doInit(options)
  181. },
  182. onShow() {
  183. if (this.showSplash) {
  184. return
  185. }
  186. this._doInit()
  187. },
  188. _doInit(options) {
  189. options = options || {}
  190. if (!this.isLoggedIn()) {
  191. this.currentRole = ''
  192. if (!this.showSplash) {
  193. this.loadProducts()
  194. }
  195. return
  196. }
  197. this.syncRoleAndTabBar()
  198. if (options.inviteCode && options.type === 'parent_invite') {
  199. this.handleParentInvite(options.inviteCode)
  200. } else {
  201. var storedCode = uni.getStorageSync('inviteCode')
  202. var storedType = uni.getStorageSync('inviteType')
  203. if (storedCode && storedType === 'parent_invite') {
  204. this.handleParentInvite(storedCode)
  205. uni.removeStorageSync('inviteCode')
  206. uni.removeStorageSync('inviteType')
  207. }
  208. }
  209. },
  210. methods: {
  211. isLoggedIn() {
  212. return !!uni.getStorageSync('token')
  213. },
  214. normalizeCurrentRole() {
  215. const role = uni.getStorageSync('role') || 'parent'
  216. const currentRole = uni.getStorageSync('currentRole')
  217. if (!currentRole) {
  218. return role
  219. }
  220. // 非规划师账号不允许落到规划师首页
  221. if (currentRole === 'teacher' && role !== 'teacher') {
  222. return role
  223. }
  224. // 只有家长账号允许切换到孩子视角
  225. if (currentRole === 'child' && role !== 'parent') {
  226. return role
  227. }
  228. return currentRole
  229. },
  230. syncRoleAndTabBar() {
  231. this.currentRole = this.normalizeCurrentRole()
  232. uni.setStorageSync('currentRole', this.currentRole)
  233. },
  234. // ===== 发现页 / 未登录态方法 =====
  235. loadProducts() {
  236. this.loading = true
  237. var params = { page: 1, size: 10 }
  238. if (this.currentType) {
  239. params.productType = this.currentType
  240. }
  241. productList(params).then(function(res) {
  242. this.loading = false
  243. if (res.code === 200 && res.data) {
  244. this.products = res.data.records || []
  245. }
  246. }.bind(this)).catch(function() {
  247. this.loading = false
  248. }.bind(this))
  249. },
  250. onTypeChange(value) {
  251. this.currentType = value
  252. this.loadProducts()
  253. },
  254. goShop() {
  255. uni.navigateTo({ url: '/pages/action/index' })
  256. },
  257. goDetail(id) {
  258. uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
  259. },
  260. handleLogin() {
  261. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/index/index') })
  262. },
  263. async handleParentInvite(code) {
  264. // 延迟显示,等待登录完成
  265. setTimeout(async () => {
  266. const hasToken = uni.getStorageSync('token')
  267. if (!hasToken) {
  268. // 未登录,先去登录
  269. uni.reLaunch({
  270. url: '/pages/login/login?inviteCode=' + code
  271. })
  272. return
  273. }
  274. // 已登录,显示确认框
  275. uni.showModal({
  276. title: '加入家庭',
  277. content: '您已被邀请加入家庭,是否接受?',
  278. success: async (res) => {
  279. if (res.confirm) {
  280. try {
  281. uni.showLoading({ title: '加入中...' })
  282. const result = await acceptParentInvite(code)
  283. uni.hideLoading()
  284. if (result.code === 200) {
  285. const { familyId, role, token } = result.data
  286. uni.setStorageSync('familyId', familyId)
  287. uni.setStorageSync('role', role)
  288. uni.setStorageSync('token', token)
  289. uni.showToast({ title: '加入成功', icon: 'success' })
  290. // 刷新页面
  291. setTimeout(() => {
  292. uni.reLaunch({ url: '/pages/index/index' })
  293. }, 1500)
  294. }
  295. } catch (e) {
  296. uni.hideLoading()
  297. uni.showToast({ title: e.message || '加入失败', icon: 'none' })
  298. }
  299. }
  300. }
  301. })
  302. }, 500)
  303. },
  304. hexToRgba: function(hex, alpha) {
  305. var r = parseInt(hex.slice(1, 3), 16)
  306. var g = parseInt(hex.slice(3, 5), 16)
  307. var b = parseInt(hex.slice(5, 7), 16)
  308. return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
  309. }
  310. },
  311. computed: {
  312. dimList: function() {
  313. return DIMENSIONS
  314. },
  315. splashDimList: function() {
  316. return DIMENSIONS
  317. },
  318. energyDotColors: function() {
  319. return ['#8D6E63', '#FF6B35', '#FFD700', '#4CAF50', '#42A5F5']
  320. }
  321. }
  322. }
  323. </script>
  324. <style>
  325. .discover-container {
  326. min-height: 100vh;
  327. background: #f5f7fa;
  328. padding-bottom: 100rpx;
  329. }
  330. /* ===== 推荐 ===== */
  331. .recommend-section {
  332. margin: 20rpx 30rpx;
  333. }
  334. .section-header {
  335. display: flex;
  336. justify-content: space-between;
  337. align-items: center;
  338. margin-bottom: 20rpx;
  339. }
  340. .section-title {
  341. font-size: 30rpx;
  342. font-weight: bold;
  343. color: #333;
  344. }
  345. .section-more {
  346. font-size: 24rpx;
  347. color: #5B9BD5;
  348. }
  349. .type-filter-scroll {
  350. white-space: nowrap;
  351. margin-bottom: 20rpx;
  352. }
  353. .filter-chip {
  354. display: inline-block;
  355. padding: 8rpx 24rpx;
  356. font-size: 24rpx;
  357. color: #666;
  358. background: #f0f0f0;
  359. border-radius: 30rpx;
  360. margin-right: 16rpx;
  361. }
  362. .filter-chip.active {
  363. background: #5B9BD5;
  364. color: #fff;
  365. }
  366. .loading-state,
  367. .empty-state {
  368. display: flex;
  369. justify-content: center;
  370. padding: 60rpx 0;
  371. }
  372. .loading-text,
  373. .empty-text {
  374. font-size: 26rpx;
  375. color: #999;
  376. }
  377. .product-grid {
  378. display: flex;
  379. flex-wrap: wrap;
  380. justify-content: space-between;
  381. }
  382. .product-card {
  383. width: 48%;
  384. background: #fff;
  385. border-radius: 16rpx;
  386. overflow: hidden;
  387. margin-bottom: 20rpx;
  388. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  389. }
  390. .product-cover {
  391. width: 100%;
  392. height: 200rpx;
  393. background: #f0f0f0;
  394. }
  395. .product-info {
  396. padding: 14rpx;
  397. }
  398. .product-name {
  399. display: block;
  400. font-size: 26rpx;
  401. color: #333;
  402. margin-bottom: 10rpx;
  403. overflow: hidden;
  404. text-overflow: ellipsis;
  405. white-space: nowrap;
  406. }
  407. .product-price-row {
  408. display: flex;
  409. align-items: baseline;
  410. }
  411. .product-price {
  412. font-size: 28rpx;
  413. color: #5B9BD5;
  414. font-weight: bold;
  415. margin-right: 10rpx;
  416. }
  417. .product-price-login {
  418. font-size: 24rpx;
  419. color: #999;
  420. }
  421. .product-member {
  422. font-size: 20rpx;
  423. color: #999;
  424. }
  425. /* ===== 五维全景幸福矩阵 ===== */
  426. .why-section {
  427. margin: 30rpx;
  428. }
  429. .dim-matrix {
  430. display: flex;
  431. flex-wrap: wrap;
  432. gap: 20rpx;
  433. justify-content: center;
  434. }
  435. .dim-card {
  436. width: calc(33.33% - 14rpx);
  437. box-sizing: border-box;
  438. background: #fff;
  439. border-radius: 20rpx;
  440. padding: 28rpx 16rpx 24rpx;
  441. display: flex;
  442. flex-direction: column;
  443. align-items: center;
  444. text-align: center;
  445. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  446. transition: transform 0.2s ease, box-shadow 0.2s ease;
  447. position: relative;
  448. overflow: hidden;
  449. }
  450. .dim-card:active {
  451. transform: scale(0.96);
  452. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.1);
  453. }
  454. .dim-icon-circle {
  455. width: 72rpx;
  456. height: 72rpx;
  457. border-radius: 50%;
  458. display: flex;
  459. align-items: center;
  460. justify-content: center;
  461. margin-bottom: 14rpx;
  462. flex-shrink: 0;
  463. }
  464. .dim-icon {
  465. font-size: 36rpx;
  466. line-height: 1;
  467. }
  468. .dim-tag {
  469. font-size: 22rpx;
  470. font-weight: 600;
  471. padding: 4rpx 14rpx;
  472. border-radius: 20rpx;
  473. margin-bottom: 10rpx;
  474. max-width: 100%;
  475. overflow: hidden;
  476. text-overflow: ellipsis;
  477. white-space: nowrap;
  478. }
  479. .dim-desc {
  480. font-size: 20rpx;
  481. color: #888;
  482. line-height: 1.5;
  483. display: -webkit-box;
  484. -webkit-line-clamp: 2;
  485. -webkit-box-orient: vertical;
  486. overflow: hidden;
  487. }
  488. /* 五维能量环 */
  489. .dim-energy-row {
  490. display: flex;
  491. justify-content: center;
  492. gap: 12rpx;
  493. margin-top: 24rpx;
  494. opacity: 0.5;
  495. }
  496. .energy-dot {
  497. width: 10rpx;
  498. height: 10rpx;
  499. border-radius: 50%;
  500. }
  501. /* ===== 底部登录 ===== */
  502. .login-footer {
  503. margin: 40rpx 30rpx;
  504. display: flex;
  505. flex-direction: column;
  506. align-items: center;
  507. }
  508. .login-btn {
  509. width: 100%;
  510. height: 88rpx;
  511. line-height: 88rpx;
  512. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  513. color: #fff;
  514. font-size: 32rpx;
  515. font-weight: bold;
  516. border-radius: 44rpx;
  517. text-align: center;
  518. border: none;
  519. }
  520. .login-btn::after {
  521. border: none;
  522. }
  523. .login-footer-text {
  524. font-size: 20rpx;
  525. color: #bbb;
  526. margin-top: 16rpx;
  527. }
  528. /* ===== 加载占位 ===== */
  529. .loading-container {
  530. display: flex;
  531. justify-content: center;
  532. align-items: center;
  533. height: 100vh;
  534. }
  535. /* ===== 品牌启动页覆盖 ===== */
  536. .splash-overlay {
  537. position: fixed;
  538. top: 0;
  539. left: 0;
  540. right: 0;
  541. bottom: 0;
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. background: linear-gradient(160deg, #FFF7ED 0%, #F97316 100%);
  546. z-index: 9999;
  547. }
  548. .splash-content {
  549. display: flex;
  550. flex-direction: column;
  551. align-items: center;
  552. opacity: 0;
  553. animation: splash-fade-in 0.8s ease forwards;
  554. }
  555. @keyframes splash-fade-in {
  556. from { opacity: 0; transform: translateY(20rpx); }
  557. to { opacity: 1; transform: translateY(0); }
  558. }
  559. .splash-logo-mark {
  560. width: 144rpx;
  561. height: 144rpx;
  562. border-radius: 36rpx;
  563. background: rgba(255,255,255,0.3);
  564. display: flex;
  565. align-items: center;
  566. justify-content: center;
  567. margin-bottom: 24rpx;
  568. }
  569. .splash-logo-char {
  570. font-size: 72rpx;
  571. font-weight: 700;
  572. color: #FFFFFF;
  573. line-height: 1;
  574. }
  575. .splash-brand-name {
  576. font-size: 56rpx;
  577. font-weight: 700;
  578. color: #FFFFFF;
  579. letter-spacing: 8rpx;
  580. margin-bottom: 12rpx;
  581. text-shadow: 0 2rpx 12rpx rgba(0,0,0,0.1);
  582. }
  583. .splash-tagline {
  584. font-size: 28rpx;
  585. color: rgba(255,255,255,0.85);
  586. letter-spacing: 4rpx;
  587. font-weight: 400;
  588. }
  589. .splash-loading {
  590. position: absolute;
  591. bottom: 120rpx;
  592. left: 0;
  593. right: 0;
  594. display: flex;
  595. justify-content: center;
  596. align-items: center;
  597. gap: 12rpx;
  598. }
  599. .splash-dot {
  600. width: 14rpx;
  601. height: 14rpx;
  602. border-radius: 50%;
  603. background: rgba(255,255,255,0.6);
  604. animation: splash-dot-bounce 1.4s ease-in-out infinite both;
  605. }
  606. .splash-dot--1 { animation-delay: -0.32s; }
  607. .splash-dot--2 { animation-delay: -0.16s; }
  608. .splash-dot--3 { animation-delay: 0s; }
  609. @keyframes splash-dot-bounce {
  610. 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  611. 40% { transform: scale(1); opacity: 1; }
  612. }
  613. /* ===== 五维图标行 ===== */
  614. .splash-dims-row {
  615. display: flex;
  616. flex-direction: row;
  617. align-items: center;
  618. justify-content: center;
  619. gap: 16rpx;
  620. margin: 16rpx 0 20rpx;
  621. }
  622. .splash-dim-item {
  623. display: flex;
  624. flex-direction: column;
  625. align-items: center;
  626. gap: 6rpx;
  627. opacity: 0;
  628. transform: translateY(20rpx);
  629. animation: splash-dim-enter 0.4s ease forwards;
  630. }
  631. .splash-dim-circle {
  632. width: 64rpx;
  633. height: 64rpx;
  634. border-radius: 50%;
  635. display: flex;
  636. align-items: center;
  637. justify-content: center;
  638. }
  639. .splash-dim-icon {
  640. font-size: 28rpx;
  641. line-height: 1;
  642. color: #FFFFFF;
  643. }
  644. .splash-dim-label {
  645. font-size: 18rpx;
  646. color: rgba(255, 255, 255, 0.7);
  647. line-height: 1;
  648. }
  649. @keyframes splash-dim-enter {
  650. from { opacity: 0; transform: translateY(20rpx); }
  651. to { opacity: 1; transform: translateY(0); }
  652. }
  653. /* ===== 角色切换淡入淡出 ===== */
  654. .role-switch-wrapper {
  655. width: 100%;
  656. min-height: 100vh;
  657. }
  658. .fade-enter-active,
  659. .fade-leave-active {
  660. transition: opacity 0.3s ease;
  661. }
  662. .fade-enter,
  663. .fade-leave-to {
  664. opacity: 0;
  665. }
  666. </style>