hookehuyr

feat(上传): 添加独立的媒体上传页面

实现媒体文件上传功能,包括图片和视频的选择、预览和上传
移除Dashboard页面的上传逻辑,改为跳转到新页面
添加文件大小和时长限制校验
......@@ -29,6 +29,7 @@ export default {
'pages/AlbumList/index',
'pages/ActivitiesCover/index',
'pages/PointsList/index',
'pages/UploadMedia/index',
],
window: {
backgroundTextStyle: 'light',
......
......@@ -60,7 +60,6 @@
<Photograph size="20" class="mr-2" />
拍照留念,奖励积分
</view>
<view class="text-xs text-gray-200 mt-1">支持jpg、png格式图片(≤10MB)或60秒内视频</view>
</view>
</view>
......@@ -206,36 +205,10 @@ const uploadFile = (filePath) => {
});
};
/**
* 打开拍照上传页面
*/
const openCamera = () => {
Taro.chooseMedia({
count: 1,
mediaType: ['image', 'video'],
sourceType: ['album', 'camera'],
maxDuration: 60,
sizeType: ['compressed'],
success: function (res) {
const tempFile = res.tempFiles[0];
const { tempFilePath, size, duration, fileType } = tempFile;
if (fileType === 'image') {
if (size > 10 * 1024 * 1024) {
showToast('图片大小不能超过10MB', 'error');
return;
}
}
if (fileType === 'video') {
if (duration > 60) {
showToast('视频时长不能超过60秒', 'error');
return;
}
}
uploadFile(tempFilePath);
},
fail: function () {
showToast('选择文件失败', 'error');
}
});
Taro.navigateTo({ url: '/pages/UploadMedia/index' });
}
</script>
......
export default {
navigationBarTitleText: '拍照留念',
navigationBarBackgroundColor: '#ffffff',
navigationBarTextStyle: 'black',
backgroundColor: '#f9fafb'
}
\ No newline at end of file
.upload-media-page {
min-height: 100vh;
background-color: #f9fafb;
}
.upload-area {
padding: 1rem;
}
.upload-button {
border: 2px dashed #d1d5db;
border-radius: 0.5rem;
padding: 2rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-bottom: 1rem;
background-color: #ffffff;
transition: all 0.3s ease;
&:active {
background-color: #f3f4f6;
border-color: #9ca3af;
}
}
.preview-container {
margin-bottom: 1rem;
.preview-item {
position: relative;
border-radius: 0.5rem;
overflow: hidden;
background-color: #ffffff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}
.remove-button {
position: absolute;
top: 0.5rem;
right: 0.5rem;
width: 2rem;
height: 2rem;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
}
.video-overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
.play-button {
width: 4rem;
height: 4rem;
background-color: rgba(0, 0, 0, 0.6);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
}
}
.file-info {
margin-top: 0.75rem;
padding: 0.75rem;
background-color: #ffffff;
border-radius: 0.5rem;
}
.action-buttons {
display: flex;
gap: 0.75rem;
.button {
flex: 1;
padding: 0.75rem;
border-radius: 0.5rem;
text-align: center;
font-weight: 500;
transition: all 0.3s ease;
&.secondary {
background-color: #f3f4f6;
color: #374151;
&:active {
background-color: #e5e7eb;
}
}
&.primary {
background-color: #3b82f6;
color: #ffffff;
&:active {
background-color: #2563eb;
}
}
}
}
.video-modal {
position: fixed;
inset: 0;
background-color: #000000;
z-index: 9999;
.close-button {
position: absolute;
top: 1rem;
right: 1rem;
width: 2.5rem;
height: 2.5rem;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
}
video {
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
}
}
.preview-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 1);
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
.preview-container {
position: relative;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.preview-image {
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
.close-btn {
position: absolute;
top: 20rpx;
right: 20rpx;
width: 60rpx;
height: 60rpx;
background: rgba(0, 0, 0, 0.5);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
}
}
\ No newline at end of file
This diff is collapsed. Click to expand it.