chore: 清理备份文件目录中的原始页面文件
移除 docs/backups/original-pages/ 目录下的四个备份文件: - message-index.vue.bak - product-center-index.vue.bak - search-index.vue.bak - material-list-index.vue.bak 这些文件是开发过程中的临时备份,现已不再需要。
Showing
4 changed files
with
0 additions
and
148 deletions
This diff is collapsed. Click to expand it.
| 1 | -<template> | ||
| 2 | - <view class="min-h-screen bg-[#F9FAFB] pb-safe"> | ||
| 3 | - <NavHeader title="我的消息" /> | ||
| 4 | - | ||
| 5 | - <!-- 列表区域 --> | ||
| 6 | - <view class="p-4"> | ||
| 7 | - <template v-if="messageList.length > 0"> | ||
| 8 | - <view | ||
| 9 | - v-for="item in messageList" | ||
| 10 | - :key="item.id" | ||
| 11 | - class="bg-white rounded-xl p-4 mb-3 shadow-sm active:opacity-70 transition-opacity" | ||
| 12 | - @tap="handleItemClick(item)" | ||
| 13 | - > | ||
| 14 | - <view class="flex justify-between items-start mb-2"> | ||
| 15 | - <view class="flex-1 mr-2"> | ||
| 16 | - <view class="text-base font-bold text-gray-900 line-clamp-1"> | ||
| 17 | - {{ item.title }} | ||
| 18 | - </view> | ||
| 19 | - </view> | ||
| 20 | - <text class="text-xs text-gray-400 shrink-0 mt-1"> | ||
| 21 | - {{ item.create_time }} | ||
| 22 | - </text> | ||
| 23 | - </view> | ||
| 24 | - | ||
| 25 | - <view class="text-sm text-gray-600 line-clamp-2 leading-relaxed"> | ||
| 26 | - {{ item.intro || item.content || '暂无简介' }} | ||
| 27 | - </view> | ||
| 28 | - </view> | ||
| 29 | - | ||
| 30 | - <!-- 加载更多/没有更多 --> | ||
| 31 | - <view class="py-4 text-center text-[24rpx] text-gray-400"> | ||
| 32 | - <text v-if="loading">加载中...</text> | ||
| 33 | - <text v-else-if="!hasMore">没有更多了</text> | ||
| 34 | - <text v-else>上拉加载更多</text> | ||
| 35 | - </view> | ||
| 36 | - </template> | ||
| 37 | - | ||
| 38 | - <!-- 空状态 --> | ||
| 39 | - <nut-empty | ||
| 40 | - v-else-if="!loading && messageList.length === 0" | ||
| 41 | - description="暂无消息" | ||
| 42 | - image="empty" | ||
| 43 | - /> | ||
| 44 | - </view> | ||
| 45 | - </view> | ||
| 46 | -</template> | ||
| 47 | - | ||
| 48 | -<script setup> | ||
| 49 | -import { ref } from 'vue' | ||
| 50 | -import { useLoad, usePullDownRefresh, useReachBottom, stopPullDownRefresh } from '@tarojs/taro' | ||
| 51 | -import { useGo } from '@/hooks/useGo' | ||
| 52 | -import NavHeader from '@/components/NavHeader.vue' | ||
| 53 | -import { myListAPI } from '@/api/news' | ||
| 54 | -import { mockMessageListAPI } from '@/utils/mockData' | ||
| 55 | - | ||
| 56 | -// ⚠️ MOCK 数据开关 - 开发环境使用 mock 数据,生产环境使用真实 API | ||
| 57 | -const USE_MOCK_DATA = process.env.NODE_ENV === 'development' | ||
| 58 | - | ||
| 59 | -const go = useGo() | ||
| 60 | - | ||
| 61 | -const messageList = ref([]) | ||
| 62 | -const page = ref(1) | ||
| 63 | -const limit = ref(10) | ||
| 64 | -const hasMore = ref(true) | ||
| 65 | -const loading = ref(false) | ||
| 66 | - | ||
| 67 | -/** | ||
| 68 | - * @description 加载消息列表 | ||
| 69 | - * @param {boolean} refresh 是否刷新 | ||
| 70 | - */ | ||
| 71 | -const fetchMessageList = async (refresh = false) => { | ||
| 72 | - if (loading.value) return | ||
| 73 | - | ||
| 74 | - if (refresh) { | ||
| 75 | - page.value = 1 | ||
| 76 | - hasMore.value = true | ||
| 77 | - } else if (!hasMore.value) { | ||
| 78 | - return | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - loading.value = true | ||
| 82 | - | ||
| 83 | - try { | ||
| 84 | - console.log('[Message] 使用 Mock 数据:', USE_MOCK_DATA) | ||
| 85 | - | ||
| 86 | - // 根据开关选择使用真实 API 或 Mock 数据 | ||
| 87 | - const res = USE_MOCK_DATA | ||
| 88 | - ? await mockMessageListAPI({ | ||
| 89 | - page: page.value, | ||
| 90 | - limit: limit.value | ||
| 91 | - }) | ||
| 92 | - : await myListAPI({ | ||
| 93 | - page: page.value, | ||
| 94 | - limit: limit.value | ||
| 95 | - }) | ||
| 96 | - | ||
| 97 | - if (res.code === 1) { | ||
| 98 | - const list = res.data?.list || [] | ||
| 99 | - | ||
| 100 | - if (refresh) { | ||
| 101 | - messageList.value = list | ||
| 102 | - } else { | ||
| 103 | - messageList.value = [...messageList.value, ...list] | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - if (list.length < limit.value) { | ||
| 107 | - hasMore.value = false | ||
| 108 | - } else { | ||
| 109 | - page.value++ | ||
| 110 | - } | ||
| 111 | - } | ||
| 112 | - } catch (err) { | ||
| 113 | - console.error('获取消息列表失败:', err) | ||
| 114 | - } finally { | ||
| 115 | - loading.value = false | ||
| 116 | - if (refresh) { | ||
| 117 | - stopPullDownRefresh() | ||
| 118 | - } | ||
| 119 | - } | ||
| 120 | -} | ||
| 121 | - | ||
| 122 | -/** | ||
| 123 | - * @description 跳转到详情页 | ||
| 124 | - * @param {Object} item 消息对象 | ||
| 125 | - */ | ||
| 126 | -const handleItemClick = (item) => { | ||
| 127 | - go('/pages/message-detail/index', { id: item.id }) | ||
| 128 | -} | ||
| 129 | - | ||
| 130 | -// 页面加载 | ||
| 131 | -useLoad(() => { | ||
| 132 | - fetchMessageList(true) | ||
| 133 | -}) | ||
| 134 | - | ||
| 135 | -// 下拉刷新 | ||
| 136 | -usePullDownRefresh(() => { | ||
| 137 | - fetchMessageList(true) | ||
| 138 | -}) | ||
| 139 | - | ||
| 140 | -// 上拉加载更多 | ||
| 141 | -useReachBottom(() => { | ||
| 142 | - fetchMessageList() | ||
| 143 | -}) | ||
| 144 | -</script> | ||
| 145 | - | ||
| 146 | -<style lang="less"> | ||
| 147 | -/* Scoped styles if needed */ | ||
| 148 | -</style> |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment