index.vue 14 KB

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