ArticleBookshelf.vue 13 KB

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