index.vue 14 KB

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