index.vue 12 KB

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