ArticleBookshelf.vue 14 KB

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