index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view class="discover-container">
  3. <!-- 品牌头部 -->
  4. <view class="brand-header">
  5. <image class="brand-logo" src="/static/logo.png" mode="aspectFit" />
  6. <view class="brand-text-wrap">
  7. <text class="brand-title">浠艾福</text>
  8. <text class="brand-subtitle">家庭健康成长俱乐部</text>
  9. </view>
  10. </view>
  11. <!-- 五行沙盘预览 -->
  12. <wuxing-sandbox mode="preview" badgeText="登录查看完整报告" @point-click="handleLogin" />
  13. <!-- 活动/商品推荐 -->
  14. <view class="recommend-section">
  15. <view class="section-header">
  16. <text class="section-title">🔥 热门推荐</text>
  17. <text class="section-more" @click="goShop">查看更多 ›</text>
  18. </view>
  19. <scroll-view scroll-x enable-flex show-scrollbar="false" class="type-filter-scroll">
  20. <view
  21. v-for="item in typeList"
  22. :key="item.value"
  23. :class="['filter-chip', currentType === item.value ? 'active' : '']"
  24. @click="onTypeChange(item.value)"
  25. >
  26. {{ item.label }}
  27. </view>
  28. </scroll-view>
  29. <view v-if="loading" class="loading-state">
  30. <text class="loading-text">加载中...</text>
  31. </view>
  32. <view v-else-if="products.length === 0" class="empty-state">
  33. <text class="empty-text">暂无商品,去商城看看吧</text>
  34. </view>
  35. <view v-else class="product-grid">
  36. <view
  37. v-for="item in products"
  38. :key="item.id"
  39. class="product-card"
  40. @click="goDetail(item.id)"
  41. >
  42. <image class="product-cover" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
  43. <view class="product-info">
  44. <text class="product-name">{{ item.name }}</text>
  45. <view class="product-price-row">
  46. <text class="product-price">¥{{ item.price }}</text>
  47. <text v-if="item.memberPrice" class="product-member">会员¥{{ item.memberPrice }}</text>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 推荐文章(未登录可见) -->
  54. <view class="article-section">
  55. <view class="section-header">
  56. <text class="section-title">📖 成长文章</text>
  57. <text class="section-more" @click="goAllArticles">查看全部 ›</text>
  58. </view>
  59. <view class="article-list">
  60. <view v-for="(item, index) in featuredArticles" :key="item.id" class="article-card" @click="goArticleDetail(item.id)">
  61. <view class="article-cover" :style="{ background: coverGradients[index % coverGradients.length] }">
  62. <text class="article-cover-icon">{{ coverIcons[index % coverIcons.length] }}</text>
  63. </view>
  64. <view class="article-info">
  65. <text class="article-title">{{ item.title }}</text>
  66. <text class="article-desc">{{ item.summary || item.title }}</text>
  67. <text class="article-meta">{{ item.publishedAt ? item.publishedAt.slice(0, 10) : '' }} · {{ item.readTime || 3 }}分钟阅读</text>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 为何选择浠艾福 -->
  73. <view class="why-section">
  74. <view class="section-header">
  75. <text class="section-title">💡 为什么选择浠艾福</text>
  76. </view>
  77. <view class="feature-grid">
  78. <view class="feature-item">
  79. <text class="feature-icon">🎯</text>
  80. <text class="feature-title">科学评估</text>
  81. <text class="feature-desc">DAN少儿核心素养评估体系</text>
  82. </view>
  83. <view class="feature-item">
  84. <text class="feature-icon">🏆</text>
  85. <text class="feature-title">积分激励</text>
  86. <text class="feature-desc">完成任务得积分,兑换心愿</text>
  87. </view>
  88. <view class="feature-item">
  89. <text class="feature-icon">👨‍👩‍👧‍👦</text>
  90. <text class="feature-title">家庭参与</text>
  91. <text class="feature-desc">全家一起见证成长每一步</text>
  92. </view>
  93. <view class="feature-item">
  94. <text class="feature-icon">🌟</text>
  95. <text class="feature-title">专业规划</text>
  96. <text class="feature-desc">成长规划师一对一指导</text>
  97. </view>
  98. </view>
  99. </view>
  100. <!-- 底部登录按钮 -->
  101. <view class="login-footer">
  102. <button class="login-btn" @click="handleLogin">登录 / 注册</button>
  103. <text class="login-footer-text">登录即表示同意《用户协议》和《隐私政策》</text>
  104. </view>
  105. <!-- 未登录态自定义底部导航 -->
  106. <bottom-nav current="index" />
  107. <!-- 底部占位 -->
  108. <view style="height: 20rpx;"></view>
  109. </view>
  110. </template>
  111. <script>
  112. import { productList, getFeaturedArticles } from '@/utils/api.js'
  113. import WuxingSandbox from '../../components/wuxing-sandbox.vue'
  114. import BottomNav from '../../components/bottom-nav.vue'
  115. export default {
  116. components: { WuxingSandbox, BottomNav },
  117. data() {
  118. return {
  119. typeList: [
  120. { label: '全部', value: '' },
  121. { label: '活动', value: 'activity' },
  122. { label: '课程', value: 'course' },
  123. { label: '实物', value: 'physical' },
  124. { label: '数字', value: 'digital' },
  125. { label: '服务', value: 'service' }
  126. ],
  127. currentType: '',
  128. products: [],
  129. loading: false,
  130. featuredArticles: [],
  131. coverGradients: [
  132. 'linear-gradient(135deg, #D6EAF8, #8FC5E8)',
  133. 'linear-gradient(135deg, #E8F5E9, #81C784)',
  134. 'linear-gradient(135deg, #FFF3E0, #FFB74D)',
  135. 'linear-gradient(135deg, #F3E5F5, #CE93D8)',
  136. 'linear-gradient(135deg, #FCE4EC, #F06292)'
  137. ],
  138. coverIcons: ['🌱', '🏃', '🎯', '🌟', '📚']
  139. }
  140. },
  141. onShow() {
  142. this.loadProducts()
  143. this.loadFeaturedArticles()
  144. },
  145. methods: {
  146. loadProducts() {
  147. this.loading = true
  148. const params = { page: 1, size: 10 }
  149. if (this.currentType) {
  150. params.productType = this.currentType
  151. }
  152. productList(params).then(res => {
  153. this.loading = false
  154. if (res.code === 200 && res.data) {
  155. this.products = res.data.records || []
  156. }
  157. }).catch(() => {
  158. this.loading = false
  159. })
  160. },
  161. onTypeChange(value) {
  162. this.currentType = value
  163. this.loadProducts()
  164. },
  165. goShop() {
  166. uni.navigateTo({ url: '/pages/shop/index' })
  167. },
  168. goDetail(id) {
  169. const token = uni.getStorageSync('token')
  170. if (token) {
  171. uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
  172. } else {
  173. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/discover/index') })
  174. }
  175. },
  176. handleLogin() {
  177. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/discover/index') })
  178. },
  179. async loadFeaturedArticles() {
  180. try {
  181. const res = await getFeaturedArticles({ size: 3 })
  182. if (res.code === 200 && res.data) {
  183. let list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  184. this.featuredArticles = list
  185. }
  186. } catch (e) {
  187. // 静默处理
  188. }
  189. },
  190. goArticleDetail(id) {
  191. var token = uni.getStorageSync('token')
  192. if (token) {
  193. uni.navigateTo({ url: '/pages/mind/article-detail?id=' + id })
  194. } else {
  195. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/discover/index') })
  196. }
  197. },
  198. goAllArticles() {
  199. uni.navigateTo({ url: '/pages/mind/articles' })
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped>
  205. .discover-container {
  206. min-height: 100vh;
  207. background: #f5f7fa;
  208. padding-bottom: 100rpx;
  209. }
  210. /* ===== 品牌头部 ===== */
  211. .brand-header {
  212. display: flex;
  213. flex-direction: row;
  214. align-items: center;
  215. padding: 20rpx 30rpx 12rpx;
  216. background: linear-gradient(180deg, #EBF2FA 0%, #f5f9fc 100%);
  217. }
  218. .brand-logo {
  219. width: 64rpx;
  220. height: 64rpx;
  221. border-radius: 14rpx;
  222. flex-shrink: 0;
  223. }
  224. .brand-text-wrap {
  225. display: flex;
  226. flex-direction: column;
  227. margin-left: 14rpx;
  228. }
  229. .brand-title {
  230. font-size: 32rpx;
  231. font-weight: bold;
  232. color: #2C5282;
  233. letter-spacing: 4rpx;
  234. line-height: 1.2;
  235. }
  236. .brand-subtitle {
  237. font-size: 20rpx;
  238. color: #5B9BD5;
  239. margin-top: 2rpx;
  240. line-height: 1.2;
  241. }
  242. /* ===== 推荐 ===== */
  243. .recommend-section {
  244. margin: 20rpx 30rpx;
  245. }
  246. .section-header {
  247. display: flex;
  248. justify-content: space-between;
  249. align-items: center;
  250. margin-bottom: 20rpx;
  251. }
  252. .section-title {
  253. font-size: 30rpx;
  254. font-weight: bold;
  255. color: #333;
  256. }
  257. .section-more {
  258. font-size: 24rpx;
  259. color: #5B9BD5;
  260. }
  261. .type-filter-scroll {
  262. white-space: nowrap;
  263. margin-bottom: 20rpx;
  264. }
  265. .filter-chip {
  266. display: inline-block;
  267. padding: 8rpx 24rpx;
  268. font-size: 24rpx;
  269. color: #666;
  270. background: #f0f0f0;
  271. border-radius: 30rpx;
  272. margin-right: 16rpx;
  273. }
  274. .filter-chip.active {
  275. background: #5B9BD5;
  276. color: #fff;
  277. }
  278. .loading-state,
  279. .empty-state {
  280. display: flex;
  281. justify-content: center;
  282. padding: 60rpx 0;
  283. }
  284. .loading-text,
  285. .empty-text {
  286. font-size: 26rpx;
  287. color: #999;
  288. }
  289. .product-grid {
  290. display: flex;
  291. flex-wrap: wrap;
  292. justify-content: space-between;
  293. }
  294. .product-card {
  295. width: 48%;
  296. background: #fff;
  297. border-radius: 16rpx;
  298. overflow: hidden;
  299. margin-bottom: 20rpx;
  300. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  301. }
  302. .product-cover {
  303. width: 100%;
  304. height: 200rpx;
  305. background: #f0f0f0;
  306. }
  307. .product-info {
  308. padding: 14rpx;
  309. }
  310. .product-name {
  311. display: block;
  312. font-size: 26rpx;
  313. color: #333;
  314. margin-bottom: 10rpx;
  315. overflow: hidden;
  316. text-overflow: ellipsis;
  317. white-space: nowrap;
  318. }
  319. .product-price-row {
  320. display: flex;
  321. align-items: baseline;
  322. }
  323. .product-price {
  324. font-size: 28rpx;
  325. color: #5B9BD5;
  326. font-weight: bold;
  327. margin-right: 10rpx;
  328. }
  329. .product-member {
  330. font-size: 20rpx;
  331. color: #999;
  332. }
  333. .recommend-scroll {
  334. display: flex;
  335. white-space: nowrap;
  336. overflow-x: auto;
  337. padding-bottom: 10rpx;
  338. }
  339. .recommend-card {
  340. display: inline-flex;
  341. flex-direction: column;
  342. width: 260rpx;
  343. background: #fff;
  344. border-radius: 20rpx;
  345. overflow: hidden;
  346. margin-right: 20rpx;
  347. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  348. }
  349. .card-banner {
  350. padding: 14rpx 20rpx;
  351. background: #5B9BD5;
  352. color: #fff;
  353. font-size: 22rpx;
  354. font-weight: bold;
  355. text-align: center;
  356. }
  357. .card-body {
  358. padding: 16rpx;
  359. white-space: normal;
  360. }
  361. .card-title {
  362. font-size: 24rpx;
  363. font-weight: bold;
  364. color: #333;
  365. display: block;
  366. margin-bottom: 6rpx;
  367. }
  368. .card-desc {
  369. font-size: 20rpx;
  370. color: #999;
  371. display: block;
  372. margin-bottom: 10rpx;
  373. }
  374. .card-meta {
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. }
  379. .card-price {
  380. font-size: 26rpx;
  381. color: #5B9BD5;
  382. font-weight: bold;
  383. }
  384. .card-tag {
  385. font-size: 18rpx;
  386. color: #5B9BD5;
  387. background: rgba(91,155,213,0.1);
  388. padding: 2rpx 10rpx;
  389. border-radius: 10rpx;
  390. }
  391. /* ===== 推荐文章 ===== */
  392. .article-section {
  393. margin: 20rpx 30rpx 0;
  394. }
  395. .article-list {
  396. display: flex;
  397. flex-direction: column;
  398. gap: 16rpx;
  399. }
  400. .article-card {
  401. display: flex;
  402. background: #fff;
  403. border-radius: 16rpx;
  404. overflow: hidden;
  405. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  406. cursor: pointer;
  407. }
  408. .article-cover {
  409. width: 180rpx;
  410. flex-shrink: 0;
  411. display: flex;
  412. align-items: center;
  413. justify-content: center;
  414. }
  415. .article-cover-icon {
  416. font-size: 48rpx;
  417. }
  418. .article-info {
  419. flex: 1;
  420. padding: 16rpx;
  421. display: flex;
  422. flex-direction: column;
  423. justify-content: center;
  424. }
  425. .article-title {
  426. font-size: 26rpx;
  427. font-weight: bold;
  428. color: #333;
  429. line-height: 1.4;
  430. overflow: hidden;
  431. text-overflow: ellipsis;
  432. white-space: nowrap;
  433. }
  434. .article-desc {
  435. font-size: 22rpx;
  436. color: #999;
  437. line-height: 1.3;
  438. margin-top: 6rpx;
  439. overflow: hidden;
  440. text-overflow: ellipsis;
  441. white-space: nowrap;
  442. }
  443. .article-meta {
  444. font-size: 20rpx;
  445. color: #ccc;
  446. margin-top: 6rpx;
  447. }
  448. /* ===== 为何选择 ===== */
  449. .why-section {
  450. margin: 30rpx;
  451. }
  452. .feature-grid {
  453. display: flex;
  454. flex-direction: row;
  455. flex-wrap: wrap;
  456. justify-content: space-between;
  457. }
  458. .feature-item {
  459. width: calc(50% - 10rpx);
  460. box-sizing: border-box;
  461. background: #fff;
  462. border-radius: 20rpx;
  463. padding: 24rpx;
  464. margin-bottom: 20rpx;
  465. display: flex;
  466. flex-direction: column;
  467. align-items: center;
  468. text-align: center;
  469. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  470. }
  471. .feature-icon {
  472. font-size: 48rpx;
  473. margin-bottom: 10rpx;
  474. }
  475. .feature-title {
  476. font-size: 24rpx;
  477. font-weight: bold;
  478. color: #333;
  479. margin-bottom: 6rpx;
  480. }
  481. .feature-desc {
  482. font-size: 20rpx;
  483. color: #999;
  484. }
  485. /* ===== 底部登录 ===== */
  486. .login-footer {
  487. margin: 40rpx 30rpx;
  488. display: flex;
  489. flex-direction: column;
  490. align-items: center;
  491. }
  492. .login-btn {
  493. width: 100%;
  494. height: 88rpx;
  495. line-height: 88rpx;
  496. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  497. color: #fff;
  498. font-size: 32rpx;
  499. font-weight: bold;
  500. border-radius: 44rpx;
  501. text-align: center;
  502. border: none;
  503. }
  504. .login-btn::after {
  505. border: none;
  506. }
  507. .login-footer-text {
  508. font-size: 20rpx;
  509. color: #bbb;
  510. margin-top: 16rpx;
  511. }
  512. </style>