wangzhibo
2025-10-23 cad64c1de2c45856b0774933c5801b05b64984e8
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<template>
    <view class="min-h-screen bg-gray-100">
        <!-- Tab 切换 -->
        <view class="p-2 w-95-percent">
            <uni-segmented-control :current="currentTab" :values="tabs" @clickItem="onTabChange" style-type="button"
                active-color="#3b82f6" class="mb-4" />
        </view>
        <!-- 加载提示 -->
        <view v-if="loading" class="text-center text-gray-500 py-8">
            加载中...
        </view>
        <!-- 预约信息卡片列表 -->
        <scroll-view scroll-y class="p-2 h-calc-100vh-120px w-95-percent">
            <view v-for="(item, index) in filterednotices" :key="index"
                class="bg-white rounded-lg shadow p-4 mb-4 flex flex-row" @click="gotoDetail(item)">
 
                <div class="w-24 h-16 mt-4 flex-shrink-0 mr-2 rounded-5">
                    <img :src="parseContentImg(item.content) || `https://farm.evcc.top/Uploads/yuanboyuan/news/${encodeURIComponent(item.category)}.jpg`"
                        mode="aspectFill" alt="icon" class="w-24 h-16 rounded-5" />
                </div>
                <!-- 右侧内容 -->
                <div class="flex-1 space-y-2">
                    <view class="text-sm space-y-2">
                        <!--<text class="text-gray-600 font-bold">消息标题:</text> -->
                        <text>{{ item.title.length > 36 ? item.title.slice(0, 36) + '……' : item.title }}</text>
                    </view>
                    <view class="text-sm space-y-2">
                        <text class="text-gray-600">发布时间:</text>
                        <text>{{ item.createTime }}</text>
                    </view>
                    <!--
                    <view class="text-sm space-y-2">
                        <text class="text-gray-600">消息正文:</text>
                        <text>{{ parseContentText(item.content) }}</text>
                    </view>
                    -->
                </div>
 
                <!-- 卡片内容 -->
 
            </view>
            <!-- 无数据提示 -->
            <view v-if="!filterednotices.length" class="text-center text-gray-500 py-8">
                暂无{{ tabs[currentTab] }}的信息
            </view>
        </scroll-view>
    </view>
</template>
 
<script>
    import {
        ref,
        computed,
        onMounted
    } from 'vue'
    import {
        apiService
    } from '@/apiservice/apiService'
 
    export default {
        setup() {
            // Tab 数据
            const tabs = ['景区动态', '新闻报道', '活动演出', '景区通知'];
            const currentTab = ref(0);
            let notices = ref([]);
            const loading = ref(false);
 
            // 获取预约列表
            const fetchnotices = async () => {
                loading.value = true;
                try {
                    const res = await apiService.noticeList()
                    if (res.code === 1000) {
                        notices.value = res.data
 
                    } else {
                        console.warn('查询失败:', res.message)
                    }
 
                } catch (error) {
                    console.error('获取预约信息错误:', error);
                    uni.showToast({
                        title: '网络错误',
                        icon: 'none'
                    });
                } finally {
                    loading.value = false;
                }
            };
 
            const parseContentImg = (content = '') => {
                if (!content || typeof content !== 'string') {
                    return null;
                }
                const imgMatch = content.match(/<img[^>]+src=["']?([^"'>]+)["']?/i);
                const imgSrc = imgMatch ? imgMatch[1] : null;
 
                return imgSrc;
 
            };
            const parseContentText = (content = '') => {
                if (!content || typeof content !== 'string') {
                    return '';
                }
                let text = content
                    .replace(/<[^>]+>/g, '') // 去掉HTML标签
                    .replace(/\s+/g, ' ') // 合并多余空格
                    .trim();
                if (text.length > 50) {
                    text = text.slice(0, 50) + '......'; // 截取前50字符
                }
 
                return text;
            };
            const gotoDetail = (item) => {
                const data = encodeURIComponent(JSON.stringify(item));
                  uni.navigateTo({
                    url: `/pages/index/notices-detail?data=${data}`
                  });
            };
 
            // 根据当前 Tab 过滤数据
            const filterednotices = computed(() => {
                return notices.value.filter(item => item.category === tabs[currentTab.value]);
            });
 
 
            // Tab 切换
            const onTabChange = (e) => {
                currentTab.value = e.currentIndex;
            };
 
            // 页面加载时获取数据
            onMounted(() => {
                fetchnotices();
            });
 
            return {
                tabs,
                currentTab,
                notices,
                filterednotices,
                loading,
                onTabChange,
                parseContentImg,
                parseContentText,
                gotoDetail
            };
        }
    };
</script>
 
<style>
    .min-h-screen {
        min-height: 100vh;
    }
 
    .bg-gray-100 {
        background-color: #f3f4f6;
    }
 
    .ml-5 {
        left: 10rpx;
    }
 
    .w-95-percent {
        width: 95%;
    }
 
    .mr-5 {
        right: 10rpx;
    }
 
    .mb-4 {
        margin-bottom: 1rem;
    }
 
    .mt-4 {
        margin-top: 1rem;
    }
 
    .text-center {
        text-align: center;
    }
 
    .text-gray-500 {
        color: #6b7280;
    }
 
    .text-gray-600 {
        color: #4b5563;
    }
 
    .py-8 {
        padding-top: 2rem;
        /* 32px */
        padding-bottom: 2rem;
    }
 
    .h-calc-100vh-120px {
        height: calc(100vh - 120px);
    }
 
    .px-4 {
        padding-left: 1rem;
        padding-right: 1rem;
    }
 
    .bg-white {
        background-color: #ffffff;
    }
 
    .rounded-lg {
        border-radius: 0.5rem;
        /* 8px */
    }
 
    .shadow {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    }
 
    .p-4 {
        padding: 1rem;
    }
    
    .p-2 {
        padding: 0.5rem;
    }
 
    .mb-4 {
        margin-bottom: 1rem;
    }
 
    .mt-1 {
        margin-top: 0.2rem;
    }
 
    .relative {
        position: relative;
    }
 
    .absolute {
        position: absolute;
    }
 
    .top-2 {
        top: 0.5rem;
        /* 8px */
    }
 
    .right-2 {
        right: 0.5rem;
        /* 8px */
    }
 
    .bg-red-500 {
        background-color: #ef4444;
    }
 
    .bg-blue-500 {
        background-color: #3b82f6;
    }
 
    .text-white {
        color: #ffffff;
    }
 
    .text-sm {
        font-size: 0.875rem;
        /* 14px */
        line-height: 1.25rem;
        /* 20px */
    }
 
    .text-base {
        font-size: 1rem;
        /* 14px */
        line-height: 1.5rem;
        /* 20px */
    }
 
    .px-2 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
 
    .py-1 {
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }
 
    .rounded {
        border-radius: 0.25rem;
        /* 4px */
    }
 
    .space-y-2 {
        margin-top: 0.5rem;
        /* 8px */
    }
 
    .flex {
        display: flex;
    }
 
    .justify-between {
        justify-content: space-between;
    }
 
    .font-bold {
        font-weight: 700;
    }
 
    .text-lg {
        font-size: 1.125rem;
        /* 18px */
        line-height: 1.75rem;
        /* 28px */
    }
 
    .w-24 {
        width: 6rem;
        /* 32px */
 
    }
 
    .h-16 {
        height: 5rem;
        /* 32px */
    }
 
    .flex-shrink-0 {
        flex-shrink: 0;
    }
 
    .mr-2 {
        margin-right: 0.5rem;
        /* 8px */
    }
 
    .rounded-5 {
        border-radius: 5px;
    }
</style>