ArticleBookshelf.vue 14 KB

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