index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <view class="ac-container">
  3. <!-- 自定义导航栏 -->
  4. <view class="ac-nav">
  5. <view class="ac-nav-left" @click="onBack">
  6. <text class="ac-nav-back">&#x2190;</text>
  7. </view>
  8. <text class="ac-nav-title">知识中心</text>
  9. <view class="ac-nav-right">
  10. <text class="ac-nav-search-icon" @click="focusSearch">&#x1F50D;</text>
  11. <text class="ac-nav-add" @click="goEdit">+</text>
  12. </view>
  13. </view>
  14. <!-- 搜索栏(聚焦时展开) -->
  15. <view v-if="searchFocused || searchKeyword" class="ac-search-bar">
  16. <input
  17. class="ac-search-input"
  18. v-model="searchKeyword"
  19. placeholder="搜索文章..."
  20. confirm-type="search"
  21. @confirm="onSearch"
  22. @blur="onSearchBlur"
  23. />
  24. <text class="ac-search-cancel" @click="searchKeyword = ''; searchFocused = false; onSearch()">取消</text>
  25. </view>
  26. <!-- Tab 导航(药丸式) -->
  27. <view class="ac-tabs">
  28. <scroll-view scroll-x show-scrollbar="false" class="ac-tab-scroll">
  29. <view
  30. v-for="tab in tabList"
  31. :key="tab.code"
  32. :class="['ac-tab', currentTab === tab.code ? 'active' : '']"
  33. :style="currentTab === tab.code ? 'background:' + tab.color + ';color:#fff;border-color:' + tab.color : ''"
  34. @click="onTabChange(tab.code)"
  35. >
  36. {{ tab.name }}
  37. </view>
  38. </scroll-view>
  39. </view>
  40. <!-- 书册式推荐阅读 -->
  41. <ArticleBookshelf
  42. v-if="recommendedArticles.length > 0 || !recommendLoading"
  43. :articles="recommendedArticles"
  44. :loading="recommendLoading"
  45. :isLoggedIn="isLoggedIn"
  46. @articleClick="goDetail"
  47. @moreArticles="goExplore"
  48. />
  49. <!-- 文章列表区域 -->
  50. <scroll-view scroll-y class="ac-scroll" @scrolltolower="onLoadMore">
  51. <!-- 骨架屏 -->
  52. <view v-if="loading && articles.length === 0" class="ac-skeleton-wrap">
  53. <view v-for="n in 3" :key="n" class="sk-card">
  54. <view class="sk-cover"></view>
  55. <view class="sk-body">
  56. <view class="sk-row sk-tag"></view>
  57. <view class="sk-row sk-title"></view>
  58. <view class="sk-row sk-desc"></view>
  59. <view class="sk-row sk-footer"></view>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 空状态 -->
  64. <view v-else-if="articles.length === 0" class="ac-empty">
  65. <image class="ac-empty-img" src="/static/empty-article.png" mode="aspectFit"></image>
  66. <text class="ac-empty-text">暂无文章</text>
  67. </view>
  68. <!-- 文章列表 -->
  69. <view v-else class="ac-feed">
  70. <view
  71. v-for="item in articles"
  72. :key="item.id"
  73. class="ac-card"
  74. hover-class="ac-card-pressed"
  75. @click="goDetail(item.id)"
  76. >
  77. <view class="ac-card-media">
  78. <image
  79. class="ac-card-cover"
  80. :src="item.coverImage || '/static/default-article.png'"
  81. mode="aspectFill"
  82. />
  83. <view class="ac-card-dimension-tags" v-if="item.relatedDimensions">
  84. <view
  85. v-for="dim in parseDimensions(item.relatedDimensions)"
  86. :key="dim.code"
  87. class="ac-card-dim-tag"
  88. :style="'background:' + dim.color"
  89. >{{ dim.name }}</view>
  90. </view>
  91. </view>
  92. <view class="ac-card-body">
  93. <view class="ac-card-meta-top">
  94. <text class="ac-card-category" v-if="item.categoryName">{{ item.categoryName }}</text>
  95. <text class="ac-card-readtime">&#x1F4D6; {{ item.readTime || 3 }}分钟</text>
  96. </view>
  97. <text class="ac-card-title">{{ item.title }}</text>
  98. <text class="ac-card-summary" v-if="item.summary">{{ item.summary }}</text>
  99. <view class="ac-card-footer">
  100. <text class="ac-card-author">{{ item.author || '浠艾福' }}</text>
  101. <text class="ac-card-sep">|</text>
  102. <text class="ac-card-date">{{ formatDate(item.publishedAt) }}</text>
  103. <text class="ac-card-fav">&#x2B50; {{ item.favCount || 0 }}</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <!-- 加载更多 / 没有更多 -->
  109. <view v-if="loadingMore" class="ac-loading-more">
  110. <text class="ac-loading-text">加载中...</text>
  111. </view>
  112. <view v-if="noMore && articles.length > 0" class="ac-no-more">
  113. <text class="ac-no-more-text">— 没有更多了 —</text>
  114. </view>
  115. <view class="ac-bottom-gap"></view>
  116. </scroll-view>
  117. <!-- 浮动发布按钮 -->
  118. <view class="ac-fab" @click="goEdit">
  119. <text class="ac-fab-icon">+</text>
  120. </view>
  121. </view>
  122. </template>
  123. <script>
  124. import { getArticleList, getFeaturedArticles } from '@/utils/api.js'
  125. export default {
  126. data() {
  127. return {
  128. tabList: [
  129. { code: '', name: '全部', color: '#F97316' },
  130. { code: 'body', name: '身', color: '#FF8C42' },
  131. { code: 'mind', name: '心', color: '#FF6B9D' },
  132. { code: 'wisdom', name: '智', color: '#6366F1' },
  133. { code: 'action', name: '行', color: '#10B981' },
  134. { code: 'wealth', name: '富', color: '#F59E0B' }
  135. ],
  136. currentTab: '',
  137. articles: [],
  138. page: 1,
  139. size: 10,
  140. total: 0,
  141. loading: false,
  142. loadingMore: false,
  143. noMore: false,
  144. searchKeyword: '',
  145. searchFocused: false,
  146. isLoggedIn: false,
  147. recommendedArticles: [],
  148. recommendLoading: false
  149. }
  150. },
  151. components: {
  152. ArticleBookshelf: () => require('@/components/ArticleBookshelf.vue')
  153. },
  154. onLoad(options) {
  155. // 支持从外部传入 dimension 参数,默认选中对应 tab
  156. if (options && options.dimension) {
  157. this.currentTab = options.dimension
  158. }
  159. this.isLoggedIn = !!uni.getStorageSync('token')
  160. this.loadArticles()
  161. this.loadRecommendedArticles()
  162. },
  163. onShow() {
  164. this.isLoggedIn = !!uni.getStorageSync('token')
  165. },
  166. methods: {
  167. async loadArticles(isLoadMore) {
  168. if (!isLoadMore) {
  169. if (this.loading) return
  170. this.loading = true
  171. this.page = 1
  172. this.articles = []
  173. this.noMore = false
  174. } else {
  175. if (this.loadingMore || this.noMore) return
  176. this.loadingMore = true
  177. }
  178. try {
  179. var params = { page: this.page, size: this.size }
  180. if (this.currentTab) {
  181. params.dimensionCode = this.currentTab
  182. }
  183. if (this.searchKeyword && this.searchKeyword.trim()) {
  184. params.keyword = this.searchKeyword.trim()
  185. }
  186. var res = await getArticleList(params)
  187. if (res.code === 200 && res.data) {
  188. var list = res.data.records || []
  189. if (this.page === 1) {
  190. this.articles = list
  191. } else {
  192. this.articles = this.articles.concat(list)
  193. }
  194. this.total = res.data.total || 0
  195. this.noMore = this.articles.length >= this.total
  196. }
  197. } catch (e) {
  198. uni.showToast({ title: '加载失败', icon: 'none' })
  199. } finally {
  200. this.loading = false
  201. this.loadingMore = false
  202. }
  203. },
  204. onTabChange(code) {
  205. if (this.currentTab === code) return
  206. this.currentTab = code
  207. this.searchKeyword = ''
  208. this.searchFocused = false
  209. this.page = 1
  210. this.articles = []
  211. this.noMore = false
  212. this.loadArticles()
  213. },
  214. async loadRecommendedArticles() {
  215. var self = this
  216. self.recommendLoading = true
  217. try {
  218. var res = await getFeaturedArticles({ size: 8 })
  219. if (res && res.code === 200 && res.data) {
  220. self.recommendedArticles = res.data.list || res.data || []
  221. }
  222. } catch (e) {
  223. // silent fail
  224. } finally {
  225. self.recommendLoading = false
  226. }
  227. },
  228. onLoadMore() {
  229. if (this.noMore || this.loading || this.loadingMore) return
  230. this.page++
  231. this.loadArticles(true)
  232. },
  233. goDetail(idOrArticle) {
  234. var id = idOrArticle && idOrArticle.id ? idOrArticle.id : idOrArticle
  235. uni.navigateTo({ url: '/pages/article-center/article-detail?id=' + id })
  236. },
  237. goEdit() {
  238. var isLoggedIn = !!uni.getStorageSync('token')
  239. if (isLoggedIn) {
  240. uni.navigateTo({ url: '/pages/article-center/article-edit' })
  241. } else {
  242. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/article-center/index') })
  243. }
  244. },
  245. goExplore() {
  246. uni.showToast({ title: '书库即将上线', icon: 'none' })
  247. },
  248. formatDate(dateStr) {
  249. if (!dateStr) return ''
  250. return dateStr.slice(0, 10)
  251. },
  252. parseDimensions(str) {
  253. if (!str) return []
  254. var dimMap = {
  255. body: { code: 'body', color: '#FF8C42', name: '身' },
  256. mind: { code: 'mind', color: '#FF6B9D', name: '心' },
  257. wisdom: { code: 'wisdom', color: '#6366F1', name: '智' },
  258. action: { code: 'action', color: '#10B981', name: '行' },
  259. wealth: { code: 'wealth', color: '#F59E0B', name: '富' }
  260. }
  261. var codes = str.split(',').map(function(s) { return s.trim().toLowerCase() })
  262. return codes.filter(function(c) { return dimMap[c] }).map(function(c) { return dimMap[c] })
  263. },
  264. focusSearch() {
  265. this.searchFocused = true
  266. },
  267. onSearch() {
  268. this.page = 1
  269. this.articles = []
  270. this.noMore = false
  271. this.loadArticles()
  272. },
  273. onSearchBlur() {
  274. if (!this.searchKeyword) {
  275. this.searchFocused = false
  276. }
  277. },
  278. onBack() {
  279. uni.navigateBack()
  280. }
  281. }
  282. }
  283. </script>
  284. <style scoped>
  285. /* ====================================
  286. 知识中心 — 重设计
  287. 白色导航 + 药丸Tab + 精装卡片
  288. ==================================== */
  289. .ac-container {
  290. min-height: 100vh;
  291. background: #f5f7fa;
  292. position: relative;
  293. }
  294. /* ---- 导航栏(白色简约) ---- */
  295. .ac-nav {
  296. display: flex;
  297. align-items: center;
  298. justify-content: space-between;
  299. padding: 84rpx 28rpx 20rpx;
  300. background: #fff;
  301. position: sticky;
  302. top: 0;
  303. z-index: 100;
  304. }
  305. .ac-nav-left {
  306. width: 60rpx;
  307. height: 48rpx;
  308. display: flex;
  309. align-items: center;
  310. justify-content: flex-start;
  311. flex-shrink: 0;
  312. }
  313. .ac-nav-back {
  314. font-size: 36rpx;
  315. color: #333;
  316. font-weight: bold;
  317. }
  318. .ac-nav-title {
  319. font-size: 32rpx;
  320. font-weight: bold;
  321. color: #1a1a1a;
  322. flex: 1;
  323. text-align: center;
  324. }
  325. .ac-nav-right {
  326. display: flex;
  327. align-items: center;
  328. gap: 20rpx;
  329. flex-shrink: 0;
  330. }
  331. .ac-nav-search-icon {
  332. font-size: 32rpx;
  333. color: #666;
  334. }
  335. .ac-nav-add {
  336. font-size: 40rpx;
  337. color: #F97316;
  338. font-weight: 300;
  339. line-height: 1;
  340. }
  341. /* ---- 搜索展开条 ---- */
  342. .ac-search-bar {
  343. display: flex;
  344. align-items: center;
  345. padding: 12rpx 28rpx 16rpx;
  346. background: #fff;
  347. border-bottom: 1rpx solid #f0f0f0;
  348. }
  349. .ac-search-input {
  350. flex: 1;
  351. height: 60rpx;
  352. background: #f5f5f5;
  353. border-radius: 30rpx;
  354. padding: 0 28rpx;
  355. font-size: 26rpx;
  356. color: #333;
  357. }
  358. .ac-search-cancel {
  359. font-size: 26rpx;
  360. color: #999;
  361. margin-left: 16rpx;
  362. flex-shrink: 0;
  363. }
  364. /* ---- Tab 药丸导航 ---- */
  365. .ac-tabs {
  366. padding: 16rpx 28rpx;
  367. background: #fff;
  368. border-bottom: 1rpx solid #f0f0f0;
  369. position: sticky;
  370. z-index: 10;
  371. }
  372. .ac-tab-scroll {
  373. white-space: nowrap;
  374. display: flex;
  375. }
  376. .ac-tab {
  377. display: inline-flex;
  378. align-items: center;
  379. justify-content: center;
  380. height: 52rpx;
  381. padding: 0 28rpx;
  382. margin-right: 16rpx;
  383. font-size: 24rpx;
  384. color: #666;
  385. background: #f0f0f0;
  386. border-radius: 26rpx;
  387. border: 2rpx solid #f0f0f0;
  388. flex-shrink: 0;
  389. transition: all 0.2s;
  390. }
  391. .ac-tab.active {
  392. font-weight: 600;
  393. }
  394. /* ---- 滚动列表区域 ---- */
  395. .ac-scroll {
  396. height: calc(100vh - 200rpx);
  397. }
  398. /* ---- 骨架屏 ---- */
  399. .ac-skeleton-wrap { padding: 24rpx 28rpx; }
  400. .sk-card {
  401. background: #fff;
  402. border-radius: 24rpx;
  403. overflow: hidden;
  404. margin-bottom: 24rpx;
  405. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  406. }
  407. .sk-cover {
  408. height: 340rpx;
  409. background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  410. background-size: 200% 100%;
  411. animation: sk-shimmer 1.5s infinite;
  412. }
  413. .sk-body { padding: 24rpx; }
  414. .sk-row {
  415. height: 22rpx;
  416. background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  417. background-size: 200% 100%;
  418. border-radius: 6rpx;
  419. margin-bottom: 14rpx;
  420. animation: sk-shimmer 1.5s infinite;
  421. }
  422. .sk-tag { width: 20%; }
  423. .sk-title { width: 65%; }
  424. .sk-desc { width: 90%; }
  425. .sk-footer { width: 40%; height: 18rpx; }
  426. @keyframes sk-shimmer {
  427. 0% { background-position: -200% 0; }
  428. 100% { background-position: 200% 0; }
  429. }
  430. /* ---- 空状态 ---- */
  431. .ac-empty {
  432. display: flex;
  433. flex-direction: column;
  434. align-items: center;
  435. padding-top: 240rpx;
  436. }
  437. .ac-empty-img {
  438. width: 200rpx;
  439. height: 200rpx;
  440. margin-bottom: 28rpx;
  441. }
  442. .ac-empty-text {
  443. font-size: 28rpx;
  444. color: #bbb;
  445. }
  446. /* ---- 文章卡片(新版) ---- */
  447. .ac-feed {
  448. padding: 24rpx 28rpx;
  449. }
  450. .ac-card {
  451. background: #fff;
  452. border-radius: 24rpx;
  453. overflow: hidden;
  454. margin-bottom: 24rpx;
  455. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  456. transition: transform 0.15s;
  457. }
  458. .ac-card-pressed {
  459. transform: scale(0.97);
  460. opacity: 0.9;
  461. }
  462. /* 封面 + 维度浮标 */
  463. .ac-card-media {
  464. position: relative;
  465. width: 100%;
  466. overflow: hidden;
  467. }
  468. .ac-card-cover {
  469. display: block;
  470. width: 100%;
  471. height: 340rpx;
  472. background: #f0f0f0;
  473. }
  474. .ac-card-dimension-tags {
  475. position: absolute;
  476. bottom: 12rpx;
  477. left: 16rpx;
  478. display: flex;
  479. gap: 8rpx;
  480. }
  481. .ac-card-dim-tag {
  482. padding: 2rpx 14rpx;
  483. border-radius: 12rpx;
  484. font-size: 20rpx;
  485. color: #fff;
  486. font-weight: 500;
  487. line-height: 1.4;
  488. }
  489. /* 正文区 */
  490. .ac-card-body {
  491. padding: 24rpx 24rpx 28rpx;
  492. }
  493. .ac-card-meta-top {
  494. display: flex;
  495. align-items: center;
  496. margin-bottom: 12rpx;
  497. }
  498. .ac-card-category {
  499. font-size: 20rpx;
  500. color: #F97316;
  501. background: rgba(249,115,22,0.08);
  502. padding: 2rpx 14rpx;
  503. border-radius: 8rpx;
  504. margin-right: 16rpx;
  505. }
  506. .ac-card-readtime {
  507. font-size: 20rpx;
  508. color: #aaa;
  509. }
  510. .ac-card-title {
  511. display: block;
  512. font-size: 30rpx;
  513. font-weight: 600;
  514. color: #1a1a1a;
  515. line-height: 1.45;
  516. margin-bottom: 10rpx;
  517. overflow: hidden;
  518. text-overflow: ellipsis;
  519. display: -webkit-box;
  520. -webkit-line-clamp: 2;
  521. -webkit-box-orient: vertical;
  522. }
  523. .ac-card-summary {
  524. display: block;
  525. font-size: 24rpx;
  526. color: #999;
  527. line-height: 1.5;
  528. margin-bottom: 16rpx;
  529. overflow: hidden;
  530. text-overflow: ellipsis;
  531. display: -webkit-box;
  532. -webkit-line-clamp: 2;
  533. -webkit-box-orient: vertical;
  534. }
  535. .ac-card-footer {
  536. display: flex;
  537. align-items: center;
  538. font-size: 20rpx;
  539. color: #bbb;
  540. }
  541. .ac-card-author {
  542. color: #888;
  543. }
  544. .ac-card-sep {
  545. margin: 0 10rpx;
  546. color: #ddd;
  547. }
  548. .ac-card-date {
  549. flex: 1;
  550. }
  551. .ac-card-fav {
  552. color: #ccc;
  553. }
  554. /* ---- 加载更多 / 没有更多 ---- */
  555. .ac-loading-more,
  556. .ac-no-more {
  557. text-align: center;
  558. padding: 30rpx;
  559. }
  560. .ac-loading-text {
  561. font-size: 24rpx;
  562. color: #bbb;
  563. }
  564. .ac-no-more-text {
  565. font-size: 24rpx;
  566. color: #ddd;
  567. }
  568. .ac-bottom-gap {
  569. height: 140rpx;
  570. }
  571. /* ---- 浮动发布按钮 ---- */
  572. .ac-fab {
  573. position: fixed;
  574. right: 36rpx;
  575. bottom: 100rpx;
  576. width: 96rpx;
  577. height: 96rpx;
  578. background: linear-gradient(135deg, #F97316, #EA580C);
  579. color: #fff;
  580. border-radius: 50%;
  581. display: flex;
  582. align-items: center;
  583. justify-content: center;
  584. box-shadow: 0 6rpx 20rpx rgba(249,115,22,0.35);
  585. z-index: 100;
  586. }
  587. .ac-fab:active {
  588. transform: scale(0.92);
  589. opacity: 0.85;
  590. }
  591. .ac-fab-icon {
  592. font-size: 48rpx;
  593. font-weight: 300;
  594. line-height: 1;
  595. }
  596. </style>