index.vue
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!--
* @Date:2026-02-03 21:26:58
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-02-12 18:24:35
* @FilePath: /manulife-weapp/src/pages/message-detail/index.vue
* @Description: 消息详情页
-->
<template>
<view class="min-h-screen bg-white pb-safe">
<NavHeader title="消息详情" />
<view v-if="detail" class="p-5">
<!-- 内容区域 -->
<view class="rich-text-content">
<rich-text :nodes="formattedContent" />
</view>
<!-- 顶部时间 -->
<view class="mt-4 text-right">
<text class="text-xs text-gray-400">{{ detail.created_time }}</text>
</view>
<!-- 关联计划书(可选) -->
<!-- <view v-if="detail.pk_id" class="mt-2 pt-4 border-t border-gray-200">
<view class="text-sm text-gray-500 mb-2">关联计划书</view>
<view class="text-xs text-gray-400">订单ID: {{ detail.pk_id }}</view>
</view> -->
</view>
<!-- 加载中 -->
<view v-else-if="loading" class="flex justify-center py-10">
<view class="w-8 h-8 border-4 border-gray-200 border-t-blue-600 rounded-full animate-spin"></view>
</view>
<!-- 错误/空状态 -->
<nut-empty v-else description="未找到消息内容" image="error" />
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import { useLoad } from '@tarojs/taro'
import NavHeader from '@/components/navigation/NavHeader.vue'
import { detailAPI } from '@/api/news'
const detail = ref(null)
const loading = ref(true)
/**
* @description 格式化富文本内容,处理图片宽度等问题
*/
const formattedContent = computed(() => {
if (!detail.value?.note) return ''
// 简单的正则替换,确保图片宽度不超过容器
const content = detail.value.note.replace(
/<img/g,
'<img style="max-width:100%;height:auto;display:block;"'
)
return content
})
/**
* @description 获取消息详情
* @param {string|number} id 消息ID
*/
const fetchDetail = async (id) => {
loading.value = true
try {
const res = await detailAPI({ i: id })
if (res.code === 1) {
detail.value = res.data
}
} catch (err) {
console.error('获取消息详情失败:', err)
} finally {
loading.value = false
}
}
useLoad((options) => {
if (options.id) {
fetchDetail(options.id)
}
})
</script>
<style lang="less">
.rich-text-content {
font-size: 28rpx;
color: #333;
line-height: 1.8;
/* 确保富文本样式正确 */
p {
margin-bottom: 20rpx;
}
}
</style>