This commit is contained in:
zpc 2025-12-28 19:19:32 +08:00
parent c640b911b1
commit e205e63ff0

View File

@ -35,17 +35,18 @@
<view class="container"> <view class="container">
<view style="height: 80rpx"></view> <view style="height: 80rpx"></view>
<!-- 图片预览区域 --> <!-- 图片列表区域 -->
<view class="preview-box"> <view class="preview-box">
<text class="preview-title">图片预览 ({{ imageList.length }}/{{ MAX_IMAGES }})</text> <text class="preview-title">图片列表 ({{ imageList.length }}/{{ MAX_IMAGES }})</text>
<!-- 多图预览列表 --> <!-- 多图预览列表 -->
<view class="multi-preview-container" v-if="imageList.length > 0"> <view class="multi-preview-container" v-if="imageList.length > 0">
<view <view
class="preview-item" class="preview-item"
:class="{ 'preview-item-selected': currentImageIndex === index }"
v-for="(img, index) in imageList" v-for="(img, index) in imageList"
:key="index" :key="index"
@click="handlePreviewImage(index)" @click="handleSelectImage(index)"
> >
<image :src="img.watermark" mode="aspectFill" class="preview-thumb"></image> <image :src="img.watermark" mode="aspectFill" class="preview-thumb"></image>
<view class="delete-btn" @click.stop="removeImage(index)"> <view class="delete-btn" @click.stop="removeImage(index)">
@ -61,12 +62,16 @@
@click="handleAddMorePhoto" @click="handleAddMorePhoto"
> >
<text class="add-icon">+</text> <text class="add-icon">+</text>
<text class="add-text">继续拍摄</text> <text class="add-text">添加</text>
</view>
</view> </view>
</view> </view>
<!-- 单图预览兼容模式显示当前选中的图片 --> <!-- 当前图片预览区域 -->
<view class="preview-img" v-if="imageSrc"> <view class="current-preview-box" v-if="imageSrc">
<text class="preview-title">当前图片预览</text>
<!-- 单图预览显示当前选中的图片 -->
<view class="preview-img">
<image <image
:src="imageSrc" :src="imageSrc"
@click="handlePreviewCurrentImage" @click="handlePreviewCurrentImage"
@ -160,15 +165,21 @@
<!-- 底部操作按钮 --> <!-- 底部操作按钮 -->
<view class="footer"> <view class="footer">
<button type="primary" class="btn-cancel" @click="handleRetakePhoto"> <view class="footer-row">
重拍 <button type="primary" class="btn-action btn-cancel" @click="handleRetakePhoto">
重新开始拍摄
</button> </button>
<button type="primary" class="btn-cancel" @click="handleRetakeCancel"> <button type="primary" class="btn-action btn-continue" @click="handleAddMorePhoto">
清空 继续拍照
</button>
</view>
<view class="footer-row">
<button type="primary" class="btn-action btn-delete" @click="handleDeleteCurrentImage">
删除图片
</button> </button>
<button <button
type="primary" type="primary"
class="btn-save" class="btn-action btn-save"
@click="handleSaveImage" @click="handleSaveImage"
:disabled="isSubmitting" :disabled="isSubmitting"
> >
@ -176,7 +187,7 @@
</button> </button>
<button <button
type="primary" type="primary"
class="btn-submit" class="btn-action btn-submit"
@click="handleSaveAndSubmit" @click="handleSaveAndSubmit"
:disabled="isSubmitting" :disabled="isSubmitting"
> >
@ -184,6 +195,7 @@
</button> </button>
</view> </view>
</view> </view>
</view>
</uni-popup> </uni-popup>
</view> </view>
</template> </template>
@ -234,6 +246,7 @@ const originalImageSrc = ref("");
// //
const imageList = ref([]); // [{original, watermark, sizeInfo}] const imageList = ref([]); // [{original, watermark, sizeInfo}]
const MAX_IMAGES = 15; // const MAX_IMAGES = 15; //
const currentImageIndex = ref(0); //
const imageSizeInfo = ref({ const imageSizeInfo = ref({
original: { original: {
width: 0, width: 0,
@ -374,23 +387,56 @@ const addImageToList = async (imgPath) => {
}); });
}; };
// //
const removeImage = (index) => { const removeImage = (index) => {
uni.showModal({
title: '提示',
content: '确定要删除该图片吗?',
confirmText: '确定',
cancelText: '取消',
success: (res) => {
if (res.confirm) {
//
if (imageList.value.length > index) { if (imageList.value.length > index) {
imageList.value.splice(index, 1); imageList.value.splice(index, 1);
// //
if (imageList.value.length > 0) { if (imageList.value.length > 0) {
const newIndex = Math.min(index, imageList.value.length - 1); const newIndex = Math.min(index, imageList.value.length - 1);
currentImageIndex.value = newIndex;
imageSrc.value = imageList.value[newIndex].watermark; imageSrc.value = imageList.value[newIndex].watermark;
originalImageSrc.value = imageList.value[newIndex].original; originalImageSrc.value = imageList.value[newIndex].original;
} else { } else {
currentImageIndex.value = 0;
imageSrc.value = ""; imageSrc.value = "";
originalImageSrc.value = ""; originalImageSrc.value = "";
} }
} }
}
//
}
});
}; };
// //
const handleDeleteCurrentImage = () => {
if (imageList.value.length === 0) {
uni.showToast({
title: '没有可删除的图片',
icon: 'none'
});
return;
}
removeImage(currentImageIndex.value);
};
//
const handleSelectImage = (index) => {
currentImageIndex.value = index;
imageSrc.value = imageList.value[index].watermark;
originalImageSrc.value = imageList.value[index].original;
};
//
const handlePreviewImage = (index) => { const handlePreviewImage = (index) => {
const urls = imageList.value.map((img) => img.watermark); const urls = imageList.value.map((img) => img.watermark);
uni.previewImage({ uni.previewImage({
@ -898,6 +944,15 @@ onLoad(async () => {
padding: 20rpx; padding: 20rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
text-align: center; text-align: center;
border-bottom: 1rpx solid #eee;
}
/* 当前图片预览区域 */
.current-preview-box {
background: #fff;
padding: 20rpx;
margin-bottom: 20rpx;
text-align: center;
} }
.preview-title { .preview-title {
@ -924,6 +979,14 @@ onLoad(async () => {
border-radius: 8rpx; border-radius: 8rpx;
overflow: hidden; overflow: hidden;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15); box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.15);
border: 4rpx solid transparent;
box-sizing: border-box;
}
/* 选中状态 */
.preview-item-selected {
border: 4rpx solid #007aff;
box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.4);
} }
.preview-thumb { .preview-thumb {
@ -1055,8 +1118,23 @@ onLoad(async () => {
.footer { .footer {
display: flex; display: flex;
justify-content: space-between; flex-direction: column;
gap: 20rpx;
margin-top: 40rpx; margin-top: 40rpx;
padding-bottom: 40rpx;
}
.footer-row {
display: flex;
justify-content: space-between;
gap: 16rpx;
}
.btn-action {
flex: 1;
font-size: 26rpx;
padding: 16rpx 0;
margin: 0;
} }
.btn-cancel { .btn-cancel {
@ -1064,6 +1142,16 @@ onLoad(async () => {
color: #fff; color: #fff;
} }
.btn-continue {
background: #17a2b8;
color: #fff;
}
.btn-delete {
background: #dc3545;
color: #fff;
}
.btn-save { .btn-save {
background: #28a745; background: #28a745;
color: #fff; color: #fff;
@ -1075,7 +1163,8 @@ onLoad(async () => {
} }
.btn-save:disabled, .btn-save:disabled,
.btn-submit:disabled { .btn-submit:disabled,
.btn-action:disabled {
background: #ccc !important; background: #ccc !important;
color: #999 !important; color: #999 !important;
opacity: 0.6; opacity: 0.6;