ArticleBookshelf.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view class="bs-section">
  3. <!-- 书册头部 -->
  4. <view class="bs-header">
  5. <view class="bs-header-left">
  6. <text class="bs-book-icon">&#x1F4DA;</text>
  7. <view class="bs-header-text">
  8. <text class="bs-title">推荐阅读</text>
  9. <text class="bs-subtitle">Knowledge · 知识</text>
  10. </view>
  11. </view>
  12. <view class="bs-header-right" @click="$emit('moreArticles')">
  13. <text class="bs-more-text">书库</text>
  14. <text class="bs-more-arrow">&#x203A;</text>
  15. </view>
  16. </view>
  17. <!-- 无数据 -->
  18. <view v-if="(!articles || articles.length === 0) && !loading" class="bs-empty">
  19. <text class="bs-empty-text">书册整理中,敬请期待...</text>
  20. </view>
  21. <!-- 骨架屏 -->
  22. <view v-else-if="loading && (!articles || articles.length === 0)" class="bs-shelf-skeleton">
  23. <view class="bs-skeleton-shelf">
  24. <view v-for="n in 3" :key="n" class="bs-skeleton-book"></view>
  25. </view>
  26. </view>
  27. <!-- 书册展示区 -->
  28. <view v-else class="bs-bookcase">
  29. <!-- 书架装饰线 -->
  30. <view class="bs-shelf-top-border"></view>
  31. <!-- 书籍横向滚动(每屏3本) -->
  32. <scroll-view
  33. scroll-x
  34. class="bs-books-scroll"
  35. :scroll-left="scrollLeft"
  36. scroll-with-animation
  37. :show-scrollbar="false"
  38. @scroll="onScroll"
  39. >
  40. <view class="bs-books-inner">
  41. <!-- 左内边距起始 -->
  42. <view class="bs-book-spacer"></view>
  43. <!-- 书籍列表 -->
  44. <view
  45. v-for="(article, idx) in displayArticles"
  46. :key="idx"
  47. class="bs-book-wrap"
  48. @click="$emit('articleClick', article)"
  49. >
  50. <!-- 竖版封面主体 -->
  51. <view
  52. class="bs-book-cover"
  53. :style="{
  54. background: getBookColor(article, idx)
  55. }"
  56. >
  57. <!-- 封面图 -->
  58. <image
  59. v-if="article.coverImage"
  60. class="bs-cover-img"
  61. :src="getImageUrl(article.coverImage)"
  62. mode="aspectFill"
  63. />
  64. <!-- 无封面图时:渐变底 + 书名 -->
  65. <view v-else class="bs-cover-text">
  66. <text
  67. class="bs-cover-title"
  68. :style="{ color: getTextColor(article, idx) }"
  69. >{{ article.title }}</text>
  70. </view>
  71. <!-- 底部分类标签 -->
  72. <view class="bs-cover-bottom">
  73. <text
  74. class="bs-cover-category"
  75. :style="{
  76. background: getTextColor(article, idx),
  77. color: getBookColor(article, idx)
  78. }"
  79. >{{ getCategoryLabel(article) }}</text>
  80. </view>
  81. <!-- 右侧书页切边(3D效果) -->
  82. <view class="bs-cover-edge"></view>
  83. </view>
  84. <!-- 封面底部阴影(书架效果) -->
  85. <view class="bs-book-shadow"></view>
  86. </view>
  87. <!-- 右内边距结尾 -->
  88. <view class="bs-book-spacer"></view>
  89. </view>
  90. </scroll-view>
  91. <!-- 书架底板装饰 -->
  92. <view class="bs-shelf-bottom">
  93. <view class="bs-shelf-plank"></view>
  94. <view class="bs-shelf-bracket bs-shelf-bracket-left"></view>
  95. <view class="bs-shelf-bracket bs-shelf-bracket-right"></view>
  96. </view>
  97. <!-- 翻页指示器 -->
  98. <view class="bs-page-dots" v-if="displayArticles.length > 3">
  99. <view
  100. v-for="n in dotCount"
  101. :key="n"
  102. class="bs-dot"
  103. :class="{ 'bs-dot-active': isActiveDot(n) }"
  104. ></view>
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. // 五维配色体系(书脊颜色)
  111. import config from '@/config.js'
  112. var DIMENSION_COLORS = {
  113. body: { bg: 'linear-gradient(180deg, #FF8C42 0%, #E8762A 100%)', text: '#FFF5EE' },
  114. mind: { bg: 'linear-gradient(180deg, #FF6B9D 0%, #E84A7F 100%)', text: '#FFF0F5' },
  115. wisdom: { bg: 'linear-gradient(180deg, #6366F1 0%, #4F46E5 100%)', text: '#EEF2FF' },
  116. action: { bg: 'linear-gradient(180deg, #10B981 0%, #059669 100%)', text: '#ECFDF5' },
  117. wealth: { bg: 'linear-gradient(180deg, #F59E0B 0%, #D97706 100%)', text: '#FFFBEB' }
  118. }
  119. // 回退渐变(用于无维度分类的文章)
  120. var FALLBACK_GRADIENTS = [
  121. { bg: 'linear-gradient(180deg, #8B5CF6 0%, #7C3AED 100%)', text: '#F5F3FF' },
  122. { bg: 'linear-gradient(180deg, #06B6D4 0%, #0891B2 100%)', text: '#ECFEFF' },
  123. { bg: 'linear-gradient(180deg, #EC4899 0%, #DB2777 100%)', text: '#FDF2F8' },
  124. { bg: 'linear-gradient(180deg, #14B8A6 0%, #0D9488 100%)', text: '#F0FDFA' },
  125. { bg: 'linear-gradient(180deg, #F97316 0%, #EA580C 100%)', text: '#FFF7ED' }
  126. ]
  127. export default {
  128. name: 'ArticleBookshelf',
  129. props: {
  130. articles: { type: Array, default: function() { return [] } },
  131. loading: { type: Boolean, default: false },
  132. isLoggedIn: { type: Boolean, default: false }
  133. },
  134. data: function() {
  135. return {
  136. scrollLeft: 0,
  137. activeDot: 1
  138. }
  139. },
  140. computed: {
  141. // 每屏 3 本,指示器数量 = ceil(n/3)
  142. dotCount: function() {
  143. return Math.max(1, Math.ceil(this.displayArticles.length / 3))
  144. },
  145. displayArticles: function() {
  146. if (!this.articles || this.articles.length === 0) {
  147. return [
  148. { title: '培养孩子自驱力的关键', category: '家庭成长', summary: '如何帮助孩子建立内在动机' },
  149. { title: '五维能量与家庭健康管理', category: '健康科普', summary: '科学理解健康的五个维度' },
  150. { title: '亲子沟通的心理学智慧', category: '心理养育', summary: '有效的倾听与表达技巧' },
  151. { title: '规划师推荐的书单', category: '成长规划', summary: '培养未来领导力的阅读路径' },
  152. { title: '儿童营养均衡完全指南', category: '营养健康', summary: '0-12岁各阶段营养需求' }
  153. ]
  154. }
  155. return this.articles.slice(0, 12)
  156. }
  157. },
  158. methods: {
  159. // 提取首个维度 code(兼容字符串 "mind,emotion" / JSON 字符串 / 数组 ['mind','emotion'])
  160. getFirstDimension: function(article) {
  161. if (!article || !article.relatedDimensions) return ''
  162. var raw = article.relatedDimensions
  163. var first = ''
  164. if (typeof raw === 'string') {
  165. var trimmed = raw.trim()
  166. if (trimmed.indexOf('[') === 0) {
  167. try {
  168. var parsed = JSON.parse(trimmed)
  169. if (Array.isArray(parsed)) first = parsed[0] || ''
  170. } catch (e) {
  171. first = ''
  172. }
  173. }
  174. if (!first) {
  175. first = trimmed.split(',')[0] || ''
  176. }
  177. } else if (Array.isArray(raw)) {
  178. first = raw[0] || ''
  179. }
  180. return String(first).trim().toLowerCase()
  181. },
  182. getBookColor: function(article, idx) {
  183. var firstDim = this.getFirstDimension(article)
  184. if (firstDim && DIMENSION_COLORS[firstDim]) {
  185. return DIMENSION_COLORS[firstDim].bg
  186. }
  187. if (article && article.dimensionCode && DIMENSION_COLORS[article.dimensionCode]) {
  188. return DIMENSION_COLORS[article.dimensionCode].bg
  189. }
  190. return FALLBACK_GRADIENTS[idx % FALLBACK_GRADIENTS.length].bg
  191. },
  192. getTextColor: function(article, idx) {
  193. var firstDim = this.getFirstDimension(article)
  194. if (firstDim && DIMENSION_COLORS[firstDim]) {
  195. return DIMENSION_COLORS[firstDim].text
  196. }
  197. if (article && article.dimensionCode && DIMENSION_COLORS[article.dimensionCode]) {
  198. return DIMENSION_COLORS[article.dimensionCode].text
  199. }
  200. return FALLBACK_GRADIENTS[idx % FALLBACK_GRADIENTS.length].text
  201. },
  202. getImageUrl: function(path) {
  203. return config.API_BASE_URL + path
  204. },
  205. getCategoryLabel: function(article) {
  206. if (!article) return '推荐'
  207. if (article.categoryName) return article.categoryName
  208. if (article.category) return article.category
  209. return '推荐'
  210. },
  211. // 滚动时计算当前指示器位置(每 3 本一组)
  212. onScroll: function(e) {
  213. var scrollLeft = e.detail.scrollLeft || 0
  214. // 每本封面宽 200rpx + 间距 24rpx ≈ 224rpx/本;scrollLeft 为 px,需转 px 后按 3 本一组
  215. var groupWidth = uni.upx2px(224) * 3
  216. var groupIndex = Math.floor(scrollLeft / groupWidth)
  217. this.activeDot = Math.min(groupIndex + 1, this.dotCount)
  218. },
  219. isActiveDot: function(dotIndex) {
  220. return dotIndex === this.activeDot
  221. }
  222. }
  223. }
  224. </script>
  225. <style scoped>
  226. /* ======================================
  227. ArticleBookshelf — 书册风格推荐阅读组件
  228. 浠艾福 (Care Family) 设计系统
  229. ====================================== */
  230. /* ---- Section Container ---- */
  231. .bs-section {
  232. margin: 24rpx 0;
  233. padding: 0 0 16rpx;
  234. }
  235. /* ---- Header ---- */
  236. .bs-header {
  237. display: flex;
  238. flex-direction: row;
  239. align-items: center;
  240. justify-content: space-between;
  241. padding: 0 32rpx 20rpx;
  242. }
  243. .bs-header-left {
  244. display: flex;
  245. flex-direction: row;
  246. align-items: center;
  247. }
  248. .bs-book-icon {
  249. font-size: 48rpx;
  250. margin-right: 14rpx;
  251. line-height: 1;
  252. }
  253. .bs-header-text {
  254. display: flex;
  255. flex-direction: column;
  256. }
  257. .bs-title {
  258. font-size: 34rpx;
  259. font-weight: 700;
  260. color: #1a1a2e;
  261. letter-spacing: 2rpx;
  262. line-height: 1.2;
  263. }
  264. .bs-subtitle {
  265. font-size: 20rpx;
  266. color: #9CA3AF;
  267. font-family: 'Georgia', serif;
  268. font-style: italic;
  269. margin-top: 2rpx;
  270. }
  271. .bs-header-right {
  272. display: flex;
  273. flex-direction: row;
  274. align-items: center;
  275. padding: 8rpx 16rpx;
  276. background: rgba(91, 155, 213, 0.08);
  277. border-radius: 20rpx;
  278. }
  279. .bs-more-text {
  280. font-size: 22rpx;
  281. color: #5B9BD5;
  282. font-weight: 500;
  283. }
  284. .bs-more-arrow {
  285. font-size: 28rpx;
  286. color: #5B9BD5;
  287. margin-left: 4rpx;
  288. }
  289. /* ---- Empty State ---- */
  290. .bs-empty {
  291. padding: 40rpx 0;
  292. display: flex;
  293. justify-content: center;
  294. }
  295. .bs-empty-text {
  296. font-size: 24rpx;
  297. color: #9CA3AF;
  298. font-family: 'Georgia', serif;
  299. font-style: italic;
  300. }
  301. /* ---- Skeleton ---- */
  302. .bs-shelf-skeleton {
  303. padding: 0 28rpx;
  304. }
  305. .bs-skeleton-shelf {
  306. display: flex;
  307. flex-direction: row;
  308. align-items: flex-start;
  309. gap: 24rpx;
  310. padding-top: 16rpx;
  311. }
  312. .bs-skeleton-book {
  313. width: 200rpx;
  314. height: 280rpx;
  315. border-radius: 8rpx;
  316. background: linear-gradient(180deg, #e8e8e8 0%, #f0f0f0 50%, #e8e8e8 100%);
  317. background-size: 200% 100%;
  318. animation: skeleton-wave 1.4s ease-in-out infinite;
  319. flex-shrink: 0;
  320. }
  321. @keyframes skeleton-wave {
  322. 0% { background-position: 200% 0; }
  323. 100% { background-position: -200% 0; }
  324. }
  325. /* ---- Bookcase ---- */
  326. .bs-bookcase {
  327. position: relative;
  328. }
  329. /* 书架顶部装饰线 */
  330. .bs-shelf-top-border {
  331. height: 6rpx;
  332. margin: 0 28rpx;
  333. background: linear-gradient(90deg,
  334. transparent 0%,
  335. #8B7355 10%,
  336. #A0896A 30%,
  337. #C4A882 50%,
  338. #A0896A 70%,
  339. #8B7355 90%,
  340. transparent 100%
  341. );
  342. border-radius: 3rpx;
  343. }
  344. /* ---- Books Scroll ---- */
  345. .bs-books-scroll {
  346. white-space: nowrap;
  347. padding: 20rpx 0 0;
  348. width: 100%;
  349. }
  350. .bs-books-inner {
  351. display: inline-flex;
  352. flex-direction: row;
  353. align-items: flex-start;
  354. }
  355. .bs-book-spacer {
  356. width: 28rpx;
  357. flex-shrink: 0;
  358. }
  359. /* ---- Single Book (竖版封面) ---- */
  360. .bs-book-wrap {
  361. display: flex;
  362. flex-direction: column;
  363. align-items: center;
  364. flex-shrink: 0;
  365. margin-right: 24rpx;
  366. position: relative;
  367. }
  368. .bs-book-cover {
  369. width: 200rpx;
  370. height: 280rpx;
  371. border-radius: 8rpx 8rpx 4rpx 4rpx;
  372. position: relative;
  373. display: flex;
  374. align-items: center;
  375. justify-content: center;
  376. overflow: hidden;
  377. box-shadow:
  378. 4rpx 0 10rpx rgba(0,0,0,0.18),
  379. -2rpx 0 4rpx rgba(0,0,0,0.08),
  380. 0 6rpx 14rpx rgba(0,0,0,0.12);
  381. transition: transform 0.18s, box-shadow 0.18s;
  382. }
  383. .bs-book-wrap:active .bs-book-cover {
  384. transform: translateY(-6rpx) scale(1.02);
  385. box-shadow:
  386. 6rpx 0 14rpx rgba(0,0,0,0.25),
  387. -3rpx 0 6rpx rgba(0,0,0,0.1),
  388. 0 10rpx 22rpx rgba(0,0,0,0.18);
  389. }
  390. /* 封面图 */
  391. .bs-cover-img {
  392. width: 100%;
  393. height: 100%;
  394. }
  395. /* 无封面图时:渐变底 + 书名 */
  396. .bs-cover-text {
  397. width: 100%;
  398. height: 100%;
  399. display: flex;
  400. align-items: center;
  401. justify-content: center;
  402. padding: 20rpx 16rpx;
  403. box-sizing: border-box;
  404. }
  405. .bs-cover-title {
  406. font-size: 24rpx;
  407. font-weight: 700;
  408. line-height: 1.5;
  409. letter-spacing: 1rpx;
  410. text-align: center;
  411. overflow: hidden;
  412. text-overflow: ellipsis;
  413. display: -webkit-box;
  414. -webkit-line-clamp: 4;
  415. -webkit-box-orient: vertical;
  416. word-break: break-all;
  417. }
  418. /* 底部分类标签 */
  419. .bs-cover-bottom {
  420. position: absolute;
  421. bottom: 0;
  422. left: 0;
  423. right: 0;
  424. display: flex;
  425. justify-content: center;
  426. padding: 10rpx 0 12rpx;
  427. background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.25) 100%);
  428. }
  429. .bs-cover-category {
  430. font-size: 16rpx;
  431. font-weight: 600;
  432. padding: 3rpx 8rpx;
  433. border-radius: 4rpx;
  434. max-width: 160rpx;
  435. overflow: hidden;
  436. text-overflow: ellipsis;
  437. white-space: nowrap;
  438. display: inline-block;
  439. text-align: center;
  440. }
  441. /* 右侧书页切边(3D效果) */
  442. .bs-cover-edge {
  443. position: absolute;
  444. top: 10rpx;
  445. bottom: 10rpx;
  446. right: 0;
  447. width: 6rpx;
  448. background: linear-gradient(180deg,
  449. rgba(0,0,0,0.25) 0%,
  450. rgba(0,0,0,0.1) 50%,
  451. rgba(0,0,0,0.2) 100%
  452. );
  453. border-radius: 0 4rpx 4rpx 0;
  454. }
  455. /* 封面底部投影(书架效果) */
  456. .bs-book-shadow {
  457. width: 160rpx;
  458. height: 14rpx;
  459. margin-top: 8rpx;
  460. border-radius: 50%;
  461. background: radial-gradient(ellipse at center, rgba(0,0,0,0.18) 0%, rgba(0,0,0,0) 70%);
  462. flex-shrink: 0;
  463. }
  464. /* ---- 书架底板 ---- */
  465. .bs-shelf-bottom {
  466. position: relative;
  467. height: 24rpx;
  468. margin: 0 20rpx;
  469. }
  470. .bs-shelf-plank {
  471. position: absolute;
  472. bottom: 0;
  473. left: 0;
  474. right: 0;
  475. height: 14rpx;
  476. background: linear-gradient(180deg, #C4A882 0%, #A0896A 100%);
  477. border-radius: 2rpx;
  478. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.15);
  479. }
  480. .bs-shelf-bracket {
  481. position: absolute;
  482. bottom: 6rpx;
  483. width: 16rpx;
  484. height: 20rpx;
  485. background: #8B7355;
  486. border-radius: 2rpx 2rpx 0 0;
  487. }
  488. .bs-shelf-bracket-left { left: 32rpx; }
  489. .bs-shelf-bracket-right { right: 32rpx; }
  490. /* ---- Page Dots ---- */
  491. .bs-page-dots {
  492. display: flex;
  493. flex-direction: row;
  494. justify-content: center;
  495. padding-top: 16rpx;
  496. gap: 8rpx;
  497. }
  498. .bs-dot {
  499. width: 10rpx;
  500. height: 10rpx;
  501. border-radius: 50%;
  502. background: #D1D5DB;
  503. transition: all 0.25s;
  504. }
  505. .bs-dot-active {
  506. background: #8B7355;
  507. width: 24rpx;
  508. border-radius: 5rpx;
  509. }
  510. </style>