hookehuyr

refactor(媒体预览): 移除useMediaPreview composable并实现内联媒体处理逻辑

将原本通过useMediaPreview composable处理的媒体预览功能改为内联实现
在AlbumList和FamilyAlbum组件中直接处理图片预览和视频播放逻辑
调整ShareButton组件的右侧间距从40rpx改为30rpx
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
25 v-for="(item, index) in displayedAlbumData" 25 v-for="(item, index) in displayedAlbumData"
26 :key="item.id || index" 26 :key="item.id || index"
27 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"
28 - @click="handleMediaClick(item, albumData)" 28 + @click="handleItemClick(item, index)"
29 > 29 >
30 <image 30 <image
31 :src="item.media_type === 'VIDEO' ? item.thumbnail : item.media_url" 31 :src="item.media_type === 'VIDEO' ? item.thumbnail : item.media_url"
...@@ -67,14 +67,7 @@ ...@@ -67,14 +67,7 @@
67 </view> 67 </view>
68 </view> 68 </view>
69 69
70 - <!-- 图片预览 --> 70 +
71 - <nut-image-preview
72 - v-model:show="previewVisible"
73 - :images="previewImages"
74 - :init-no="previewIndex"
75 - :show-index="false"
76 - @close="closePreview"
77 - />
78 71
79 <!-- 视频播放器 --> 72 <!-- 视频播放器 -->
80 <view 73 <view
...@@ -119,25 +112,80 @@ ...@@ -119,25 +112,80 @@
119 import { ref, onMounted, computed } from 'vue'; 112 import { ref, onMounted, computed } from 'vue';
120 import Taro, { useDidShow } from '@tarojs/taro'; 113 import Taro, { useDidShow } from '@tarojs/taro';
121 import { Close, Photograph } from '@nutui/icons-vue-taro'; 114 import { Close, Photograph } from '@nutui/icons-vue-taro';
122 -import { useMediaPreview } from '@/composables/useMediaPreview'; 115 +
123 import { getPhotoListAPI } from '@/api/photo'; 116 import { getPhotoListAPI } from '@/api/photo';
124 117
125 -// 使用媒体预览 composable 118 +// 视频播放相关状态
126 -const { 119 +const videoVisible = ref(false);
127 - previewVisible, 120 +const currentVideo = ref(null);
128 - previewImages, 121 +const videoId = ref(0);
129 - previewIndex, 122 +
130 - videoVisible, 123 +/**
131 - currentVideo, 124 + * 处理媒体项点击事件
132 - videoId, 125 + * @param {Object} item - 媒体项
133 - handleMediaClick, 126 + * @param {number} index - 索引
134 - closePreview, 127 + */
135 - closeVideo, 128 +const handleItemClick = (item, index) => {
136 - handleVideoPlay, 129 + if (item.media_type === 'VIDEO') {
137 - handleVideoPause, 130 + // 播放视频
138 - handleFullscreenChange, 131 + currentVideo.value = {
139 - handleVideoError 132 + url: item.media_url,
140 -} = useMediaPreview(); 133 + thumbnail: item.thumbnail
134 + };
135 + videoId.value = Date.now();
136 + videoVisible.value = true;
137 + } else {
138 + // 预览图片
139 + const imageUrls = albumData.value
140 + .filter(media => media.media_type === 'IMAGE')
141 + .map(media => media.media_url);
142 +
143 + Taro.previewImage({
144 + urls: imageUrls,
145 + current: item.media_url
146 + });
147 + }
148 +};
149 +
150 +/**
151 + * 关闭视频播放器
152 + */
153 +const closeVideo = () => {
154 + videoVisible.value = false;
155 + currentVideo.value = null;
156 +};
157 +
158 +/**
159 + * 视频播放事件处理
160 + */
161 +const handleVideoPlay = () => {
162 + console.log('视频开始播放');
163 +};
164 +
165 +/**
166 + * 视频暂停事件处理
167 + */
168 +const handleVideoPause = () => {
169 + console.log('视频暂停播放');
170 +};
171 +
172 +/**
173 + * 视频全屏变化事件处理
174 + */
175 +const handleFullscreenChange = () => {
176 + console.log('视频全屏状态变化');
177 +};
178 +
179 +/**
180 + * 视频错误事件处理
181 + */
182 +const handleVideoError = (error) => {
183 + console.error('视频播放错误:', error);
184 + Taro.showToast({
185 + title: '视频播放失败',
186 + icon: 'none'
187 + });
188 +};
141 189
142 // 家庭相册数据 190 // 家庭相册数据
143 const albumData = ref([]); 191 const albumData = ref([]);
......
1 <!-- 1 <!--
2 * @Date: 2025-09-03 14:34:58 2 * @Date: 2025-09-03 14:34:58
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-09-08 11:50:44 4 + * @LastEditTime: 2025-09-15 12:52:03
5 * @FilePath: /lls_program/src/components/ShareButton/index.vue 5 * @FilePath: /lls_program/src/components/ShareButton/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -50,7 +50,7 @@ const handleSharePoster = () => { ...@@ -50,7 +50,7 @@ const handleSharePoster = () => {
50 .share-button-container { 50 .share-button-container {
51 position: fixed; 51 position: fixed;
52 top: 40rpx; 52 top: 40rpx;
53 - right: 40rpx; 53 + right: 30rpx;
54 z-index: 1000; 54 z-index: 1000;
55 display: flex; 55 display: flex;
56 flex-direction: column; 56 flex-direction: column;
......
...@@ -66,14 +66,7 @@ ...@@ -66,14 +66,7 @@
66 </view> 66 </view>
67 </view> 67 </view>
68 68
69 - <!-- 图片预览 --> 69 +
70 - <nut-image-preview
71 - v-model:show="previewVisible"
72 - :images="previewImages"
73 - :init-no="previewIndex"
74 - :show-index="false"
75 - @close="closePreview"
76 - />
77 70
78 <!-- 视频播放器 --> 71 <!-- 视频播放器 -->
79 <view 72 <view
...@@ -120,28 +113,56 @@ ...@@ -120,28 +113,56 @@
120 import { ref, onMounted } from 'vue'; 113 import { ref, onMounted } from 'vue';
121 import Taro, { useDidShow } from '@tarojs/taro'; 114 import Taro, { useDidShow } from '@tarojs/taro';
122 import { Photograph, Close } from '@nutui/icons-vue-taro'; 115 import { Photograph, Close } from '@nutui/icons-vue-taro';
123 -import { useMediaPreview } from '@/composables/useMediaPreview'; 116 +
124 import { getPhotoListAPI, deletePhotoAPI } from '@/api/photo'; 117 import { getPhotoListAPI, deletePhotoAPI } from '@/api/photo';
125 118
126 // 响应式数据 119 // 响应式数据
127 const albumList = ref([]); 120 const albumList = ref([]);
128 121
129 -// 使用媒体预览 composable 122 +// 视频播放相关状态
130 -const { 123 +const videoVisible = ref(false);
131 - previewVisible, 124 +const currentVideo = ref(null);
132 - previewImages, 125 +const videoId = ref(0);
133 - previewIndex, 126 +
134 - videoVisible, 127 +/**
135 - currentVideo, 128 + * 关闭视频播放器
136 - videoId, 129 + */
137 - handleMediaClick, 130 +const closeVideo = () => {
138 - closePreview, 131 + videoVisible.value = false;
139 - closeVideo, 132 + currentVideo.value = null;
140 - handleVideoPlay, 133 +};
141 - handleVideoPause, 134 +
142 - handleFullscreenChange, 135 +/**
143 - handleVideoError, 136 + * 视频播放事件处理
144 -} = useMediaPreview(); 137 + */
138 +const handleVideoPlay = () => {
139 + console.log('视频开始播放');
140 +};
141 +
142 +/**
143 + * 视频暂停事件处理
144 + */
145 +const handleVideoPause = () => {
146 + console.log('视频暂停播放');
147 +};
148 +
149 +/**
150 + * 视频全屏变化事件处理
151 + */
152 +const handleFullscreenChange = () => {
153 + console.log('视频全屏状态变化');
154 +};
155 +
156 +/**
157 + * 视频错误事件处理
158 + */
159 +const handleVideoError = (error) => {
160 + console.error('视频播放错误:', error);
161 + Taro.showToast({
162 + title: '视频播放失败',
163 + icon: 'none'
164 + });
165 +};
145 166
146 // 删除相关状态 167 // 删除相关状态
147 const currentDeleteItem = ref(null); 168 const currentDeleteItem = ref(null);
...@@ -195,7 +216,25 @@ const fetchAlbumList = async () => { ...@@ -195,7 +216,25 @@ const fetchAlbumList = async () => {
195 * @param {number} index - 项目索引 216 * @param {number} index - 项目索引
196 */ 217 */
197 const handleItemClick = (item, index) => { 218 const handleItemClick = (item, index) => {
198 - handleMediaClick(item, albumList.value); 219 + if (item.type === 'video') {
220 + // 播放视频
221 + currentVideo.value = {
222 + url: item.url,
223 + thumbnail: item.thumbnail
224 + };
225 + videoId.value = Date.now();
226 + videoVisible.value = true;
227 + } else {
228 + // 预览图片
229 + const imageUrls = albumList.value
230 + .filter(media => media.type === 'image')
231 + .map(media => media.url);
232 +
233 + Taro.previewImage({
234 + urls: imageUrls,
235 + current: item.url
236 + });
237 + }
199 }; 238 };
200 239
201 /** 240 /**
......