feat(相册): 添加上传功能并限制显示图片数量
- 新增上传照片功能入口,包括空状态和正常状态的显示 - 使用计算属性限制首页最多显示3张图片 - 优化相册空状态UI,添加相机图标和提示文字
Showing
1 changed file
with
34 additions
and
13 deletions
| ... | @@ -20,8 +20,9 @@ | ... | @@ -20,8 +20,9 @@ |
| 20 | 20 | ||
| 21 | <!-- 相册内容 --> | 21 | <!-- 相册内容 --> |
| 22 | <view v-else-if="albumData.length > 0" class="grid grid-cols-2 gap-3"> | 22 | <view v-else-if="albumData.length > 0" class="grid grid-cols-2 gap-3"> |
| 23 | + <!-- 显示最多3张图片 --> | ||
| 23 | <view | 24 | <view |
| 24 | - v-for="(item, index) in albumData" | 25 | + v-for="(item, index) in displayedAlbumData" |
| 25 | :key="item.id || index" | 26 | :key="item.id || index" |
| 26 | class="rounded-lg overflow-hidden aspect-square relative cursor-pointer shadow-md" | 27 | class="rounded-lg overflow-hidden aspect-square relative cursor-pointer shadow-md" |
| 27 | @click="handleMediaClick(item, albumData)" | 28 | @click="handleMediaClick(item, albumData)" |
| ... | @@ -39,20 +40,28 @@ | ... | @@ -39,20 +40,28 @@ |
| 39 | > | 40 | > |
| 40 | 视频 | 41 | 视频 |
| 41 | </view> | 42 | </view> |
| 42 | - <!-- 我的标识 --> | 43 | + </view> |
| 43 | - <!-- <view | 44 | + |
| 44 | - v-if="item.is_my" | 45 | + <!-- 上传照片功能框 --> |
| 45 | - class="absolute top-2 right-2 px-2 py-1 bg-blue-500 bg-opacity-80 rounded text-white text-xs" | 46 | + <view |
| 46 | - > | 47 | + class="rounded-lg aspect-square relative cursor-pointer shadow-md bg-gray-100 flex flex-col items-center justify-center border-2 border-dashed border-gray-100 hover:border-blue-400 transition-colors" |
| 47 | - 我的 | 48 | + @click="navigateToUpload" |
| 48 | - </view> --> | 49 | + > |
| 50 | + <view class="text-gray-400 text-2xl mb-1">+</view> | ||
| 51 | + <view class="text-gray-500 text-xs text-center">拍照留念</view> | ||
| 49 | </view> | 52 | </view> |
| 50 | </view> | 53 | </view> |
| 51 | 54 | ||
| 52 | <!-- 空状态 --> | 55 | <!-- 空状态 --> |
| 53 | - <view v-else class="text-center py-8 text-gray-400"> | 56 | + <view v-else class="grid grid-cols-2 gap-3"> |
| 54 | - <view class="text-sm">暂无相册内容</view> | 57 | + <!-- 空状态时的上传功能框 --> |
| 55 | - <!-- <view class="text-xs mt-1">快去上传第一张照片吧~</view> --> | 58 | + <view |
| 59 | + class="rounded-lg aspect-square relative cursor-pointer shadow-md bg-gray-100 flex flex-col items-center justify-center border-2 border-dashed border-gray-100 hover:border-blue-400 transition-colors" | ||
| 60 | + @click="navigateToUpload" | ||
| 61 | + > | ||
| 62 | + <view class="text-gray-400 text-3xl mb-2">📷</view> | ||
| 63 | + <view class="text-gray-500 text-xs text-center px-2">上传第一张<br/>照片吧~</view> | ||
| 64 | + </view> | ||
| 56 | </view> | 65 | </view> |
| 57 | </view> | 66 | </view> |
| 58 | 67 | ||
| ... | @@ -105,7 +114,7 @@ | ... | @@ -105,7 +114,7 @@ |
| 105 | </template> | 114 | </template> |
| 106 | 115 | ||
| 107 | <script setup> | 116 | <script setup> |
| 108 | -import { ref, onMounted } from 'vue'; | 117 | +import { ref, onMounted, computed } from 'vue'; |
| 109 | import Taro, { useDidShow } from '@tarojs/taro'; | 118 | import Taro, { useDidShow } from '@tarojs/taro'; |
| 110 | import { Close } from '@nutui/icons-vue-taro'; | 119 | import { Close } from '@nutui/icons-vue-taro'; |
| 111 | import { useMediaPreview } from '@/composables/useMediaPreview'; | 120 | import { useMediaPreview } from '@/composables/useMediaPreview'; |
| ... | @@ -132,6 +141,11 @@ const { | ... | @@ -132,6 +141,11 @@ const { |
| 132 | const albumData = ref([]); | 141 | const albumData = ref([]); |
| 133 | const loading = ref(false); | 142 | const loading = ref(false); |
| 134 | 143 | ||
| 144 | +// 计算属性:显示最多3张图片 | ||
| 145 | +const displayedAlbumData = computed(() => { | ||
| 146 | + return albumData.value.slice(0, 3); | ||
| 147 | +}); | ||
| 148 | + | ||
| 135 | /** | 149 | /** |
| 136 | * 获取家庭相册数据 | 150 | * 获取家庭相册数据 |
| 137 | * @param {boolean} isRefresh - 是否为刷新操作,刷新时不显示loading状态 | 151 | * @param {boolean} isRefresh - 是否为刷新操作,刷新时不显示loading状态 |
| ... | @@ -142,7 +156,7 @@ const fetchAlbumData = async (isRefresh = false) => { | ... | @@ -142,7 +156,7 @@ const fetchAlbumData = async (isRefresh = false) => { |
| 142 | if (!isRefresh) { | 156 | if (!isRefresh) { |
| 143 | loading.value = true; | 157 | loading.value = true; |
| 144 | } | 158 | } |
| 145 | - | 159 | + |
| 146 | const response = await getPhotoListAPI({ | 160 | const response = await getPhotoListAPI({ |
| 147 | page: 0, | 161 | page: 0, |
| 148 | limit: 4 // 首页只显示4张 | 162 | limit: 4 // 首页只显示4张 |
| ... | @@ -170,6 +184,13 @@ const openAlbumList = () => { | ... | @@ -170,6 +184,13 @@ const openAlbumList = () => { |
| 170 | Taro.navigateTo({ url: '/pages/AlbumList/index' }); | 184 | Taro.navigateTo({ url: '/pages/AlbumList/index' }); |
| 171 | }; | 185 | }; |
| 172 | 186 | ||
| 187 | +/** | ||
| 188 | + * 跳转到上传媒体页面 | ||
| 189 | + */ | ||
| 190 | +const navigateToUpload = () => { | ||
| 191 | + Taro.navigateTo({ url: '/pages/UploadMedia/index' }); | ||
| 192 | +}; | ||
| 193 | + | ||
| 173 | // 组件挂载时获取数据 | 194 | // 组件挂载时获取数据 |
| 174 | onMounted(() => { | 195 | onMounted(() => { |
| 175 | // fetchAlbumData(); | 196 | // fetchAlbumData(); | ... | ... |
-
Please register or login to post a comment