| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <template>
- <view class="container">
- <!-- 品牌头部 -->
- <view class="brand-header">
- <image class="brand-logo" src="/static/logo.png" mode="aspectFit" />
- <text class="brand-title">心智成长</text>
- <text class="brand-slogan">探索内心世界,培养健康心智</text>
- </view>
- <!-- 功能入口 -->
- <view class="func-section" v-if="sectionVisible('func_entries')">
- <view class="func-grid">
- <view class="func-item" v-for="item in funcList" :key="item.label">
- <view class="func-icon-wrap">
- <text class="func-icon">{{ item.icon }}</text>
- </view>
- <text class="func-label">{{ item.label }}</text>
- </view>
- </view>
- </view>
- <!-- 每日心理 -->
- <view class="section" v-if="sectionVisible('daily_tip')">
- <view class="section-header">
- <text class="section-title">每日心理</text>
- </view>
- <view class="tip-card">
- <view class="tip-left-bar"></view>
- <view class="tip-body">
- <text class="tip-title">{{ dailyTip.title }}</text>
- <text class="tip-content">{{ dailyTip.content }}</text>
- <view class="tip-footer">
- <text class="tip-source">{{ dailyTip.source }}</text>
- </view>
- </view>
- </view>
- </view>
- <!-- 推荐阅读 -->
- <view class="section" v-if="sectionVisible('recommended_reading')">
- <view class="section-header">
- <text class="section-title">推荐阅读</text>
- </view>
- <view class="article-list">
- <view class="article-card" v-for="article in articles" :key="article.id" @click="goArticleDetail(article.id)">
- <view class="article-category" :style="{ background: article.categoryColor }">
- <text class="article-category-text">{{ article.category }}</text>
- </view>
- <text class="article-title">{{ article.title }}</text>
- <text class="article-summary">{{ article.summary }}</text>
- <view class="article-meta">
- <view class="meta-item">
- <text class="meta-icon">📖</text>
- <text class="meta-text">{{ article.views }}</text>
- </view>
- <view class="meta-item">
- <text class="meta-icon">👍</text>
- <text class="meta-text">{{ article.likes }}</text>
- </view>
- <text class="article-date">{{ article.date }}</text>
- </view>
- </view>
- </view>
- </view>
- <!-- 会员专属内容(后台可配置,登录后可见) -->
- <view class="section" v-if="sectionVisible('premium_content')">
- <view class="section-header">
- <text class="section-title">👑 会员专属</text>
- </view>
- <view class="premium-card">
- <text class="premium-text">深度心智测评报告、个性化成长方案等会员专属内容</text>
- </view>
- </view>
- <!-- 底部占位 -->
- <view class="bottom-spacer"></view>
- </view>
- </template>
- <script>
- import { getVisibleSections, getFeaturedArticles } from '../../utils/api.js'
- export default {
- data() {
- return {
- visibleSections: [],
- funcList: [
- { icon: '\u{1F4D6}', label: '阅读' },
- { icon: '\u{1F9E9}', label: '认知' },
- { icon: '\u{1F4AA}', label: '专注' },
- { icon: '\u{1F3AF}', label: '决策' },
- { icon: '\u{1F31F}', label: '心智测评' }
- ],
- dailyTip: {
- title: '成长型思维',
- content: '拥有成长型思维的孩子相信自己的能力可以通过努力提升,他们更愿意接受挑战,从失败中学习。作为家长,多鼓励孩子的努力而非天赋,可以帮助孩子建立成长型思维。',
- source: '—— 卡罗尔·德韦克《终身成长》'
- },
- articles: []
- }
- },
- onShow() {
- this.resetTabBar()
- this.loadSectionConfig()
- this.loadFeaturedArticles()
- },
- methods: {
- resetTabBar() {
- uni.setTabBarItem({ index: 1, text: '身体' })
- uni.setTabBarItem({ index: 2, text: '心智' })
- },
- async loadSectionConfig() {
- var token = uni.getStorageSync('token')
- var role = null
- if (token) {
- role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
- }
- var res
- try {
- res = await getVisibleSections({ pageKey: 'mind', role: role })
- if (res.code === 200 && res.data) {
- this.visibleSections = res.data.map(function(s) { return s.sectionKey })
- }
- } catch (e) {
- // 默认显示所有公开区块
- this.visibleSections = ['func_entries', 'daily_tip', 'recommended_reading']
- }
- },
- sectionVisible(sectionKey) {
- return this.visibleSections.indexOf(sectionKey) !== -1
- },
- async loadFeaturedArticles() {
- try {
- const res = await getFeaturedArticles({ size: 5 })
- if (res.code === 200 && res.data) {
- const gradientColors = [
- 'linear-gradient(135deg, #8B5CF6, #A78BFA)',
- 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
- 'linear-gradient(135deg, #10B981, #34D399)',
- 'linear-gradient(135deg, #8B5CF6, #C084FC)',
- 'linear-gradient(135deg, #F97316, #FB923C)'
- ]
- let list = Array.isArray(res.data) ? res.data : (res.data.records || [])
- this.articles = 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',
- likes: '0',
- date: item.publishedAt ? item.publishedAt.slice(0, 10) : ''
- }
- })
- }
- } catch (e) {
- // 静默处理,保持空列表
- }
- },
- goArticleDetail(id) {
- var token = uni.getStorageSync('token')
- if (token) {
- uni.navigateTo({ url: '/pages/mind/article-detail?id=' + id })
- } else {
- uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/mind/index') })
- }
- }
- }
- }
- </script>
- <style scoped>
- .container {
- min-height: 100vh;
- background: #f5f7fa;
- padding-bottom: 120rpx;
- }
- /* ===== 品牌头部 ===== */
- .brand-header {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 30rpx 30rpx 16rpx;
- background: linear-gradient(180deg, #1A2A4A 0%, #1E3A5F 60%, #f5f7fa 100%);
- }
- .brand-logo {
- width: 80rpx;
- height: 80rpx;
- border-radius: 18rpx;
- margin-bottom: 8rpx;
- }
- .brand-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #8FC5E8;
- letter-spacing: 4rpx;
- }
- .brand-slogan {
- font-size: 22rpx;
- color: rgba(143, 197, 232, 0.6);
- margin-top: 6rpx;
- }
- /* ===== 功能入口 ===== */
- .func-section {
- margin: 20rpx 30rpx;
- }
- .func-grid {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- background: #fff;
- border-radius: 20rpx;
- padding: 24rpx 16rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .func-item {
- display: flex;
- flex-direction: column;
- align-items: center;
- flex: 1;
- }
- .func-icon-wrap {
- width: 80rpx;
- height: 80rpx;
- border-radius: 40rpx;
- background: linear-gradient(135deg, #D6EAF8, #EBF2FA);
- display: flex;
- align-items: center;
- justify-content: center;
- margin-bottom: 10rpx;
- }
- .func-icon {
- font-size: 40rpx;
- }
- .func-label {
- font-size: 22rpx;
- color: #666;
- font-weight: 500;
- }
- /* ===== 通用区块 ===== */
- .section {
- margin: 20rpx 30rpx;
- }
- .section-header {
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- /* ===== 每日心理 ===== */
- .tip-card {
- background: #fff;
- border-radius: 20rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- display: flex;
- flex-direction: row;
- overflow: hidden;
- }
- .tip-left-bar {
- width: 6rpx;
- background: linear-gradient(180deg, #5B9BD5, #8FC5E8);
- flex-shrink: 0;
- }
- .tip-body {
- flex: 1;
- padding: 28rpx 24rpx;
- }
- .tip-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #5B9BD5;
- display: block;
- margin-bottom: 12rpx;
- }
- .tip-content {
- font-size: 24rpx;
- color: #666;
- line-height: 1.6;
- display: block;
- margin-bottom: 16rpx;
- }
- .tip-footer {
- display: flex;
- flex-direction: row;
- justify-content: flex-end;
- }
- .tip-source {
- font-size: 22rpx;
- color: #bbb;
- }
- /* ===== 推荐阅读 ===== */
- .article-list {
- display: flex;
- flex-direction: column;
- gap: 20rpx;
- }
- .article-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 28rpx 24rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- }
- .article-category {
- display: inline-block;
- padding: 4rpx 18rpx;
- border-radius: 20rpx;
- margin-bottom: 14rpx;
- }
- .article-category-text {
- font-size: 20rpx;
- color: #fff;
- font-weight: 500;
- }
- .article-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 10rpx;
- }
- .article-summary {
- font-size: 24rpx;
- color: #888;
- line-height: 1.5;
- display: block;
- margin-bottom: 20rpx;
- }
- .article-meta {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- }
- .meta-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- margin-right: 20rpx;
- }
- .meta-icon {
- font-size: 22rpx;
- margin-right: 4rpx;
- }
- .meta-text {
- font-size: 22rpx;
- color: #bbb;
- }
- .article-date {
- font-size: 22rpx;
- color: #bbb;
- margin-left: auto;
- }
- /* ===== 会员专属 ===== */
- .premium-card {
- background: linear-gradient(135deg, #D6EAF8, #EBF2FA);
- border-radius: 20rpx;
- padding: 30rpx 24rpx;
- text-align: center;
- }
- .premium-text {
- font-size: 26rpx;
- color: #3A7CC4;
- line-height: 1.5;
- }
- /* ===== 底部 ===== */
- .bottom-spacer {
- height: 120rpx;
- }
- </style>
|