index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view>
  3. <!-- 未登录态 — 发现页/引流内容,直接内嵌,不跳转 -->
  4. <view v-if="!currentRole" class="discover-container">
  5. <!-- 品牌头部 -->
  6. <view class="brand-header">
  7. <image class="brand-logo" src="/static/logo.png" mode="aspectFit" />
  8. <view class="brand-text-wrap">
  9. <text class="brand-title">浠艾福</text>
  10. <text class="brand-subtitle">家庭健康成长俱乐部</text>
  11. </view>
  12. </view>
  13. <!-- 五行沙盘预览 -->
  14. <wuxing-sandbox mode="preview" badgeText="登录查看完整报告" @point-click="handleLogin" />
  15. <!-- 活动/商品推荐 -->
  16. <view class="recommend-section">
  17. <view class="section-header">
  18. <text class="section-title">🔥 热门推荐</text>
  19. <text class="section-more" @click="goShop">查看更多 ›</text>
  20. </view>
  21. <scroll-view scroll-x enable-flex show-scrollbar="false" class="type-filter-scroll">
  22. <view
  23. v-for="item in typeList"
  24. :key="item.value"
  25. :class="['filter-chip', currentType === item.value ? 'active' : '']"
  26. @click="onTypeChange(item.value)"
  27. >
  28. {{ item.label }}
  29. </view>
  30. </scroll-view>
  31. <view v-if="loading" class="loading-state">
  32. <text class="loading-text">加载中...</text>
  33. </view>
  34. <view v-else-if="products.length === 0" class="empty-state">
  35. <text class="empty-text">暂无商品,去商城看看吧</text>
  36. </view>
  37. <view v-else class="product-grid">
  38. <view
  39. v-for="item in products"
  40. :key="item.id"
  41. class="product-card"
  42. @click="goDetail(item.id)"
  43. >
  44. <image class="product-cover" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
  45. <view class="product-info">
  46. <text class="product-name">{{ item.name }}</text>
  47. <view class="product-price-row">
  48. <text class="product-price">¥{{ item.price }}</text>
  49. <text v-if="item.memberPrice" class="product-member">会员¥{{ item.memberPrice }}</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 为何选择浠艾福 -->
  56. <view class="why-section">
  57. <view class="section-header">
  58. <text class="section-title">💡 为什么选择浠艾福</text>
  59. </view>
  60. <view class="feature-grid">
  61. <view class="feature-item">
  62. <text class="feature-icon">🎯</text>
  63. <text class="feature-title">科学评估</text>
  64. <text class="feature-desc">DAN少儿核心素养评估体系</text>
  65. </view>
  66. <view class="feature-item">
  67. <text class="feature-icon">🏆</text>
  68. <text class="feature-title">积分激励</text>
  69. <text class="feature-desc">完成任务得积分,兑换心愿</text>
  70. </view>
  71. <view class="feature-item">
  72. <text class="feature-icon">👨‍👩‍👧‍👦</text>
  73. <text class="feature-title">家庭参与</text>
  74. <text class="feature-desc">全家一起见证成长每一步</text>
  75. </view>
  76. <view class="feature-item">
  77. <text class="feature-icon">🌟</text>
  78. <text class="feature-title">专业规划</text>
  79. <text class="feature-desc">成长规划师一对一指导</text>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 底部登录按钮 -->
  84. <view class="login-footer">
  85. <button class="login-btn" @click="handleLogin">登录 / 注册</button>
  86. <text class="login-footer-text">登录即表示同意《用户协议》和《隐私政策》</text>
  87. </view>
  88. <!-- 底部占位 -->
  89. <view style="height: 120rpx;"></view>
  90. <!-- 未登录态自定义底栏(仅 首页/行动) -->
  91. <bottom-nav v-if="!currentRole" current="index" />
  92. </view>
  93. <!-- 登录态 — 按角色渲染 -->
  94. <template v-else>
  95. <parent-index v-if="currentRole === 'parent'" />
  96. <child-index v-else-if="currentRole === 'child'" />
  97. <teacher-index v-else-if="currentRole === 'teacher'" />
  98. <view v-else class="loading-container">
  99. <text>加载中...</text>
  100. </view>
  101. </template>
  102. </view>
  103. </template>
  104. <script>
  105. import ParentIndex from './parent-index.vue'
  106. import ChildIndex from './child-index.vue'
  107. import TeacherIndex from '../teacher/index.vue'
  108. import WuxingSandbox from '../../components/wuxing-sandbox.vue'
  109. import BottomNav from '../../components/bottom-nav.vue'
  110. import { acceptParentInvite, productList } from '../../utils/api.js'
  111. export default {
  112. components: {
  113. ParentIndex,
  114. ChildIndex,
  115. TeacherIndex,
  116. WuxingSandbox,
  117. BottomNav
  118. },
  119. data() {
  120. return {
  121. currentRole: '',
  122. typeList: [
  123. { label: '全部', value: '' },
  124. { label: '活动', value: 'activity' },
  125. { label: '课程', value: 'course' },
  126. { label: '实物', value: 'physical' },
  127. { label: '数字', value: 'digital' },
  128. { label: '服务', value: 'service' }
  129. ],
  130. currentType: '',
  131. products: [],
  132. loading: false
  133. }
  134. },
  135. onLoad(options) {
  136. if (!this.isLoggedIn()) {
  137. this.currentRole = ''
  138. setTimeout(() => { uni.hideTabBar() }, 100)
  139. return
  140. }
  141. this.syncRoleAndTabBar()
  142. // 检查是否有邀请码参数
  143. if (options.inviteCode && options.type === 'parent_invite') {
  144. this.handleParentInvite(options.inviteCode)
  145. } else {
  146. // 检查是否有存储的邀请码(登录后返回)
  147. const storedCode = uni.getStorageSync('inviteCode')
  148. const storedType = uni.getStorageSync('inviteType')
  149. if (storedCode && storedType === 'parent_invite') {
  150. this.handleParentInvite(storedCode)
  151. // 清除存储
  152. uni.removeStorageSync('inviteCode')
  153. uni.removeStorageSync('inviteType')
  154. }
  155. }
  156. },
  157. onShow() {
  158. if (!this.isLoggedIn()) {
  159. this.currentRole = ''
  160. setTimeout(() => { uni.hideTabBar() }, 100)
  161. return
  162. }
  163. this.syncRoleAndTabBar()
  164. setTimeout(() => { uni.showTabBar() }, 100)
  165. },
  166. methods: {
  167. isLoggedIn() {
  168. return !!uni.getStorageSync('token')
  169. },
  170. normalizeCurrentRole() {
  171. const role = uni.getStorageSync('role') || 'parent'
  172. const currentRole = uni.getStorageSync('currentRole')
  173. if (!currentRole) {
  174. return role
  175. }
  176. // 非规划师账号不允许落到规划师首页
  177. if (currentRole === 'teacher' && role !== 'teacher') {
  178. return role
  179. }
  180. // 只有家长账号允许切换到孩子视角
  181. if (currentRole === 'child' && role !== 'parent') {
  182. return role
  183. }
  184. return currentRole
  185. },
  186. syncTabBarText(role) {
  187. const secondText = role === 'teacher' ? '家庭管理' : '任务'
  188. const thirdText = role === 'teacher' ? '消息' : '心愿单'
  189. uni.setTabBarItem({ index: 1, text: secondText })
  190. uni.setTabBarItem({ index: 2, text: thirdText })
  191. },
  192. syncRoleAndTabBar() {
  193. this.currentRole = this.normalizeCurrentRole()
  194. uni.setStorageSync('currentRole', this.currentRole)
  195. this.syncTabBarText(this.currentRole)
  196. },
  197. // ===== 发现页 / 未登录态方法 =====
  198. loadProducts() {
  199. this.loading = true
  200. const params = { page: 1, size: 10 }
  201. if (this.currentType) {
  202. params.productType = this.currentType
  203. }
  204. productList(params).then(res => {
  205. this.loading = false
  206. if (res.code === 200 && res.data) {
  207. this.products = res.data.records || []
  208. }
  209. }).catch(() => {
  210. this.loading = false
  211. })
  212. },
  213. onTypeChange(value) {
  214. this.currentType = value
  215. this.loadProducts()
  216. },
  217. goShop() {
  218. uni.navigateTo({ url: '/pages/shop/index' })
  219. },
  220. goDetail(id) {
  221. uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
  222. },
  223. handleLogin() {
  224. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/index/index') })
  225. },
  226. async handleParentInvite(code) {
  227. // 延迟显示,等待登录完成
  228. setTimeout(async () => {
  229. const hasToken = uni.getStorageSync('token')
  230. if (!hasToken) {
  231. // 未登录,先去登录
  232. uni.reLaunch({
  233. url: '/pages/login/login?inviteCode=' + code
  234. })
  235. return
  236. }
  237. // 已登录,显示确认框
  238. uni.showModal({
  239. title: '加入家庭',
  240. content: '您已被邀请加入家庭,是否接受?',
  241. success: async (res) => {
  242. if (res.confirm) {
  243. try {
  244. uni.showLoading({ title: '加入中...' })
  245. const result = await acceptParentInvite(code)
  246. uni.hideLoading()
  247. if (result.code === 200) {
  248. const { familyId, role, token } = result.data
  249. uni.setStorageSync('familyId', familyId)
  250. uni.setStorageSync('role', role)
  251. uni.setStorageSync('token', token)
  252. uni.showToast({ title: '加入成功', icon: 'success' })
  253. // 刷新页面
  254. setTimeout(() => {
  255. uni.reLaunch({ url: '/pages/index/index' })
  256. }, 1500)
  257. }
  258. } catch (e) {
  259. uni.hideLoading()
  260. uni.showToast({ title: e.message || '加入失败', icon: 'none' })
  261. }
  262. }
  263. }
  264. })
  265. }, 500)
  266. }
  267. }
  268. }
  269. </script>
  270. <style>
  271. .discover-container {
  272. min-height: 100vh;
  273. background: #f5f7fa;
  274. padding-bottom: 100rpx;
  275. }
  276. /* ===== 品牌头部 ===== */
  277. .brand-header {
  278. display: flex;
  279. flex-direction: row;
  280. align-items: center;
  281. padding: 20rpx 30rpx 12rpx;
  282. background: linear-gradient(180deg, #EBF2FA 0%, #f5f9fc 100%);
  283. }
  284. .brand-logo {
  285. width: 64rpx;
  286. height: 64rpx;
  287. border-radius: 14rpx;
  288. flex-shrink: 0;
  289. }
  290. .brand-text-wrap {
  291. display: flex;
  292. flex-direction: column;
  293. margin-left: 14rpx;
  294. }
  295. .brand-title {
  296. font-size: 32rpx;
  297. font-weight: bold;
  298. color: #2C5282;
  299. letter-spacing: 4rpx;
  300. line-height: 1.2;
  301. }
  302. .brand-subtitle {
  303. font-size: 20rpx;
  304. color: #5B9BD5;
  305. margin-top: 2rpx;
  306. line-height: 1.2;
  307. }
  308. /* ===== 推荐 ===== */
  309. .recommend-section {
  310. margin: 20rpx 30rpx;
  311. }
  312. .section-header {
  313. display: flex;
  314. justify-content: space-between;
  315. align-items: center;
  316. margin-bottom: 20rpx;
  317. }
  318. .section-title {
  319. font-size: 30rpx;
  320. font-weight: bold;
  321. color: #333;
  322. }
  323. .section-more {
  324. font-size: 24rpx;
  325. color: #5B9BD5;
  326. }
  327. .type-filter-scroll {
  328. white-space: nowrap;
  329. margin-bottom: 20rpx;
  330. }
  331. .filter-chip {
  332. display: inline-block;
  333. padding: 8rpx 24rpx;
  334. font-size: 24rpx;
  335. color: #666;
  336. background: #f0f0f0;
  337. border-radius: 30rpx;
  338. margin-right: 16rpx;
  339. }
  340. .filter-chip.active {
  341. background: #5B9BD5;
  342. color: #fff;
  343. }
  344. .loading-state,
  345. .empty-state {
  346. display: flex;
  347. justify-content: center;
  348. padding: 60rpx 0;
  349. }
  350. .loading-text,
  351. .empty-text {
  352. font-size: 26rpx;
  353. color: #999;
  354. }
  355. .product-grid {
  356. display: flex;
  357. flex-wrap: wrap;
  358. justify-content: space-between;
  359. }
  360. .product-card {
  361. width: 48%;
  362. background: #fff;
  363. border-radius: 16rpx;
  364. overflow: hidden;
  365. margin-bottom: 20rpx;
  366. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  367. }
  368. .product-cover {
  369. width: 100%;
  370. height: 200rpx;
  371. background: #f0f0f0;
  372. }
  373. .product-info {
  374. padding: 14rpx;
  375. }
  376. .product-name {
  377. display: block;
  378. font-size: 26rpx;
  379. color: #333;
  380. margin-bottom: 10rpx;
  381. overflow: hidden;
  382. text-overflow: ellipsis;
  383. white-space: nowrap;
  384. }
  385. .product-price-row {
  386. display: flex;
  387. align-items: baseline;
  388. }
  389. .product-price {
  390. font-size: 28rpx;
  391. color: #5B9BD5;
  392. font-weight: bold;
  393. margin-right: 10rpx;
  394. }
  395. .product-member {
  396. font-size: 20rpx;
  397. color: #999;
  398. }
  399. /* ===== 为何选择 ===== */
  400. .why-section {
  401. margin: 30rpx;
  402. }
  403. .feature-grid {
  404. display: flex;
  405. flex-direction: row;
  406. flex-wrap: wrap;
  407. justify-content: space-between;
  408. }
  409. .feature-item {
  410. width: calc(50% - 10rpx);
  411. box-sizing: border-box;
  412. background: #fff;
  413. border-radius: 20rpx;
  414. padding: 24rpx;
  415. margin-bottom: 20rpx;
  416. display: flex;
  417. flex-direction: column;
  418. align-items: center;
  419. text-align: center;
  420. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  421. }
  422. .feature-icon {
  423. font-size: 48rpx;
  424. margin-bottom: 10rpx;
  425. }
  426. .feature-title {
  427. font-size: 24rpx;
  428. font-weight: bold;
  429. color: #333;
  430. margin-bottom: 6rpx;
  431. }
  432. .feature-desc {
  433. font-size: 20rpx;
  434. color: #999;
  435. }
  436. /* ===== 底部登录 ===== */
  437. .login-footer {
  438. margin: 40rpx 30rpx;
  439. display: flex;
  440. flex-direction: column;
  441. align-items: center;
  442. }
  443. .login-btn {
  444. width: 100%;
  445. height: 88rpx;
  446. line-height: 88rpx;
  447. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  448. color: #fff;
  449. font-size: 32rpx;
  450. font-weight: bold;
  451. border-radius: 44rpx;
  452. text-align: center;
  453. border: none;
  454. }
  455. .login-btn::after {
  456. border: none;
  457. }
  458. .login-footer-text {
  459. font-size: 20rpx;
  460. color: #bbb;
  461. margin-top: 16rpx;
  462. }
  463. /* ===== 加载占位 ===== */
  464. .loading-container {
  465. display: flex;
  466. justify-content: center;
  467. align-items: center;
  468. height: 100vh;
  469. }
  470. </style>