index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <view class="discover-container" :style="{ '--font-scale': fontScale }">
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  121. export default {
  122. mixins: [fontScaleMixin],
  123. components: { WuxingSandbox },
  124. data() {
  125. return {
  126. typeList: [
  127. { label: '全部', value: '' },
  128. { label: '活动', value: 'activity' },
  129. { label: '课程', value: 'course' },
  130. { label: '实物', value: 'physical' },
  131. { label: '数字', value: 'digital' },
  132. { label: '服务', value: 'service' }
  133. ],
  134. currentType: '',
  135. products: [],
  136. loading: false,
  137. featuredArticles: [],
  138. coverGradients: [
  139. 'linear-gradient(135deg, #D6EAF8, #8FC5E8)',
  140. 'linear-gradient(135deg, #E8F5E9, #81C784)',
  141. 'linear-gradient(135deg, #FFF3E0, #FFB74D)',
  142. 'linear-gradient(135deg, #F3E5F5, #CE93D8)',
  143. 'linear-gradient(135deg, #FCE4EC, #F06292)'
  144. ],
  145. coverIcons: ['🌱', '🏃', '🎯', '🌟', '📚'],
  146. isMember: false
  147. }
  148. },
  149. onLoad(options) {
  150. if (options && options.type) {
  151. this.currentType = options.type
  152. }
  153. },
  154. onShow() {
  155. this.checkMemberStatus()
  156. this.loadProducts()
  157. this.loadFeaturedArticles()
  158. },
  159. methods: {
  160. formatDuration(seconds) {
  161. if (!seconds || seconds <= 0) return '0分钟'
  162. var mins = Math.round(seconds / 60)
  163. if (mins < 60) return mins + '分钟'
  164. var hours = Math.floor(mins / 60)
  165. var restMins = mins % 60
  166. return restMins > 0 ? hours + '小时' + restMins + '分钟' : hours + '小时'
  167. },
  168. checkMemberStatus() {
  169. var that = this
  170. getMyMembership().then(function(res) {
  171. if (res.data && res.data.memberLevel) {
  172. that.isMember = res.data.memberLevel !== 'FREE'
  173. }
  174. }).catch(function() {})
  175. },
  176. goUpgrade() {
  177. uni.navigateTo({ url: '/pages/membership/upgrade' })
  178. },
  179. loadProducts() {
  180. this.loading = true
  181. const params = { page: 1, size: 10 }
  182. if (this.currentType) {
  183. params.productType = this.currentType
  184. }
  185. productList(params).then(res => {
  186. this.loading = false
  187. if (res.code === 200 && res.data) {
  188. this.products = res.data.records || []
  189. }
  190. }).catch(() => {
  191. this.loading = false
  192. })
  193. },
  194. onTypeChange(value) {
  195. this.currentType = value
  196. this.loadProducts()
  197. },
  198. goShop() {
  199. uni.navigateTo({ url: '/pages/shop/index/index' })
  200. },
  201. goDetail(id) {
  202. uni.navigateTo({ url: '/pages/discover-detail/product-detail/product-detail?id=' + id })
  203. },
  204. handleLogin() {
  205. this.openLoginSheet({ redirect: '/pages/discover/index' })
  206. },
  207. // 登录成功:刷新推荐列表
  208. onLoginSuccess() {
  209. this.loadProducts()
  210. this.loadFeaturedArticles()
  211. },
  212. async loadFeaturedArticles() {
  213. try {
  214. const res = await getFeaturedArticles({ size: 3 })
  215. if (res.code === 200 && res.data) {
  216. let list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  217. this.featuredArticles = list
  218. }
  219. } catch (e) {
  220. // 静默处理
  221. }
  222. },
  223. goArticleDetail(id) {
  224. uni.navigateTo({ url: '/pages/article-center/article-detail?id=' + id })
  225. },
  226. getImageUrl: function(path) {
  227. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  228. var s = String(path).trim()
  229. if (!s || s === 'null' || s === '/null') return ''
  230. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  231. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  232. },
  233. goKnowledgeCenter() {
  234. uni.navigateTo({ url: '/pages/article-center/index' })
  235. }
  236. }
  237. }
  238. </script>
  239. <style scoped>
  240. .discover-container {
  241. min-height: 100vh;
  242. background: #f5f7fa;
  243. padding-bottom: 100rpx;
  244. }
  245. /* ===== 推荐 ===== */
  246. .recommend-section {
  247. margin: 20rpx 30rpx;
  248. }
  249. .section-header {
  250. display: flex;
  251. justify-content: space-between;
  252. align-items: center;
  253. margin-bottom: 20rpx;
  254. }
  255. .section-title {
  256. font-size: 30rpx;
  257. font-weight: bold;
  258. color: #333;
  259. }
  260. .section-more {
  261. font-size: 24rpx;
  262. color: #5B9BD5;
  263. }
  264. .type-filter-scroll {
  265. white-space: nowrap;
  266. margin-bottom: 20rpx;
  267. }
  268. .filter-chip {
  269. display: inline-block;
  270. padding: 8rpx 24rpx;
  271. font-size: 24rpx;
  272. color: #666;
  273. background: #f0f0f0;
  274. border-radius: 30rpx;
  275. margin-right: 16rpx;
  276. }
  277. .filter-chip.active {
  278. background: #5B9BD5;
  279. color: #fff;
  280. }
  281. .loading-state,
  282. .empty-state {
  283. display: flex;
  284. justify-content: center;
  285. padding: 60rpx 0;
  286. }
  287. .loading-text,
  288. .empty-text {
  289. font-size: 26rpx;
  290. color: #999;
  291. }
  292. .product-grid {
  293. display: flex;
  294. flex-wrap: wrap;
  295. justify-content: space-between;
  296. }
  297. .product-card {
  298. width: 48%;
  299. background: #fff;
  300. border-radius: 16rpx;
  301. overflow: hidden;
  302. margin-bottom: 20rpx;
  303. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  304. }
  305. .product-cover {
  306. width: 100%;
  307. height: 200rpx;
  308. background: #f0f0f0;
  309. }
  310. .product-info {
  311. padding: 14rpx;
  312. }
  313. .product-name {
  314. display: block;
  315. font-size: 26rpx;
  316. color: #333;
  317. margin-bottom: 10rpx;
  318. overflow: hidden;
  319. text-overflow: ellipsis;
  320. white-space: nowrap;
  321. }
  322. .product-price-row {
  323. display: flex;
  324. align-items: baseline;
  325. }
  326. .product-price {
  327. font-size: 28rpx;
  328. color: #5B9BD5;
  329. font-weight: bold;
  330. margin-right: 10rpx;
  331. }
  332. .product-member {
  333. font-size: 20rpx;
  334. color: #999;
  335. }
  336. .recommend-scroll {
  337. display: flex;
  338. white-space: nowrap;
  339. overflow-x: auto;
  340. padding-bottom: 10rpx;
  341. }
  342. .recommend-card {
  343. display: inline-flex;
  344. flex-direction: column;
  345. width: 260rpx;
  346. background: #fff;
  347. border-radius: 20rpx;
  348. overflow: hidden;
  349. margin-right: 20rpx;
  350. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  351. }
  352. .card-banner {
  353. padding: 14rpx 20rpx;
  354. background: #5B9BD5;
  355. color: #fff;
  356. font-size: 22rpx;
  357. font-weight: bold;
  358. text-align: center;
  359. }
  360. .card-body {
  361. padding: 16rpx;
  362. white-space: normal;
  363. }
  364. .card-title {
  365. font-size: 24rpx;
  366. font-weight: bold;
  367. color: #333;
  368. display: block;
  369. margin-bottom: 6rpx;
  370. }
  371. .card-desc {
  372. font-size: 20rpx;
  373. color: #999;
  374. display: block;
  375. margin-bottom: 10rpx;
  376. }
  377. .card-meta {
  378. display: flex;
  379. align-items: center;
  380. justify-content: space-between;
  381. }
  382. .card-price {
  383. font-size: 26rpx;
  384. color: #5B9BD5;
  385. font-weight: bold;
  386. }
  387. .card-tag {
  388. font-size: 18rpx;
  389. color: #5B9BD5;
  390. background: rgba(91,155,213,0.1);
  391. padding: 2rpx 10rpx;
  392. border-radius: 10rpx;
  393. }
  394. /* ===== 家庭会员推荐卡片 ===== */
  395. .member-card {
  396. margin: 20rpx 30rpx 0;
  397. }
  398. .member-card-bg {
  399. display: flex;
  400. align-items: center;
  401. background: linear-gradient(135deg, #F97316, #FB923C);
  402. border-radius: 20rpx;
  403. padding: 24rpx 30rpx;
  404. }
  405. .member-card-icon {
  406. font-size: 48rpx;
  407. margin-right: 16rpx;
  408. }
  409. .member-card-texts {
  410. flex: 1;
  411. display: flex;
  412. flex-direction: column;
  413. }
  414. .member-card-title {
  415. font-size: 30rpx;
  416. font-weight: bold;
  417. color: #fff;
  418. }
  419. .member-card-desc {
  420. font-size: 22rpx;
  421. color: rgba(255,255,255,0.85);
  422. margin-top: 4rpx;
  423. }
  424. .member-card-action {
  425. margin-left: 16rpx;
  426. }
  427. .member-card-btn {
  428. display: inline-block;
  429. padding: 8rpx 24rpx;
  430. background: #fff;
  431. color: #F97316;
  432. font-size: 24rpx;
  433. font-weight: bold;
  434. border-radius: 30rpx;
  435. }
  436. /* ===== 推荐文章 ===== */
  437. .article-section {
  438. margin: 20rpx 30rpx 0;
  439. }
  440. .article-list {
  441. display: flex;
  442. flex-direction: column;
  443. gap: 16rpx;
  444. }
  445. .article-card {
  446. display: flex;
  447. background: #fff;
  448. border-radius: 16rpx;
  449. overflow: hidden;
  450. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  451. cursor: pointer;
  452. }
  453. .article-cover {
  454. width: 180rpx;
  455. flex-shrink: 0;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. }
  460. .article-cover-icon {
  461. font-size: 48rpx;
  462. }
  463. .article-info {
  464. flex: 1;
  465. padding: 16rpx;
  466. display: flex;
  467. flex-direction: column;
  468. justify-content: center;
  469. }
  470. .article-title {
  471. font-size: 26rpx;
  472. font-weight: bold;
  473. color: #333;
  474. line-height: 1.4;
  475. overflow: hidden;
  476. text-overflow: ellipsis;
  477. white-space: nowrap;
  478. }
  479. .article-desc {
  480. font-size: 22rpx;
  481. color: #999;
  482. line-height: 1.3;
  483. margin-top: 6rpx;
  484. overflow: hidden;
  485. text-overflow: ellipsis;
  486. white-space: nowrap;
  487. }
  488. .article-meta {
  489. font-size: 20rpx;
  490. color: #ccc;
  491. margin-top: 6rpx;
  492. }
  493. /* ===== 为何选择 ===== */
  494. .why-section {
  495. margin: 30rpx;
  496. }
  497. .feature-grid {
  498. display: flex;
  499. flex-direction: row;
  500. flex-wrap: wrap;
  501. justify-content: space-between;
  502. }
  503. .feature-item {
  504. width: calc(50% - 10rpx);
  505. box-sizing: border-box;
  506. background: #fff;
  507. border-radius: 20rpx;
  508. padding: 24rpx;
  509. margin-bottom: 20rpx;
  510. display: flex;
  511. flex-direction: column;
  512. align-items: center;
  513. text-align: center;
  514. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  515. }
  516. .feature-icon {
  517. font-size: 48rpx;
  518. margin-bottom: 10rpx;
  519. }
  520. .feature-title {
  521. font-size: 24rpx;
  522. font-weight: bold;
  523. color: #333;
  524. margin-bottom: 6rpx;
  525. }
  526. .feature-desc {
  527. font-size: 20rpx;
  528. color: #999;
  529. }
  530. /* ===== 底部登录 ===== */
  531. .login-footer {
  532. margin: 40rpx 30rpx;
  533. display: flex;
  534. flex-direction: column;
  535. align-items: center;
  536. }
  537. .login-btn {
  538. width: 100%;
  539. height: 88rpx;
  540. line-height: 88rpx;
  541. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  542. color: #fff;
  543. font-size: 32rpx;
  544. font-weight: bold;
  545. border-radius: 44rpx;
  546. text-align: center;
  547. border: none;
  548. }
  549. .login-btn::after {
  550. border: none;
  551. }
  552. .login-footer-text {
  553. font-size: 20rpx;
  554. color: #bbb;
  555. margin-top: 16rpx;
  556. }
  557. </style>