ArticleBookshelf.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. getBookColor: function(article, idx) {
  160. if (article && article.relatedDimensions) {
  161. var dims = article.relatedDimensions.split(',')
  162. var firstDim = (dims[0] || '').trim().toLowerCase()
  163. if (DIMENSION_COLORS[firstDim]) {
  164. return DIMENSION_COLORS[firstDim].bg
  165. }
  166. }
  167. if (article && article.dimensionCode && DIMENSION_COLORS[article.dimensionCode]) {
  168. return DIMENSION_COLORS[article.dimensionCode].bg
  169. }
  170. return FALLBACK_GRADIENTS[idx % FALLBACK_GRADIENTS.length].bg
  171. },
  172. getTextColor: function(article, idx) {
  173. if (article && article.relatedDimensions) {
  174. var dims = article.relatedDimensions.split(',')
  175. var firstDim = (dims[0] || '').trim().toLowerCase()
  176. if (DIMENSION_COLORS[firstDim]) {
  177. return DIMENSION_COLORS[firstDim].text
  178. }
  179. }
  180. if (article && article.dimensionCode && DIMENSION_COLORS[article.dimensionCode]) {
  181. return DIMENSION_COLORS[article.dimensionCode].text
  182. }
  183. return FALLBACK_GRADIENTS[idx % FALLBACK_GRADIENTS.length].text
  184. },
  185. getImageUrl: function(path) {
  186. return config.API_BASE_URL + path
  187. },
  188. getCategoryLabel: function(article) {
  189. if (!article) return '推荐'
  190. if (article.categoryName) return article.categoryName
  191. if (article.category) return article.category
  192. return '推荐'
  193. },
  194. // 滚动时计算当前指示器位置(每 3 本一组)
  195. onScroll: function(e) {
  196. var scrollLeft = e.detail.scrollLeft || 0
  197. // 每本封面宽 200rpx + 间距 24rpx ≈ 224rpx/本;scrollLeft 为 px,需转 px 后按 3 本一组
  198. var groupWidth = uni.upx2px(224) * 3
  199. var groupIndex = Math.floor(scrollLeft / groupWidth)
  200. this.activeDot = Math.min(groupIndex + 1, this.dotCount)
  201. },
  202. isActiveDot: function(dotIndex) {
  203. return dotIndex === this.activeDot
  204. }
  205. }
  206. }
  207. </script>
  208. <style scoped>
  209. /* ======================================
  210. ArticleBookshelf — 书册风格推荐阅读组件
  211. 浠艾福 (Care Family) 设计系统
  212. ====================================== */
  213. /* ---- Section Container ---- */
  214. .bs-section {
  215. margin: 24rpx 0;
  216. padding: 0 0 16rpx;
  217. }
  218. /* ---- Header ---- */
  219. .bs-header {
  220. display: flex;
  221. flex-direction: row;
  222. align-items: center;
  223. justify-content: space-between;
  224. padding: 0 32rpx 20rpx;
  225. }
  226. .bs-header-left {
  227. display: flex;
  228. flex-direction: row;
  229. align-items: center;
  230. }
  231. .bs-book-icon {
  232. font-size: 48rpx;
  233. margin-right: 14rpx;
  234. line-height: 1;
  235. }
  236. .bs-header-text {
  237. display: flex;
  238. flex-direction: column;
  239. }
  240. .bs-title {
  241. font-size: 34rpx;
  242. font-weight: 700;
  243. color: #1a1a2e;
  244. letter-spacing: 2rpx;
  245. line-height: 1.2;
  246. }
  247. .bs-subtitle {
  248. font-size: 20rpx;
  249. color: #9CA3AF;
  250. font-family: 'Georgia', serif;
  251. font-style: italic;
  252. margin-top: 2rpx;
  253. }
  254. .bs-header-right {
  255. display: flex;
  256. flex-direction: row;
  257. align-items: center;
  258. padding: 8rpx 16rpx;
  259. background: rgba(91, 155, 213, 0.08);
  260. border-radius: 20rpx;
  261. }
  262. .bs-more-text {
  263. font-size: 22rpx;
  264. color: #5B9BD5;
  265. font-weight: 500;
  266. }
  267. .bs-more-arrow {
  268. font-size: 28rpx;
  269. color: #5B9BD5;
  270. margin-left: 4rpx;
  271. }
  272. /* ---- Empty State ---- */
  273. .bs-empty {
  274. padding: 40rpx 0;
  275. display: flex;
  276. justify-content: center;
  277. }
  278. .bs-empty-text {
  279. font-size: 24rpx;
  280. color: #9CA3AF;
  281. font-family: 'Georgia', serif;
  282. font-style: italic;
  283. }
  284. /* ---- Skeleton ---- */
  285. .bs-shelf-skeleton {
  286. padding: 0 28rpx;
  287. }
  288. .bs-skeleton-shelf {
  289. display: flex;
  290. flex-direction: row;
  291. align-items: flex-start;
  292. gap: 24rpx;
  293. padding-top: 16rpx;
  294. }
  295. .bs-skeleton-book {
  296. width: 200rpx;
  297. height: 280rpx;
  298. border-radius: 8rpx;
  299. background: linear-gradient(180deg, #e8e8e8 0%, #f0f0f0 50%, #e8e8e8 100%);
  300. background-size: 200% 100%;
  301. animation: skeleton-wave 1.4s ease-in-out infinite;
  302. flex-shrink: 0;
  303. }
  304. @keyframes skeleton-wave {
  305. 0% { background-position: 200% 0; }
  306. 100% { background-position: -200% 0; }
  307. }
  308. /* ---- Bookcase ---- */
  309. .bs-bookcase {
  310. position: relative;
  311. }
  312. /* 书架顶部装饰线 */
  313. .bs-shelf-top-border {
  314. height: 6rpx;
  315. margin: 0 28rpx;
  316. background: linear-gradient(90deg,
  317. transparent 0%,
  318. #8B7355 10%,
  319. #A0896A 30%,
  320. #C4A882 50%,
  321. #A0896A 70%,
  322. #8B7355 90%,
  323. transparent 100%
  324. );
  325. border-radius: 3rpx;
  326. }
  327. /* ---- Books Scroll ---- */
  328. .bs-books-scroll {
  329. white-space: nowrap;
  330. padding: 20rpx 0 0;
  331. width: 100%;
  332. }
  333. .bs-books-inner {
  334. display: inline-flex;
  335. flex-direction: row;
  336. align-items: flex-start;
  337. }
  338. .bs-book-spacer {
  339. width: 28rpx;
  340. flex-shrink: 0;
  341. }
  342. /* ---- Single Book (竖版封面) ---- */
  343. .bs-book-wrap {
  344. display: flex;
  345. flex-direction: column;
  346. align-items: center;
  347. flex-shrink: 0;
  348. margin-right: 24rpx;
  349. position: relative;
  350. }
  351. .bs-book-cover {
  352. width: 200rpx;
  353. height: 280rpx;
  354. border-radius: 8rpx 8rpx 4rpx 4rpx;
  355. position: relative;
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. overflow: hidden;
  360. box-shadow:
  361. 4rpx 0 10rpx rgba(0,0,0,0.18),
  362. -2rpx 0 4rpx rgba(0,0,0,0.08),
  363. 0 6rpx 14rpx rgba(0,0,0,0.12);
  364. transition: transform 0.18s, box-shadow 0.18s;
  365. }
  366. .bs-book-wrap:active .bs-book-cover {
  367. transform: translateY(-6rpx) scale(1.02);
  368. box-shadow:
  369. 6rpx 0 14rpx rgba(0,0,0,0.25),
  370. -3rpx 0 6rpx rgba(0,0,0,0.1),
  371. 0 10rpx 22rpx rgba(0,0,0,0.18);
  372. }
  373. /* 封面图 */
  374. .bs-cover-img {
  375. width: 100%;
  376. height: 100%;
  377. }
  378. /* 无封面图时:渐变底 + 书名 */
  379. .bs-cover-text {
  380. width: 100%;
  381. height: 100%;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. padding: 20rpx 16rpx;
  386. box-sizing: border-box;
  387. }
  388. .bs-cover-title {
  389. font-size: 24rpx;
  390. font-weight: 700;
  391. line-height: 1.5;
  392. letter-spacing: 1rpx;
  393. text-align: center;
  394. overflow: hidden;
  395. text-overflow: ellipsis;
  396. display: -webkit-box;
  397. -webkit-line-clamp: 4;
  398. -webkit-box-orient: vertical;
  399. word-break: break-all;
  400. }
  401. /* 底部分类标签 */
  402. .bs-cover-bottom {
  403. position: absolute;
  404. bottom: 0;
  405. left: 0;
  406. right: 0;
  407. display: flex;
  408. justify-content: center;
  409. padding: 10rpx 0 12rpx;
  410. background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.25) 100%);
  411. }
  412. .bs-cover-category {
  413. font-size: 16rpx;
  414. font-weight: 600;
  415. padding: 3rpx 8rpx;
  416. border-radius: 4rpx;
  417. max-width: 160rpx;
  418. overflow: hidden;
  419. text-overflow: ellipsis;
  420. white-space: nowrap;
  421. display: inline-block;
  422. text-align: center;
  423. }
  424. /* 右侧书页切边(3D效果) */
  425. .bs-cover-edge {
  426. position: absolute;
  427. top: 10rpx;
  428. bottom: 10rpx;
  429. right: 0;
  430. width: 6rpx;
  431. background: linear-gradient(180deg,
  432. rgba(0,0,0,0.25) 0%,
  433. rgba(0,0,0,0.1) 50%,
  434. rgba(0,0,0,0.2) 100%
  435. );
  436. border-radius: 0 4rpx 4rpx 0;
  437. }
  438. /* 封面底部投影(书架效果) */
  439. .bs-book-shadow {
  440. width: 160rpx;
  441. height: 14rpx;
  442. margin-top: 8rpx;
  443. border-radius: 50%;
  444. background: radial-gradient(ellipse at center, rgba(0,0,0,0.18) 0%, rgba(0,0,0,0) 70%);
  445. flex-shrink: 0;
  446. }
  447. /* ---- 书架底板 ---- */
  448. .bs-shelf-bottom {
  449. position: relative;
  450. height: 24rpx;
  451. margin: 0 20rpx;
  452. }
  453. .bs-shelf-plank {
  454. position: absolute;
  455. bottom: 0;
  456. left: 0;
  457. right: 0;
  458. height: 14rpx;
  459. background: linear-gradient(180deg, #C4A882 0%, #A0896A 100%);
  460. border-radius: 2rpx;
  461. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.15);
  462. }
  463. .bs-shelf-bracket {
  464. position: absolute;
  465. bottom: 6rpx;
  466. width: 16rpx;
  467. height: 20rpx;
  468. background: #8B7355;
  469. border-radius: 2rpx 2rpx 0 0;
  470. }
  471. .bs-shelf-bracket-left { left: 32rpx; }
  472. .bs-shelf-bracket-right { right: 32rpx; }
  473. /* ---- Page Dots ---- */
  474. .bs-page-dots {
  475. display: flex;
  476. flex-direction: row;
  477. justify-content: center;
  478. padding-top: 16rpx;
  479. gap: 8rpx;
  480. }
  481. .bs-dot {
  482. width: 10rpx;
  483. height: 10rpx;
  484. border-radius: 50%;
  485. background: #D1D5DB;
  486. transition: all 0.25s;
  487. }
  488. .bs-dot-active {
  489. background: #8B7355;
  490. width: 24rpx;
  491. border-radius: 5rpx;
  492. }
  493. </style>