| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698 |
- <template>
- <view class="container">
- <!-- 自定义导航栏 -->
- <view class="nav-header">
- <view class="nav-left" @click="onBack">
- <text class="nav-back-icon">←</text>
- </view>
- <view class="nav-search" @click="focusSearch">
- <text class="nav-search-icon">🔍</text>
- <input
- v-if="searchFocused || searchKeyword"
- class="nav-search-input"
- v-model="searchKeyword"
- placeholder="搜索文章..."
- confirm-type="search"
- @confirm="onSearch"
- @blur="onSearchBlur"
- />
- <text v-else class="nav-search-placeholder">搜索文章...</text>
- </view>
- <view class="nav-right" @click="goCreate">
- <text class="nav-add-btn">+</text>
- </view>
- </view>
- <scroll-view scroll-y class="page-scroll" @scrolltolower="onLoadMore">
- <!-- 品牌头部 -->
- <PageBanner :theme="bannerTheme"
- :tagline="bannerTagline"
- :quote="bannerQuote" />
- <!-- 维度筛选 -->
- <view class="filter-section">
- <scroll-view scroll-x enable-flex show-scrollbar="false" class="dimension-scroll">
- <view class="filter-chips">
- <view
- v-for="dim in dimensionList"
- :key="dim.code"
- :class="['filter-chip', currentDimension === dim.code ? 'active' : '']"
- :style="dim.activeStyle"
- @click="onDimensionChange(dim.code)"
- >
- {{ dim.label }}
- </view>
- </view>
- </scroll-view>
- </view>
- <!-- 分类筛选 -->
- <view class="filter-section" v-if="categoryList.length > 1">
- <scroll-view scroll-x enable-flex show-scrollbar="false" class="category-scroll">
- <view class="filter-chips">
- <view
- v-for="cat in categoryList"
- :key="cat.value"
- :class="['filter-chip', currentCategory === cat.value ? 'active' : '']"
- @click="onCategoryChange(cat.value)"
- >
- {{ cat.label }}
- </view>
- </view>
- </scroll-view>
- </view>
- <!-- 全部文章 -->
- <view class="all-articles-section">
- <view class="section-header">
- <text class="section-title">全部文章</text>
- <text class="section-subtitle" v-if="total > 0">共 {{ total }} 篇</text>
- </view>
- <view v-if="loading && articles.length === 0" class="loading-wrap">
- <text class="loading-text">加载中...</text>
- </view>
- <view v-else-if="articles.length === 0" class="empty-wrap">
- <text class="empty-icon">📚</text>
- <text class="empty-text">暂无相关知识</text>
- </view>
- <view v-else class="article-grid">
- <view
- v-for="item in articles"
- :key="item.id"
- class="article-card"
- @click="goDetail(item.id)"
- >
- <image
- class="article-cover"
- :src="getImageUrl(item.coverImage) || '/static/default-article.png'"
- mode="aspectFill"
- />
- <view class="article-body">
- <view class="article-meta">
- <text class="article-category">{{ item.categoryName || '知识' }}</text>
- <view class="article-type-tags">
- <text v-if="item.contentType" class="type-tag" :class="'type-' + item.contentType">{{ contentTypeLabel(item.contentType) }}</text>
- <text v-if="item.difficultyLevel > 0" class="difficulty-tag">{{ '★'.repeat(item.difficultyLevel) }}</text>
- </view>
- </view>
- <text class="article-title">{{ item.title }}</text>
- <text class="article-summary">{{ item.summary || item.content }}</text>
- <view class="article-footer">
- <text class="article-author">{{ item.author || '浠艾福' }}</text>
- <text class="article-read-count">阅读 {{ item.readCount || 0 }}</text>
- </view>
- </view>
- </view>
- </view>
- <view v-if="loadingMore" class="loading-more">
- <text class="loading-text">加载中...</text>
- </view>
- <view v-if="noMore && articles.length > 0" class="no-more">
- <text class="no-more-text">— 没有更多了 —</text>
- </view>
- <view v-if="!isLoggedIn" class="login-hint-bar">
- <text class="login-hint-text">🔒 登录后解锁全部内容</text>
- </view>
- </view>
- <view class="bottom-spacer"></view>
- </scroll-view>
- </view>
- </template>
- <script>
- import PageBanner from '../../components/PageBanner.vue'
- import { getArticleCategories, getArticleList, getFeaturedArticles } from '../../utils/api.js'
- import config from '@/config.js'
- var dimensionConfig = {
- all: { label: '全部', color: '#64748B', theme: 'mind-wisdom', tagline: '探索知识,滋养成长', quote: '学而时习之,不亦说乎' },
- body: { label: '身', color: '#FF8C42', theme: 'health', tagline: '主动健康,从知识开始', quote: '健康是人生的第一财富' },
- mind: { label: '心', color: '#FF6B9D', theme: 'mind-wisdom', tagline: '探索内心世界,培养健康心智', quote: '知己知彼,百战不殆' },
- wisdom: { label: '智', color: '#6366F1', theme: 'wisdom', tagline: '聪明学习,快乐成长', quote: '学而不思则罔,思而不学则殆' },
- action:{ label: '行', color: '#10B981', theme: 'action', tagline: '知行合一,方得始终', quote: '纸上得来终觉浅,绝知此事要躬行' },
- wealth:{ label: '富', color: '#F59E0B', theme: 'wealth', tagline: '理财智慧,从小培养', quote: '君子爱财,取之有道' }
- }
- export default {
- components: { PageBanner },
- data() {
- return {
- currentDimension: 'all',
- categoryList: [{ id: '', name: '全部' }],
- categoryMap: {},
- currentCategory: '',
- articles: [],
- featuredArticles: [],
- page: 1,
- size: 10,
- total: 0,
- loading: false,
- loadingMore: false,
- noMore: false,
- isLoggedIn: false,
- searchKeyword: '',
- searchFocused: false
- }
- },
- computed: {
- dimensionList: function() {
- var self = this
- return Object.keys(dimensionConfig).map(function(k) {
- var cfg = dimensionConfig[k]
- var activeStyle = ''
- if (k === self.currentDimension) {
- activeStyle = 'background:' + cfg.color + ';color:#fff;'
- }
- return { code: k, label: cfg.label, color: cfg.color, activeStyle: activeStyle }
- })
- },
- bannerTheme: function() {
- return dimensionConfig[this.currentDimension] ? dimensionConfig[this.currentDimension].theme : 'mind-wisdom'
- },
- bannerTagline: function() {
- return dimensionConfig[this.currentDimension] ? dimensionConfig[this.currentDimension].tagline : ''
- },
- bannerQuote: function() {
- return dimensionConfig[this.currentDimension] ? dimensionConfig[this.currentDimension].quote : ''
- }
- },
- onLoad: function(options) {
- this.isLoggedIn = !!uni.getStorageSync('token')
- this.loadFeaturedArticles()
- if (options && options.dimension && dimensionConfig[options.dimension]) {
- this.currentDimension = options.dimension
- }
- this.loadCategories()
- },
- onShow: function() {
- this.isLoggedIn = !!uni.getStorageSync('token')
- },
- methods: {
- loadFeaturedArticles: function() {
- var self = this
- getFeaturedArticles({ size: 5 }).then(function(res) {
- if (res.code === 200 && res.data) {
- var gradientColors = [
- 'linear-gradient(135deg, #6366F1, #818CF8)',
- 'linear-gradient(135deg, #8B5CF6, #A78BFA)',
- 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
- 'linear-gradient(135deg, #10B981, #34D399)',
- 'linear-gradient(135deg, #F97316, #FB923C)'
- ]
- var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
- self.featuredArticles = list.map(function(item, index) {
- return {
- id: item.id,
- category: item.categoryName || '成长文章',
- categoryColor: gradientColors[index % gradientColors.length],
- title: item.title || '',
- summary: item.summary || '',
- views: item.viewCount ? String(item.viewCount) : '0',
- date: item.publishedAt ? item.publishedAt.slice(0, 10) : ''
- }
- })
- }
- }).catch(function() {})
- },
- contentTypeLabel: function(type) {
- var labels = { article: '文章', knowledge: '知识点', course: '课程', tip: '贴士' }
- return labels[type] || type
- },
- async loadCategories() {
- try {
- const res = await getArticleCategories()
- if (res.code === 200 && res.data) {
- const cats = Array.isArray(res.data) ? res.data : []
- var map = {}
- cats.forEach(function(c) { map[c.id] = c.name })
- this.categoryMap = map
- this.categoryList = [{ id: '', name: '全部' }].concat(cats)
- }
- } catch (e) {
- this.categoryList = [
- { id: '', name: '全部' },
- { id: 1, name: '心理健康' },
- { id: 2, name: '情绪管理' }
- ]
- }
- this.loadArticles()
- },
- onDimensionChange: function(code) {
- this.currentDimension = code
- this.page = 1
- this.articles = []
- this.noMore = false
- this.loadArticles()
- },
- onCategoryChange: function(id) {
- this.currentCategory = id
- this.page = 1
- this.articles = []
- this.noMore = false
- this.loadArticles()
- },
- async loadArticles() {
- if (this.loading) return
- this.loading = true
- try {
- var params = { page: this.page, size: this.size }
- if (this.currentCategory) {
- params.categoryId = this.currentCategory
- }
- if (this.currentDimension !== 'all') {
- params.dimensionCode = this.currentDimension
- }
- if (this.searchKeyword && this.searchKeyword.trim()) {
- params.keyword = this.searchKeyword.trim()
- }
- const res = await getArticleList(params)
- if (res.code === 200 && res.data) {
- var pageData = res.data
- var list = pageData.records || []
- var mapped = list.map(function(item) {
- return {
- id: item.id,
- title: item.title || '',
- summary: item.summary || '',
- content: item.content || '',
- coverImage: item.coverImage || '',
- author: item.author || '浠艾福',
- categoryName: item.categoryName || item.category || '',
- publishDate: item.publishedAt ? item.publishedAt.slice(0, 10) : '',
- readCount: item.viewCount || 0,
- contentType: item.contentType || '',
- difficultyLevel: item.difficultyLevel || 0
- }
- })
- if (this.page === 1) {
- this.articles = mapped
- } else {
- this.articles = this.articles.concat(mapped)
- }
- this.total = pageData.total || 0
- this.noMore = this.articles.length >= this.total
- } else {
- if (this.page === 1) {
- this.articles = []
- }
- }
- } catch (e) {
- uni.showToast({ title: '加载失败', icon: 'none' })
- } finally {
- this.loading = false
- }
- },
- onLoadMore() {
- if (this.noMore || this.loading) return
- this.page++
- this.loadArticles()
- },
- goDetail(id) {
- uni.navigateTo({ url: '/pages/article-center/article-detail?id=' + id })
- },
- goCreate() {
- if (this.isLoggedIn) {
- uni.navigateTo({ url: '/pages/article-center/article-edit' })
- } else {
- uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/mind-extra/articles') })
- }
- },
- onBack() {
- uni.navigateBack()
- },
- focusSearch: function() {
- this.searchFocused = true
- },
- onSearch: function() {
- this.page = 1
- this.articles = []
- this.noMore = false
- this.loadArticles()
- },
- onSearchBlur: function() {
- if (!this.searchKeyword) {
- this.searchFocused = false
- }
- },
- getImageUrl: function(path) {
- return config.API_BASE_URL + path
- }
- }
- }
- </script>
- <style scoped>
- .container {
- display: flex;
- flex-direction: column;
- height: 100vh;
- background: #f5f7fa;
- }
- /* 自定义导航栏 */
- .nav-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 80rpx 24rpx 16rpx;
- background: linear-gradient(135deg, #667eea, #764ba2);
- position: relative;
- z-index: 20;
- }
- .nav-left {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .nav-back-icon {
- font-size: 36rpx;
- color: #fff;
- font-weight: bold;
- }
- .nav-search {
- flex: 1;
- display: flex;
- align-items: center;
- background: rgba(255,255,255,0.25);
- border-radius: 32rpx;
- padding: 10rpx 20rpx;
- margin: 0 16rpx;
- }
- .nav-search-icon {
- font-size: 24rpx;
- margin-right: 10rpx;
- flex-shrink: 0;
- }
- .nav-search-placeholder {
- font-size: 24rpx;
- color: rgba(255,255,255,0.7);
- }
- .nav-search-input {
- flex: 1;
- font-size: 24rpx;
- color: #fff;
- background: transparent;
- }
- .nav-search-input::placeholder {
- color: rgba(255,255,255,0.7);
- }
- .nav-right {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .nav-add-btn {
- font-size: 48rpx;
- color: #fff;
- font-weight: 300;
- line-height: 1;
- }
- /* 页面滚动容器 */
- .page-scroll {
- flex: 1;
- }
- /* 区块通用标题 */
- .section-header {
- display: flex;
- align-items: baseline;
- padding: 0 4rpx;
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- .section-subtitle {
- font-size: 24rpx;
- color: #999;
- margin-left: 12rpx;
- }
- /* ===== 推荐阅读 ===== */
- .featured-section {
- margin: 24rpx 24rpx 16rpx;
- padding: 0 4rpx;
- }
- .featured-grid {
- display: flex;
- flex-direction: column;
- }
- .featured-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 28rpx 24rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- margin-bottom: 20rpx;
- }
- .featured-card:active {
- opacity: 0.8;
- }
- .featured-category {
- display: inline-block;
- padding: 4rpx 18rpx;
- border-radius: 20rpx;
- margin-bottom: 14rpx;
- }
- .featured-category-text {
- font-size: 20rpx;
- color: #fff;
- font-weight: 500;
- }
- .featured-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 10rpx;
- line-height: 1.4;
- }
- .featured-summary {
- font-size: 24rpx;
- color: #888;
- line-height: 1.5;
- display: block;
- margin-bottom: 16rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
- .featured-meta {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .featured-views {
- font-size: 22rpx;
- color: #bbb;
- margin-right: 20rpx;
- }
- .featured-date {
- font-size: 22rpx;
- color: #bbb;
- margin-left: auto;
- }
- /* ===== 全部文章 ===== */
- .all-articles-section {
- margin: 8rpx 24rpx 0;
- padding: 0 4rpx;
- }
- /* 筛选条 */
- .filter-section {
- background: #fff;
- padding: 16rpx 0 12rpx;
- border-bottom: 1rpx solid #eee;
- }
- .dimension-scroll,
- .category-scroll {
- white-space: nowrap;
- }
- .dimension-scroll {
- border-bottom: 1rpx solid #f0f0f0;
- padding-bottom: 12rpx;
- }
- .filter-chips {
- display: flex;
- padding: 0 20rpx;
- gap: 16rpx;
- }
- .filter-chip {
- display: inline-block;
- padding: 8rpx 24rpx;
- font-size: 24rpx;
- color: #666;
- background: #f0f0f0;
- border-radius: 30rpx;
- flex-shrink: 0;
- }
- .filter-chip.active {
- background: #5B9BD5;
- color: #fff;
- }
- .filter-chip:first-child {
- margin-left: 4rpx;
- }
- /* 文章元信息标签 */
- .article-meta {
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- margin-bottom: 10rpx;
- }
- .article-type-tags {
- display: flex;
- align-items: center;
- gap: 8rpx;
- margin-left: auto;
- }
- .type-tag {
- font-size: 18rpx;
- padding: 2rpx 10rpx;
- border-radius: 6rpx;
- background: #f0f0f0;
- color: #666;
- }
- .type-tag.type-article {
- background: #e8f4fd;
- color: #2b7fc4;
- }
- .type-tag.type-knowledge {
- background: #e8f8ee;
- color: #2a9055;
- }
- .type-tag.type-course {
- background: #fef3e2;
- color: #c47a2b;
- }
- .type-tag.type-tip {
- background: #f3e8fd;
- color: #7b2bc4;
- }
- .difficulty-tag {
- font-size: 18rpx;
- color: #f59e0b;
- }
- .loading-wrap,
- .empty-wrap {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-top: 120rpx;
- }
- .loading-text {
- font-size: 26rpx;
- color: #999;
- }
- .empty-icon {
- font-size: 100rpx;
- margin-bottom: 24rpx;
- }
- .empty-text {
- font-size: 28rpx;
- color: #999;
- }
- .article-grid {
- padding: 20rpx 24rpx;
- }
- .article-card {
- background: #fff;
- border-radius: 16rpx;
- overflow: hidden;
- margin-bottom: 20rpx;
- box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
- }
- .article-cover {
- width: 100%;
- height: 280rpx;
- background: linear-gradient(135deg, #667eea, #764ba2);
- }
- .article-body {
- padding: 20rpx;
- }
- .article-category {
- font-size: 20rpx;
- color: #5B9BD5;
- background: rgba(91,155,213,0.1);
- padding: 2rpx 12rpx;
- border-radius: 8rpx;
- margin-right: 12rpx;
- }
- .article-date {
- font-size: 20rpx;
- color: #999;
- }
- .article-title {
- display: block;
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- margin-bottom: 8rpx;
- line-height: 1.4;
- }
- .article-summary {
- display: block;
- font-size: 24rpx;
- color: #666;
- line-height: 1.5;
- margin-bottom: 12rpx;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
- .article-footer {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .article-author {
- font-size: 20rpx;
- color: #999;
- }
- .article-read-count {
- font-size: 20rpx;
- color: #bbb;
- }
- .loading-more,
- .no-more {
- text-align: center;
- padding: 30rpx;
- }
- .no-more-text {
- font-size: 24rpx;
- color: #ccc;
- }
- /* 未登录提示 */
- .login-hint-bar {
- text-align: center;
- padding: 20rpx;
- background: #fef9e7;
- border-top: 1rpx solid #f0e6c0;
- margin: 20rpx 24rpx 0;
- border-radius: 12rpx;
- }
- .login-hint-text {
- font-size: 24rpx;
- color: #b8860b;
- }
- /* 底部占位 */
- .bottom-spacer {
- height: 120rpx;
- }
- </style>
|