index.vue
3.61 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
<view class="message-detail-page">
<view class="page-content">
<view class="hero-card">
<text class="hero-title">消息详情</text>
<text class="hero-desc">
进入详情页后,当前消息会在 mock 中自动标记为已读,返回列表即可看到状态变化。
</text>
</view>
<view v-if="loading" class="placeholder-card">
<text class="section-title">加载中</text>
<text class="section-desc">正在获取消息详情...</text>
</view>
<view v-else-if="detail" class="detail-card">
<view class="detail-meta">
<text class="detail-category">{{ detail.category }}</text>
<text class="detail-time">{{ detail.created_time }}</text>
</view>
<text class="detail-title">{{ detail.title }}</text>
<text class="detail-content">{{ detail.content }}</text>
</view>
<view v-else class="placeholder-card">
<text class="section-title">未找到消息</text>
<text class="section-desc">
当前消息不存在,或者真实接口还没有返回这条详情数据。
</text>
</view>
<button class="back-btn" @tap="goBack">返回消息列表</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import Taro, { useLoad } from '@tarojs/taro'
import { messageDetailAPI } from '@/api/message'
const loading = ref(true)
const detail = ref(null)
const fetchMessageDetail = async (id) => {
loading.value = true
try {
const response = await messageDetailAPI({ id })
if (response?.code === 1) {
detail.value = response.data
return
}
detail.value = null
Taro.showToast({
title: response?.msg || '获取详情失败',
icon: 'none',
})
} catch (error) {
console.error('获取消息详情失败:', error)
detail.value = null
} finally {
loading.value = false
}
}
const goBack = () => {
Taro.navigateBack()
}
useLoad((options) => {
const id = String(options?.id || '').trim()
if (!id) {
loading.value = false
return
}
fetchMessageDetail(id)
})
</script>
<style lang="less">
.message-detail-page {
min-height: 100vh;
background:
radial-gradient(circle at top right, rgba(166, 121, 57, 0.16), transparent 30%),
linear-gradient(180deg, #fffaf4 0%, #f4f6fb 100%);
.page-content {
padding: 32rpx 24rpx 48rpx;
box-sizing: border-box;
}
.hero-card,
.detail-card,
.placeholder-card {
padding: 32rpx;
border-radius: 28rpx;
background: rgba(255, 255, 255, 0.94);
border: 2rpx solid rgba(166, 121, 57, 0.08);
box-shadow: 0 20rpx 60rpx rgba(15, 23, 42, 0.06);
box-sizing: border-box;
}
.hero-title,
.section-title,
.detail-title {
display: block;
color: #111827;
}
.hero-title,
.detail-title {
font-size: 40rpx;
font-weight: 700;
}
.hero-desc,
.section-desc,
.detail-content {
display: block;
margin-top: 16rpx;
font-size: 26rpx;
line-height: 1.8;
color: #6b7280;
white-space: pre-wrap;
}
.detail-card,
.placeholder-card,
.back-btn {
margin-top: 24rpx;
}
.detail-meta {
display: flex;
align-items: center;
gap: 16rpx;
margin-bottom: 18rpx;
}
.detail-category {
padding: 8rpx 14rpx;
border-radius: 999rpx;
font-size: 22rpx;
color: #92400e;
background: #fef3c7;
}
.detail-time {
font-size: 22rpx;
color: #9ca3af;
}
.back-btn {
border-radius: 999rpx;
font-size: 28rpx;
line-height: 84rpx;
color: #0f172a;
background: #ffffff;
border: 2rpx solid #d1d5db;
}
}
</style>