- 迁移内容数据到服务端接口,移除本地模拟数据 - 首页新增推荐课程加载与未读消息检查 - 资讯、课程、搜索页面支持分页加载与错误重试 - 登录页新增恢复课程、消息、帮助页的路由逻辑 - 评估分析页新增处理中状态动效与阶段提示 - API 环境切换到正式域名 airz.hqling.cloud
109 lines
7.6 KiB
Plaintext
109 lines
7.6 KiB
Plaintext
<template>
|
|
<view class="page" :style="pageStyle()">
|
|
<AppHeader title="融资课堂" />
|
|
<scroll-view scroll-y :style="contentStyle(96, false)">
|
|
<view class="classroom-content">
|
|
<view class="classroom-hero"><view class="hero-copy"><text class="hero-eyebrow">实用融资知识</text><text class="hero-title">准备更充分</text><text class="hero-title hero-title-next">申请更从容</text><text class="hero-desc">每次几分钟,掌握一个知识点</text></view><image src="/packages/content/static/news-policy.png" mode="aspectFill" class="hero-image"></image></view>
|
|
<view class="topic-section">
|
|
<text class="section-title">按场景学习</text>
|
|
<view class="topic-list">
|
|
<view v-for="item in topics" :key="item.id" :class="activeTopic == item.id ? 'topic-card selected-topic' : 'topic-card'" @click="selectTopic(item.id)">
|
|
<AppIcon :name="item.icon" :size="48" />
|
|
<view class="topic-copy"><text class="topic-title">{{ item.title }}</text><text class="topic-desc">{{ item.desc }}</text></view>
|
|
<text v-if="activeTopic == item.id" class="topic-selected">已选</text><AppIcon v-else name="chevron-right" :size="28" muted />
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="lesson-section">
|
|
<view class="section-head"><text class="section-title">{{ activeTopic == '' ? '精选课程' : activeTopicTitle }}</text><view class="all-lessons" @click="selectTopic('')"><text class="lesson-count">{{ activeTopic == '' ? total + ' 门课程' : '查看全部' }}</text></view></view>
|
|
<view v-if="loading" class="content-state"><text>正在加载课程…</text></view>
|
|
<view v-else-if="error.length > 0" class="content-state"><text>{{ error }}</text><text class="content-retry" @click="reload">重新加载</text></view>
|
|
<view v-else-if="lessons.length == 0" class="content-state"><text>暂无课程</text></view>
|
|
<view class="lesson-card" v-for="item in lessons" :key="item.id" @click="openLesson(item.id)">
|
|
<image :src="item.image" mode="aspectFill" class="lesson-card-image"></image>
|
|
<view class="lesson-copy"><text class="lesson-title">{{ item.title }}</text><text class="lesson-desc">{{ item.desc }}</text><view class="lesson-meta"><text class="lesson-duration">{{ item.duration }}</text><text class="lesson-tag">{{ item.tag }}</text></view></view>
|
|
</view>
|
|
<text v-if="moreError.length > 0" class="content-state">{{ moreError }}</text>
|
|
<text v-if="hasMore" class="content-retry" @click="more">{{ loadingMore ? '正在加载…' : '加载更多' }}</text>
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup lang="uts">
|
|
import { usePageLayout } from '@/services/layout.uts'
|
|
import { fetchLessons, FinanceLesson } from '@/services/content.uts'
|
|
import AppHeader from '@/components/AppHeader.uvue'
|
|
import AppIcon from '@/components/AppIcon.uvue'
|
|
const { contentStyle, pageStyle } = usePageLayout()
|
|
type LessonTopic = { id: string, title: string, desc: string, icon: string }
|
|
const topics: LessonTopic[] = [
|
|
{ id: 'credit', title: '个人信用提升', desc: '了解信用记录与还款能力', icon: 'user' },
|
|
{ id: 'business', title: '小微经营融资', desc: '梳理经营材料与融资成本', icon: 'building' },
|
|
{ id: 'documents', title: '材料准备清单', desc: '按申请场景,逐项检查资料', icon: 'file-text' }
|
|
]
|
|
const activeTopic = ref(''); const lessons = ref<FinanceLesson[]>([]); const total = ref(0); const hasMore = ref(false)
|
|
const loading = ref(false); const loadingMore = ref(false); const error = ref(''); const moreError = ref('')
|
|
let generation = 0; let visible = false; let page = 1
|
|
const activeTopicTitle = computed((): string => topics.find((item: LessonTopic): boolean => item.id == activeTopic.value)?.title ?? '精选课程')
|
|
async function load(append: boolean) {
|
|
if (!visible || loading.value || loadingMore.value || (append && !hasMore.value)) return
|
|
const request = append ? generation : ++generation
|
|
if (append) { loadingMore.value = true; moreError.value = '' }
|
|
else { loading.value = true; error.value = ''; lessons.value = []; total.value = 0; hasMore.value = false; page = 1 }
|
|
try {
|
|
const result = await fetchLessons(activeTopic.value, append ? page + 1 : 1)
|
|
if (!visible || request != generation) return
|
|
lessons.value = append ? lessons.value.concat(result.items) : result.items
|
|
total.value = result.total; hasMore.value = result.hasMore
|
|
if (append) page++
|
|
} catch (err) {
|
|
if (visible && request == generation) {
|
|
const message = err instanceof Error ? err.message : '课程加载失败,请重试'
|
|
if (append) moreError.value = message; else error.value = message
|
|
}
|
|
} finally { if (request == generation) { loading.value = false; loadingMore.value = false } }
|
|
}
|
|
function reload() { load(false) }
|
|
const more = () => { load(true) }
|
|
const selectTopic = (id: string) => { generation++; loading.value = false; loadingMore.value = false; activeTopic.value = activeTopic.value == id ? '' : id; reload() }
|
|
const openLesson = (id: string) => { uni.navigateTo({ url: '/packages/content/lesson/lesson?id=' + id }) }
|
|
onShow(() => { visible = true; loading.value = false; loadingMore.value = false; reload() })
|
|
onHide(() => { visible = false; generation++ })
|
|
onUnload(() => { visible = false; generation++ })
|
|
</script>
|
|
|
|
<style>
|
|
.content-state { padding: 30rpx 0; color: #66758a; font-size: 25rpx; line-height: 40rpx; }
|
|
.content-retry { color: #0868f7; font-size: 25rpx; padding: 22rpx 0; }
|
|
.classroom-content { padding: 24rpx 28rpx 48rpx; }
|
|
.classroom-hero { border-radius: 20rpx; background-color: #e8f2ff; flex-direction: row; overflow: hidden; align-items: center; }
|
|
.hero-copy { flex: 1; padding: 28rpx 12rpx 28rpx 26rpx; }
|
|
.hero-eyebrow { color: #0868f7; font-size: 22rpx; font-weight: 600; }
|
|
.hero-title { color: #14335f; font-size: 37rpx; line-height: 51rpx; font-weight: 700; margin-top: 10rpx; }
|
|
.hero-title-next { margin-top: 0; }
|
|
.hero-desc { color: #4b6586; font-size: 23rpx; line-height: 36rpx; margin-top: 14rpx; }
|
|
.hero-image { width: 230rpx; height: 280rpx; flex-shrink: 0; }
|
|
.topic-section { margin-top: 28rpx; }
|
|
.topic-list { margin-top: 16rpx; }
|
|
.topic-card { flex-direction: row; align-items: center; min-height: 116rpx; padding: 18rpx 22rpx; border-radius: 16rpx; border: 1rpx solid #e5ecf5; background-color: #ffffff; margin-bottom: 12rpx; }
|
|
.selected-topic { background-color: #eef5ff; border-color: #99c1fb; }
|
|
.topic-copy { flex: 1; margin-left: 20rpx; }
|
|
.topic-title { color: #172640; font-size: 28rpx; line-height: 40rpx; font-weight: 600; }
|
|
.topic-desc { color: #66758a; font-size: 23rpx; line-height: 34rpx; margin-top: 4rpx; }
|
|
.topic-selected { color: #0868f7; font-size: 23rpx; margin-left: 10rpx; }
|
|
.lesson-section { margin-top: 18rpx; }
|
|
.section-head { flex-direction: row; align-items: center; justify-content: space-between; }
|
|
.all-lessons { padding: 12rpx 0 12rpx 20rpx; }
|
|
.lesson-count { color: #0868f7; font-size: 23rpx; }
|
|
.lesson-card { margin-top: 16rpx; padding: 20rpx; border-radius: 18rpx; background-color: #ffffff; border: 1rpx solid #e5ecf5; flex-direction: row; align-items: center; }
|
|
.lesson-card-image { width: 142rpx; height: 150rpx; border-radius: 12rpx; margin-right: 20rpx; flex-shrink: 0; }
|
|
.lesson-copy { flex: 1; }
|
|
.lesson-title { color: #172640; font-size: 30rpx; line-height: 42rpx; font-weight: 600; }
|
|
.lesson-desc { color: #66758a; font-size: 24rpx; line-height: 36rpx; margin-top: 8rpx; }
|
|
.lesson-meta { flex-direction: row; align-items: center; margin-top: 12rpx; }
|
|
.lesson-duration { color: #66758a; font-size: 22rpx; }
|
|
.lesson-tag { margin-left: 16rpx; color: #0868f7; font-size: 22rpx; }
|
|
</style>
|