index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  226. var s = String(path).trim()
  227. if (!s || s === 'null' || s === '/null') return ''
  228. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  229. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  230. },
  231. goKnowledgeCenter() {
  232. uni.navigateTo({ url: '/pages/article-center/index' })
  233. }
  234. }
  235. }
  236. </script>
  237. <style scoped>
  238. .discover-container {
  239. min-height: 100vh;
  240. background: #f5f7fa;
  241. padding-bottom: 100rpx;
  242. }
  243. /* ===== 推荐 ===== */
  244. .recommend-section {
  245. margin: 20rpx 30rpx;
  246. }
  247. .section-header {
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. margin-bottom: 20rpx;
  252. }
  253. .section-title {
  254. font-size: 30rpx;
  255. font-weight: bold;
  256. color: #333;
  257. }
  258. .section-more {
  259. font-size: 24rpx;
  260. color: #5B9BD5;
  261. }
  262. .type-filter-scroll {
  263. white-space: nowrap;
  264. margin-bottom: 20rpx;
  265. }
  266. .filter-chip {
  267. display: inline-block;
  268. padding: 8rpx 24rpx;
  269. font-size: 24rpx;
  270. color: #666;
  271. background: #f0f0f0;
  272. border-radius: 30rpx;
  273. margin-right: 16rpx;
  274. }
  275. .filter-chip.active {
  276. background: #5B9BD5;
  277. color: #fff;
  278. }
  279. .loading-state,
  280. .empty-state {
  281. display: flex;
  282. justify-content: center;
  283. padding: 60rpx 0;
  284. }
  285. .loading-text,
  286. .empty-text {
  287. font-size: 26rpx;
  288. color: #999;
  289. }
  290. .product-grid {
  291. display: flex;
  292. flex-wrap: wrap;
  293. justify-content: space-between;
  294. }
  295. .product-card {
  296. width: 48%;
  297. background: #fff;
  298. border-radius: 16rpx;
  299. overflow: hidden;
  300. margin-bottom: 20rpx;
  301. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  302. }
  303. .product-cover {
  304. width: 100%;
  305. height: 200rpx;
  306. background: #f0f0f0;
  307. }
  308. .product-info {
  309. padding: 14rpx;
  310. }
  311. .product-name {
  312. display: block;
  313. font-size: 26rpx;
  314. color: #333;
  315. margin-bottom: 10rpx;
  316. overflow: hidden;
  317. text-overflow: ellipsis;
  318. white-space: nowrap;
  319. }
  320. .product-price-row {
  321. display: flex;
  322. align-items: baseline;
  323. }
  324. .product-price {
  325. font-size: 28rpx;
  326. color: #5B9BD5;
  327. font-weight: bold;
  328. margin-right: 10rpx;
  329. }
  330. .product-member {
  331. font-size: 20rpx;
  332. color: #999;
  333. }
  334. .recommend-scroll {
  335. display: flex;
  336. white-space: nowrap;
  337. overflow-x: auto;
  338. padding-bottom: 10rpx;
  339. }
  340. .recommend-card {
  341. display: inline-flex;
  342. flex-direction: column;
  343. width: 260rpx;
  344. background: #fff;
  345. border-radius: 20rpx;
  346. overflow: hidden;
  347. margin-right: 20rpx;
  348. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  349. }
  350. .card-banner {
  351. padding: 14rpx 20rpx;
  352. background: #5B9BD5;
  353. color: #fff;
  354. font-size: 22rpx;
  355. font-weight: bold;
  356. text-align: center;
  357. }
  358. .card-body {
  359. padding: 16rpx;
  360. white-space: normal;
  361. }
  362. .card-title {
  363. font-size: 24rpx;
  364. font-weight: bold;
  365. color: #333;
  366. display: block;
  367. margin-bottom: 6rpx;
  368. }
  369. .card-desc {
  370. font-size: 20rpx;
  371. color: #999;
  372. display: block;
  373. margin-bottom: 10rpx;
  374. }
  375. .card-meta {
  376. display: flex;
  377. align-items: center;
  378. justify-content: space-between;
  379. }
  380. .card-price {
  381. font-size: 26rpx;
  382. color: #5B9BD5;
  383. font-weight: bold;
  384. }
  385. .card-tag {
  386. font-size: 18rpx;
  387. color: #5B9BD5;
  388. background: rgba(91,155,213,0.1);
  389. padding: 2rpx 10rpx;
  390. border-radius: 10rpx;
  391. }
  392. /* ===== 家庭会员推荐卡片 ===== */
  393. .member-card {
  394. margin: 20rpx 30rpx 0;
  395. }
  396. .member-card-bg {
  397. display: flex;
  398. align-items: center;
  399. background: linear-gradient(135deg, #F97316, #FB923C);
  400. border-radius: 20rpx;
  401. padding: 24rpx 30rpx;
  402. }
  403. .member-card-icon {
  404. font-size: 48rpx;
  405. margin-right: 16rpx;
  406. }
  407. .member-card-texts {
  408. flex: 1;
  409. display: flex;
  410. flex-direction: column;
  411. }
  412. .member-card-title {
  413. font-size: 30rpx;
  414. font-weight: bold;
  415. color: #fff;
  416. }
  417. .member-card-desc {
  418. font-size: 22rpx;
  419. color: rgba(255,255,255,0.85);
  420. margin-top: 4rpx;
  421. }
  422. .member-card-action {
  423. margin-left: 16rpx;
  424. }
  425. .member-card-btn {
  426. display: inline-block;
  427. padding: 8rpx 24rpx;
  428. background: #fff;
  429. color: #F97316;
  430. font-size: 24rpx;
  431. font-weight: bold;
  432. border-radius: 30rpx;
  433. }
  434. /* ===== 推荐文章 ===== */
  435. .article-section {
  436. margin: 20rpx 30rpx 0;
  437. }
  438. .article-list {
  439. display: flex;
  440. flex-direction: column;
  441. gap: 16rpx;
  442. }
  443. .article-card {
  444. display: flex;
  445. background: #fff;
  446. border-radius: 16rpx;
  447. overflow: hidden;
  448. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  449. cursor: pointer;
  450. }
  451. .article-cover {
  452. width: 180rpx;
  453. flex-shrink: 0;
  454. display: flex;
  455. align-items: center;
  456. justify-content: center;
  457. }
  458. .article-cover-icon {
  459. font-size: 48rpx;
  460. }
  461. .article-info {
  462. flex: 1;
  463. padding: 16rpx;
  464. display: flex;
  465. flex-direction: column;
  466. justify-content: center;
  467. }
  468. .article-title {
  469. font-size: 26rpx;
  470. font-weight: bold;
  471. color: #333;
  472. line-height: 1.4;
  473. overflow: hidden;
  474. text-overflow: ellipsis;
  475. white-space: nowrap;
  476. }
  477. .article-desc {
  478. font-size: 22rpx;
  479. color: #999;
  480. line-height: 1.3;
  481. margin-top: 6rpx;
  482. overflow: hidden;
  483. text-overflow: ellipsis;
  484. white-space: nowrap;
  485. }
  486. .article-meta {
  487. font-size: 20rpx;
  488. color: #ccc;
  489. margin-top: 6rpx;
  490. }
  491. /* ===== 为何选择 ===== */
  492. .why-section {
  493. margin: 30rpx;
  494. }
  495. .feature-grid {
  496. display: flex;
  497. flex-direction: row;
  498. flex-wrap: wrap;
  499. justify-content: space-between;
  500. }
  501. .feature-item {
  502. width: calc(50% - 10rpx);
  503. box-sizing: border-box;
  504. background: #fff;
  505. border-radius: 20rpx;
  506. padding: 24rpx;
  507. margin-bottom: 20rpx;
  508. display: flex;
  509. flex-direction: column;
  510. align-items: center;
  511. text-align: center;
  512. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  513. }
  514. .feature-icon {
  515. font-size: 48rpx;
  516. margin-bottom: 10rpx;
  517. }
  518. .feature-title {
  519. font-size: 24rpx;
  520. font-weight: bold;
  521. color: #333;
  522. margin-bottom: 6rpx;
  523. }
  524. .feature-desc {
  525. font-size: 20rpx;
  526. color: #999;
  527. }
  528. /* ===== 底部登录 ===== */
  529. .login-footer {
  530. margin: 40rpx 30rpx;
  531. display: flex;
  532. flex-direction: column;
  533. align-items: center;
  534. }
  535. .login-btn {
  536. width: 100%;
  537. height: 88rpx;
  538. line-height: 88rpx;
  539. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  540. color: #fff;
  541. font-size: 32rpx;
  542. font-weight: bold;
  543. border-radius: 44rpx;
  544. text-align: center;
  545. border: none;
  546. }
  547. .login-btn::after {
  548. border: none;
  549. }
  550. .login-footer-text {
  551. font-size: 20rpx;
  552. color: #bbb;
  553. margin-top: 16rpx;
  554. }
  555. </style>