index.vue 14 KB

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