index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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 === 0 && 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(id) {
  234. uni.navigateTo({ url: '/pages/article-center/article-detail?id=' + id })
  235. },
  236. goEdit() {
  237. var isLoggedIn = !!uni.getStorageSync('token')
  238. if (isLoggedIn) {
  239. uni.navigateTo({ url: '/pages/article-center/article-edit' })
  240. } else {
  241. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/article-center/index') })
  242. }
  243. },
  244. goExplore() {
  245. uni.showToast({ title: '书库即将上线', icon: 'none' })
  246. },
  247. formatDate(dateStr) {
  248. if (!dateStr) return ''
  249. return dateStr.slice(0, 10)
  250. },
  251. parseDimensions(str) {
  252. if (!str) return []
  253. var dimMap = {
  254. body: { code: 'body', color: '#FF8C42', name: '身' },
  255. mind: { code: 'mind', color: '#FF6B9D', name: '心' },
  256. wisdom: { code: 'wisdom', color: '#6366F1', name: '智' },
  257. action: { code: 'action', color: '#10B981', name: '行' },
  258. wealth: { code: 'wealth', color: '#F59E0B', name: '富' }
  259. }
  260. var codes = str.split(',').map(function(s) { return s.trim().toLowerCase() })
  261. return codes.filter(function(c) { return dimMap[c] }).map(function(c) { return dimMap[c] })
  262. },
  263. focusSearch() {
  264. this.searchFocused = true
  265. },
  266. onSearch() {
  267. this.page = 1
  268. this.articles = []
  269. this.noMore = false
  270. this.loadArticles()
  271. },
  272. onSearchBlur() {
  273. if (!this.searchKeyword) {
  274. this.searchFocused = false
  275. }
  276. },
  277. onBack() {
  278. uni.navigateBack()
  279. }
  280. }
  281. }
  282. </script>
  283. <style scoped>
  284. /* ====================================
  285. 知识中心 — 重设计
  286. 白色导航 + 药丸Tab + 精装卡片
  287. ==================================== */
  288. .ac-container {
  289. min-height: 100vh;
  290. background: #f5f7fa;
  291. position: relative;
  292. }
  293. /* ---- 导航栏(白色简约) ---- */
  294. .ac-nav {
  295. display: flex;
  296. align-items: center;
  297. justify-content: space-between;
  298. padding: 84rpx 28rpx 20rpx;
  299. background: #fff;
  300. position: sticky;
  301. top: 0;
  302. z-index: 100;
  303. }
  304. .ac-nav-left {
  305. width: 60rpx;
  306. height: 48rpx;
  307. display: flex;
  308. align-items: center;
  309. justify-content: flex-start;
  310. flex-shrink: 0;
  311. }
  312. .ac-nav-back {
  313. font-size: 36rpx;
  314. color: #333;
  315. font-weight: bold;
  316. }
  317. .ac-nav-title {
  318. font-size: 32rpx;
  319. font-weight: bold;
  320. color: #1a1a1a;
  321. flex: 1;
  322. text-align: center;
  323. }
  324. .ac-nav-right {
  325. display: flex;
  326. align-items: center;
  327. gap: 20rpx;
  328. flex-shrink: 0;
  329. }
  330. .ac-nav-search-icon {
  331. font-size: 32rpx;
  332. color: #666;
  333. }
  334. .ac-nav-add {
  335. font-size: 40rpx;
  336. color: #F97316;
  337. font-weight: 300;
  338. line-height: 1;
  339. }
  340. /* ---- 搜索展开条 ---- */
  341. .ac-search-bar {
  342. display: flex;
  343. align-items: center;
  344. padding: 12rpx 28rpx 16rpx;
  345. background: #fff;
  346. border-bottom: 1rpx solid #f0f0f0;
  347. }
  348. .ac-search-input {
  349. flex: 1;
  350. height: 60rpx;
  351. background: #f5f5f5;
  352. border-radius: 30rpx;
  353. padding: 0 28rpx;
  354. font-size: 26rpx;
  355. color: #333;
  356. }
  357. .ac-search-cancel {
  358. font-size: 26rpx;
  359. color: #999;
  360. margin-left: 16rpx;
  361. flex-shrink: 0;
  362. }
  363. /* ---- Tab 药丸导航 ---- */
  364. .ac-tabs {
  365. padding: 16rpx 28rpx;
  366. background: #fff;
  367. border-bottom: 1rpx solid #f0f0f0;
  368. position: sticky;
  369. z-index: 10;
  370. }
  371. .ac-tab-scroll {
  372. white-space: nowrap;
  373. display: flex;
  374. }
  375. .ac-tab {
  376. display: inline-flex;
  377. align-items: center;
  378. justify-content: center;
  379. height: 52rpx;
  380. padding: 0 28rpx;
  381. margin-right: 16rpx;
  382. font-size: 24rpx;
  383. color: #666;
  384. background: #f0f0f0;
  385. border-radius: 26rpx;
  386. border: 2rpx solid #f0f0f0;
  387. flex-shrink: 0;
  388. transition: all 0.2s;
  389. }
  390. .ac-tab.active {
  391. font-weight: 600;
  392. }
  393. /* ---- 滚动列表区域 ---- */
  394. .ac-scroll {
  395. height: calc(100vh - 200rpx);
  396. }
  397. /* ---- 骨架屏 ---- */
  398. .ac-skeleton-wrap { padding: 24rpx 28rpx; }
  399. .sk-card {
  400. background: #fff;
  401. border-radius: 24rpx;
  402. overflow: hidden;
  403. margin-bottom: 24rpx;
  404. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  405. }
  406. .sk-cover {
  407. height: 340rpx;
  408. background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  409. background-size: 200% 100%;
  410. animation: sk-shimmer 1.5s infinite;
  411. }
  412. .sk-body { padding: 24rpx; }
  413. .sk-row {
  414. height: 22rpx;
  415. background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  416. background-size: 200% 100%;
  417. border-radius: 6rpx;
  418. margin-bottom: 14rpx;
  419. animation: sk-shimmer 1.5s infinite;
  420. }
  421. .sk-tag { width: 20%; }
  422. .sk-title { width: 65%; }
  423. .sk-desc { width: 90%; }
  424. .sk-footer { width: 40%; height: 18rpx; }
  425. @keyframes sk-shimmer {
  426. 0% { background-position: -200% 0; }
  427. 100% { background-position: 200% 0; }
  428. }
  429. /* ---- 空状态 ---- */
  430. .ac-empty {
  431. display: flex;
  432. flex-direction: column;
  433. align-items: center;
  434. padding-top: 240rpx;
  435. }
  436. .ac-empty-img {
  437. width: 200rpx;
  438. height: 200rpx;
  439. margin-bottom: 28rpx;
  440. }
  441. .ac-empty-text {
  442. font-size: 28rpx;
  443. color: #bbb;
  444. }
  445. /* ---- 文章卡片(新版) ---- */
  446. .ac-feed {
  447. padding: 24rpx 28rpx;
  448. }
  449. .ac-card {
  450. background: #fff;
  451. border-radius: 24rpx;
  452. overflow: hidden;
  453. margin-bottom: 24rpx;
  454. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  455. transition: transform 0.15s;
  456. }
  457. .ac-card-pressed {
  458. transform: scale(0.97);
  459. opacity: 0.9;
  460. }
  461. /* 封面 + 维度浮标 */
  462. .ac-card-media {
  463. position: relative;
  464. width: 100%;
  465. overflow: hidden;
  466. }
  467. .ac-card-cover {
  468. display: block;
  469. width: 100%;
  470. height: 340rpx;
  471. background: #f0f0f0;
  472. }
  473. .ac-card-dimension-tags {
  474. position: absolute;
  475. bottom: 12rpx;
  476. left: 16rpx;
  477. display: flex;
  478. gap: 8rpx;
  479. }
  480. .ac-card-dim-tag {
  481. padding: 2rpx 14rpx;
  482. border-radius: 12rpx;
  483. font-size: 20rpx;
  484. color: #fff;
  485. font-weight: 500;
  486. line-height: 1.4;
  487. }
  488. /* 正文区 */
  489. .ac-card-body {
  490. padding: 24rpx 24rpx 28rpx;
  491. }
  492. .ac-card-meta-top {
  493. display: flex;
  494. align-items: center;
  495. margin-bottom: 12rpx;
  496. }
  497. .ac-card-category {
  498. font-size: 20rpx;
  499. color: #F97316;
  500. background: rgba(249,115,22,0.08);
  501. padding: 2rpx 14rpx;
  502. border-radius: 8rpx;
  503. margin-right: 16rpx;
  504. }
  505. .ac-card-readtime {
  506. font-size: 20rpx;
  507. color: #aaa;
  508. }
  509. .ac-card-title {
  510. display: block;
  511. font-size: 30rpx;
  512. font-weight: 600;
  513. color: #1a1a1a;
  514. line-height: 1.45;
  515. margin-bottom: 10rpx;
  516. overflow: hidden;
  517. text-overflow: ellipsis;
  518. display: -webkit-box;
  519. -webkit-line-clamp: 2;
  520. -webkit-box-orient: vertical;
  521. }
  522. .ac-card-summary {
  523. display: block;
  524. font-size: 24rpx;
  525. color: #999;
  526. line-height: 1.5;
  527. margin-bottom: 16rpx;
  528. overflow: hidden;
  529. text-overflow: ellipsis;
  530. display: -webkit-box;
  531. -webkit-line-clamp: 2;
  532. -webkit-box-orient: vertical;
  533. }
  534. .ac-card-footer {
  535. display: flex;
  536. align-items: center;
  537. font-size: 20rpx;
  538. color: #bbb;
  539. }
  540. .ac-card-author {
  541. color: #888;
  542. }
  543. .ac-card-sep {
  544. margin: 0 10rpx;
  545. color: #ddd;
  546. }
  547. .ac-card-date {
  548. flex: 1;
  549. }
  550. .ac-card-fav {
  551. color: #ccc;
  552. }
  553. /* ---- 加载更多 / 没有更多 ---- */
  554. .ac-loading-more,
  555. .ac-no-more {
  556. text-align: center;
  557. padding: 30rpx;
  558. }
  559. .ac-loading-text {
  560. font-size: 24rpx;
  561. color: #bbb;
  562. }
  563. .ac-no-more-text {
  564. font-size: 24rpx;
  565. color: #ddd;
  566. }
  567. .ac-bottom-gap {
  568. height: 140rpx;
  569. }
  570. /* ---- 浮动发布按钮 ---- */
  571. .ac-fab {
  572. position: fixed;
  573. right: 36rpx;
  574. bottom: 100rpx;
  575. width: 96rpx;
  576. height: 96rpx;
  577. background: linear-gradient(135deg, #F97316, #EA580C);
  578. color: #fff;
  579. border-radius: 50%;
  580. display: flex;
  581. align-items: center;
  582. justify-content: center;
  583. box-shadow: 0 6rpx 20rpx rgba(249,115,22,0.35);
  584. z-index: 100;
  585. }
  586. .ac-fab:active {
  587. transform: scale(0.92);
  588. opacity: 0.85;
  589. }
  590. .ac-fab-icon {
  591. font-size: 48rpx;
  592. font-weight: 300;
  593. line-height: 1;
  594. }
  595. </style>