首页支持不同参数page和aid进行页面跳转和文章跳转

This commit is contained in:
minimaxagent1 2025-08-05 17:47:10 +08:00
parent fe2c53f01b
commit 8537f196df
3 changed files with 308 additions and 3 deletions

View File

@ -95,6 +95,13 @@
}
},
{
"path": "pages/article/article-detail",
"style": {
"navigationBarTitleText": "文章详情",
"enablePullDownRefresh": false,
"navigationStyle": "custom"
}
}, {
"path": "pages/institutionalStructure/donationRecord",
"style": {
"navigationBarTitleText": "",

View File

@ -0,0 +1,229 @@
<template>
<view class="page">
<!-- 自定义导航栏 -->
<custom-navbar :title="articleData.title || '文章详情'" />
<!-- 加载状态 -->
<view v-if="loading" class="loading-container">
<view class="loading-content">
<text>加载中...</text>
</view>
</view>
<!-- 文章内容 -->
<view v-else-if="articleData" class="article-container">
<!-- 文章标题 -->
<view class="article-header">
<text class="article-title">{{ articleData.title }}</text>
<text v-if="articleData.subtitle" class="article-subtitle">{{ articleData.subtitle }}</text>
</view>
<!-- 文章封面图 -->
<view v-if="articleData.coverUrl" class="article-cover">
<image :src="articleData.coverUrl" mode="aspectFill" />
</view>
<!-- 文章内容 -->
<view class="article-content">
<rich-text :nodes="articleData.content"></rich-text>
</view>
<!-- 文章信息 -->
<view class="article-info">
<text class="info-item">发布时间{{ formatTime(articleData.createTime) }}</text>
<text v-if="articleData.templeName" class="info-item">寺庙{{ articleData.templeName }}</text>
</view>
</view>
<!-- 错误状态 -->
<view v-else class="error-container">
<view class="error-content">
<text>内容加载失败</text>
<button class="retry-btn" @click="loadArticleData">重新加载</button>
</view>
</view>
</view>
</template>
<script>
import CustomNavbar from "../../components/custom-navbar/custom-navbar.vue";
export default {
components: {
CustomNavbar
},
data() {
return {
loading: true,
articleData: null,
articleId: null
}
},
onLoad(options) {
//
if (options.id) {
this.articleId = options.id;
this.loadArticleData();
} else {
//
const storedArticle = uni.getStorageSync('currentArticle');
if (storedArticle) {
this.articleData = storedArticle;
this.loading = false;
//
uni.removeStorageSync('currentArticle');
} else {
this.loading = false;
uni.showToast({
title: '文章数据不存在',
icon: 'none'
});
}
}
},
methods: {
//
async loadArticleData() {
if (!this.articleId) {
this.loading = false;
return;
}
this.loading = true;
try {
const { getArticleById } = await import('@/api/article/article.js');
const response = await getArticleById(this.articleId);
if (response.code === 200 && response.data) {
this.articleData = response.data;
} else {
uni.showToast({
title: response.msg || '获取文章失败',
icon: 'none'
});
}
} catch (error) {
console.error('获取文章详情失败:', error);
uni.showToast({
title: '网络错误',
icon: 'none'
});
} finally {
this.loading = false;
}
},
//
formatTime(timeStr) {
if (!timeStr) return '';
const date = new Date(timeStr);
return date.toLocaleDateString('zh-CN') + ' ' + date.toLocaleTimeString('zh-CN', { hour12: false });
}
}
}
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background-color: #f5f5f5;
}
.loading-container,
.error-container {
display: flex;
justify-content: center;
align-items: center;
height: 60vh;
}
.loading-content,
.error-content {
text-align: center;
color: #666;
font-size: 28rpx;
}
.retry-btn {
margin-top: 20rpx;
padding: 20rpx 40rpx;
background-color: #4C97E7;
color: white;
border: none;
border-radius: 10rpx;
font-size: 28rpx;
}
.article-container {
padding: 30rpx;
background-color: white;
margin: 20rpx;
border-radius: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.article-header {
margin-bottom: 30rpx;
}
.article-title {
display: block;
font-size: 36rpx;
font-weight: bold;
color: #333;
line-height: 1.4;
margin-bottom: 10rpx;
}
.article-subtitle {
display: block;
font-size: 28rpx;
color: #666;
line-height: 1.3;
}
.article-cover {
margin-bottom: 30rpx;
border-radius: 15rpx;
overflow: hidden;
image {
width: 100%;
height: 400rpx;
}
}
.article-content {
margin-bottom: 30rpx;
line-height: 1.8;
font-size: 30rpx;
color: #333;
:deep(p) {
margin-bottom: 20rpx;
}
:deep(a) {
color: #4C97E7;
text-decoration: underline;
}
:deep(img) {
max-width: 100%;
height: auto;
margin: 20rpx 0;
}
}
.article-info {
padding-top: 30rpx;
border-top: 1rpx solid #eee;
.info-item {
display: block;
font-size: 24rpx;
color: #999;
margin-bottom: 10rpx;
}
}
</style>

View File

@ -368,9 +368,78 @@ import { getArticleById } from "../../api/article/article.js";
}
},
// - 使
navigateToPage(pageType) {
navigateToPage(pageType);
// page aid
async navigateToPage(item, index) {
try {
console.log('导航项信息:', item);
console.log('导航项索引:', index);
// 使page
if (item.page) {
console.log('使用page字段进行路由跳转:', item.page);
//
const { navigateToPage: routerNavigate } = await import("../../utils/router.js");
routerNavigate(item.page);
return;
}
// page使aid
if (item.aid) {
console.log('使用aid字段获取文章详情:', item.aid);
//
uni.showLoading({
title: '加载中...',
mask: true
});
// API
const response = await getArticleById(item.aid);
//
uni.hideLoading();
if (response.code === 200 && response.data) {
console.log('获取文章详情成功:', response.data);
// 使
uni.setStorageSync('currentArticle', response.data);
//
uni.navigateTo({
url: '/pages/article/article-detail',
fail: (err) => {
console.error('跳转到文章详情页面失败:', err);
uni.showToast({
title: '页面跳转失败',
icon: 'none'
});
}
});
} else {
console.error('获取文章详情失败:', response);
uni.showToast({
title: '获取内容失败',
icon: 'none'
});
}
} else {
console.error('导航项既没有page字段也没有aid字段:', item);
uni.showToast({
title: '配置错误',
icon: 'none'
});
}
} catch (error) {
//
uni.hideLoading();
console.error('导航跳转出错:', error);
uni.showToast({
title: '网络错误',
icon: 'none'
});
}
}
}
}